This commit is contained in:
DingZQ
2025-03-22 13:26:25 +08:00
parent ea09d71604
commit 434805029b
2 changed files with 25 additions and 3 deletions

View File

@@ -5,6 +5,18 @@ import shutil
import redis import redis
import urllib.request 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): def queryallrecordsbydatewithtype(date: str):
print(f'queryallrecordsbydatewithtype: {date}') print(f'queryallrecordsbydatewithtype: {date}')
@@ -90,6 +102,7 @@ def auto_cache_data():
str_prev_day = prev_day.strftime('%Y-%m-%d') str_prev_day = prev_day.strftime('%Y-%m-%d')
print(str_prev_day) print(str_prev_day)
queryallrecordsbydate(str_prev_day)
queryallrecordsbydatewithtype(str_prev_day) queryallrecordsbydatewithtype(str_prev_day)
queryallrecordsbydateproperty(str_prev_day) queryallrecordsbydateproperty(str_prev_day)
queryallscadarecordsbydate(str_prev_day) queryallscadarecordsbydate(str_prev_day)

15
main.py
View File

@@ -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: #def query_all_record_by_date(query_date: str, bucket: str="realtime_simulation_result", client: InfluxDBClient=client) -> tuple:
@app.get("/queryallrecordsbydate/") @app.get("/queryallrecordsbydate/")
async def fastapi_query_all_records_by_date(querydate: str) -> dict[str, list]: 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], global redis_client
"links": results[1] } 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 #2025-03-15, DingZQ
@app.get("/queryallrecordsbydatewithtype/") @app.get("/queryallrecordsbydatewithtype/")