def update_one_public_model(): """ 数据库建一个model的collection, 记载public的数据分析工具包简介 """ user = user_business.get_by_user_ID('system') MNIST = Model(name='MNIST手写识别', description='MNIST手写识别', usage=0, classification=0, target_py_code="/lib/aaa/xxx", input_data={ 'shape': { 'DO': 550000, 'D1': 28, 'D2': 28 }, 'ranks': 3, 'type': 'DT_FLOAT', 'target_input_addr': '/lib/xxx/aaa' }, cnn_level=1, evaluate_matrix=[0, 1], optimization_algorithm=[0]) MNIST = model_repo.create(MNIST) ownership_business.add(user, False, model=MNIST)
def add_toolkit_with_ownership(name, description, target_py_code, entry_function, parameter_spec, user_ID, is_private): toolkit = toolkit_business.add(name, description, target_py_code, entry_function, parameter_spec) user = user_business.get_by_user_ID(user_ID) ownership_business.add(user, is_private, toolkit=toolkit)
def first_save_to_db(user_ID, name, description, input_info, output_info, examples, version, deploy_name, server, input_type, model_base_path, job, job_id, model_name, related_fields, related_tasks, tags, is_private, data_fields, input_data_demo_string, service_name,projectId, **optional): """ :param user_ID: :param name: :param description: :param input_info: :param output_info: :param examples: :param version: :param deploy_name: :param server: :param input_type: :param model_base_path: :param job: :param job_id: :param is_private: :param service_name: :param model_name: :param optional: :return: """ user = user_business.get_by_user_ID(user_ID) served_model = served_model_business.add(name, description, input_info, output_info, examples, version, deploy_name, server, input_type, model_base_path, job, service_name, model_name, related_fields, related_tasks, tags, is_private, data_fields, input_data_demo_string, create_time=datetime.utcnow(), user=user, user_ID=user_ID, projectId=projectId, **optional) ownership_business.add(user, is_private, served_model=served_model) job_business.update_job_by_id(job_id, served_model=served_model) return served_model
def add_model_with_ownership(user_ID, is_private, name, description, category, target_py_code, entry_function, model_type, to_code_function, parameter_spec, input, steps): """ add_model_with_ownership :param user_ID: :param is_private: :param name: :param description: :param category: :param target_py_code: :param entry_function: :param to_code_function: :param parameter_spec: :param input: :return: """ model = model_business.add(name, description, category, target_py_code, entry_function, model_type, to_code_function, parameter_spec, input, steps) user = UserBusiness.get_by_user_ID(user_ID) ownership_business.add(user, is_private, model=model) return model
def create_user_request_comments(user_request_id, user_ID, comments, comments_type, request_answer_id): # create a new user_request_comments object created_user_request_comments = comments_business.\ add_user_request_comments(user_request_id=user_request_id, comments_user_ID=user_ID, comments=comments, comments_type=comments_type, request_answer_id=request_answer_id) if created_user_request_comments: # get user object user = user_business.get_by_user_ID(user_ID=user_ID) # create ownership relation if ownership_business.add( user, user_request_comments=created_user_request_comments): return created_user_request_comments else: raise RuntimeError( 'Cannot create ownership of the new user_request_comments') else: raise RuntimeError('Cannot create the new user_request_comments')
def create_user_request(title, user_ID, **kwargs): # create a new user_request object user = user_business.get_by_user_ID(user_ID) created_user_request = user_request_business.add_user_request(title=title, user=user, status=0, **kwargs) # 记录历史记录 statistics = StatisticsBusiness.action(user_obj=user, entity_obj=created_user_request, entity_type="userRequest", action="create") # 记录世界频道消息 # 推送消息 world = WorldService.system_send( channel=CHANNEL.request, message= f"用户{created_user_request.user.user_ID}发布了需求{created_user_request.title}" ) if created_user_request: # 默认发布者star created_user_request = user_service.update_request_star( created_user_request.id, user_ID) # get user object user = user_business.get_by_user_ID(user_ID=user_ID) # create ownership relation if ownership_business.add(user, user_request=created_user_request): return created_user_request else: raise RuntimeError( 'Cannot create ownership of the new user_request') else: raise RuntimeError('Cannot create the new user_request')
def fork(project_id, new_user_ID): """ fork project :param project_id: :param new_user_ID: :return: """ # get project project = project_business.get_by_id(project_id) # get ownership, and check privacy ownership = ownership_business.get_ownership_by_owned_item( project, 'project') if ownership.private is True: raise NameError('forked project is private, fork failed') if ownership.user.user_ID == new_user_ID: raise NameError('you are forking your self project') # get user object user = UserBusiness.get_by_user_ID(new_user_ID) # copy and save project project_cp = project_business.copy(project) # create ownership relation ownership_business.add(user, True, project=project_cp) # copy staging data sets sds_array = staging_data_set_business.get_by_project_id(project_id, False) for sds in sds_array: staging_data_service.copy_staging_data_set(sds, project_cp) # copy jobs and save jobs = project.jobs jobs_cp = [] for job in jobs: # get source sds if hasattr(job, 'staging_data_set') and job.staging_data_set: sds_cp = staging_data_set_business.get_by_name_and_project( job.staging_data_set.name, job.staging_data_set.project) # sds_cp = staging_data_service.copy_staging_data_set( # job.staging_data_set, project_cp) else: sds_cp = None # copy job job_cp = job_business.copy_job(job, project_cp, sds_cp) if not job_cp: continue jobs_cp.append(job_cp) # copy result staging data set by job and bind to project try: # get result sds result_sds = staging_data_set_business.get_by_job_id(job['id']) # bind job to sds staging_data_set_business.update_job_by_name_and_project( result_sds.name, result_sds.project, job_cp) # staging_data_service.copy_staging_data_set(result_sds, project_cp, # belonged_job=job_cp) except DoesNotExist: pass project_business.update_by_id(project_cp['id'], jobs=jobs_cp) project_cp.reload() return project_cp
def add_data_set(user_ID, is_private, name, description): path = os.path.join(UPLOAD_FOLDER, user_ID, name) ds = data_set_business.add(name=name, description=description, path=path) user = UserBusiness.get_by_user_ID(user_ID) ownership_business.add(user, is_private, data_set=ds) return ds