添加ECG自动获取区间功能,优化相关提示信息

This commit is contained in:
marques
2025-06-04 22:26:32 +08:00
parent 064422fe9d
commit c46916a4ef
4 changed files with 216 additions and 22 deletions

View File

@ -9,7 +9,8 @@ from PySide6.QtWidgets import QMessageBox, QMainWindow, QApplication, QButtonGro
from matplotlib import gridspec, patches
from matplotlib.backends.backend_qt import NavigationToolbar2QT
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
from numpy import (diff, where, correlate, corrcoef, sum as np_sum, max as np_max, min as np_min, arange, array,
from numpy import (diff, where, correlate, corrcoef, searchsorted, sum as np_sum, max as np_max, min as np_min, arange,
array,
append, delete, abs as np_abs, argmin as np_argmin, argmax as np_argmax, asarray)
from overrides import overrides
from pandas import read_csv, DataFrame
@ -989,13 +990,31 @@ class MainWindow_precisely_align(QMainWindow):
Config["IV_Coordinate"]["BCG_front_2"] = self.ui.spinBox_BCG_front_JJIV_2.value()
Config["Coordinate"]["BCG_front_2"] = self.data.Jpeak[:-2][self.ui.spinBox_BCG_front_JJIV_2.value()]
self.ui.spinBox_BCG_front_Signal_2.setValue(Config["Coordinate"]["BCG_front_2"])
estimate_ECG_front_1 = self.data.get_corresponding_interval(Config["Coordinate"]["BCG_front_1"]).data[
"new_point"]
estimate_ECG_front_2 = self.data.get_corresponding_interval(Config["Coordinate"]["BCG_front_2"]).data[
"new_point"]
PublicFunc.text_output(self.ui, Constants.CORRESPONDING_INTERVAL_PROMOTE_TEMPLATE.format(
Config["Coordinate"]["BCG_front_1"],
Config["Coordinate"]["BCG_front_2"],
self.data.get_corresponding_interval(Config["Coordinate"]["BCG_front_1"]).data["new_point"],
self.data.get_corresponding_interval(Config["Coordinate"]["BCG_front_2"]).data["new_point"],
estimate_ECG_front_1, estimate_ECG_front_2
), Constants.TIPS_TYPE_INFO)
if self.ui.checkBox_ECG_autoset.isChecked():
extend_second = int(self.ui.spinBox_ECG_expend_second.value())
reponse = self.data.get_rriv_from_ecg_point(
estimate_ECG_front_1, extend_second, "right").data
Config["IV_Coordinate"]["ECG_front_1"] = reponse["estimate_RRIV"]
Config["Coordinate"]["ECG_front_1"] = reponse["extend_point"]
reponse = self.data.get_rriv_from_ecg_point(
estimate_ECG_front_2, extend_second, "left").data
Config["IV_Coordinate"]["ECG_front_2"] = reponse["estimate_RRIV"]
Config["Coordinate"]["ECG_front_2"] = reponse["extend_point"]
elif sender == self.ui.spinBox_BCG_back_JJIV_1:
if self.ui.spinBox_BCG_back_JJIV_1.value() >= len(self.data.Jpeak[:-2]):
self.ui.spinBox_BCG_back_JJIV_1.setValue(len(self.data.Jpeak[:-2]) - 1)
@ -1008,13 +1027,30 @@ class MainWindow_precisely_align(QMainWindow):
Config["IV_Coordinate"]["BCG_back_2"] = self.ui.spinBox_BCG_back_JJIV_2.value()
Config["Coordinate"]["BCG_back_2"] = self.data.Jpeak[:-2][self.ui.spinBox_BCG_back_JJIV_2.value()]
self.ui.spinBox_BCG_back_Signal_2.setValue(Config["Coordinate"]["BCG_back_2"])
estimate_ECG_back_1 = self.data.get_corresponding_interval(
Config["Coordinate"]["BCG_back_1"]).data["new_point"]
estimate_ECG_back_2 = self.data.get_corresponding_interval(
Config["Coordinate"]["BCG_back_2"]).data["new_point"]
PublicFunc.text_output(self.ui, Constants.CORRESPONDING_INTERVAL_PROMOTE_TEMPLATE.format(
Config["Coordinate"]["BCG_back_1"],
Config["Coordinate"]["BCG_back_2"],
self.data.get_corresponding_interval(Config["Coordinate"]["BCG_back_1"]).data["new_point"],
self.data.get_corresponding_interval(Config["Coordinate"]["BCG_back_2"]).data["new_point"],
estimate_ECG_back_1, estimate_ECG_back_2
), Constants.TIPS_TYPE_INFO)
if self.ui.checkBox_ECG_autoset.isChecked():
extend_second = int(self.ui.spinBox_ECG_expend_second.value())
reponse = self.data.get_rriv_from_ecg_point(
estimate_ECG_back_1, extend_second, "right").data
Config["IV_Coordinate"]["ECG_back_1"] = reponse["estimate_RRIV"]
Config["Coordinate"]["ECG_back_1"] = reponse["extend_point"]
reponse = self.data.get_rriv_from_ecg_point(
estimate_ECG_back_2, extend_second, "left").data
Config["IV_Coordinate"]["ECG_back_2"] = reponse["estimate_RRIV"]
Config["Coordinate"]["ECG_back_2"] = reponse["extend_point"]
elif sender == self.ui.spinBox_ECG_front_RRIV_1:
if self.ui.spinBox_ECG_front_RRIV_1.value() >= len(self.data.Rpeak[:-2]):
self.ui.spinBox_ECG_front_RRIV_1.setValue(len(self.data.Rpeak[:-2]) - 1)
@ -1312,30 +1348,64 @@ class MainWindow_precisely_align(QMainWindow):
Config["IV_Coordinate"]["BCG_front_2"] = indices[-1]
Config["Coordinate"]["BCG_front_1"] = self.data.Jpeak[:-2][indices[0]]
Config["Coordinate"]["BCG_front_2"] = self.data.Jpeak[:-2][indices[-1]]
estimate_ECG_front_1 = self.data.get_corresponding_interval(
Config["Coordinate"]["BCG_front_1"]).data["new_point"]
estimate_ECG_front_2 = self.data.get_corresponding_interval(
Config["Coordinate"]["BCG_front_2"]).data["new_point"]
PublicFunc.text_output(
self.ui,
Constants.CORRESPONDING_INTERVAL_PROMOTE_TEMPLATE.format(
Config["Coordinate"]["BCG_front_1"],
Config["Coordinate"]["BCG_front_2"],
self.data.get_corresponding_interval(
Config["Coordinate"]["BCG_front_1"]).data["new_point"],
self.data.get_corresponding_interval(
Config["Coordinate"]["BCG_front_2"]).data["new_point"],
estimate_ECG_front_1, estimate_ECG_front_2
), Constants.TIPS_TYPE_INFO)
if self.ui.checkBox_ECG_autoset.isChecked():
extend_second = int(self.ui.spinBox_ECG_expend_second.value())
reponse = self.data.get_rriv_from_ecg_point(
estimate_ECG_front_1, extend_second, "right").data
Config["IV_Coordinate"]["ECG_front_1"] = reponse["estimate_RRIV"]
Config["Coordinate"]["ECG_front_1"] = reponse["extend_point"]
reponse = self.data.get_rriv_from_ecg_point(
estimate_ECG_front_2, extend_second, "left").data
Config["IV_Coordinate"]["ECG_front_2"] = reponse["estimate_RRIV"]
Config["Coordinate"]["ECG_front_2"] = reponse["extend_point"]
elif self.ui.radioButton_BCG_back.isChecked():
Config["IV_Coordinate"]["BCG_back_1"] = indices[0]
Config["IV_Coordinate"]["BCG_back_2"] = indices[-1]
Config["Coordinate"]["BCG_back_1"] = self.data.Jpeak[:-2][indices[0]]
Config["Coordinate"]["BCG_back_2"] = self.data.Jpeak[:-2][indices[-1]]
estimate_ECG_back_1 = self.data.get_corresponding_interval(
Config["Coordinate"]["BCG_back_1"]).data["new_point"]
estimate_ECG_back_2 = self.data.get_corresponding_interval(
Config["Coordinate"]["BCG_back_2"]).data["new_point"]
PublicFunc.text_output(
self.ui, Constants.CORRESPONDING_INTERVAL_PROMOTE_TEMPLATE.format(
Config["Coordinate"]["BCG_back_1"],
Config["Coordinate"]["BCG_back_2"],
self.data.get_corresponding_interval(
Config["Coordinate"]["BCG_back_1"]).data["new_point"],
self.data.get_corresponding_interval(
Config["Coordinate"]["BCG_back_2"]).data["new_point"],
estimate_ECG_back_1, estimate_ECG_back_2
), Constants.TIPS_TYPE_INFO)
if self.ui.checkBox_ECG_autoset.isChecked():
extend_second = int(self.ui.spinBox_ECG_expend_second.value())
reponse = self.data.get_rriv_from_ecg_point(
estimate_ECG_back_1, extend_second, "right").data
Config["IV_Coordinate"]["ECG_back_1"] = reponse["estimate_RRIV"]
Config["Coordinate"]["ECG_back_1"] = reponse["extend_point"]
reponse = self.data.get_rriv_from_ecg_point(
estimate_ECG_back_2, extend_second, "left").data
Config["IV_Coordinate"]["ECG_back_2"] = reponse["estimate_RRIV"]
Config["Coordinate"]["ECG_back_2"] = reponse["extend_point"]
elif self.ui.radioButton_ECG_front.isChecked() or self.ui.radioButton_ECG_back.isChecked():
if rect_left < 0:
rect_left = 0
@ -1374,7 +1444,6 @@ class MainWindow_precisely_align(QMainWindow):
Config["Coordinate"]["ECG_back_1"] = self.data.Rpeak[:-2][indices[0]]
Config["Coordinate"]["ECG_back_2"] = self.data.Rpeak[:-2][indices[-1]]
self.figToolbar.rect_start_x = None
self.figToolbar.rect_end_x = None
@ -2138,6 +2207,24 @@ class Data:
return Result().success(info=Constants.PRECISELY_ALIGN_GET_CORRESPONDING_INTERVAL_FINISHED, data=result)
def get_rriv_from_ecg_point(self, point:int, expend_second:int, side="left"):
extend_point = expend_second * Config["InputConfig"]["UseFreq"]
if side == "left":
extend_point = max(point + extend_point, 0)
elif side == "right":
extend_point = min(point - extend_point, max(self.Rpeak))
else:
return Result().failure(info=Constants.PRECISELY_ALIGN_GET_RRIV_FROM_ECG_POINT_FAILURE +
Constants.FAILURE_REASON["Invalid_Side_Parameter"])
extend_estimate_RRIV = searchsorted(self.Rpeak[:-2], extend_point, side)
result = {
"estimate_RRIV": extend_estimate_RRIV,
"extend_point": extend_point
}
return Result().success(info=Constants.PRECISELY_ALIGN_GET_RRIV_FROM_ECG_POINT_FINISHED, data=result)
class CustomNavigationToolbar(NavigationToolbar2QT):