Update auto_store_non_realtime
This commit is contained in:
@@ -6,6 +6,18 @@ import time
|
|||||||
from influxdb_client import InfluxDBClient, BucketsApi, WriteApi, OrganizationsApi, Point, QueryApi
|
from influxdb_client import InfluxDBClient, BucketsApi, WriteApi, OrganizationsApi, Point, QueryApi
|
||||||
import influxdb_info
|
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
|
# 2025/02/06
|
||||||
def get_next_period_time() -> str:
|
def get_next_period_time() -> str:
|
||||||
@@ -35,14 +47,19 @@ def store_non_realtime_SCADA_data_job() -> None:
|
|||||||
# 获取当前时间
|
# 获取当前时间
|
||||||
current_time = datetime.now()
|
current_time = datetime.now()
|
||||||
# 只在0点、6点、12点、18点执行任务
|
# 只在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
|
# 获取下一个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'
|
get_history_data_end_time: str = get_next_time() # get_history_data_end_time 类型为 str,格式为'2025-02-06T12:00:00+08:00'
|
||||||
print(get_history_data_end_time)
|
# print(get_next_time)
|
||||||
# 调用函数执行任务
|
# 调用函数执行任务
|
||||||
influxdb_api.store_non_realtime_SCADA_data_to_influxdb(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(
|
print('{} -- Successfully store non realtime SCADA data.'.format(
|
||||||
datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
|
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
|
# 2025/02/06
|
||||||
|
|||||||
Reference in New Issue
Block a user