Update influxdb_api to try query data
This commit is contained in:
@@ -423,7 +423,7 @@ def store_realtime_SCADA_data_to_influxdb(get_real_value_time: str, bucket: str
|
||||
|
||||
# 创建Point对象
|
||||
point = (
|
||||
Point('reservoir_liquid_level_realtime')
|
||||
Point('reservoir_liquid_level_realtime') # measurement name
|
||||
.tag("date", datetime.fromisoformat(get_real_value_time).strftime('%Y-%m-%d'))
|
||||
.tag("description", data['description'])
|
||||
.tag("device_ID", data['device_ID'])
|
||||
@@ -1319,27 +1319,27 @@ if __name__ == "__main__":
|
||||
# client.close()
|
||||
|
||||
# step2: 先查询pg数据库中scada_info的信息,然后存储SCADA数据到SCADA_data这个bucket里
|
||||
query_pg_scada_info_realtime('bb')
|
||||
query_pg_scada_info_non_realtime('bb')
|
||||
# query_pg_scada_info_realtime('bb')
|
||||
# query_pg_scada_info_non_realtime('bb')
|
||||
|
||||
# 手动执行
|
||||
# store_realtime_SCADA_data_to_influxdb(get_real_value_time='2025-02-07T16:52:00+08:00')
|
||||
store_non_realtime_SCADA_data_to_influxdb(get_history_data_end_time='2025-02-08T12:00:00+08:00')
|
||||
# store_non_realtime_SCADA_data_to_influxdb(get_history_data_end_time='2025-02-08T12:00:00+08:00')
|
||||
|
||||
# step3: 查询测试示例
|
||||
# with InfluxDBClient(url=url, token=token, org=org_name) as client:
|
||||
with InfluxDBClient(url=url, token=token, org=org_name) as client:
|
||||
# 示例1:query_latest_record_by_ID
|
||||
# bucket_name = "realtime_simulation_result" # 数据存储的 bucket 名称
|
||||
# node_id = "ZBBDTZDP000022" # 查询的节点 ID
|
||||
# link_id = "ZBBGXSZW000002"
|
||||
#
|
||||
# latest_record = query_latest_record_by_ID(ID=node_id, type="node", bucket=bucket_name, client=client)
|
||||
# # latest_record = query_latest_record_by_ID(ID=link_id, type="link", bucket=bucket_name, client=client)
|
||||
#
|
||||
# if latest_record:
|
||||
# print("最新记录:", latest_record)
|
||||
# else:
|
||||
# print("未找到符合条件的记录。")
|
||||
bucket_name = "realtime_simulation_result" # 数据存储的 bucket 名称
|
||||
node_id = "ZBBDTZDP000022" # 查询的节点 ID
|
||||
link_id = "ZBBGXSZW000002"
|
||||
|
||||
latest_record = query_latest_record_by_ID(ID=node_id, type="node", bucket=bucket_name, client=client)
|
||||
# latest_record = query_latest_record_by_ID(ID=link_id, type="link", bucket=bucket_name, client=client)
|
||||
|
||||
if latest_record:
|
||||
print("最新记录:", latest_record)
|
||||
else:
|
||||
print("未找到符合条件的记录。")
|
||||
|
||||
# 示例2:query_all_record_by_time
|
||||
# node_records, link_records = query_all_record_by_time(query_time="2024-11-25T06:00:00+08:00")
|
||||
|
||||
Reference in New Issue
Block a user