Add all fastapi methods

This commit is contained in:
DingZQ
2022-10-29 22:48:55 +08:00
parent ba7d99eba7
commit 7f14b541ed

123
main.py
View File

@@ -817,6 +817,129 @@ async def fastapi_delete_link(network: str, link: str) -> ChangeSet:
elif is_valve(network, link):
return delete_valve(network, ChangeSet(ps))
############################################################
# demand 9.[DEMANDS]
############################################################
@app.get('/getdemandschema')
async def fast_get_demand_schema(network: str) -> dict[str, dict[str, Any]]:
return get_demand_schema(network)
@app.get("/getdemandproperties/")
async def fastapi_get_demand_properties(network: str, demand: str) -> dict[str, Any]:
return get_demand(network, demand)
# example: set_demand(p, ChangeSet({'junction': 'j1', 'demands': [{'demand': 10.0, 'pattern': None, 'category': 'x'}, {'demand': 20.0, 'pattern': None, 'category': None}]}))
@app.post("/setdemandproperties/")
async def fastapi_set_demand_properties(network: str, demand: str, req: Request) -> ChangeSet:
props = await req.json()
ps = { 'id' : demand } | props
return set_demand(network, ChangeSet(ps))
############################################################
# status 10.[STATUS]
############################################################
@app.get('/getstatusschema')
async def fast_get_status_schema(network: str) -> dict[str, dict[str, Any]]:
return get_status_schema(network)
@app.get("/getstatusproperties/")
async def fastapi_get_status_properties(network: str, demand: str) -> dict[str, Any]:
return get_status(network, demand)
# example: set_status(p, ChangeSet({'link': 'p0', 'status': LINK_STATUS_OPEN, 'setting': 10.0}))
@app.post("/setstatusproperties/")
async def fastapi_set_status_properties(network: str, status: str, req: Request) -> ChangeSet:
props = await req.json()
ps = { 'id' : status } | props
return set_status(network, ChangeSet(ps))
############################################################
# pattern 11.[PATTERNS]
############################################################
@app.get('/getpatternschema')
async def fast_get_pattern_schema(network: str) -> dict[str, dict[str, Any]]:
return get_pattern_schema(network)
@app.get("/getpatternproperties/")
async def fastapi_get_pattern_properties(network: str, pattern: str) -> dict[str, Any]:
return get_pattern(network, pattern)
# example: set_pattern(p, ChangeSet({'id' : 'p0', 'factors': [1.0, 2.0, 3.0]}))
@app.post("/setpatternproperties/")
async def fastapi_set_pattern_properties(network: str, pattern: str, req: Request) -> ChangeSet:
props = await req.json()
ps = { 'id' : pattern } | props
return set_pattern(network, ChangeSet(ps))
############################################################
# curve 12.[CURVES]
############################################################
@app.get('/getcurveschema')
async def fast_get_curve_schema(network: str) -> dict[str, dict[str, Any]]:
return get_curve_schema(network)
@app.get("/getcurveproperties/")
async def fastapi_get_curve_properties(network: str, curve: str) -> dict[str, Any]:
return get_curve(network, curve)
# example: set_curve(p, ChangeSet({'id' : 'c0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))
@app.post("/setcurveproperties/")
async def fastapi_set_curve_properties(network: str, curve: str, req: Request) -> ChangeSet:
props = await req.json()
ps = { 'id' : curve } | props
return set_curve(network, ChangeSet(ps))
############################################################
# emitter 16.[EMITTERS]
############################################################
@app.get('/getemitterschema')
async def fast_get_emitter_schema(network: str) -> dict[str, dict[str, Any]]:
return get_emitter_schema(network)
@app.get("/getemitterproperties/")
async def fastapi_get_emitter_properties(network: str, junction: str) -> dict[str, Any]:
return get_emitter(network, junction)
# example: set_emitter(p, ChangeSet({'junction': 'j1', 'coefficient': 10.0}))
@app.post("/setemitterproperties/")
async def fastapi_set_emitter_properties(network: str, junction: str, req: Request) -> ChangeSet:
props = await req.json()
ps = { 'id' : junction } | props
return set_emitter(network, ChangeSet(ps))
############################################################
# time 21.[TIME]
############################################################
@app.get('/gettimeschema')
async def fast_get_time_schema(network: str) -> dict[str, dict[str, Any]]:
return get_time_schema(network)
@app.get("/gettimeproperties/")
async def fastapi_get_time_properties(network: str) -> dict[str, Any]:
return get_time(network)
@app.post("/settimeproperties/")
async def fastapi_set_time_properties(network: str, time: str, req: Request) -> ChangeSet:
props = await req.json()
return set_time(network, ChangeSet(props))
############################################################
# option 23.[OPTIONS]
############################################################
@app.get('/getoptionschema')
async def fast_get_option_schema(network: str) -> dict[str, dict[str, Any]]:
return get_option_schema(network)
@app.get("/getoptionproperties/")
async def fastapi_get_option_properties(network: str) -> dict[str, Any]:
return get_option(network)
@app.post("/setoptionproperties/")
async def fastapi_set_option_properties(network: str, req: Request) -> ChangeSet:
props = await req.json()
return set_option(network, ChangeSet(props))
# inp file
@app.post("/uploadinp/", status_code=status.HTTP_200_OK)
async def upload_inp(file: bytes = File(), name: str = None):