Add more code from WMH

This commit is contained in:
DingZQ
2025-02-08 20:11:27 +08:00
parent f6f37d012b
commit e360540989
6 changed files with 382 additions and 61 deletions

View File

@@ -15,7 +15,7 @@ def get_next_period_time() -> str:
# 获取当前时间,并设定为北京时间
now = datetime.now() # now 类型为 datetime表示当前本地时间
# 获取当前的小时数并计算下一个6小时时间点
next_period_hour = (now.hour // 6 + 1) * 6 # next_period_hour 类型为 int表示下一个6小时时间点的小时部分
next_period_hour = (now.hour // 6 + 1) * 6 - 6 # next_period_hour 类型为 int表示下一个6小时时间点的小时部分
# 如果计算的小时大于23表示进入第二天调整为00:00
if next_period_hour >= 24:
next_period_hour = 0
@@ -37,6 +37,7 @@ def store_non_realtime_SCADA_data_job() -> None:
if current_time.hour % 6 == 0 and current_time.minute == 0:
# 获取下一个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)
# 调用函数执行任务
influxdb_api.store_non_realtime_SCADA_data_to_influxdb(get_history_data_end_time)
print('{} -- Successfully store non realtime SCADA data.'.format(
@@ -50,9 +51,13 @@ def store_non_realtime_SCADA_data_task() -> None:
该任务会一直运行定期调用store_non_realtime_SCADA_data_job获取SCADA数据。
:return:
"""
# 等待到整分对齐
now = datetime.now()
wait_seconds = 60 - now.second
time.sleep(wait_seconds)
try:
# 每分钟检查一次执行store_non_realtime_SCADA_data_job
schedule.every(1).minute.do(store_non_realtime_SCADA_data_job)
schedule.every(1).minute.at(":00").do(store_non_realtime_SCADA_data_job)
# 持续执行任务,检查是否有待执行的任务
while True: