Add influx db api
This commit is contained in:
27
main.py
27
main.py
@@ -24,6 +24,7 @@ from influxdb_client import InfluxDBClient, BucketsApi, WriteApi, OrganizationsA
|
||||
from typing import List, Dict
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from dateutil import parser
|
||||
import influxdb_api
|
||||
|
||||
JUNCTION = 0
|
||||
RESERVOIR = 1
|
||||
@@ -1946,6 +1947,7 @@ async def get_json():
|
||||
|
||||
############################################################
|
||||
# DingZQ, 2024-12-09, Add sample API to return real time data/simulation result
|
||||
# influx db operation
|
||||
############################################################
|
||||
@app.get("/getrealtimedata/")
|
||||
async def get_realtimedata():
|
||||
@@ -1957,6 +1959,31 @@ async def get_simulationresult():
|
||||
data = [random.randint(0, 100) for _ in range(100)]
|
||||
return data
|
||||
|
||||
# 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):
|
||||
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):
|
||||
return influxdb_api.query_latest_record_by_ID(id, type='link', client=influx_client);
|
||||
|
||||
# def query_all_record_by_time(query_time: str, bucket: str="realtime_data", client: InfluxDBClient=client) -> tuple:
|
||||
@app.get("/queryallrecordbytime/")
|
||||
async def query_all_record_by_time(querytime: str) -> dict[str, list]:
|
||||
results: tuple = influxdb_api.query_all_record_by_time(query_time=querytime, client=influx_client);
|
||||
return { "nodes": results[0],
|
||||
"links": results[1] }
|
||||
|
||||
# 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("/querynodecurvebyidpropertydatarage/")
|
||||
async def query_node_curve_by_id_property_datarage(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("/querylinkcurvebyidpropertydatarage/")
|
||||
async def query_link_curve_by_id_property_datarage(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);
|
||||
|
||||
|
||||
# DingZQ, 2024-12-31, generate openapi.json
|
||||
|
||||
Reference in New Issue
Block a user