Merge branch 'master' into cxh_dev

This commit is contained in:
marques
2025-06-10 14:24:57 +08:00
12 changed files with 369 additions and 20 deletions

View File

@ -7,11 +7,11 @@
每个功能运行时,若./Config目录下不存在该功能对应的yaml配置文件则程序将创建一份默认的配置文件。配置文件的内容主要涉及一些对应功能的界面默认初始值的设置此配置文件可以根据用户需要自行修改或是在修改了相应参数后在导入设置界面中单击“确定”即可保存相关参数到yaml文件中。
## TODO LIST
1、根据选定区域获取峰值时将绘制的区域设置为有上限和下限的矩形根据矩形获取到的横纵区域来计算峰值
~~1、根据选定区域获取峰值时将绘制的区域设置为有上限和下限的矩形根据矩形获取到的横纵区域来计算峰值~~
~~2、体动选取区域的判别尚未做的很完整选中多个已有的体动的区域时可能会出现问题~~
3、部分模块在导入失败后重新导入时会出现问题已知模块有<人工纠正><体动标注><呼吸可用性及间期标注><睡眠呼吸暂停事件标注>,主要是涉及到按钮状态的设置,有待后续优化。当前将这些有涉及到的功能,禁止了导入数据后在不关闭界面的情况下直接重新导入
~~3、部分模块在导入失败后重新导入时会出现问题已知模块有<人工纠正>、<体动标注>、<呼吸可用性及间期标注>、<睡眠呼吸暂停事件标注>,主要是涉及到按钮状态的设置,有待后续优化。当前将这些有涉及到的功能,禁止了导入数据后在不关闭界面的情况下直接重新导入~~
4、在J峰算法定位的时候滤波导致的信号偏移导致之后的峰值坐标点与实际峰值出现偏移
@ -21,7 +21,7 @@
~~7、各个模块中的检测父级文件夹是否存在的功能仍存在问题无法正确创建文件夹~~
8、将导入设置中的采样率修改为自动获取数据文件名中的采样率
~~8、将导入设置中的采样率修改为自动获取数据文件名中的采样率~~
## 1、主菜单

View File

