新增设备启动时间偏差计算功能,更新相关错误提示信息

This commit is contained in:
2025-12-16 13:35:43 +08:00
parent 10be50b71c
commit ca8bc9d7d5
3 changed files with 98 additions and 2 deletions

View File

@ -1,7 +1,8 @@
import traceback
from datetime import datetime
from logging import error, info
from pathlib import Path
import json
from PySide6.QtWidgets import QMessageBox, QWidget, QPushButton, QProgressBar, QApplication, QRadioButton, QCheckBox
from func.utils.Constants import Constants
@ -227,6 +228,76 @@ class PublicFunc:
}
return Result().success(data=data)
@staticmethod
def get_machine_start_time_bias(psg_dir_path, orgBcg_dir_path):
# 查看orgBcg文件夹下是否有zd5y2_jf_info.json文件
orgBcg_info_path = [p for p in Path(orgBcg_dir_path).glob("*info*") if
p.suffix == ".json"]
if len(orgBcg_info_path) == 0:
return Result().failure(
info=Constants.INPUT_FAILURE + "\n" +
"*info.json" +
str(orgBcg_dir_path) +
Constants.FAILURE_REASON["File_Not_Exist"])
elif len(orgBcg_info_path) > 1:
return Result().failure(
info=Constants.INPUT_FAILURE + "\n" +
"*info.json" +
str(orgBcg_dir_path) +
Constants.FAILURE_REASON["File_More_Than_One"])
else:
orgBcg_info_path = orgBcg_info_path[0]
with open(orgBcg_info_path, 'r', encoding='utf-8') as f:
orgBcg_info = json.load(f)
machine_start_time_str = orgBcg_info.get("StartDate", None)
if machine_start_time_str is None:
return Result().failure(
info=Constants.INPUT_FAILURE + "\n" +
"*info.json" +
str(orgBcg_dir_path) +
Constants.FAILURE_REASON["orgBcg_Machine_Start_Time_Not_Exist"])
# 查看psg文件夹下是否有StartTime_Raw.txt文件
psg_start_time_path = [p for p in Path(psg_dir_path).glob("StartTime_Raw*") if
p.suffix == ".txt"]
if len(psg_start_time_path) == 0:
return Result().failure(
info=Constants.INPUT_FAILURE + "\n" +
"StartTime_Raw.txt" +
str(psg_dir_path) +
Constants.FAILURE_REASON["File_Not_Exist"])
elif len(psg_start_time_path) > 1:
return Result().failure(
info=Constants.INPUT_FAILURE + "\n" +
"StartTime_Raw.txt" +
str(psg_dir_path) +
Constants.FAILURE_REASON["File_More_Than_One"])
else:
psg_start_time_path = psg_start_time_path[0]
with open(psg_start_time_path, 'r', encoding='utf-8') as f:
# 读取第一行
psg_start_time_str = f.readline().strip()
print(psg_start_time_str)
try:
# 计算时间差,单位为秒
fmt = "%Y-%m-%d %H:%M:%S"
machine_start_time = datetime.strptime(machine_start_time_str, fmt)
psg_start_time = datetime.strptime(psg_start_time_str, fmt)
time_bias = (psg_start_time - machine_start_time).total_seconds()
except Exception as e:
traceback.print_exc()
return Result().failure(
info=Constants.INPUT_FAILURE + "\n" +
"时间格式错误,无法计算时间差:" +
str(e))
return Result().success(data={"time_bias":time_bias})
@staticmethod
def examine_artifact(artifact):
# 检查体动标签正确性,长度