1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- from glob import glob
- from json import load, dump
- from os import path, mkdir
- from shutil import rmtree
- from time import time
- from uuid import uuid1
- from pycs import ApplicationStatus
- from pycs.observable import ObservableDict
- from pycs.pipeline.PipelineManager import PipelineManager
- from pycs.projects.Project import Project
- class ProjectManager(ObservableDict):
- def __init__(self, app_status: ApplicationStatus):
-
- self.app_status = app_status
-
-
- super().__init__({}, app_status)
- app_status['projects'] = self
-
- for folder in glob('projects/*'):
-
- with open(path.join(folder, 'project.json'), 'r') as file:
- project = Project(load(file), self)
- project['jobs'] = {}
- self[project['id']] = project
- def __write_project(self, uuid):
- with open(path.join('projects', uuid, 'project.json'), 'w') as file:
- copy = self[uuid].copy()
- del copy['jobs']
- dump(copy, file, indent=4)
- def create_project(self, name, description, model):
-
- uuid = str(uuid1())
- self[uuid] = Project({
- 'id': uuid,
- 'name': name,
- 'description': description,
- 'created': int(time()),
- 'pipeline': {
- 'model-distribution': model
- },
- 'data': {},
- 'jobs': {}
- }, self)
-
- folder = path.join('projects', uuid)
- mkdir(folder)
-
- self.__write_project(uuid)
- def update_project(self, uuid, update):
-
- if uuid not in self.keys():
- return
-
- self[uuid].update_properties(update)
- self.__write_project(uuid)
- def delete_project(self, uuid):
-
- if uuid not in self.keys():
- return
-
- folder = path.join('projects', uuid)
- rmtree(folder)
-
- del self[uuid]
- def predict(self, uuid, identifiers):
-
- if uuid not in self.keys():
- return
- project = self[uuid]
-
- with PipelineManager(project) as pm:
-
-
- for file_id in identifiers:
- if file_id in project['data'].keys():
- pm.run(project['data'][file_id])
|