@ -87,8 +87,12 @@ class SettingWindow(QMainWindow):
self.root_path = root_path
self.sampID = sampID
self.msgBox = QMessageBox()
self.msgBox.setWindowTitle(Constants.MAINWINDOW_MSGBOX_TITLE)
self.config = None
self.__read_config__()
self.__examine_freq__()
self.ui.spinBox_input_freq_signal_OrgBCG.valueChanged.connect(self.__update_ui__)
self.ui.spinBox_input_freq_signal_Tho.valueChanged.connect(self.__update_ui__)
@ -237,6 +241,59 @@ class SettingWindow(QMainWindow):
str(self.ui.spinBox_input_freq_signal_SpO2.value()) +
Params.ENDSWITH_TXT))))
def __examine_freq__(self):
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():
Config["Path"]["Input_Tho"] = str(Path(Config["Path"]["Input_Tho"]).parent)
if Path(Config["Path"]["Input_Abd"]).is_file():
Config["Path"]["Input_Abd"] = str(Path(Config["Path"]["Input_Abd"]).parent)
if Path(Config["Path"]["Input_FlowT"]).is_file():
Config["Path"]["Input_FlowT"] = str(Path(Config["Path"]["Input_FlowT"]).parent)
if Path(Config["Path"]["Input_FlowP"]).is_file():
Config["Path"]["Input_FlowP"] = str(Path(Config["Path"]["Input_FlowP"]).parent)
if Path(Config["Path"]["Input_SpO2"]).is_file():
Config["Path"]["Input_SpO2"] = str(Path(Config["Path"]["Input_SpO2"]).parent)
result = PublicFunc.examine_file(Config["Path"]["Input_OrgBCG"], Filename.ORGBCG_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["OrgBCGFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.ORGBCG_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_Tho"], Filename.THO_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["ThoFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.THO_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_Abd"], Filename.ABD_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["AbdFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.ABD_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_FlowT"], Filename.FLOWT_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["FlowTFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.FLOWT_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_FlowP"], Filename.FLOWP_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["FlowPFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.FLOWP_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_SpO2"], Filename.SPO2_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["SpO2Freq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.SPO2_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
# 数据回显
self.ui.spinBox_input_freq_signal_OrgBCG.setValue(Config["InputConfig"]["OrgBCGFreq"])
self.ui.spinBox_input_freq_signal_Tho.setValue(Config["InputConfig"]["ThoFreq"])
self.ui.spinBox_input_freq_signal_Abd.setValue(Config["InputConfig"]["AbdFreq"])
self.ui.spinBox_input_freq_signal_FlowT.setValue(Config["InputConfig"]["FlowTFreq"])
self.ui.spinBox_input_freq_signal_FlowP.setValue(Config["InputConfig"]["FlowPFreq"])
self.ui.spinBox_input_freq_signal_SpO2.setValue(Config["InputConfig"]["SpO2Freq"])
class MainWindow_SA_label(QMainWindow):

View File

@ -86,8 +86,12 @@ class SettingWindow(QMainWindow):
self.root_path = root_path
self.sampID = sampID
self.msgBox = QMessageBox()
self.msgBox.setWindowTitle(Constants.MAINWINDOW_MSGBOX_TITLE)
self.config = None
self.__read_config__()
self.__examine_freq__()
self.ui.spinBox_input_orgBcg_freq.valueChanged.connect(self.__update_ui__)
self.ui.spinBox_input_Tho_freq.valueChanged.connect(self.__update_ui__)
@ -195,6 +199,35 @@ class SettingWindow(QMainWindow):
str(self.ui.spinBox_input_Abd_freq.value()) +
Params.ENDSWITH_TXT))))
def __examine_freq__(self):
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():
Config["Path"]["Input_Tho"] = str(Path(Config["Path"]["Input_Tho"]).parent)
if Path(Config["Path"]["Input_Abd"]).is_file():
Config["Path"]["Input_Abd"] = str(Path(Config["Path"]["Input_Abd"]).parent)
result = PublicFunc.examine_file(Config["Path"]["Input_orgBcg"], Filename.ORGBCG_RAW, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["orgBcgFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.ORGBCG_RAW + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_Tho"], Filename.THO_RAW, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["ThoFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.THO_RAW + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_Abd"], Filename.ABD_RAW, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["AbdFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.ABD_RAW + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
# 数据回显
self.ui.spinBox_input_orgBcg_freq.setValue(Config["InputConfig"]["orgBcgFreq"])
self.ui.spinBox_input_Tho_freq.setValue(Config["InputConfig"]["ThoFreq"])
self.ui.spinBox_input_Abd_freq.setValue(Config["InputConfig"]["AbdFreq"])
class MainWindow_approximately_align(QMainWindow):
@ -980,7 +1013,6 @@ class MainWindow_approximately_align(QMainWindow):
return Result().failure(info=Constants.DRAW_FAILURE + "\n" + format_exc())
class Data:
def __init__(self):
@ -994,7 +1026,6 @@ class Data:
self.processed_downsample_Tho = None
self.processed_downsample_Abd = None
def open_file(self):
if Path(Config["Path"]["Input_orgBcg"]).is_file():
Config["Path"]["Input_orgBcg"] = str(Path(Config["Path"]["Input_orgBcg"]).parent)

View File

@ -71,8 +71,12 @@ class SettingWindow(QMainWindow):
self.root_path = root_path
self.sampID = sampID
self.msgBox = QMessageBox()
self.msgBox.setWindowTitle(Constants.MAINWINDOW_MSGBOX_TITLE)
self.config = None
self.__read_config__()
self.__examine_freq__()
self.ui.spinBox_input_freq_orgBcg.valueChanged.connect(self.__update_ui__)
self.ui.spinBox_input_freq_BCG.valueChanged.connect(self.__update_ui__)
@ -152,6 +156,27 @@ class SettingWindow(QMainWindow):
str(self.ui.spinBox_input_freq_BCG.value()) +
Params.ENDSWITH_TXT))))
def __examine_freq__(self):
if Path(Config["Path"]["Input_orgBcg"]).is_file():
Config["Path"]["Input_orgBcg"] = str(Path(Config["Path"]["Input_orgBcg"]).parent)
if Path(Config["Path"]["Input_BCG"]).is_file():
Config["Path"]["Input_BCG"] = str(Path(Config["Path"]["Input_BCG"]).parent)
result = PublicFunc.examine_file(Config["Path"]["Input_orgBcg"], Filename.ORGBCG_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["orgBcgFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.ORGBCG_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_BCG"], Filename.BCG_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["BCGFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.BCG_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
# 数据回显
self.ui.spinBox_input_freq_orgBcg.setValue(Config["InputConfig"]["orgBcgFreq"])
self.ui.spinBox_input_freq_BCG.setValue(Config["InputConfig"]["BCGFreq"])
class MainWindow_artifact_label(QMainWindow):

View File

@ -73,8 +73,12 @@ class SettingWindow(QMainWindow):
self.root_path = root_path
self.sampID = sampID
self.msgBox = QMessageBox()
self.msgBox.setWindowTitle(Constants.MAINWINDOW_MSGBOX_TITLE)
self.config = None
self.__read_config__()
self.__examine_freq__()
self.ui.spinBox_input_freq_signal_BCG.valueChanged.connect(self.__update_ui__)
self.ui.radioButton_30s_mode.clicked.connect(self.__update_mode__)
@ -149,6 +153,19 @@ class SettingWindow(QMainWindow):
elif self.ui.radioButton_10s_mode.isChecked():
Config["Mode"] = "10s"
def __examine_freq__(self):
if Path(Config["Path"]["Input_BCG"]).is_file():
Config["Path"]["Input_BCG"] = str(Path(Config["Path"]["Input_BCG"]).parent)
result = PublicFunc.examine_file(Config["Path"]["Input_BCG"], Filename.BCG_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["BCGFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.BCG_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
# 数据回显
self.ui.spinBox_input_freq_signal_BCG.setValue(Config["InputConfig"]["BCGFreq"])
class MainWindow_bcg_quality_label(QMainWindow):
@ -990,7 +1007,7 @@ class Data():
result = PublicFunc.examine_file(Config["Path"]["Input_BCG"], Filename.BCG_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["Path"]["Input_BCG"] = result.data["path"]
Config["InputConfig"]["ThoFreq"] = result.data["freq"]
Config["InputConfig"]["BCGFreq"] = result.data["freq"]
else:
return result

View File

@ -51,8 +51,12 @@ class SettingWindow(QMainWindow):
self.root_path = root_path
self.sampID = sampID
self.msgBox = QMessageBox()
self.msgBox.setWindowTitle(Constants.MAINWINDOW_MSGBOX_TITLE)
self.config = None
self.__read_config__()
self.__examine_freq__()
self.ui.spinBox_input_freq.valueChanged.connect(self.__update_ui__)
self.ui.pushButton_confirm.clicked.connect(self.__write_config__)
@ -112,6 +116,19 @@ class SettingWindow(QMainWindow):
str(self.ui.spinBox_input_freq.value()) +
Params.ENDSWITH_TXT))))
def __examine_freq__(self):
if Path(Config["Path"]["Input"]).is_file():
Config["Path"]["Input"] = str(Path(Config["Path"]["Input"]).parent)
result = PublicFunc.examine_file(Config["Path"]["Input"], Filename.BCG_FILTER, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["Freq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.BCG_FILTER + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
# 数据回显
self.ui.spinBox_input_freq.setValue(Config["InputConfig"]["Freq"])
class MainWindow_detect_Jpeak(QMainWindow):

View File

@ -51,8 +51,12 @@ class SettingWindow(QMainWindow):
self.root_path = root_path
self.sampID = sampID
self.msgBox = QMessageBox()
self.msgBox.setWindowTitle(Constants.MAINWINDOW_MSGBOX_TITLE)
self.config = None
self.__read_config__()
self.__examine_freq__()
self.ui.spinBox_input_freq.valueChanged.connect(self.__update_ui__)
self.ui.pushButton_confirm.clicked.connect(self.__write_config__)
@ -109,6 +113,20 @@ class SettingWindow(QMainWindow):
str(self.ui.spinBox_input_freq.value()) +
Params.ENDSWITH_TXT))))
def __examine_freq__(self):
if Path(Config["Path"]["Input"]).is_file():
Config["Path"]["Input"] = str(Path(Config["Path"]["Input"]).parent)
result = PublicFunc.examine_file(Config["Path"]["Input"], Filename.ECG_FILTER, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["Freq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.ECG_FILTER + Constants.FAILURE_REASON["Get_Freq_Not_Correct"],
Constants.MSGBOX_TYPE_ERROR)
# 数据回显
self.ui.spinBox_input_freq.setValue(Config["InputConfig"]["Freq"])
class MainWindow_detect_Rpeak(QMainWindow):

View File

@ -60,8 +60,12 @@ class SettingWindow(QMainWindow):
self.root_path = root_path
self.sampID = sampID
self.msgBox = QMessageBox()
self.msgBox.setWindowTitle(Constants.MAINWINDOW_MSGBOX_TITLE)
self.config = None
self.__read_config__()
self.__examine_freq__()
self.ui.spinBox_input_freq_signal.valueChanged.connect(self.__update_ui__)
self.ui.spinBox_bandPassOrder.valueChanged.connect(self.__update_ui__)
@ -192,6 +196,25 @@ class SettingWindow(QMainWindow):
else:
raise ValueError("模式不存在")
def __examine_freq__(self):
if Config["Mode"] == "BCG":
signal = Filename.BCG_FILTER
elif Config["Mode"] == "ECG":
signal = Filename.ECG_FILTER
else:
raise ValueError("模式不存在")
if Path(Config["Path"]["Input_Signal"]).is_file():
Config["Path"]["Input_Signal"] = str(Path(Config["Path"]["Input_Signal"]).parent)
result = PublicFunc.examine_file(Config["Path"]["Input_Signal"], signal, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["Freq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, signal + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
# 数据回显
self.ui.spinBox_input_freq_signal.setValue(Config["InputConfig"]["Freq"])
class MainWindow_label_check(QMainWindow):
@ -758,6 +781,7 @@ class MainWindow_label_check(QMainWindow):
elif event.button == 3:
self.is_right_button_pressed = True
self.figToolbar.rect_start_x = event.xdata
self.figToolbar.rect_start_y = event.ydata
# 如果矩形patch已存在先移除
if self.figToolbar.rect_patch_ax0 is not None and self.figToolbar.rect_patch_ax1 is not None:
self.figToolbar.rect_patch_ax0.remove()
@ -768,9 +792,11 @@ class MainWindow_label_check(QMainWindow):
def on_release(self, event):
if self.figToolbar.action_Label_Multiple.isChecked():
if self.figToolbar.rect_start_x is not None:
if self.figToolbar.rect_start_x is not None and self.figToolbar.rect_start_y is not None:
self.figToolbar.rect_end_x = event.xdata
if self.figToolbar.rect_start_x is not None and self.figToolbar.rect_end_x is not None:
self.figToolbar.rect_end_y = event.ydata
if ((self.figToolbar.rect_start_x is not None and self.figToolbar.rect_end_x is not None) and
(self.figToolbar.rect_start_y is not None and self.figToolbar.rect_end_y is not None)):
if self.figToolbar.rect_start_x < self.figToolbar.rect_end_x:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_end_x
@ -780,9 +806,20 @@ class MainWindow_label_check(QMainWindow):
else:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_start_x
if self.figToolbar.rect_start_y < self.figToolbar.rect_end_y:
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_end_y
elif self.figToolbar.rect_start_y > self.figToolbar.rect_end_y:
rect_bottom = self.figToolbar.rect_end_y
rect_top = self.figToolbar.rect_start_y
else:
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_start_y
else:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_start_x
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_start_y
if event.button == 1 and self.is_left_button_pressed:
self.is_left_button_pressed = False
if rect_left < 0:
@ -796,6 +833,13 @@ class MainWindow_label_check(QMainWindow):
rect_left = 0
rect_right = 0
selected_area_for_add_points = self.data.processed_data[int(rect_left):int(rect_right)]
# 找到子列表的最小值
min_value = min(selected_area_for_add_points)
# 遍历子列表,将不满足条件的元素替换为最小值
selected_area_for_add_points = [
y if rect_bottom < y < rect_top else min_value
for y in selected_area_for_add_points
]
peaks_idx, _ = find_peaks(selected_area_for_add_points,
height=Config["FindPeaks"]["MinHeight"],
distance=Config["FindPeaks"]["MinInterval"])
@ -827,6 +871,8 @@ class MainWindow_label_check(QMainWindow):
self.__redraw_peaks__()
self.figToolbar.rect_start_x = None
self.figToolbar.rect_end_x = None
self.figToolbar.rect_start_y = None
self.figToolbar.rect_end_y = None
self.data.corrected_peak.sort()
self.data.corrected_peak_y = [self.data.processed_data[x] for x in self.data.corrected_peak]
self.__update_tableWidget_and_info__()
@ -850,6 +896,8 @@ class MainWindow_label_check(QMainWindow):
def on_hold(self, event):
if self.figToolbar.rect_start_x is not None and event.xdata is not None:
self.figToolbar.rect_end_x = event.xdata
if self.figToolbar.rect_start_y is not None and event.ydata is not None:
self.figToolbar.rect_end_y = event.ydata
# 如果矩形patch不存在则创建一个新的
if self.figToolbar.rect_patch_ax0 is None:
@ -878,14 +926,24 @@ class MainWindow_label_check(QMainWindow):
# 更新矩形patch的位置和大小
x_start = self.figToolbar.rect_start_x
x_end = self.figToolbar.rect_end_x
rect_down = min(self.ax0.get_ylim()[0], self.ax1.get_ylim()[0]) - 1000
rect_up = max(self.ax0.get_ylim()[1], self.ax1.get_ylim()[1]) + 1000
self.figToolbar.rect_patch_ax0.set_xy((min(x_start, x_end), rect_down))
if self.is_left_button_pressed:
y_start = self.figToolbar.rect_start_y
y_end = self.figToolbar.rect_end_y
self.figToolbar.rect_patch_ax0.set_xy((min(x_start, x_end), min(y_start, y_end)))
self.figToolbar.rect_patch_ax0.set_height(abs(y_end - y_start))
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), min(y_start, y_end)))
self.figToolbar.rect_patch_ax1.set_height(abs(y_end - y_start))
elif self.is_right_button_pressed:
y_start = min(self.ax0.get_ylim()[0], self.ax1.get_ylim()[0]) - 1000
y_end = max(self.ax0.get_ylim()[1], self.ax1.get_ylim()[1]) + 1000
self.figToolbar.rect_patch_ax0.set_xy((min(x_start, x_end), y_start))
self.figToolbar.rect_patch_ax0.set_height(abs(y_end - y_start))
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), y_start))
self.figToolbar.rect_patch_ax1.set_height(abs(y_end - y_start))
self.figToolbar.rect_patch_ax0.set_width(abs(x_end - x_start))
self.figToolbar.rect_patch_ax0.set_height(rect_up - rect_down)
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), rect_down))
self.figToolbar.rect_patch_ax1.set_width(abs(x_end - x_start))
self.figToolbar.rect_patch_ax1.set_height(rect_up - rect_down)
self.canvas.draw()
@ -1071,6 +1129,8 @@ class CustomNavigationToolbar(NavigationToolbar2QT):
# 初始化矩形选择区域
self.rect_start_x = None
self.rect_end_x = None
self.rect_start_y = None
self.rect_end_y = None
self.rect_patch_ax0 = None # 用于绘制矩形的patch
self.rect_patch_ax1 = None # 用于绘制矩形的patch

