完成了<呼吸可用性及间期标注>的代码重构

修复了<人工纠正>中多次寻峰时会保存多个相同峰值横坐标的问题
This commit is contained in:
Yorusora
2025-05-22 15:58:29 +08:00
parent 17b896e49d
commit b57bd9e7fa
8 changed files with 1637 additions and 74 deletions

View File

@ -9,7 +9,7 @@ from PySide6.QtWidgets import QMessageBox, QMainWindow, QApplication, QTableWidg
from matplotlib import gridspec, patches
from matplotlib.backends.backend_qt import NavigationToolbar2QT
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
from numpy import append, delete, arange
from numpy import append, delete, arange, setdiff1d
from overrides import overrides
from pandas import read_csv, DataFrame
from scipy.signal import find_peaks
@ -818,6 +818,7 @@ class MainWindow_label_check(QMainWindow):
height=Config["FindPeaks"]["MinHeight"],
distance=Config["FindPeaks"]["MinInterval"])
peaks_idx = peaks_idx + int(rect_left)
peaks_idx = setdiff1d(peaks_idx, self.data.corrected_peak)
if len(peaks_idx) != 0:
PublicFunc.text_output(self.ui, f"{Constants.LABEL_CHECK_ADD_POINTS_SUCCESSFULLY}{peaks_idx}",
Constants.TIPS_TYPE_INFO)

File diff suppressed because it is too large Load Diff

View File

@ -275,6 +275,7 @@ class ConfigParams:
}
}
RESP_QUALITY_LABEL_PREPROCESS_FC: int = 1
RESP_QUALITY_LABEL_PARTS_TIME_SEC: int = 30
RESP_QUALITY_LABEL_LABEL_TRANSPARENCY: float = 0.2
RESP_QUALITY_LABEL_ACTION_LABEL_MULTIPLE_SHORTCUT_KEY: str = "Z"
@ -341,7 +342,7 @@ class ConfigParams:
RESP_QUALITY_LABEL_INPUT_XINXIAO_DEFAULT_FS: int = 1000
RESP_QUALITY_LABEL_INPUT_THO_DEFAULT_FS: int = 200
RESP_QUALITY_LABEL_PARTS_TIME_SEC: int = 30
RESP_QUALITY_LABEL_THRESHOLD1_DEFAULT: float = 0.65

View File

