From 71979940195ff437e124ba1ff7b0e758fcba4276 Mon Sep 17 00:00:00 2001 From: Yorusora Date: Tue, 3 Jun 2025 23:23:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E5=A4=84=E7=9A=84Re?= =?UTF-8?q?sult=E7=BB=93=E6=9E=9C=E6=9C=AAreturn=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func/Module_approximately_align.py | 2 -- func/Module_artifact_label.py | 6 ++--- func/Module_bcg_quality_label.py | 6 ++--- func/Module_precisely_align.py | 6 ++--- func/Module_preprocess.py | 43 +++++++++++++++++++----------- func/Module_resp_quality_label.py | 15 +++++------ func/utils/Constants.py | 1 + 7 files changed, 44 insertions(+), 35 deletions(-) diff --git a/func/Module_approximately_align.py b/func/Module_approximately_align.py index 8d4b482..0c6f03d 100644 --- a/func/Module_approximately_align.py +++ b/func/Module_approximately_align.py @@ -1230,7 +1230,6 @@ class Data: tho_bias_list.append(tho_seg_pos // temp_freq) abd_bias_list.append(abd_seg_pos // temp_freq) - result = { "tho_bias_list": tho_bias_list, "abd_bias_list": abd_bias_list, @@ -1238,7 +1237,6 @@ class Data: "epoch_max": epoch_max } - except Exception as e: return Result().failure( info=Constants.APPROXIMATELY_EPOCH_GET_FAILURE + Constants.FAILURE_REASON[ diff --git a/func/Module_artifact_label.py b/func/Module_artifact_label.py index 4c946ae..6523f98 100644 --- a/func/Module_artifact_label.py +++ b/func/Module_artifact_label.py @@ -1338,7 +1338,7 @@ class Data: def resample(self): if self.orgBcg is None: - Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) + return Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) try: if Config["InputConfig"]["orgBcgFreq"] != Config["InputConfig"]["UseFreq"]: @@ -1348,8 +1348,8 @@ class Data: else: return Result().success(info=Constants.RESAMPLE_NO_NEED) except Exception as e: - Result().failure(info=Constants.RESAMPLE_FAILURE + - Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) + return Result().failure(info=Constants.RESAMPLE_FAILURE + + Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) return Result().success(info=Constants.RESAMPLE_FINISHED) diff --git a/func/Module_bcg_quality_label.py b/func/Module_bcg_quality_label.py index d903e9f..8a51c6f 100644 --- a/func/Module_bcg_quality_label.py +++ b/func/Module_bcg_quality_label.py @@ -1072,7 +1072,7 @@ class Data(): def resample(self): if self.BCG is None: - Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) + return Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) try: if Config["InputConfig"]["BCGFreq"] != Config["InputConfig"]["UseFreq"]: @@ -1082,8 +1082,8 @@ class Data(): else: return Result().success(info=Constants.RESAMPLE_NO_NEED) except Exception as e: - Result().failure(info=Constants.RESAMPLE_FAILURE + - Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) + return Result().failure(info=Constants.RESAMPLE_FAILURE + + Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) return Result().success(info=Constants.RESAMPLE_FINISHED) diff --git a/func/Module_precisely_align.py b/func/Module_precisely_align.py index 98934a6..005a798 100644 --- a/func/Module_precisely_align.py +++ b/func/Module_precisely_align.py @@ -1559,7 +1559,7 @@ class Data: def resample(self): if self.raw_orgBcg is None or self.raw_BCG is None or self.raw_ECG is None: - Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) + return Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) try: if Config["InputConfig"]["orgBcgFreq"] != Config["InputConfig"]["UseFreq"]: @@ -1569,8 +1569,8 @@ class Data: else: return Result().success(info=Constants.RESAMPLE_NO_NEED) except Exception as e: - Result().failure(info=Constants.RESAMPLE_FAILURE + - Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) + return Result().failure(info=Constants.RESAMPLE_FAILURE + + Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) return Result().success(info=Constants.RESAMPLE_FINISHED) diff --git a/func/Module_preprocess.py b/func/Module_preprocess.py index f016e26..ed869a4 100644 --- a/func/Module_preprocess.py +++ b/func/Module_preprocess.py @@ -432,7 +432,7 @@ class Data: def resample(self): if self.raw_data is None: - Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) + return Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) try: if Config["InputConfig"]["Freq"] != Config["OutputConfig"]["Freq"]: @@ -442,34 +442,45 @@ class Data: else: return Result().success(info=Constants.RESAMPLE_NO_NEED) except Exception as e: - Result().failure(info=Constants.RESAMPLE_FAILURE + + return Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) return Result().success(info=Constants.RESAMPLE_FINISHED) def preprocess(self): if self.raw_data is None: - Result().failure(info=Constants.PREPROCESS_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) + return Result().failure(info=Constants.PREPROCESS_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) try: - if Config["Mode"] == "BCG": - self.processed_data = Butterworth_for_BCG_PreProcess(self.raw_data, type='bandpass', - low_cut=Config["Filter"]["BCGBandPassLow"], - high_cut=Config["Filter"]["BCGBandPassHigh"], - order=Config["Filter"]["BCGBandPassOrder"], - sample_rate=Config["OutputConfig"]["Freq"]) + if Config["Filter"]["BCGBandPassOrder"] == 0: + self.processed_data = self.raw_data + else: + if Config["Filter"]["BCGBandPassLow"] >= Config["Filter"]["BCGBandPassHigh"]: + return Result().failure( + info=Constants.PREPROCESS_FAILURE + Constants.FAILURE_REASON["Filter_Args_Not_Correct"]) + self.processed_data = Butterworth_for_BCG_PreProcess(self.raw_data, type='bandpass', + low_cut=Config["Filter"]["BCGBandPassLow"], + high_cut=Config["Filter"]["BCGBandPassHigh"], + order=Config["Filter"]["BCGBandPassOrder"], + sample_rate=Config["OutputConfig"]["Freq"]) elif Config["Mode"] == "ECG": - self.processed_data = Butterworth_for_ECG_PreProcess(self.raw_data, type='bandpass', - low_cut=Config["Filter"]["ECGBandPassLow"], - high_cut=Config["Filter"]["ECGBandPassHigh"], - order=Config["Filter"]["ECGBandPassOrder"], - sample_rate=Config["OutputConfig"]["Freq"]) + if Config["Filter"]["ECGBandPassOrder"] == 0: + self.processed_data = self.raw_data + else: + if Config["Filter"]["ECGBandPassLow"] >= Config["Filter"]["ECGBandPassHigh"]: + return Result().failure( + info=Constants.PREPROCESS_FAILURE + Constants.FAILURE_REASON["Filter_Args_Not_Correct"]) + self.processed_data = Butterworth_for_ECG_PreProcess(self.raw_data, type='bandpass', + low_cut=Config["Filter"]["ECGBandPassLow"], + high_cut=Config["Filter"]["ECGBandPassHigh"], + order=Config["Filter"]["ECGBandPassOrder"], + sample_rate=Config["OutputConfig"]["Freq"]) else: raise ValueError("模式不存在") except Exception as e: - Result().failure(info=Constants.PREPROCESS_FAILURE + - Constants.FAILURE_REASON["Preprocess_Exception"] + "\n" + format_exc()) + return Result().failure(info=Constants.PREPROCESS_FAILURE + + Constants.FAILURE_REASON["Preprocess_Exception"] + "\n" + format_exc()) return Result().success(info=Constants.PREPROCESS_FINISHED) diff --git a/func/Module_resp_quality_label.py b/func/Module_resp_quality_label.py index e2e0163..2c7f594 100644 --- a/func/Module_resp_quality_label.py +++ b/func/Module_resp_quality_label.py @@ -806,8 +806,7 @@ class MainWindow_resp_quality_label(QMainWindow): def __slot_btn_refilter_orgBcg__(self): PublicFunc.__disableAllButton__(self, ButtonState) if len(self.data.OrgBCG_Processed) == 0: - Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) - return + return Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) if self.ui.radioButton_orgBcg_fillterMode_custom.isChecked(): if self.check_filter_args() is False: @@ -1301,7 +1300,7 @@ class Data(): def resample_tho(self): if self.Tho is None: - Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) + return Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) try: if Config["InputConfig"]["ThoFreq"] != Config["InputConfig"]["ThoUseFreq"]: @@ -1311,8 +1310,8 @@ class Data(): else: return Result().success(info=Constants.RESAMPLE_NO_NEED) except Exception as e: - Result().failure(info=Constants.RESAMPLE_FAILURE + - Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) + return Result().failure(info=Constants.RESAMPLE_FAILURE + + Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) return Result().success(info=Constants.RESAMPLE_FINISHED) @@ -1477,7 +1476,7 @@ class Data(): def resample_tho_and_OrgBCG(self): if (self.OrgBCG is None) or (self.Tho is None): - Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) + return Result().failure(info=Constants.RESAMPLE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"]) try: if ((Config["InputConfig"]["OrgBCGFreq"] != Config["InputConfig"]["OrgBCGUseFreq"]) @@ -1494,8 +1493,8 @@ class Data(): else: return Result().success(info=Constants.RESAMPLE_NO_NEED) except Exception as e: - Result().failure(info=Constants.RESAMPLE_FAILURE + - Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) + return Result().failure(info=Constants.RESAMPLE_FAILURE + + Constants.FAILURE_REASON["Resample_Exception"] + "\n" + format_exc()) return Result().success(info=Constants.RESAMPLE_FINISHED) diff --git a/func/utils/Constants.py b/func/utils/Constants.py index 7cbdab4..b1c6d08 100644 --- a/func/utils/Constants.py +++ b/func/utils/Constants.py @@ -106,6 +106,7 @@ class Constants: "Data_Length_not_Correct": "(orgBcg和BCG长度不匹配)", "Artifact_Format_Not_Correct": "(体动长度或格式不正确)", "Data_Length_Not_Correct": "(信号长度不正确)", + "Filter_Args_Not_Correct": "(滤波器参数输入不正确)", "Open_Data_Exception": "(打开数据异常)", "Process_Exception": "(处理异常)",