diff --git a/influxdb_api.py b/influxdb_api.py index 31ea5dd..73e3ce4 100644 --- a/influxdb_api.py +++ b/influxdb_api.py @@ -1346,10 +1346,8 @@ def query_SCADA_data_by_device_ID_and_time_range(query_ids_list: List[str], star :param client: 已初始化的 InfluxDBClient 实例。 :return: """ - 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'))) + 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'))) query_api = client.query_api() # 将北京时间转换为 UTC 时间 @@ -1413,6 +1411,7 @@ def query_all_SCADA_records_by_date(query_date: str, bucket: str="SCADA_data", c # 将北京时间转换为 UTC 时间 bg_start_time, bg_end_time = time_api.parse_beijing_date_range(query_date) + bg_end_time = bg_start_time + timedelta(hours=2) # 服务器性能不行,暂时返回2个小时的数据 utc_start_time = bg_start_time.astimezone(timezone.utc) utc_end_time = bg_end_time.astimezone(timezone.utc) @@ -1847,12 +1846,9 @@ def query_all_record_by_date_property(query_date: str, type: str, property: str, :param client: 已初始化的InfluxDBClient 实例。 :return: list(dict): result_records """ - 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'))) + 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'))) + query_api = client.query_api() # 确定 measurement if type == "node": @@ -1865,6 +1861,7 @@ def query_all_record_by_date_property(query_date: str, type: str, property: str, # start_time = (datetime.strptime(query_date, "%Y-%m-%d") - timedelta(days=1)).replace(hour=16, minute=0, second=0, tzinfo=timezone.utc).isoformat() bg_start_time, bg_end_time = time_api.parse_beijing_date_range(query_date) + bg_end_time = bg_start_time + timedelta(hours=2) # 服务器性能不行,暂时返回2个小时的数据 utc_start_time = time_api.to_utc_time(bg_start_time) utc_end_time = time_api.to_utc_time(bg_end_time)