class ProjectReposResource(Resource): def __init__(self): self._model = ProjectModel(ConnTool()) def get(self, pid): data, code = self._model.get_project_repos(pid) return data, code def patch(self, pid): parser = reqparse.RequestParser() parser.add_argument('repositories', type=dict, required=True) args = parser.parse_args() if 'repositories' in args: repos_parser = reqparse.RequestParser() repos_parser.add_argument('Github', action='append', type=int, location=('repositories', )) repos_parser.add_argument('action', required=True, location=('repositories', )) args['repositories'] = repos_parser.parse_args(req=args) data, code = self._model.update_repos(pid, args) return data, code
class ProjectSettingResource(Resource): def __init__(self): self._model = ProjectModel(ConnTool()) def get(self, pid): data, code = self._model.get_project_setting(pid) return data, code def delete(self, pid): data, code = self._model.delete_project(pid) return data, code def patch(self, pid): parser = reqparse.RequestParser() parser.add_argument('collaborator', required=False) parser.add_argument('collabAction', required=False) parser.add_argument('name', required=False) args = parser.parse_args() data, code = 'wrong args', 404 print(args) if args['collaborator'] != None and args['collabAction'] != None: data, code = self._model.update_collaborator( pid, args['collaborator'], args['collabAction']) elif args['name'] != None: data, code = self._model.update_name(pid, args['name']) return data, code
def deleteEnv( user_email="", enterprise_id: uuid.UUID = uuid.uuid4(), project_id: uuid.UUID = uuid.uuid4(), env_id: uuid.UUID = uuid.uuid4(), user: UserModel = None, enterprise: EnterpriseModel = None, project: ProjectModel = None ): try: if not user: user = getUser(user_email) if not enterprise: enterprise = getEnterpriseModel(user=user, enterprise_id=enterprise_id) if enterprise["error"]: return enterprise enterprise = enterprise["message"] if not project: project = getProjectModel(user=user, enterprise=enterprise, project_id=project_id) if project["error"]: return project project = project["message"] if not enterprise_id in user.enterprises: return {"message": "Unable to find this enterprise in your profile", "error": True, "data": None} if not project_id in enterprise.projects: return {"message": "Unable to find this project in your profile", "error": True, "data": None} if not env_id in project.envs: return {"message": "Unable to find this env in your profile", "error": True, "data": None} env = EnvModel.objects.filter(id = env_id).delete() env.save() project.envs.remove(env_id) project.save() return {"message": "Key deleted correctly", "error": False, "data": None} except Exception as error: print(f"Some error has happend deleting key at key_consumer.py. error: {error}") return {"message": f"Some error has happend: {error}", "error": True}
def control_new(self): self.project = ProjectModel() # 从主窗口中获得路径和名称 pro_dir, pro_name = self.mw.view_new() # 给项目对象赋值 self.project.new_project(pro_dir, pro_name) # 将窗口标题改成项目路径 self.mw.view_set_window_title(self.project.get_total_pro_dir())
class ProjectsResource(Resource): def __init__(self): self._model = ProjectModel(ConnTool()) def get(self): data, code = self._model.get_project_list() return data, code def post(self): parser = reqparse.RequestParser() parser.add_argument('name', required=True, help='name is required.') args = parser.parse_args() data, code = self._model.add_project(args['name']) return data, code
def train_model(model: ProjectModel, train_args: Dict[str, Any]) -> History: """Trains the model. :param model: the model to train. :param train_args: training arguments; see DEFAULT_TRAIN_ARGS for available arguments. :return: the training history. """ train_args = {**DEFAULT_TRAIN_ARGS, **train_args} print('Training args: {0}'.format(train_args)) callbacks = [] if train_args['early_stopping']: early_stopping = EarlyStopping(monitor='val_loss', min_delta=0.01, patience=3, verbose=1, mode='auto') callbacks.append(early_stopping) if train_args['use_wandb']: callbacks.append(WandbCallback()) callbacks.extend(get_custom_wandb_callbacks()) model.network.summary() t_start = time() history = model.fit(train_args, callbacks=callbacks) t_end = time() print('Model training finished in {0:2f}s'.format(t_end - t_start)) return history
class RepositoryResource(Resource): def __init__(self): self._projectModel = ProjectModel(ConnTool()) def get(self, pid): return self._projectModel.get_avail_repos(pid)
def test_training_reproducible() -> None: """Tests that training results are reproducible.""" set_random_seed(SEED) dataset_args = {'dataset_fraction': 0.001} network_args = {'input_shape': (128, 128, 3), 'num_classes': 1000} train_args = {'epochs': 10, 'batch_size': 32, 'early_stopping': True} dataset = ILSVRCDataset(DEFAULT_DATASET_PATH) dataset.trim_dataset(dataset_args['dataset_fraction']) network = MLP(network_args) model = ProjectModel(dataset, network) history = train_model.train_model(model, train_args) assert str(history.history) == SEED_HISTORY
def createProject(user_email="", project_name="", enterprise_id: uuid.UUID = uuid.uuid4()): try: user = getUser(user_email) enterprise = getEnterpriseModel(user=user, enterprise_id=enterprise_id) if enterprise["error"]: return enterprise project = ProjectModel(name=project_name) enterprise = enterprise["message"] enterprise.projects.append(project.id) project.save() enterprise.save() return {"message": "Project created correctly", "error": True} except Exception as error: return {"message": f"Some error has happend: {error}", "error": True}
def getProjectModel(user_email="", enterprise_id: uuid.UUID = uuid.uuid4(), project_id: uuid.UUID = uuid.uuid4(), user: UserModel = None, enterprise: EnterpriseModel = None): try: if not user: user = getUser(user_email) if not enterprise: enterprise = getEnterpriseModel(user=user, enterprise_id=enterprise_id) if enterprise["error"]: return enterprise enterprise = enterprise["message"] if project_id in enterprise.projects: project = ProjectModel.objects(id=project_id).first() return {"message": project, "error": False} except Exception as error: return {"message": f"Some error has happend: {error}", "error": True}
def getProjects(user_email="", enterprise_id: uuid.UUID = uuid.uuid4(), user: UserModel = None): try: if not user: user = getUser(user_email) enterprise = getEnterpriseModel(user=user, enterprise_id=enterprise_id) if enterprise["error"]: return enterprise enterprise = enterprise["message"] projects = ProjectModel.objects(id__in=enterprise.projects).aggregate({ "$project": { "id": "$id.uuid", "name": 1, "created_at": 1, "image_src": 1 } }) return {"message": list(projects), "error": False} except Exception as error: return {"message": f"Some error has happend: {error}", "error": True}
def __init__(self): self.app = QApplication(sys.argv) self.mw = MainWindow() self.project = ProjectModel()
class MainController(object): def __init__(self): self.app = QApplication(sys.argv) self.mw = MainWindow() self.project = ProjectModel() def link_mainwindow_anction(self): self.mw.action_new.triggered.connect(self.control_new) self.mw.action_open.triggered.connect(self.control_open) self.mw.action_about.triggered.connect(self.control_about) self.mw.action_paralist_dock_isclosed.triggered.connect( self.control_paralist_dock_isclosed) self.mw.action_exit.triggered.connect(self.control_exit) self.mw.action_import_normal_datafile.triggered.connect( self.control_import_normal_datafile) def control_start(self): self.mw.setup() self.link_mainwindow_anction() self.mw.show() return self.app.exec_() def control_new(self): self.project = ProjectModel() # 从主窗口中获得路径和名称 pro_dir, pro_name = self.mw.view_new() # 给项目对象赋值 self.project.new_project(pro_dir, pro_name) # 将窗口标题改成项目路径 self.mw.view_set_window_title(self.project.get_total_pro_dir()) def control_open(self): # 显示项目文件夹选择对话框 sel_pro = self.mw.view_open() # 对原来的项目对象进行重新赋值 open_status = self.project.open_project(sel_pro) # 显示项目打开状态 self.mw.view_open_status(open_status, self.project.get_total_pro_dir()) # 将窗口标题改成项目路径 self.mw.view_set_window_title(self.project.get_total_pro_dir()) def control_import_normal_datafile(self): file_name, ok = QFileDialog.getOpenFileNames(self.mw, 'Load', 'D:/') #multi files input self.project.import_datafile(file_name) self.mw.mw_paralist_dock.display(self.project.get_datafile_group()) def control_export_data(self): pass def control_exit(self): QApplication.closeAllWindows() def control_simple_math(self): pass def control_testpoint_manage(self): pass def control_synchronization(self): pass def control_tuning(self): pass def control_para_manage(self): pass def control_temp_manage(self): pass def control_options(self): pass def control_about(self): self.mw.view_about() def control_quick_plot(self): pass def control_custom_defined_plot(self): pass def control_multi_source_plot(self): pass def control_paralist_dock_isclosed(self): self.mw.control_paralist_dock_isclosed()
def __init__(self): self._model = ProjectModel(ConnTool())
def run(self): self.project = ProjectModel("Silmarillion") self.main_window = ValinorMainWindow(self.project) self.controller = Controller(self.main_window, self.project) self.main_window.show()