Refine code with cursor
This commit is contained in:
27
main.py
27
main.py
@@ -2032,7 +2032,7 @@ async def fastapi_get_all_scada_info(network: str) -> list[dict[str, float]]:
|
||||
|
||||
# inp file
|
||||
@app.post("/uploadinp/", status_code=status.HTTP_200_OK)
|
||||
async def upload_inp(afile: bytes, name: str ):
|
||||
async def fastapi_upload_inp(afile: bytes, name: str ):
|
||||
filePath = inpDir + str(name)
|
||||
f = open(filePath, 'wb')
|
||||
f.write(afile)
|
||||
@@ -2041,7 +2041,7 @@ async def upload_inp(afile: bytes, name: str ):
|
||||
return True
|
||||
|
||||
@app.get("/downloadinp/", status_code=status.HTTP_200_OK)
|
||||
async def download_inp(name: str, response: Response):
|
||||
async def fastapi_download_inp(name: str, response: Response):
|
||||
filePath = inpDir + name
|
||||
if os.path.exists(filePath):
|
||||
return FileResponse(filePath, media_type='application/octet-stream', filename="inp.inp")
|
||||
@@ -2079,7 +2079,7 @@ async def fastapi_convert_v3_to_v2(req: Request) -> ChangeSet:
|
||||
return cs
|
||||
|
||||
@app.get("/getjson/")
|
||||
async def get_json():
|
||||
async def fastapi_get_json():
|
||||
return JSONResponse(
|
||||
status_code = status.HTTP_400_BAD_REQUEST,
|
||||
content={
|
||||
@@ -2095,12 +2095,12 @@ async def get_json():
|
||||
# influx db operation
|
||||
############################################################
|
||||
@app.get("/getrealtimedata/")
|
||||
async def get_realtimedata():
|
||||
async def fastapi_get_realtimedata():
|
||||
data = [random.randint(0, 100) for _ in range(100)]
|
||||
return data
|
||||
|
||||
@app.get("/getsimulationresult/")
|
||||
async def get_simulationresult():
|
||||
async def fastapi_get_simulationresult():
|
||||
data = [random.randint(0, 100) for _ in range(100)]
|
||||
return data
|
||||
|
||||
@@ -2109,16 +2109,16 @@ async def get_simulationresult():
|
||||
# DingZQ 2025-01-31
|
||||
# def query_latest_record_by_ID(ID: str, type: str, bucket: str="realtime_data", client: InfluxDBClient=client) -> dict:
|
||||
@app.get("/querynodelatestrecordbyid/")
|
||||
async def query_node_latest_record_by_id(id: str):
|
||||
async def fastapi_query_node_latest_record_by_id(id: str):
|
||||
return influxdb_api.query_latest_record_by_ID(id, type='node', client=influx_client)
|
||||
|
||||
@app.get("/querylinklatestrecordbyid/")
|
||||
async def query_link_latest_record_by_id(id: str):
|
||||
async def fastapi_query_link_latest_record_by_id(id: str):
|
||||
return influxdb_api.query_latest_record_by_ID(id, type='link', client=influx_client)
|
||||
|
||||
# query scada
|
||||
@app.get("/queryscadalatestrecordbyid/")
|
||||
async def query_scada_latest_record_by_id(id: str):
|
||||
async def fastapi_query_scada_latest_record_by_id(id: str):
|
||||
return influxdb_api.query_latest_record_by_ID(id, type='scada', client=influx_client)
|
||||
|
||||
|
||||
@@ -2140,24 +2140,24 @@ async def fastapi_query_all_records_by_date(querydate: str) -> dict[str, list]:
|
||||
|
||||
# def query_curve_by_ID_property_daterange(ID: str, type: str, property: str, start_date: str, end_date: str, bucket: str="realtime_data", client: InfluxDBClient=client) -> list:
|
||||
@app.get("/querynodecurvebyidpropertydaterange/")
|
||||
async def query_node_curve_by_id_property_daterange(id: str, prop: str, startdate: str, enddate: str):
|
||||
async def fastapi_query_node_curve_by_id_property_daterange(id: str, prop: str, startdate: str, enddate: str):
|
||||
return influxdb_api.query_curve_by_ID_property_daterange(id, type='node', property=prop, start_date=startdate, end_date=enddate, client=influx_client)
|
||||
|
||||
@app.get("/querylinkcurvebyidpropertydaterange/")
|
||||
async def query_link_curve_by_id_property_daterange(id: str, prop: str, startdate: str, enddate: str):
|
||||
async def fastapi_query_link_curve_by_id_property_daterange(id: str, prop: str, startdate: str, enddate: str):
|
||||
return influxdb_api.query_curve_by_ID_property_daterange(id, type='link', property=prop, start_date=startdate, end_date=enddate, client=influx_client)
|
||||
|
||||
# ids 用,隔开
|
||||
# 返回 { 'id': value1, 'id2': value2 }
|
||||
# def query_SCADA_data_by_device_ID_and_time(query_ids_list: List[str], query_time: str, bucket: str="SCADA_data", client: InfluxDBClient=client) -> Dict[str, float]:
|
||||
@app.get("/queryscadadatabydeviceidandtime/")
|
||||
async def query_scada_data_by_device_id_and_time(ids: str, querytime: str):
|
||||
async def fastapi_query_scada_data_by_device_id_and_time(ids: str, querytime: str):
|
||||
query_ids = ids.split(',')
|
||||
logger.info(querytime)
|
||||
return influxdb_api.query_SCADA_data_by_device_ID_and_time(query_ids_list=query_ids, query_time=querytime, client=influx_client)
|
||||
|
||||
@app.get("/queryscadadatabydeviceidandtimerange/")
|
||||
async def query_scada_data_by_device_id_and_time_range(ids: str, starttime: str, endtime: str):
|
||||
async def fastapi_query_scada_data_by_device_id_and_time_range(ids: str, starttime: str, endtime: str):
|
||||
query_ids = ids.split(',')
|
||||
return influxdb_api.query_SCADA_data_by_device_ID_and_time_range(query_ids_list=query_ids, start_time=starttime, end_time=endtime, client=influx_client)
|
||||
|
||||
@@ -2219,8 +2219,7 @@ async def fastapi_run_project(network: str,start_time:str,end_time=None) -> str:
|
||||
else:
|
||||
print('file doesnt exists')
|
||||
#os.rename(filename, filename2)
|
||||
result = run_simulation_ex(name=network, simulation_type='realtime',
|
||||
start_datetime=start_time, end_datetime=end_time)
|
||||
result = run_simulation_ex(name=network, simulation_type='realtime', start_datetime=start_time, end_datetime=end_time)
|
||||
#os.rename(filename2, filename)
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user