Merge branch 'dingsu/shadell2' into TencentServer2

This commit is contained in:
DingZQ
2025-03-09 00:23:36 +08:00
2 changed files with 20 additions and 20 deletions

View File

@@ -1406,12 +1406,6 @@ def query_all_SCADA_records_by_date(query_date: str, bucket: str="SCADA_data", c
:return:
"""
global influxdb_cache
cache_key = f"{query_date}"
if influxdb_cache.get(cache_key) is not None:
return influxdb_cache.get(cache_key)
if client.ping(): print("{} -- Successfully connected to InfluxDB.".format( datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
else: print("{} -- Failed to connect to InfluxDB.".format( datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
@@ -1457,8 +1451,6 @@ def query_all_SCADA_records_by_date(query_date: str, bucket: str="SCADA_data", c
except Exception as e:
print(f"Error querying InfluxDB for date {query_date}: {e}")
influxdb_cache[cache_key] = SCADA_results
return SCADA_results
@@ -1842,8 +1834,6 @@ def query_all_record_by_date(query_date: str, bucket: str="realtime_simulation_r
})
return node_records, link_records
influxdb_cache = {}
# 2025/02/21 WMH
def query_all_record_by_date_property(query_date: str, type: str, property: str,
bucket: str="realtime_simulation_result", client: InfluxDBClient=client) -> list:
@@ -1857,12 +1847,6 @@ def query_all_record_by_date_property(query_date: str, type: str, property: str,
:return: list(dict): result_records
"""
global influxdb_cache
cache_key = f"{query_date}_{type}_{property}"
if influxdb_cache.get(cache_key) is not None:
return influxdb_cache.get(cache_key)
if client.ping(): print("{} -- Successfully connected to InfluxDB.".format( datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
else: print("{} -- Failed to connect to InfluxDB.".format( datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
@@ -1913,8 +1897,6 @@ def query_all_record_by_date_property(query_date: str, type: str, property: str,
property: record["_value"]
})
influxdb_cache[cache_key] = result_records
return result_records

22
main.py
View File

@@ -48,6 +48,8 @@ tmpDir = "C:/tmpfiles/"
lockedPrjs = {}
# 缓存 influxdb 查询结果提高性能
influxdb_cache = {}
if not os.path.exists(inpDir):
os.mkdir(inpDir)
@@ -2149,8 +2151,16 @@ async def fastapi_query_all_records_by_date(querydate: str) -> dict[str, list]:
# 返回 [{'time': '2024-01-01T00:00:00Z', 'ID': '1', 'value': 1.0}, {'time': '2024-01-01T00:00:00Z', 'ID': '2', 'value': 2.0}]
@app.get("/queryallrecordsbydateproperty/")
async def fastapi_query_all_records_by_date_property(querydate: str, querytype: str, property: str) -> list[dict]:
return influxdb_api.query_all_record_by_date_property(query_date=querydate, type=querytype, property=property, client=influx_client)
# 缓存查询结果提高性能
global influxdb_cache
cache_key = f"{querydate}_{querytype}_{property}"
if influxdb_cache.get(cache_key) is not None:
return influxdb_cache.get(cache_key)
result = influxdb_api.query_all_record_by_date_property(query_date=querydate, type=querytype, property=property, client=influx_client)
influxdb_cache[cache_key] = result
return result
# 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:
@@ -2185,8 +2195,16 @@ async def fastapi_query_scada_data_by_device_id_and_date(ids: str, querydate: st
# 返回所有SCADA设备在指定日期的所有记录
@app.get("/queryallscadarecordsbydate/")
async def fastapi_query_all_scada_records_by_date(querydate: str):
return influxdb_api.query_all_SCADA_records_by_date(query_date=querydate, client=influx_client)
# 缓存查询结果提高性能
global influxdb_cache
cache_key = f"{querydate}"
if influxdb_cache.get(cache_key) is not None:
return influxdb_cache.get(cache_key)
result = influxdb_api.query_all_SCADA_records_by_date(query_date=querydate, client=influx_client)
influxdb_cache[cache_key] = result
return result
@app.get("/queryinfluxdbbuckets/")