Add region APIs

This commit is contained in:
DingZQ
2023-05-02 20:16:03 +08:00
parent 599e221712
commit 068281b929

63
main.py
View File

@@ -1489,6 +1489,69 @@ async def fastapi_delete_scada_element(network: str, req: Request) -> ChangeSet:
async def fastapi_clean_scada_element(network: str) -> ChangeSet:
return clean_scada_element(network)
############################################################
# general_region 33
############################################################
@app.get('/getregionschema/')
async def fastapi_get_region_schema(network: str) -> dict[str, dict[str, Any]]:
return get_region_schema(network)
@app.get('/getregion/')
async def fastapi_get_region(network: str, id: str) -> dict[str, Any]:
return get_region(network, id)
@app.post('/setregion/')
async def fastapi_set_region(network : str, req: Request) -> ChangeSet:
props = await req.json()
return set_region(network, ChangeSet(props))
# example: add_region(p, ChangeSet({'id': 'r', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]}))
@app.post('/addregion/')
async def fastapi_add_region(network: str, req: Request) -> ChangeSet:
props = await req.json()
return add_region(network, ChangeSet(props))
@app.post('/deleteregion/')
async def fastapi_delete_region(network: str, req: Request) -> ChangeSet:
props = await req.json()
return delete_region(network, ChangeSet(props))
############################################################
# water_distribution 34
############################################################
@app.post('/distributedemandtonodes/')
async def fastapi_distribute_demand_to_nodes(network: str, demand: float, nodes: list[str], type: str = DISTRIBUTION_TYPE_ADD) -> ChangeSet:
return distribute_demand_to_nodes(network, demand, nodes, type)
@app.post("distributedemandtoregion")
async def fastapi_distribute_demand_to_region(network: str, demand: float, region: str, type: str = DISTRIBUTION_TYPE_ADD) -> ChangeSet:
return distribute_demand_to_region(network, demand, region, type)
############################################################
# district_metering_area 35
############################################################
@app.post('/calculatedistrictmeteringarea/')
async def fastapi_calculate_district_metering_area(network: str, nodes: list[str], part_count: int = 1, part_type: int = PARTITION_TYPE_RB) -> list[list[str]]:
return calculate_district_metering_area(network, nodes, part_count, part_type)
############################################################
# service_area 36
############################################################
@app.post('/calculateservicearea/')
async def fastapi_calculate_service_area(network: str, time_index: int = 0) -> dict[str, Any]:
return calculate_service_area(network, time_index)
############################################################
# virtual_district 37
############################################################
@app.post('/calculatevirtualdistrict/')
async def fastapi_calculate_virtual_district(network: str, centers: list[str]) -> dict[str, list[Any]]:
return calculate_virtual_district(network, centers)
# inp file
@app.post("/uploadinp/", status_code=status.HTTP_200_OK)