def test_create_project(pydss_project): project_name = "test-project" project_dir = os.path.join(PATH, project_name) # Intentionally not in alphabetic order so that we verify our designated # ordering. scenarios = [ PyDssScenario("b_scenario1"), PyDssScenario("a_scenario2"), ] project = PyDssProject.create_project(PATH, project_name, scenarios) assert os.path.exists(project_dir) for dir_name in PyDssScenario._SCENARIO_DIRECTORIES: for scenario in scenarios: path = os.path.join( project_dir, SCENARIOS, scenario.name, dir_name, ) assert os.path.exists(path) project2 = PyDssProject.load_project(project_dir) assert project.name == project2.name scenarios1 = project.scenarios scenarios1.sort(key=lambda x: x.name) scenarios2 = project2.scenarios scenarios2.sort(key=lambda x: x.name) assert len(scenarios1) == len(scenarios2) for i in range(len(project.scenarios)): assert scenarios1[i].name == scenarios2[i].name assert scenarios1[i].controllers == scenarios2[i].controllers
def create_project(path=None, project=None, scenarios=None, simulation_file=None, simulation_config=None, controller_types=None, export_modes=None, options=None, visualization_types=None, opendss_project_folder=None, master_dss_file=None, force=False): """Create PyDSS project.""" setup_logging("PyDSS", console_level=logging.INFO) if controller_types is not None: controller_types = [ControllerType(x) for x in controller_types.split(",")] if export_modes is not None: export_modes = [ExportMode(x) for x in export_modes.split(",")] if visualization_types is not None: visualization_types = [VisualizationType(x) for x in visualization_types.split(",")] if options is not None: options = ast.literal_eval(options) if not isinstance(options, dict): logger.error(f"options must be of type dict; received {type(options)}") sys.exit(1) scenarios = [ PyDssScenario( name=x.strip(), controller_types=controller_types, export_modes=export_modes, visualization_types=visualization_types, ) for x in scenarios.split(",") ] PyDssProject.create_project( path, project, scenarios, simulation_config, options=options, simulation_file=simulation_file, master_dss_file=master_dss_file, opendss_project_folder = opendss_project_folder, force=force, )
def test_create_project(pydss_project): project_name = "test-project" project_dir = os.path.join(PATH, project_name) thermal_upgrade = { "script": "AutomatedThermalUpgrade", "config_file": THERMAL_CONFIG, } voltage_upgrade = { "script": "AutomatedVoltageUpgrade", "config_file": VOLTAGE_CONFIG, } # Intentionally not in alphabetic order so that we verify our designated # ordering. scenarios = [ PyDssScenario("b_scenario1", post_process_infos=[thermal_upgrade]), PyDssScenario("a_scenario2", post_process_infos=[voltage_upgrade]), ] project = PyDssProject.create_project(PATH, project_name, scenarios) assert os.path.exists(project_dir) for dir_name in PyDssScenario._SCENARIO_DIRECTORIES: for scenario in scenarios: path = os.path.join( project_dir, SCENARIOS, scenario.name, dir_name, ) assert os.path.exists(path) project2 = PyDssProject.load_project(project_dir) assert project.name == project2.name scenarios1 = project.scenarios scenarios1.sort(key=lambda x: x.name) scenarios2 = project2.scenarios scenarios2.sort(key=lambda x: x.name) assert len(scenarios1) == len(scenarios2) for i in range(len(project.scenarios)): assert scenarios1[i].name == scenarios2[i].name assert scenarios1[i].controllers == scenarios2[i].controllers assert scenarios1[i].post_process_infos == scenarios2[ i].post_process_infos
async def post_pydss_create(self, request): """ --- summary: Creates a new project for PyDSS (User uploads a zipped OpenDSS model) tags: - PyDSS project requestBody: content: multipart/form-data: schema: type: object properties: master_file: type: string example: Master_Spohn_existing_VV.dss project: type: string example: test_project scenarios: type: string description: comma separated list of PyDSS scenarios to be created example: base_case,pv_scenario controller_types: type: string description: comma separated list of PyDSS controller names example: PvController,StorageController visualization_types: type: string description: comma separated list of PyDSS plot names example: Histogram,TimeSeries fileName: type: string format: binary responses: '200': description: Successfully retrieved project information content: application/json: schema: type: object examples: get_instance_status: value: Status: 200 Message: PyDSS project created UUID: None '403': description: Provided path does not exist content: application/json: schema: type: object examples: get_instance_status: value: Status: 403 Message: User does not have access to delete folders UUID: None """ from zipfile import ZipFile examples_path = os.path.join("C:/Users/alatif/Desktop/PyDSS_2.0/PyDSS/", 'examples') unzip_path = os.path.join(examples_path, "uploaded_opendss_project") zip_path = os.path.join(examples_path, "uploaded_opendss_project.zip") data = None with open(zip_path, 'wb') as fd: while True: chunk = await request.content.read(1024) if data is None: data = chunk else: data += chunk if not chunk: break fd.write(chunk) data = bytestream_decode(data) os.makedirs(unzip_path, exist_ok=True) with ZipFile(zip_path, 'r') as zipObj: zipObj.extractall(path=unzip_path) controller_types = [ControllerType(x) for x in data['controller_types'].split(",")] visualization_types = [VisualizationType(x) for x in data['visualization_types'].split(",")] scenarios = [ PyDssScenario( name=x.strip(), controller_types=controller_types, visualization_types=visualization_types, ) for x in data['scenarios'].split(",") ] PyDssProject.create_project(path=examples_path, name=data['project'], scenarios=scenarios, opendss_project_folder=unzip_path, master_dss_file=data['master_file']) try: shutil.rmtree(unzip_path) if os.path.exists(zip_path): os.remove(zip_path) except: return web.json_response({ 'Status': 403, 'Message': 'User does not have access to delete folders', 'UUID': None }) result = {'Status': 200, 'Message': 'PyDSS project created', 'UUID': None} # name, scenarios, simulation_config = None, options = None, # simulation_file = SIMULATION_SETTINGS_FILENAME, opendss_project_folder = None, # master_dss_file = OPENDSS_MASTER_FILENAME return web.json_response(result)