新增设备启动时间偏差计算功能,更新相关错误提示信息
This commit is contained in:
@ -401,6 +401,19 @@ class MainWindow_approximately_align(QMainWindow):
|
|||||||
else:
|
else:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def __preload_PreCut__(self):
|
||||||
|
time_bias_seconds = Config.get("TimeBiasSecond", None)
|
||||||
|
if time_bias_seconds is not None:
|
||||||
|
if time_bias_seconds > 0:
|
||||||
|
self.ui.spinBox_orgBcgPreCut.setValue(int(time_bias_seconds))
|
||||||
|
self.ui.spinBox_PSGPreCut.setValue(0)
|
||||||
|
self.ui.spinBox_PSGPreA.setValue(int(time_bias_seconds))
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.ui.spinBox_orgBcgPreCut.setValue(0)
|
||||||
|
self.ui.spinBox_PSGPreCut.setValue(int(-time_bias_seconds))
|
||||||
|
self.ui.spinBox_orgBcgPreA.setValue(int(-time_bias_seconds))
|
||||||
|
|
||||||
def __slot_btn_input__(self):
|
def __slot_btn_input__(self):
|
||||||
PublicFunc.__disableAllButton__(self, ButtonState)
|
PublicFunc.__disableAllButton__(self, ButtonState)
|
||||||
|
|
||||||
@ -426,6 +439,7 @@ class MainWindow_approximately_align(QMainWindow):
|
|||||||
self.ui.label_orgBcg_length.setText(str(orgBcg_seconds))
|
self.ui.label_orgBcg_length.setText(str(orgBcg_seconds))
|
||||||
self.ui.label_PSG_length.setText(str(PSG_seconds))
|
self.ui.label_PSG_length.setText(str(PSG_seconds))
|
||||||
self.__reset__()
|
self.__reset__()
|
||||||
|
self.__preload_PreCut__()
|
||||||
self.setting.close()
|
self.setting.close()
|
||||||
PublicFunc.finish_operation(self, ButtonState)
|
PublicFunc.finish_operation(self, ButtonState)
|
||||||
|
|
||||||
@ -1075,6 +1089,7 @@ class Data:
|
|||||||
self.processed_downsample_Abd = None
|
self.processed_downsample_Abd = None
|
||||||
|
|
||||||
def open_file(self):
|
def open_file(self):
|
||||||
|
info = ""
|
||||||
if Path(Config["Path"]["Input_orgBcg"]).is_file():
|
if Path(Config["Path"]["Input_orgBcg"]).is_file():
|
||||||
Config["Path"]["Input_orgBcg"] = str(Path(Config["Path"]["Input_orgBcg"]).parent)
|
Config["Path"]["Input_orgBcg"] = str(Path(Config["Path"]["Input_orgBcg"]).parent)
|
||||||
if Path(Config["Path"]["Input_Tho"]).is_file():
|
if Path(Config["Path"]["Input_Tho"]).is_file():
|
||||||
@ -1082,6 +1097,13 @@ class Data:
|
|||||||
if Path(Config["Path"]["Input_Abd"]).is_file():
|
if Path(Config["Path"]["Input_Abd"]).is_file():
|
||||||
Config["Path"]["Input_Abd"] = str(Path(Config["Path"]["Input_Abd"]).parent)
|
Config["Path"]["Input_Abd"] = str(Path(Config["Path"]["Input_Abd"]).parent)
|
||||||
|
|
||||||
|
result = PublicFunc.get_machine_start_time_bias(Config["Path"]["Input_Tho"], Config["Path"]["Input_orgBcg"])
|
||||||
|
|
||||||
|
if result.status:
|
||||||
|
Config["TimeBiasSecond"] = result.data["time_bias"]
|
||||||
|
else:
|
||||||
|
info += result.info + "\n"
|
||||||
|
|
||||||
result = PublicFunc.examine_file(Config["Path"]["Input_orgBcg"], Filename.ORGBCG_RAW, Params.ENDSWITH_TXT)
|
result = PublicFunc.examine_file(Config["Path"]["Input_orgBcg"], Filename.ORGBCG_RAW, Params.ENDSWITH_TXT)
|
||||||
if result.status:
|
if result.status:
|
||||||
Config["Path"]["Input_orgBcg"] = result.data["path"]
|
Config["Path"]["Input_orgBcg"] = result.data["path"]
|
||||||
@ -1101,6 +1123,8 @@ class Data:
|
|||||||
else:
|
else:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.raw_orgBcg = read_csv(Config["Path"]["Input_orgBcg"],
|
self.raw_orgBcg = read_csv(Config["Path"]["Input_orgBcg"],
|
||||||
encoding=Params.UTF8_ENCODING,
|
encoding=Params.UTF8_ENCODING,
|
||||||
@ -1115,7 +1139,7 @@ class Data:
|
|||||||
return Result().failure(info=Constants.INPUT_FAILURE + Constants.FAILURE_REASON[
|
return Result().failure(info=Constants.INPUT_FAILURE + Constants.FAILURE_REASON[
|
||||||
"Open_Data_Exception"] + "\n" + format_exc())
|
"Open_Data_Exception"] + "\n" + format_exc())
|
||||||
|
|
||||||
return Result().success(info=Constants.INPUT_FINISHED)
|
return Result().success(info=info + Constants.INPUT_FINISHED)
|
||||||
|
|
||||||
def save(self, epoch):
|
def save(self, epoch):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -143,6 +143,7 @@ class Constants:
|
|||||||
"OrgBCG_Cut_Length_Not_Correct": "(OrgBCG的切割长度不正确,Pre+Post长度大于信号长度)",
|
"OrgBCG_Cut_Length_Not_Correct": "(OrgBCG的切割长度不正确,Pre+Post长度大于信号长度)",
|
||||||
"PSG_Cut_Length_Not_Correct": "(PSG的切割长度不正确,Pre+Post长度大于信号长度)",
|
"PSG_Cut_Length_Not_Correct": "(PSG的切割长度不正确,Pre+Post长度大于信号长度)",
|
||||||
"Get_Freq_Not_Correct": "(无法获取数据采样率,将填入配置文件中的采样率。可能是因为文件不存在或文件命名格式不正确导致,请检查数据)",
|
"Get_Freq_Not_Correct": "(无法获取数据采样率,将填入配置文件中的采样率。可能是因为文件不存在或文件命名格式不正确导致,请检查数据)",
|
||||||
|
"orgBcg_Machine_Start_Time_Not_Exist": "(OrgBCG的设备启动时间不存在)",
|
||||||
|
|
||||||
"Open_Data_Exception": "(打开数据异常)",
|
"Open_Data_Exception": "(打开数据异常)",
|
||||||
"Process_Exception": "(处理异常)",
|
"Process_Exception": "(处理异常)",
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from logging import error, info
|
from logging import error, info
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import json
|
||||||
from PySide6.QtWidgets import QMessageBox, QWidget, QPushButton, QProgressBar, QApplication, QRadioButton, QCheckBox
|
from PySide6.QtWidgets import QMessageBox, QWidget, QPushButton, QProgressBar, QApplication, QRadioButton, QCheckBox
|
||||||
|
|
||||||
from func.utils.Constants import Constants
|
from func.utils.Constants import Constants
|
||||||
@ -227,6 +228,76 @@ class PublicFunc:
|
|||||||
}
|
}
|
||||||
return Result().success(data=data)
|
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
|
@staticmethod
|
||||||
def examine_artifact(artifact):
|
def examine_artifact(artifact):
|
||||||
# 检查体动标签正确性,长度
|
# 检查体动标签正确性,长度
|
||||||
|
|||||||
Reference in New Issue
Block a user