Update auto_store_non_realtime

This commit is contained in:
DingZQ
2025-02-09 10:17:07 +08:00
parent fa643aca49
commit 1131f7b1f9

View File

@@ -6,6 +6,18 @@ import time
from influxdb_client import InfluxDBClient, BucketsApi, WriteApi, OrganizationsApi, Point, QueryApi
import influxdb_info
# 2025/02/01
def get_next_time() -> str:
"""
获取下一个1分钟时间点返回格式为字符串'YYYY-MM-DDTHH:MM:00+08:00'
:return: 返回字符串格式的时间表示下一个1分钟的时间点
"""
# 获取当前时间,并设定为北京时间
now = datetime.now() # now 类型为 datetime表示当前本地时间
# 获取当前的分钟,并且将秒和微秒置为零
current_time = now.replace(second=0, microsecond=0) # current_time 类型为 datetime时间的秒和微秒部分被清除
return current_time.strftime('%Y-%m-%dT%H:%M:%S+08:00')
# 2025/02/06
def get_next_period_time() -> str:
@@ -35,14 +47,19 @@ def store_non_realtime_SCADA_data_job() -> None:
# 获取当前时间
current_time = datetime.now()
# 只在0点、6点、12点、18点执行任务
if current_time.hour % 6 == 0 and current_time.minute == 0:
# if current_time.hour % 6 == 0 and current_time.minute == 0:
if current_time.minute % 10 == 0:
print(f"{current_time.strftime('%Y-%m-%d %H:%M:%S')} -- Start store non realtime SCADA data task.")
# 获取下一个6小时的时间点并更新get_history_data_end_time
get_history_data_end_time: str = get_next_period_time() # get_history_data_end_time 类型为 str格式为'2025-02-06T12:00:00+08:00'
print(get_history_data_end_time)
get_history_data_end_time: str = get_next_time() # get_history_data_end_time 类型为 str格式为'2025-02-06T12:00:00+08:00'
# print(get_next_time)
# 调用函数执行任务
influxdb_api.store_non_realtime_SCADA_data_to_influxdb(get_history_data_end_time)
print('{} -- Successfully store non realtime SCADA data.'.format(
datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
else:
print(f"{current_time.strftime('%Y-%m-%d %H:%M:%S')} -- Skipping store non realtime SCADA data task.")
# 2025/02/06