@ -103,7 +103,7 @@ class Constants:
"Method_Not_Exist": "(检测方法不存在)",
"Data_Length_not_Correct": "orgBcg和BCG长度不匹配",
"Artifact_Format_Not_Correct": "(体动长度或格式不正确)",
"Get_Artifact_Format_Exception": "获取体动长度或格式异常",
"Data_Length_Not_Correct": "信号长度不正确",
"Open_Data_Exception": "(打开数据异常)",
"Process_Exception": "(处理异常)",
@ -132,6 +132,7 @@ class Constants:
"Get_File_and_Freq_Excepetion": "(检查文件是否存在并获取其数据采样率异常)",
"Update_tableWidget_Exception": "(更新表格异常)",
"Update_Info_Exception": "(更新信息异常)",
"Get_Artifact_Format_Exception": "(获取体动长度或格式异常)",
"Label_Format_Exception": "(获取标签格式异常)",
"Calculate_Peak_Exception": "(计算峰值异常)",
@ -389,11 +390,45 @@ class Constants:
RESP_QUALITY_LABEL_PLOT_LABEL_ARTIFACT: str = "Artifact"
RESP_QUALITY_LABEL_SPECTRUM_BDR_TITLE: str = "Spectrum of BDR_sync by filter OrgBCG_Sync"
RESP_QUALITY_LABEL_SPECTRUM_THO_TITLE: str = "Spectrum of THO_sync after preprocess"
RESP_QUALITY_LABEL_SPECTRUM_ORGBCG_LABEL: str = "orgBcg"
RESP_QUALITY_LABEL_SPECTRUM_ORGBCG_LABEL: str = "OrgBCG"
RESP_QUALITY_LABEL_SPECTRUM_BDR_LABEL: str = "BDR"
RESP_QUALITY_LABEL_SPECTRUM_THO_LABEL: str = "THO"
RESP_QUALITY_LABEL_SPECTRUM_THO_LABEL: str = "Tho"
RESP_QUALITY_LABEL_VIEWING_THE_FIRST_PART: str = "你正在查看第1段信号"
RESP_QUALITY_LABEL_VIEWING_THE_LAST_PART: str = "你正在查看最后1段信号"
RESP_QUALITY_LABEL_PREV_PART: str = "上一个片段index "
RESP_QUALITY_LABEL_NEXT_PART: str = "下一个片段index "
RESP_QUALITY_LABEL_JUMP: str = "跳转到片段index "
RESP_QUALITY_LABEL_LABEL_SUCCESSFULLY: str = "片段标注成功"
RESP_QUALITY_LABEL_LABEL_TYPE: str = "标注类型为:"
RESP_QUALITY_LABEL_ADD_POINTS_SUCCESSFULLY: str = "成功新增点,横坐标:"
RESP_QUALITY_LABEL_REMOVE_POINTS_SUCCESSFULLY: str = "成功删除点,横坐标:"
RESP_QUALITY_LABEL_NO_POINT_IN_THE_INTERVAL: str = "所选区间内无新增或删除点"
RESP_QUALITY_LABEL_CUSTOM_FILTER_ARGS_ERROR: str = "OrgBCG带通滤波频率设置范围应为数字范围是0~1"
RESP_QUALITY_LABEL_AUTOLABEL_ARGS_ERROR: str = "人工标注阈值设置范围应为数字范围是0~1"
RESP_QUALITY_LABEL_CHECK_ARGS_QUESTION_CONTENT: str = "你确定要执行此操作吗,请确保参数输入正确"
RESP_QUALITY_LABEL_ACTION_LABEL_MULTIPLE_NAME: str = f"批量更改标签({ConfigParams.RESP_QUALITY_LABEL_ACTION_LABEL_MULTIPLE_SHORTCUT_KEY})"
RESP_QUALITY_LABEL_A_QUALITY: int = 1
RESP_QUALITY_LABEL_B_QUALITY: int = 0
RESP_QUALITY_LABEL_C_QUALITY: int = -1
RESP_QUALITY_LABEL_KEY_VALUE = {
1: "Good",
0: "Bad",
-1: "None"
}
RESP_QUALITY_LABEL_FIGTOOLBAR_SPECTRUM_STYLESHEET: str = """
QToolBar {
border: 1px;
spacing: 2px; /* 设置工具栏按钮之间的间距 */
}
QToolButton {
height: 20px; /* 设置工具栏按钮的高度 */
width: 20px; /* 设置工具栏按钮的宽度 */
font-size: 8px; /* 设置按钮文字大小 */
}
QToolButton::menu-button {
width: 0px; /* 隐藏下拉菜单按钮 */
}
"""
# 睡眠呼吸暂停事件标注
SA_LABEL_JUMP: str = "跳转到事件"
@ -483,52 +518,6 @@ class Constants:
background-color: yellow; /* 鼠标悬停时的背景颜色 */
}"""
# 呼吸可用性及间期标注
RESP_QUALITY_LABEL_FILES_NOT_FOUND: str = f"无法找到{ConfigParams.RESP_QUALITY_LABEL_INPUT_XINXIAO_FILENAME}{ConfigParams.ENDSWITH_TXT}{ConfigParams.RESP_QUALITY_LABEL_INPUT_THO_FILENAME}{ConfigParams.ENDSWITH_TXT}{ConfigParams.RESP_QUALITY_LABEL_INPUT_ARTIFACT_FILENAME}{ConfigParams.ENDSWITH_TXT},无法执行<呼吸可用性及间期标注>"
RESP_QUALITY_LABEL_FILES_FOUND: str = f"找到{ConfigParams.RESP_QUALITY_LABEL_INPUT_XINXIAO_FILENAME}{ConfigParams.ENDSWITH_TXT}{ConfigParams.RESP_QUALITY_LABEL_INPUT_THO_FILENAME}{ConfigParams.ENDSWITH_TXT}{ConfigParams.RESP_QUALITY_LABEL_INPUT_ARTIFACT_FILENAME}{ConfigParams.ENDSWITH_TXT}"
RESP_QUALITY_LABEL_HISTORICAL_SAVE1_FOUND: str = f"找到历史存档文件{ConfigParams.RESP_QUALITY_LABEL_SAVE_RESP_QUALITY_LABNEL_FILENAME}{ConfigParams.ENDSWITH_TXT},已成功读取"
RESP_QUALITY_LABEL_HISTORICAL_SAVE2_FOUND: str = f"找到历史存档文件{ConfigParams.RESP_QUALITY_LABEL_SAVE_THO_PEAK_FILENAME}{ConfigParams.ENDSWITH_TXT},已成功读取"
RESP_QUALITY_LABEL_INPUT_SIGNAL_FAILURE: str = "导入信号失败,请检查信号长度"
RESP_QUALITY_LABEL_INPUT_SUCCESSFULLY: str = "导入数据成功"
RESP_QUALITY_LABEL_PREPROCESS_SUCCESSFULLY: str = "导入数据成功"
RESP_QUALITY_LABEL_INPUT_ARTIFACT_FAILURE_FORMAT: str = "导入体动失败,请检查体动标签格式"
RESP_QUALITY_LABEL_INPUT_ARTIFACT_FAILURE_LENGTH: str = "导入体动失败请检查体动长度是否为4的倍数"
RESP_QUALITY_LABEL_VIEWING_THE_FIRST_PART: str = "你正在查看第1段信号"
RESP_QUALITY_LABEL_VIEWING_THE_LAST_PART: str = "你正在查看最后1段信号"
RESP_QUALITY_LABEL_CUSTOM_NAVIGATIONTOOLBAR_WIDGET_NAME: str = "MainWindow"
RESP_QUALITY_LABEL_BUTTON_PRESS_EVENT: str = "button_press_event"
RESP_QUALITY_LABEL_BUTTON_RELEASE_EVENT: str = "button_release_event"
RESP_QUALITY_LABEL_MOTION_NOTIFY_EVENT: str = "motion_notify_event"
RESP_QUALITY_LABEL_ADD_POINTS_SUCCESSFULLY: str = "成功新增点,横坐标:"
RESP_QUALITY_LABEL_REMOVE_POINTS_SUCCESSFULLY: str = "成功删除点,横坐标:"
RESP_QUALITY_LABEL_NO_POINT_IN_THE_INTERVAL: str = "所选区间内无新增或删除点"
RESP_QUALITY_LABEL_SAVE_PEAKS_SUCCESSFULLY: str = "保存峰值成功"
RESP_QUALITY_LABEL_DATA_NOT_FOUND: str = "数据未导入"
RESP_QUALITY_LABEL_LABEL_SUCCESSFULLY: str = "片段标注并保存成功"
RESP_QUALITY_LABEL_RESET_SUCCESSFULLY: str = "片段重置并保存成功"
RESP_QUALITY_LABEL_PLOT_LABEL_VLINE: str = "vline"
RESP_QUALITY_LABEL_PLOT_LABEL_HLINE: str = "hline"
RESP_QUALITY_LABEL_A_QUALITY: int = 1
RESP_QUALITY_LABEL_B_QUALITY: int = 0
RESP_QUALITY_LABEL_C_QUALITY: int = -1
RESP_QUALITY_LABEL_LABELED: str = "已标注"
RESP_QUALITY_LABEL_TOBELABELED: str = "未标注"
RESP_QUALITY_LABEL_CUSTOM_FILTER_ARGS_ERROR: str = "orgBcg带通滤波频率设置范围应为数字范围是0~1"
RESP_QUALITY_LABEL_AUTOLABEL_ARGS_ERROR: str = "人工标注阈值设置范围应为数字范围是0~1"
RESP_QUALITY_LABEL_CHECK_ARGS_QUESTION_CONTENT: str = "你确定要执行此操作吗,请确保参数输入正确"
RESP_QUALITY_LABEL_KEY_VALUE = {
1: "Good",
0: "Bad",
-1: "None"
}
# 禁止实例化
def __new__(cls):
raise TypeError("Constants class cannot be instantiated")

View File

@ -94,13 +94,13 @@ class Ui_MainWindow_resp_quality_label(object):
self.gridLayout_5.addWidget(self.pushButton_calculate_peaks_save, 2, 0, 1, 1)
self.pushButton_input_data_and_label = QPushButton(self.groupBox_left)
self.pushButton_input_data_and_label.setObjectName(u"pushButton_input_data_and_label")
sizePolicy.setHeightForWidth(self.pushButton_input_data_and_label.sizePolicy().hasHeightForWidth())
self.pushButton_input_data_and_label.setSizePolicy(sizePolicy)
self.pushButton_input_data_and_label.setFont(font1)
self.pushButton_input_and_label = QPushButton(self.groupBox_left)
self.pushButton_input_and_label.setObjectName(u"pushButton_input_and_label")
sizePolicy.setHeightForWidth(self.pushButton_input_and_label.sizePolicy().hasHeightForWidth())
self.pushButton_input_and_label.setSizePolicy(sizePolicy)
self.pushButton_input_and_label.setFont(font1)
self.gridLayout_5.addWidget(self.pushButton_input_data_and_label, 0, 1, 3, 1)
self.gridLayout_5.addWidget(self.pushButton_input_and_label, 0, 1, 3, 1)
self.verticalLayout_2.addLayout(self.gridLayout_5)
@ -135,14 +135,16 @@ class Ui_MainWindow_resp_quality_label(object):
self.doubleSpinBox_quality_threshold1 = QDoubleSpinBox(self.groupBox_autoqualitylabel_options)
self.doubleSpinBox_quality_threshold1.setObjectName(u"doubleSpinBox_quality_threshold1")
self.doubleSpinBox_quality_threshold1.setFont(font1)
self.doubleSpinBox_quality_threshold1.setMaximum(10000.000000000000000)
self.doubleSpinBox_quality_threshold1.setMaximum(1.000000000000000)
self.doubleSpinBox_quality_threshold1.setSingleStep(0.100000000000000)
self.gridLayout_3.addWidget(self.doubleSpinBox_quality_threshold1, 0, 1, 1, 1)
self.doubleSpinBox_quality_threshold2 = QDoubleSpinBox(self.groupBox_autoqualitylabel_options)
self.doubleSpinBox_quality_threshold2.setObjectName(u"doubleSpinBox_quality_threshold2")
self.doubleSpinBox_quality_threshold2.setFont(font1)
self.doubleSpinBox_quality_threshold2.setMaximum(10000.000000000000000)
self.doubleSpinBox_quality_threshold2.setMaximum(1.000000000000000)
self.doubleSpinBox_quality_threshold2.setSingleStep(0.100000000000000)
self.gridLayout_3.addWidget(self.doubleSpinBox_quality_threshold2, 1, 1, 1, 1)
@ -201,14 +203,16 @@ class Ui_MainWindow_resp_quality_label(object):
self.doubleSpinBox_fillterMode_custom_low = QDoubleSpinBox(self.groupBox_threshold_setting)
self.doubleSpinBox_fillterMode_custom_low.setObjectName(u"doubleSpinBox_fillterMode_custom_low")
self.doubleSpinBox_fillterMode_custom_low.setFont(font1)
self.doubleSpinBox_fillterMode_custom_low.setMaximum(10000.000000000000000)
self.doubleSpinBox_fillterMode_custom_low.setMaximum(1.000000000000000)
self.doubleSpinBox_fillterMode_custom_low.setSingleStep(0.100000000000000)
self.gridLayout_6.addWidget(self.doubleSpinBox_fillterMode_custom_low, 3, 1, 1, 1)
self.doubleSpinBox_fillterMode_custom_high = QDoubleSpinBox(self.groupBox_threshold_setting)
self.doubleSpinBox_fillterMode_custom_high.setObjectName(u"doubleSpinBox_fillterMode_custom_high")
self.doubleSpinBox_fillterMode_custom_high.setFont(font1)
self.doubleSpinBox_fillterMode_custom_high.setMaximum(10000.000000000000000)
self.doubleSpinBox_fillterMode_custom_high.setMaximum(1.000000000000000)
self.doubleSpinBox_fillterMode_custom_high.setSingleStep(0.100000000000000)
self.gridLayout_6.addWidget(self.doubleSpinBox_fillterMode_custom_high, 3, 3, 1, 1)
@ -229,6 +233,7 @@ class Ui_MainWindow_resp_quality_label(object):
self.radioButton_orgBcg_fillterMode_preset = QRadioButton(self.groupBox_threshold_setting)
self.radioButton_orgBcg_fillterMode_preset.setObjectName(u"radioButton_orgBcg_fillterMode_preset")
self.radioButton_orgBcg_fillterMode_preset.setFont(font1)
self.radioButton_orgBcg_fillterMode_preset.setChecked(True)
self.gridLayout_6.addWidget(self.radioButton_orgBcg_fillterMode_preset, 0, 0, 1, 1)
@ -471,7 +476,7 @@ class Ui_MainWindow_resp_quality_label(object):
self.pushButton_calculate_peaks.setText(QCoreApplication.translate("MainWindow_resp_quality_label", u"\u8ba1\u7b97\u5cf0\u503c\u5e76\u7ed8\u5236", None))
self.pushButton_input_and_calculate_peaks.setText(QCoreApplication.translate("MainWindow_resp_quality_label", u"\u5bfc\u5165\u5e76\u7b97\u6cd5\u5b9a\u4f4d\u5cf0\u503c", None))
self.pushButton_calculate_peaks_save.setText(QCoreApplication.translate("MainWindow_resp_quality_label", u"\u4fdd\u5b58\u5cf0\u503c\u7ed3\u679c", None))
self.pushButton_input_data_and_label.setText(QCoreApplication.translate("MainWindow_resp_quality_label", u"\u5bfc\u5165\u5e76\u5f00\u59cb\u6807\u6ce8", None))
self.pushButton_input_and_label.setText(QCoreApplication.translate("MainWindow_resp_quality_label", u"\u5bfc\u5165\u5e76\u5f00\u59cb\u6807\u6ce8", None))
self.groupBox_autoqualitylabel_options.setTitle(QCoreApplication.translate("MainWindow_resp_quality_label", u"\u4eba\u5de5\u6807\u6ce8\u9608\u503c\u8bbe\u7f6e", None))
self.label_6.setText(QCoreApplication.translate("MainWindow_resp_quality_label", u"threshold[1]", None))
self.label_5.setText(QCoreApplication.translate("MainWindow_resp_quality_label", u"threshold[0]", None))

View File

@ -122,7 +122,7 @@
</widget>
</item>
<item row="0" column="1" rowspan="3">
<widget class="QPushButton" name="pushButton_input_data_and_label">
<widget class="QPushButton" name="pushButton_input_and_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
@ -204,7 +204,10 @@
</font>
</property>
<property name="maximum">
<double>10000.000000000000000</double>
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
@ -216,7 +219,10 @@
</font>
</property>
<property name="maximum">
<double>10000.000000000000000</double>
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
@ -324,7 +330,10 @@
</font>
</property>
<property name="maximum">
<double>10000.000000000000000</double>
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
@ -336,7 +345,10 @@
</font>
</property>
<property name="maximum">
<double>10000.000000000000000</double>
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
@ -380,6 +392,9 @@
<property name="text">
<string>预设</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">

View File

@ -100,10 +100,10 @@ class Ui_MainWindow_resp_quality_label_input_setting(object):
self.verticalLayout_3.addLayout(self.horizontalLayout_3)
self.plainTextEdit_file_path_input_Tho = QPlainTextEdit(self.groupBox_file_path_input_Tho)
self.plainTextEdit_file_path_input_Tho.setObjectName(u"plainTextEdit_file_path_input_Tho")
self.plainTextEdit_file_path_input_signal_Tho = QPlainTextEdit(self.groupBox_file_path_input_Tho)
self.plainTextEdit_file_path_input_signal_Tho.setObjectName(u"plainTextEdit_file_path_input_signal_Tho")
self.verticalLayout_3.addWidget(self.plainTextEdit_file_path_input_Tho)
self.verticalLayout_3.addWidget(self.plainTextEdit_file_path_input_signal_Tho)
self.verticalLayout_3.setStretch(0, 1)
self.verticalLayout_3.setStretch(1, 2)
@ -181,8 +181,8 @@ class Ui_MainWindow_resp_quality_label_input_setting(object):
self.plainTextEdit_file_path_input_signal_OrgBCG.setPlaceholderText(QCoreApplication.translate("MainWindow_resp_quality_label_input_setting", u"\u6587\u4ef6\u8def\u5f84", None))
self.groupBox_file_path_input_Tho.setTitle(QCoreApplication.translate("MainWindow_resp_quality_label_input_setting", u"\u540c\u6b65\u540e\u7684Effort Tho\u8def\u5f84", None))
self.label_3.setText(QCoreApplication.translate("MainWindow_resp_quality_label_input_setting", u"\u91c7\u6837\u7387(Hz)\uff1a", None))
self.plainTextEdit_file_path_input_Tho.setPlainText("")
self.plainTextEdit_file_path_input_Tho.setPlaceholderText(QCoreApplication.translate("MainWindow_resp_quality_label_input_setting", u"\u6587\u4ef6\u8def\u5f84", None))
self.plainTextEdit_file_path_input_signal_Tho.setPlainText("")
self.plainTextEdit_file_path_input_signal_Tho.setPlaceholderText(QCoreApplication.translate("MainWindow_resp_quality_label_input_setting", u"\u6587\u4ef6\u8def\u5f84", None))
self.groupBox_file_path_input_artifact.setTitle(QCoreApplication.translate("MainWindow_resp_quality_label_input_setting", u"\u4f53\u52a8Artifact_a\u8def\u5f84", None))
self.plainTextEdit_file_path_input_artifact.setPlainText("")
self.plainTextEdit_file_path_input_artifact.setPlaceholderText(QCoreApplication.translate("MainWindow_resp_quality_label_input_setting", u"\u6587\u4ef6\u8def\u5f84", None))

View File

@ -126,7 +126,7 @@
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="plainTextEdit_file_path_input_Tho">
<widget class="QPlainTextEdit" name="plainTextEdit_file_path_input_signal_Tho">
<property name="plainText">
<string/>
</property>