You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Matthew Cornell edited this page Nov 2, 2020
·
1 revision
create_models_from_json()
From: @katiehouse3
I created this utility function create models from a json for the retrospective cdc project, but it would be helpful for future projects.
To Do:
Clean up the existing code
Add as utility function
Add to documentation
defcreate_models_from_json(conn, project_name, model_json):
conn.re_authenticate_if_necessary()
# check if project existsproject= [projectforprojectinconn.projectsifproject.name==project_name]
ifnotproject:
print("could not find project= %s"%project_name)
returnproject=project[0]
# get existing modelsexisting_model= [model.nameformodelinproject.models]
# open json file as dictwithopen(model_json) asfp:
model_dict=json.load(fp)
foriinrange(len(model_dict)):
# check if model existsmodel_name=model_dict[i]['name']
# add model if not existsifmodel_nameinexisting_model:
print("model already exists: %s"%model_name)
else:
new_model=project.create_model(model_dict[i])
print("created new model: %s"%model_name)