@@ -126,7 +126,9 @@ def get_model_contents(cls, model):
126
126
@classmethod
127
127
def create_model (cls , model , project , description = None , modeler = None ,
128
128
function = None , algorithm = None , tool = None ,
129
- is_champion = False , properties = {}, ** kwargs ):
129
+ is_champion = False , properties = {},
130
+ version = None ,
131
+ ** kwargs ):
130
132
"""Creates a model into a project or folder.
131
133
132
134
Parameters
@@ -177,20 +179,31 @@ def create_model(cls, model, project, description=None, modeler=None,
177
179
The display name for the model version.
178
180
properties : array_like, optional (custom properties)
179
181
Custom model properties that can be set: name, value, type
180
-
181
182
inputVariables : array_like, optional
182
183
Model input variables. By default, these are the same as the model
183
184
project.
184
185
outputVariables : array_like, optional
185
186
Model output variables. By default, these are the same as the model
186
187
project.
188
+ version : str or int
189
+ Whether to create a new version of the model or update an
190
+ existing version. May be a specific numbered version to
191
+ replace, 'latest' to update the most recent version, or 'new' to
192
+ add a new version. Defaults to 'new'
187
193
188
194
Returns
189
195
-------
190
196
str
191
197
The model schema returned in JSON format.
192
198
193
199
"""
200
+ version = version or 'new'
201
+
202
+ # Check if the model already exists
203
+ model_obj = cls .get_model (model )
204
+
205
+ is_new_model = model_obj == None
206
+
194
207
if isinstance (model , str ):
195
208
model = {'name' : model }
196
209
@@ -209,15 +222,16 @@ def create_model(cls, model, project, description=None, modeler=None,
209
222
model ['tool' ] = tool or model .get ('tool' )
210
223
model ['champion' ] = is_champion or model .get ('champion' )
211
224
model ['role' ] = 'Champion' if model .get ('champion' ,
212
- False ) else 'Challenger'
225
+ False ) else None
213
226
model ['description' ] = description or model .get ('description' )
214
227
model .setdefault ('properties' , [{'name' : k , 'value' : v } for k , v in
215
228
properties .items ()])
216
229
217
230
# TODO: add kwargs (pop)
218
231
# model.update(kwargs)
219
- return cls .post ('/models' , json = model , headers = {
220
- 'Content-Type' : 'application/vnd.sas.models.model+json' })
232
+ if is_new_model :
233
+ return cls .post ('/models' , json = model , headers = {
234
+ 'Content-Type' : 'application/vnd.sas.models.model+json' })
221
235
222
236
@classmethod
223
237
def add_model_content (cls , model , file , name = None , role = None ):
0 commit comments