Refine influxdb api
This commit is contained in:
@@ -23,7 +23,7 @@ import time_api
|
||||
url = influxdb_info.url
|
||||
token = influxdb_info.token
|
||||
org_name = influxdb_info.org
|
||||
client = InfluxDBClient(url=url, token=token, org=org_name)
|
||||
client = InfluxDBClient(url=url, token=token, org=org_name, timeout=600*1000) # 600 seconds
|
||||
|
||||
def query_pg_scada_info_realtime(name: str) -> None:
|
||||
"""
|
||||
@@ -1334,7 +1334,7 @@ def download_history_data_manually(begin_time: str, end_time: str, bucket: str =
|
||||
########################SCADA############################################################################################################
|
||||
|
||||
# DingZQ, 2025-03-08
|
||||
def query_all_SCADA_records_by_date(query_date: str, bucket: str="SCADA_data", client: InfluxDBClient=client) -> list[dict[str, float]]:
|
||||
def query_all_SCADA_records_by_date(query_date: str, bucket: str="SCADA_data") -> list[dict[str, float]]:
|
||||
|
||||
"""
|
||||
根据日期查询所有SCADA数据
|
||||
@@ -1345,6 +1345,7 @@ def query_all_SCADA_records_by_date(query_date: str, bucket: str="SCADA_data", c
|
||||
|
||||
:return:
|
||||
"""
|
||||
client = get_new_client()
|
||||
|
||||
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')))
|
||||
@@ -1391,6 +1392,8 @@ 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}")
|
||||
|
||||
client.close()
|
||||
|
||||
return SCADA_results
|
||||
|
||||
def query_SCADA_data_by_device_ID_and_time(query_ids_list: List[str], query_time: str, bucket: str="SCADA_data") -> Dict[str, float]:
|
||||
@@ -1487,7 +1490,7 @@ def query_SCADA_data_by_device_ID_and_timerange(query_ids_list: List[str], start
|
||||
|
||||
|
||||
# DingZQ, 2025-02-15
|
||||
def query_SCADA_data_by_device_ID_and_date(query_ids_list: List[str], query_date: str, bucket: str="SCADA_data", client: InfluxDBClient=client) -> list[dict[str, float]]:
|
||||
def query_SCADA_data_by_device_ID_and_date(query_ids_list: List[str], query_date: str, bucket: str="SCADA_data") -> list[dict[str, float]]:
|
||||
"""
|
||||
根据SCADA设备的ID和日期查询值
|
||||
:param query_ids_list: SCADA设备ID的列表, 是api_query 而不是 普通的Id
|
||||
@@ -1496,9 +1499,10 @@ def query_SCADA_data_by_device_ID_and_date(query_ids_list: List[str], query_date
|
||||
:param client: 已初始化的 InfluxDBClient 实例。
|
||||
:return:
|
||||
"""
|
||||
|
||||
start_time, end_time = time_api.parse_beijing_date_range(query_date)
|
||||
|
||||
return query_SCADA_data_by_device_ID_and_time_range(query_ids_list, str(start_time), str(end_time), bucket, client)
|
||||
return query_SCADA_data_by_device_ID_and_time_range(query_ids_list, str(start_time), str(end_time), bucket)
|
||||
|
||||
|
||||
# 2025/02/01
|
||||
@@ -1672,7 +1676,9 @@ def query_latest_record_by_ID(ID: str, type: str, bucket: str="realtime_simulati
|
||||
"device_ID": ID,
|
||||
"value": record["monitored_value"],
|
||||
}
|
||||
|
||||
|
||||
client.close()
|
||||
|
||||
return None # 如果没有找到记录
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user