新增设备启动时间偏差计算功能,更新相关错误提示信息
This commit is contained in:
@ -143,6 +143,7 @@ class Constants:
|
||||
"OrgBCG_Cut_Length_Not_Correct": "(OrgBCG的切割长度不正确,Pre+Post长度大于信号长度)",
|
||||
"PSG_Cut_Length_Not_Correct": "(PSG的切割长度不正确,Pre+Post长度大于信号长度)",
|
||||
"Get_Freq_Not_Correct": "(无法获取数据采样率,将填入配置文件中的采样率。可能是因为文件不存在或文件命名格式不正确导致,请检查数据)",
|
||||
"orgBcg_Machine_Start_Time_Not_Exist": "(OrgBCG的设备启动时间不存在)",
|
||||
|
||||
"Open_Data_Exception": "(打开数据异常)",
|
||||
"Process_Exception": "(处理异常)",
|
||||
|
||||
@ -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):
|
||||
# 检查体动标签正确性,长度
|
||||
|
||||
Reference in New Issue
Block a user