Refine
This commit is contained in:
@@ -5,6 +5,18 @@ import shutil
|
||||
import redis
|
||||
import urllib.request
|
||||
|
||||
def queryallrecordsbydate(date: str):
|
||||
|
||||
print(f'queryallrecordsbydate: {date}')
|
||||
|
||||
try:
|
||||
response = urllib.request.urlopen(f'http://localhost/queryallrecordsbydate/?querydate={date}')
|
||||
html = response.read().decode('utf-8')
|
||||
#print(html)
|
||||
except urllib.error.URLError as e:
|
||||
print("Error")
|
||||
|
||||
|
||||
def queryallrecordsbydatewithtype(date: str):
|
||||
|
||||
print(f'queryallrecordsbydatewithtype: {date}')
|
||||
@@ -90,6 +102,7 @@ def auto_cache_data():
|
||||
str_prev_day = prev_day.strftime('%Y-%m-%d')
|
||||
print(str_prev_day)
|
||||
|
||||
queryallrecordsbydate(str_prev_day)
|
||||
queryallrecordsbydatewithtype(str_prev_day)
|
||||
queryallrecordsbydateproperty(str_prev_day)
|
||||
queryallscadarecordsbydate(str_prev_day)
|
||||
|
||||
15
main.py
15
main.py
@@ -2144,9 +2144,18 @@ async def fastapi_query_all_records_by_time(querytime: str) -> dict[str, list]:
|
||||
#def query_all_record_by_date(query_date: str, bucket: str="realtime_simulation_result", client: InfluxDBClient=client) -> tuple:
|
||||
@app.get("/queryallrecordsbydate/")
|
||||
async def fastapi_query_all_records_by_date(querydate: str) -> dict[str, list]:
|
||||
results: tuple = influxdb_api.query_all_record_by_date(query_date=querydate, client=influx_client)
|
||||
return { "nodes": results[0],
|
||||
"links": results[1] }
|
||||
# 缓存查询结果提高性能
|
||||
global redis_client
|
||||
cache_key = f"queryallrecordsbydate_{querydate}"
|
||||
data = redis_client.get(cache_key)
|
||||
if data:
|
||||
# 使用自定义的反序列化函数
|
||||
loaded_dict = msgpack.unpackb(data, object_hook=object_hook)
|
||||
return loaded_dict
|
||||
|
||||
nodes_links: tuple = influxdb_api.query_all_record_by_date(query_date=querydate, client=influx_client)
|
||||
return { "nodes": nodes_links[0],
|
||||
"links": nodes_links[1] }
|
||||
|
||||
#2025-03-15, DingZQ
|
||||
@app.get("/queryallrecordsbydatewithtype/")
|
||||
|
||||
Reference in New Issue
Block a user