View File

@ -92,8 +92,12 @@ class SettingWindow(QMainWindow):
self.root_path = root_path
self.sampID = sampID
self.msgBox = QMessageBox()
self.msgBox.setWindowTitle(Constants.MAINWINDOW_MSGBOX_TITLE)
self.config = None
self.__read_config__()
self.__examine_freq__()
self.ui.spinBox_input_freq_orgBcg.valueChanged.connect(self.__update_ui__)
self.ui.spinBox_input_freq_BCG.valueChanged.connect(self.__update_ui__)
@ -255,6 +259,41 @@ class SettingWindow(QMainWindow):
str(self.ui.spinBox_input_freq_ECG.value()) +
Params.ENDSWITH_TXT))))
def __examine_freq__(self):
if Path(Config["Path"]["Input_OrgBCG"]).is_file():
Config["Path"]["Input_OrgBCG"] = str(Path(Config["Path"]["Input_OrgBCG"]).parent)
if Path(Config["Path"]["Input_BCG"]).is_file():
Config["Path"]["Input_BCG"] = str(Path(Config["Path"]["Input_BCG"]).parent)
if Path(Config["Path"]["Input_Jpeak"]).is_file():
Config["Path"]["Input_Jpeak"] = str(Path(Config["Path"]["Input_Jpeak"]).parent)
if Path(Config["Path"]["Input_ECG"]).is_file():
Config["Path"]["Input_ECG"] = str(Path(Config["Path"]["Input_ECG"]).parent)
if Path(Config["Path"]["Input_Rpeak"]).is_file():
Config["Path"]["Input_Rpeak"] = str(Path(Config["Path"]["Input_Rpeak"]).parent)
result = PublicFunc.examine_file(Config["Path"]["Input_OrgBCG"], Filename.ORGBCG_RAW, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["orgBcgFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.ORGBCG_RAW + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_BCG"], Filename.BCG_FILTER, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["BCGFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.BCG_FILTER + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_ECG"], Filename.ECG_FILTER, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["ECGFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.ECG_FILTER + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
# 数据回显
self.ui.spinBox_input_freq_orgBcg.setValue(Config["InputConfig"]["orgBcgFreq"])
self.ui.spinBox_input_freq_BCG.setValue(Config["InputConfig"]["BCGFreq"])
self.ui.spinBox_input_freq_ECG.setValue(Config["InputConfig"]["ECGFreq"])
class MainWindow_precisely_align(QMainWindow):

View File

@ -53,8 +53,12 @@ class SettingWindow(QMainWindow):
self.root_path = root_path
self.sampID = sampID
self.msgBox = QMessageBox()
self.msgBox.setWindowTitle(Constants.MAINWINDOW_MSGBOX_TITLE)
self.config = None
self.__read_config__()
self.__examine_freq__()
self.ui.spinBox_input_freq.valueChanged.connect(self.__update_ui__)
self.ui.spinBox_output_freq.valueChanged.connect(self.__update_ui__)
@ -140,6 +144,26 @@ class SettingWindow(QMainWindow):
else:
raise ValueError("模式不存在")
def __examine_freq__(self):
if Config["Mode"] == "BCG":
signal = Filename.ORGBCG_RAW
elif Config["Mode"] == "ECG":
signal = Filename.ECG_RAW
else:
raise ValueError("模式不存在")
if Path(Config["Path"]["Input"]).is_file():
Config["Path"]["Input"] = str(Path(Config["Path"]["Input"]).parent)
result = PublicFunc.examine_file(Config["Path"]["Input"], signal, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["Freq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, signal + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
# 数据回显
self.ui.spinBox_input_freq.setValue(Config["InputConfig"]["Freq"])
class MainWindow_preprocess(QMainWindow):

View File

@ -74,8 +74,12 @@ class SettingWindow(QMainWindow):
self.root_path = root_path
self.sampID = sampID
self.msgBox = QMessageBox()
self.msgBox.setWindowTitle(Constants.MAINWINDOW_MSGBOX_TITLE)
self.config = None
self.__read_config__()
self.__examine_freq__()
self.ui.spinBox_input_freq_signal_OrgBCG.valueChanged.connect(self.__update_ui__)
self.ui.spinBox_input_freq_signal_Tho.valueChanged.connect(self.__update_ui__)
@ -159,6 +163,27 @@ class SettingWindow(QMainWindow):
str(self.ui.spinBox_input_freq_signal_Tho.value()) +
Params.ENDSWITH_TXT))))
def __examine_freq__(self):
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():
Config["Path"]["Input_Tho"] = str(Path(Config["Path"]["Input_Tho"]).parent)
result = PublicFunc.examine_file(Config["Path"]["Input_OrgBCG"], Filename.ORGBCG_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["OrgBCGFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.ORGBCG_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
result = PublicFunc.examine_file(Config["Path"]["Input_Tho"], Filename.THO_SYNC, Params.ENDSWITH_TXT)
if result.status:
Config["InputConfig"]["ThoFreq"] = result.data["freq"]
else:
PublicFunc.msgbox_output(self, Filename.THO_SYNC + Constants.FAILURE_REASON["Get_Freq_Not_Correct"], Constants.MSGBOX_TYPE_ERROR)
# 数据回显
self.ui.spinBox_input_freq_signal_OrgBCG.setValue(Config["InputConfig"]["OrgBCGFreq"])
self.ui.spinBox_input_freq_signal_Tho.setValue(Config["InputConfig"]["ThoFreq"])
class MainWindow_resp_quality_label(QMainWindow):
@ -1166,6 +1191,7 @@ class MainWindow_resp_quality_label(QMainWindow):
elif event.button == 3:
self.is_right_button_pressed = True
self.figToolbar.rect_start_x = event.xdata
self.figToolbar.rect_start_y = event.ydata
# 如果矩形patch已存在先移除
if self.figToolbar.rect_patch_ax1 is not None:
self.figToolbar.rect_patch_ax1.remove()
@ -1174,9 +1200,11 @@ class MainWindow_resp_quality_label(QMainWindow):
def on_release(self, event):
if self.figToolbar.action_Label_Multiple.isChecked():
if self.figToolbar.rect_start_x is not None:
if self.figToolbar.rect_start_x is not None and self.figToolbar.rect_start_y is not None:
self.figToolbar.rect_end_x = event.xdata
if self.figToolbar.rect_start_x is not None and self.figToolbar.rect_end_x is not None:
self.figToolbar.rect_end_y = event.ydata
if ((self.figToolbar.rect_start_x is not None and self.figToolbar.rect_end_x is not None) and
(self.figToolbar.rect_start_y is not None and self.figToolbar.rect_end_y is not None)):
if self.figToolbar.rect_start_x < self.figToolbar.rect_end_x:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_end_x
@ -1186,9 +1214,20 @@ class MainWindow_resp_quality_label(QMainWindow):
else:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_start_x
if self.figToolbar.rect_start_y < self.figToolbar.rect_end_y:
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_end_y
elif self.figToolbar.rect_start_y > self.figToolbar.rect_end_y:
rect_bottom = self.figToolbar.rect_end_y
rect_top = self.figToolbar.rect_start_y
else:
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_start_y
else:
rect_left = self.figToolbar.rect_start_x
rect_right = self.figToolbar.rect_start_x
rect_bottom = self.figToolbar.rect_start_y
rect_top = self.figToolbar.rect_start_y
if event.button == 1 and self.is_left_button_pressed:
self.is_left_button_pressed = False
if rect_left < Config["CurrentThoIndex"]:
@ -1205,6 +1244,13 @@ class MainWindow_resp_quality_label(QMainWindow):
rect_left = 0
rect_right = 0
selected_area_for_add_points = self.data.Tho_Processed[int(rect_left):int(rect_right)]
# 找到子列表的最小值
min_value = min(selected_area_for_add_points)
# 遍历子列表,将不满足条件的元素替换为最小值
selected_area_for_add_points = [
y if rect_bottom < y < rect_top else min_value
for y in selected_area_for_add_points
]
peaks_idx, _ = find_peaks(selected_area_for_add_points,
height=float(Config["FindPeaks"]["MinHeight"]),
distance=float(Config["FindPeaks"]["MinInterval"]))
@ -1243,6 +1289,8 @@ class MainWindow_resp_quality_label(QMainWindow):
self.data.Tho_peak_y = [self.data.Tho_Processed[x] for x in self.data.Tho_peak]
self.figToolbar.rect_start_x = None
self.figToolbar.rect_end_x = None
self.figToolbar.rect_start_y = None
self.figToolbar.rect_end_y = None
result = self.data.save_tho_peak()
if not result.status:
@ -1262,6 +1310,8 @@ class MainWindow_resp_quality_label(QMainWindow):
def on_hold(self, event):
if self.figToolbar.rect_start_x is not None and event.xdata is not None:
self.figToolbar.rect_end_x = event.xdata
if self.figToolbar.rect_start_y is not None and event.ydata is not None:
self.figToolbar.rect_end_y = event.ydata
# 如果矩形patch不存在则创建一个新的
if self.figToolbar.rect_patch_ax1 is None:
@ -1278,11 +1328,19 @@ class MainWindow_resp_quality_label(QMainWindow):
# 更新矩形patch的位置和大小
x_start = self.figToolbar.rect_start_x
x_end = self.figToolbar.rect_end_x
rect_down = self.ax1.get_ylim()[0] - 1000
rect_up = self.ax1.get_ylim()[1] + 1000
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), rect_down))
if self.is_left_button_pressed:
y_start = self.figToolbar.rect_start_y
y_end = self.figToolbar.rect_end_y
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), min(y_start, y_end)))
self.figToolbar.rect_patch_ax1.set_height(abs(y_end - y_start))
elif self.is_right_button_pressed:
y_start = min(self.ax0.get_ylim()[0], self.ax1.get_ylim()[0]) - 1000
y_end = max(self.ax0.get_ylim()[1], self.ax1.get_ylim()[1]) + 1000
self.figToolbar.rect_patch_ax1.set_xy((min(x_start, x_end), y_start))
self.figToolbar.rect_patch_ax1.set_height(abs(y_end - y_start))
self.figToolbar.rect_patch_ax1.set_width(abs(x_end - x_start))
self.figToolbar.rect_patch_ax1.set_height(rect_up - rect_down)
self.canvas.draw()
@ -1603,6 +1661,8 @@ class CustomNavigationToolbar(NavigationToolbar2QT):
# 初始化矩形选择区域
self.rect_start_x = None
self.rect_end_x = None
self.rect_start_y = None
self.rect_end_y = None
self.rect_patch_ax1 = None # 用于绘制矩形的patch
def home(self, *args):

View File

@ -114,6 +114,7 @@ class Constants:
"Save_File_Not_Found": "(保存路径不存在)",
"OrgBCG_Cut_Length_Not_Correct": "OrgBCG的切割长度不正确Pre+Post长度大于信号长度",
"PSG_Cut_Length_Not_Correct": "PSG的切割长度不正确Pre+Post长度大于信号长度",
"Get_Freq_Not_Correct": "(无法获取数据采样率,将填入配置文件中的采样率。可能是因为文件不存在或文件命名格式不正确导致,请检查数据)",
"Open_Data_Exception": "(打开数据异常)",
"Process_Exception": "(处理异常)",