Refine api query_all_record_by_date_property
This commit is contained in:
@@ -1863,13 +1863,12 @@ def query_all_record_by_date_property(query_date: str, type: str, property: str,
|
||||
raise ValueError(f"不支持的类型: {type}")
|
||||
# 将 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()
|
||||
|
||||
start_time = (datetime.strptime(query_date, "%Y-%m-%d") - timedelta(days=1)).replace(hour=16, minute=0, second=0, tzinfo=timezone.utc).isoformat()
|
||||
print(start_time)
|
||||
stop_time = (datetime.strptime(query_date, "%Y-%m-%d")).replace(hour=16, minute=0, second=0, tzinfo=timezone.utc).isoformat()
|
||||
print(stop_time)
|
||||
|
||||
print(f"now time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
bg_start_time, bg_end_time = time_api.parse_beijing_date_range(query_date)
|
||||
utc_start_time = time_api.to_utc_time(bg_start_time)
|
||||
utc_end_time = time_api.to_utc_time(bg_end_time)
|
||||
|
||||
print(f"utc_start_time: {utc_start_time}, utc_end_time: {utc_end_time}")
|
||||
|
||||
# 构建 Flux 查询语句
|
||||
print("before query influxdb")
|
||||
@@ -1877,13 +1876,11 @@ def query_all_record_by_date_property(query_date: str, type: str, property: str,
|
||||
# 构建 Flux 查询语句
|
||||
flux_query = f'''
|
||||
from(bucket: "{bucket}")
|
||||
|> range(start: {start_time}, stop: {stop_time})
|
||||
|> range(start: {utc_start_time.isoformat()}, stop: {utc_end_time.isoformat()})
|
||||
|> filter(fn: (r) =>
|
||||
r._measurement == "{measurement}" and
|
||||
r._field == "{property}"
|
||||
)
|
||||
|> group(columns: ["date"])
|
||||
|> filter(fn: (r) => r.date == "{query_date}")
|
||||
|> keep(columns: ["ID", "_time", "_value"])
|
||||
'''
|
||||
# 执行查询
|
||||
@@ -1900,7 +1897,7 @@ def query_all_record_by_date_property(query_date: str, type: str, property: str,
|
||||
result_records.append({
|
||||
"time": record["_time"],
|
||||
"ID": record["ID"],
|
||||
"value": record["_value"]
|
||||
property: record["_value"]
|
||||
})
|
||||
return result_records
|
||||
|
||||
|
||||
Reference in New Issue
Block a user