结合自动到轨迹
This commit is contained in:
61
scheduler.py
61
scheduler.py
@@ -114,12 +114,12 @@ def normalize_datetime(time_str):
|
||||
|
||||
def get_combined_tasks():
|
||||
"""
|
||||
结合接口(is_ok==1)和本地文件(true)筛选任务
|
||||
# 结合接口(is_ok==1)和本地文件(true)筛选任务
|
||||
结合接口(is_ok==1)和获取解析云端轨迹文件筛选任务
|
||||
"""
|
||||
try:
|
||||
local_times = parse_time_config()
|
||||
if not local_times:
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
# 调用你的 API 接口获取账号信息
|
||||
accounts = apis.get_accounts_from_server("68c0dbfdb7cbcd616e7c5ab5")
|
||||
@@ -127,7 +127,7 @@ def get_combined_tasks():
|
||||
return {}
|
||||
|
||||
task_list = {}
|
||||
# today = datetime.now().strftime("%Y-%m-%d")
|
||||
today = datetime.now().strftime("%Y%m%d")
|
||||
|
||||
for account in accounts:
|
||||
if account.get('is_ok') == 1:
|
||||
@@ -135,22 +135,40 @@ def get_combined_tasks():
|
||||
ip = account.get('device_ip')
|
||||
port = account.get('device_port')
|
||||
project_name = account.get('project_name')
|
||||
|
||||
# 只有在 time.txt 中是 true 的账号才会被加入
|
||||
if user in local_times and ip and port:
|
||||
address = f"{ip}:{port}"
|
||||
# full_time = f"{today} {local_times[user]}"
|
||||
# 确保时间是两位数格式
|
||||
raw_time = local_times[user]
|
||||
# # 将时间格式化为两位数:9:52:20 -> 09:52:20
|
||||
# if ':' in raw_time:
|
||||
# parts = raw_time.split(':')
|
||||
# if len(parts[0]) == 1:
|
||||
# raw_time = f"0{raw_time}" # 补齐前导零
|
||||
|
||||
# 获取轨迹文件
|
||||
save_path = apis.fetch_and_save_track_file(f"https://database.yuxindazhineng.com/team-bucket/69378c5b4f42d83d9504560d/track/{today}/{today}_1_{user}.txt")
|
||||
if save_path:
|
||||
|
||||
# 1. 解析原始文件
|
||||
raw_records = apis.parse_track_file(save_path)
|
||||
|
||||
# full_time = f"{today} {raw_time}"
|
||||
full_time = normalize_datetime(raw_time)
|
||||
task_list[address] = {"time": full_time, "user": user, "project_name": project_name}
|
||||
# 2. 按线路ID去重(重复则保留后面的记录)
|
||||
deduplicated_records = apis.deduplicate_by_line_id(raw_records)
|
||||
|
||||
# 3. 从去重后的记录中找最晚结束时间
|
||||
latest_time = apis.get_latest_end_time(deduplicated_records)
|
||||
|
||||
# 4. 写入end.txt
|
||||
# write_success = apis.write_to_file(latest_time)
|
||||
write_success = apis.writer_file_status(user, latest_time, "true")
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
# 获取状态为true的账号
|
||||
local_times = parse_time_config()
|
||||
if not local_times:
|
||||
return {}
|
||||
|
||||
# 只有在写入成功且 time.txt 中是 true 的账号才会被加入
|
||||
if write_success and user in local_times and ip and port:
|
||||
address = f"{ip}:{port}"
|
||||
# 确保时间是两位数格式
|
||||
raw_time = local_times[user]
|
||||
full_time = normalize_datetime(raw_time)
|
||||
task_list[address] = {"time": full_time, "user": user, "project_name": project_name}
|
||||
elif not write_success:
|
||||
print(f"❌ 写入end.txt失败,跳过任务: {user}")
|
||||
|
||||
return task_list
|
||||
except Exception as e:
|
||||
@@ -223,4 +241,5 @@ if __name__ == "__main__":
|
||||
try:
|
||||
monitor_center()
|
||||
except KeyboardInterrupt:
|
||||
print("\n👋 用户手动停止程序。")
|
||||
print("\n👋 用户手动停止程序。")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user