@@ -187,39 +187,35 @@ def create_performance_definition(
187
187
% max_bins
188
188
)
189
189
190
- if not project and not models :
190
+ # Separate single models from multiple models
191
+ if not isinstance (models , list ):
192
+ models = [models ]
193
+
194
+ if not project and not models [0 ]:
191
195
raise ValueError (
192
196
"No project or model specified for performance definition creation.\n "
193
197
"Please specify at least one of the two values."
194
198
)
195
-
196
199
# If no models were specified, search the supplied project for all models
197
- if not models :
200
+ elif not models [ 0 ] :
198
201
project = mr .get_project (project )
199
202
models = mr .list_models (
200
- filter = "eq(projectName, '{projectName}')" .format (
201
- projectName = project .name
202
- )
203
+ filter = f"eq(projectName, '{ project .name } ')"
203
204
)
204
-
205
- # Separate single models from multiple models
206
- if not isinstance (models , list ):
207
- models = [models ]
208
- if project :
209
- project = mr .get_project (project )
210
- project_models = mr .get (f'/projects/{ project .id } /models' )
211
- project_models = [m for m in project_models if m .name in models ]
212
- models = project_models
213
- # Necessary to eventually provide variables to the performance definition
214
- models [0 ] = mr .get_model (project_models [0 ].id )
215
205
else :
216
- # Collect all models into a list. This converts the PagedList response from mr.list_models to a normal list.
217
206
for i , model in enumerate (models ):
218
207
models [i ] = mr .get_model (model )
219
- project = mr .get_project (models [0 ].projectId )
208
+ if project :
209
+ project = mr .get_project (project )
210
+ else :
211
+ project = mr .get_project (models [0 ].projectId )
220
212
# Ensures that all models are in the same project
221
213
if not all ([model .projectId == project .id for model in models ]):
222
- raise ValueError ("Not all models are contained within the same project. Try specifying a project." )
214
+ raise ValueError (
215
+ "Not all models are contained within the same project. Try "
216
+ "specifying a project in the arguments and verify that all models"
217
+ "are from the same project."
218
+ )
223
219
224
220
# Performance data cannot be captured unless certain project properties have been configured.
225
221
for required in ["targetVariable" , "targetLevel" ]:
0 commit comments