From 837c262f91bb95a48f6ec842cf1fdbb537adc9df Mon Sep 17 00:00:00 2001 From: DingZQ Date: Mon, 24 Mar 2025 22:07:14 +0800 Subject: [PATCH] Remove influx_client --- main.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index 4d4a9b1..aec79bb 100644 --- a/main.py +++ b/main.py @@ -65,10 +65,10 @@ def object_hook(dct): redis_client = redis.Redis(host="localhost", port=6379, db=0) # influxdb数据库连接信息 -influx_url = influxdb_info.url -influx_token = influxdb_info.token -influx_org_name = influxdb_info.org -influx_client = InfluxDBClient(url=influx_url, token=influx_token, org=influx_org_name, timeout=100*1000) # 100 seconds +# influx_url = influxdb_info.url +# influx_token = influxdb_info.token +# influx_org_name = influxdb_info.org +# influx_client = InfluxDBClient(url=influx_url, token=influx_token, org=influx_org_name, timeout=100*1000) # 100 seconds # 配置日志记录器 logging.basicConfig( @@ -2121,23 +2121,23 @@ async def fastapi_get_simulationresult(): # def query_latest_record_by_ID(ID: str, type: str, bucket: str="realtime_data", client: InfluxDBClient=client) -> dict: @app.get("/querynodelatestrecordbyid/") async def fastapi_query_node_latest_record_by_id(id: str): - return influxdb_api.query_latest_record_by_ID(id, type='node', client=influx_client) + return influxdb_api.query_latest_record_by_ID(id, type='node') @app.get("/querylinklatestrecordbyid/") async def fastapi_query_link_latest_record_by_id(id: str): - return influxdb_api.query_latest_record_by_ID(id, type='link', client=influx_client) + return influxdb_api.query_latest_record_by_ID(id, type='link') # query scada @app.get("/queryscadalatestrecordbyid/") async def fastapi_query_scada_latest_record_by_id(id: str): - return influxdb_api.query_latest_record_by_ID(id, type='scada', client=influx_client) + return influxdb_api.query_latest_record_by_ID(id, type='scada') # def query_all_record_by_time(query_time: str, bucket: str="realtime_data", client: InfluxDBClient=client) -> tuple: @app.get("/queryallrecordsbytime/") async def fastapi_query_all_records_by_time(querytime: str) -> dict[str, list]: - results: tuple = influxdb_api.query_all_record_by_time(query_time=querytime, client=influx_client) + results: tuple = influxdb_api.query_all_record_by_time(query_time=querytime) return { "nodes": results[0], "links": results[1] } @@ -2153,7 +2153,7 @@ async def fastapi_query_all_records_by_date(querydate: str) -> dict[str, list]: loaded_dict = msgpack.unpackb(data, object_hook=object_hook) return loaded_dict - nodes_links: tuple = influxdb_api.query_all_record_by_date(query_date=querydate, client=influx_client) + nodes_links: tuple = influxdb_api.query_all_record_by_date(query_date=querydate) return { "nodes": nodes_links[0], "links": nodes_links[1] } @@ -2169,7 +2169,7 @@ async def fastapi_query_all_records_by_date_with_type(querydate: str, querytype: loaded_dict = msgpack.unpackb(data, object_hook=object_hook) return loaded_dict - results = influxdb_api.query_all_records_by_date_with_type(query_date=querydate, query_type=querytype, client=influx_client) + results = influxdb_api.query_all_records_by_date_with_type(query_date=querydate, query_type=querytype) packed = msgpack.packb(results, default=default_encoder) redis_client.set(cache_key, packed) @@ -2186,7 +2186,7 @@ async def fastapi_query_all_records_by_ids_date_type(ids:str, querydate: str, qu # 使用自定义的反序列化函数 results = msgpack.unpackb(data, object_hook=object_hook) else: - results = influxdb_api.query_all_records_by_date_with_type(query_date=querydate, query_type=querytype, client=influx_client) + results = influxdb_api.query_all_records_by_date_with_type(query_date=querydate, query_type=querytype) packed = msgpack.packb(results, default=default_encoder) redis_client.set(cache_key, packed) @@ -2210,7 +2210,7 @@ async def fastapi_query_all_records_by_date_property(querydate: str, querytype: loaded_dict = msgpack.unpackb(data, object_hook=object_hook) return loaded_dict - result_dict = influxdb_api.query_all_record_by_date_property(query_date=querydate, type=querytype, property=property, client=influx_client) + result_dict = influxdb_api.query_all_record_by_date_property(query_date=querydate, type=querytype, property=property) packed = msgpack.packb(result_dict, default=default_encoder) redis_client.set(cache_key, packed) @@ -2220,11 +2220,11 @@ async def fastapi_query_all_records_by_date_property(querydate: str, querytype: # 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: @app.get("/querynodecurvebyidpropertydaterange/") async def fastapi_query_node_curve_by_id_property_daterange(id: str, prop: str, startdate: str, enddate: str): - return influxdb_api.query_curve_by_ID_property_daterange(id, type='node', property=prop, start_date=startdate, end_date=enddate, client=influx_client) + return influxdb_api.query_curve_by_ID_property_daterange(id, type='node', property=prop, start_date=startdate, end_date=enddate) @app.get("/querylinkcurvebyidpropertydaterange/") async def fastapi_query_link_curve_by_id_property_daterange(id: str, prop: str, startdate: str, enddate: str): - return influxdb_api.query_curve_by_ID_property_daterange(id, type='link', property=prop, start_date=startdate, end_date=enddate, client=influx_client) + return influxdb_api.query_curve_by_ID_property_daterange(id, type='link', property=prop, start_date=startdate, end_date=enddate) # ids 用,隔开 # 返回 { 'id': value1, 'id2': value2 } @@ -2233,7 +2233,7 @@ async def fastapi_query_link_curve_by_id_property_daterange(id: str, prop: str, async def fastapi_query_scada_data_by_device_id_and_time(ids: str, querytime: str): query_ids = ids.split(',') logger.info(querytime) - return influxdb_api.query_SCADA_data_by_device_ID_and_time(query_ids_list=query_ids, query_time=querytime, client=influx_client) + return influxdb_api.query_SCADA_data_by_device_ID_and_time(query_ids_list=query_ids, query_time=querytime) @app.get("/queryscadadatabydeviceidandtimerange/") async def fastapi_query_scada_data_by_device_id_and_time_range(ids: str, starttime: str, endtime: str): @@ -2241,12 +2241,12 @@ async def fastapi_query_scada_data_by_device_id_and_time_range(ids: str, startti print(f"query_ids: {ids}, starttime: {starttime}, endtime: {endtime}") query_ids = ids.split(',') - return influxdb_api.query_SCADA_data_by_device_ID_and_timerange(query_ids_list=query_ids, start_time=starttime, end_time=endtime, client=influx_client) + return influxdb_api.query_SCADA_data_by_device_ID_and_timerange(query_ids_list=query_ids, start_time=starttime, end_time=endtime) @app.get("/queryscadadatabydeviceidanddate/") async def fastapi_query_scada_data_by_device_id_and_date(ids: str, querydate: str): query_ids = ids.split(',') - return influxdb_api.query_SCADA_data_by_device_ID_and_date(query_ids_list=query_ids, query_date=querydate, client=influx_client) + return influxdb_api.query_SCADA_data_by_device_ID_and_date(query_ids_list=query_ids, query_date=querydate) # DingZQ, 2025-03-08 # 返回所有SCADA设备在指定日期的所有记录 @@ -2261,7 +2261,7 @@ async def fastapi_query_all_scada_records_by_date(querydate: str): loaded_dict = msgpack.unpackb(data, object_hook=object_hook) return loaded_dict - result_dict = influxdb_api.query_all_SCADA_records_by_date(query_date=querydate, client=influx_client) + result_dict = influxdb_api.query_all_SCADA_records_by_date(query_date=querydate) packed = msgpack.packb(result_dict, default=default_encoder) redis_client.set(cache_key, packed) @@ -2280,7 +2280,7 @@ async def fastapi_query_all_scheme_all_records(schemetype: str, schemename: str, loaded_dict = msgpack.unpackb(data, object_hook=object_hook) return loaded_dict - results = influxdb_api.query_scheme_all_record(scheme_Type=schemetype, scheme_Name=schemename, query_date=querydate, client=influx_client) + results = influxdb_api.query_scheme_all_record(scheme_Type=schemetype, scheme_Name=schemename, query_date=querydate) packed = msgpack.packb(results, default=default_encoder) redis_client.set(cache_key, packed) @@ -2297,7 +2297,7 @@ async def fastapi_query_all_scheme_all_records(schemetype: str, schemename: str, loaded_dict = msgpack.unpackb(data, object_hook=object_hook) return loaded_dict - results = influxdb_api.query_scheme_all_record(scheme_Type=schemetype, scheme_Name=schemename, query_date=querydate, client=influx_client) + results = influxdb_api.query_scheme_all_record(scheme_Type=schemetype, scheme_Name=schemename, query_date=querydate) packed = msgpack.packb(results, default=default_encoder) redis_client.set(cache_key, packed) @@ -2316,7 +2316,7 @@ async def fastapi_query_all_scheme_all_records_property(schemetype: str, schemen # 使用自定义的反序列化函数 all_results = msgpack.unpackb(data, object_hook=object_hook) else: - all_results = influxdb_api.query_scheme_all_record(scheme_Type=schemetype, scheme_Name=schemename, query_date=querydate, client=influx_client) + all_results = influxdb_api.query_scheme_all_record(scheme_Type=schemetype, scheme_Name=schemename, query_date=querydate) packed = msgpack.packb(all_results, default=default_encoder) redis_client.set(cache_key, packed)