From ca8bc9d7d566803b4809471448e367420678c465 Mon Sep 17 00:00:00 2001 From: marques Date: Tue, 16 Dec 2025 13:35:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=BE=E5=A4=87=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=97=B6=E9=97=B4=E5=81=8F=E5=B7=AE=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func/Module_approximately_align.py | 26 ++++++++++- func/utils/Constants.py | 1 + func/utils/PublicFunc.py | 73 +++++++++++++++++++++++++++++- 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/func/Module_approximately_align.py b/func/Module_approximately_align.py index f80c5dc..59cc553 100644 --- a/func/Module_approximately_align.py +++ b/func/Module_approximately_align.py @@ -401,6 +401,19 @@ class MainWindow_approximately_align(QMainWindow): else: 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): 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_PSG_length.setText(str(PSG_seconds)) self.__reset__() + self.__preload_PreCut__() self.setting.close() PublicFunc.finish_operation(self, ButtonState) @@ -1075,6 +1089,7 @@ class Data: self.processed_downsample_Abd = None def open_file(self): + info = "" if Path(Config["Path"]["Input_orgBcg"]).is_file(): Config["Path"]["Input_orgBcg"] = str(Path(Config["Path"]["Input_orgBcg"]).parent) if Path(Config["Path"]["Input_Tho"]).is_file(): @@ -1082,6 +1097,13 @@ class Data: if Path(Config["Path"]["Input_Abd"]).is_file(): 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) if result.status: Config["Path"]["Input_orgBcg"] = result.data["path"] @@ -1101,6 +1123,8 @@ class Data: else: return result + + try: self.raw_orgBcg = read_csv(Config["Path"]["Input_orgBcg"], encoding=Params.UTF8_ENCODING, @@ -1115,7 +1139,7 @@ class Data: return Result().failure(info=Constants.INPUT_FAILURE + Constants.FAILURE_REASON[ "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): try: diff --git a/func/utils/Constants.py b/func/utils/Constants.py index 22c7ec5..1cbcf18 100644 --- a/func/utils/Constants.py +++ b/func/utils/Constants.py @@ -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": "(处理异常)", diff --git a/func/utils/PublicFunc.py b/func/utils/PublicFunc.py index fbc1740..115a164 100644 --- a/func/utils/PublicFunc.py +++ b/func/utils/PublicFunc.py @@ -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): # 检查体动标签正确性,长度