This commit is contained in:
DingZQ
2025-02-23 10:42:30 +08:00
parent ef1786a4c8
commit cfa5df6dc4

View File

@@ -1344,6 +1344,7 @@ def query_all_record_by_date(query_date: str, bucket: str="realtime_simulation_r
:param client: 已初始化的InfluxDBClient 实例。 :param client: 已初始化的InfluxDBClient 实例。
:return: dict: tuple: (node_records, link_records) :return: dict: tuple: (node_records, link_records)
""" """
if client.ping(): if client.ping():
print("{} -- Successfully connected to InfluxDB.".format( print("{} -- Successfully connected to InfluxDB.".format(
datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
@@ -1351,10 +1352,12 @@ def query_all_record_by_date(query_date: str, bucket: str="realtime_simulation_r
print("{} -- Failed to connect to InfluxDB.".format( print("{} -- Failed to connect to InfluxDB.".format(
datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
query_api = client.query_api() query_api = client.query_api()
# 将 start_date 的北京时间转换为 UTC 时间
start_time = (datetime.strptime(query_date, "%Y-%m-%d") - timedelta(days=1)).replace(hour=16, minute=0, second=0, tzinfo=timezone.utc).isoformat()
# 构建 Flux 查询语句 # 构建 Flux 查询语句
flux_query = f''' flux_query = f'''
from(bucket: "{bucket}") from(bucket: "{bucket}")
|> range(start: 2025-01-01T00:00:00Z) |> range(start: {start_time})
|> filter(fn: (r) => r["_measurement"] == "node" or r["_measurement"] == "link") |> filter(fn: (r) => r["_measurement"] == "node" or r["_measurement"] == "link")
|> filter(fn: (r) => r["date"] == "{query_date}") |> filter(fn: (r) => r["date"] == "{query_date}")
|> pivot( |> pivot(
@@ -1363,6 +1366,7 @@ def query_all_record_by_date(query_date: str, bucket: str="realtime_simulation_r
valueColumn:"_value" valueColumn:"_value"
) )
''' '''
# 执行查询 # 执行查询
tables = query_api.query(flux_query) tables = query_api.query(flux_query)
node_records = [] node_records = []