完成了<BCG的质量标注>的代码重构

This commit is contained in:
Yorusora
2025-05-23 10:25:25 +08:00
parent 54f3852b01
commit 6a325ba95b
9 changed files with 423 additions and 114 deletions

View File

@ -609,7 +609,7 @@ class MainWindow_SA_label(QMainWindow):
item = QTableWidgetItem(str(correct_End))
self.ui.tableWidget_label_add.setItem(index, 3, item)
remark = row.get("remark", None)
if str(remark) != "" and str(remark) != "nan" and row.get("isLabeled", None) == 1:
if str(remark) != Constants.STRING_IS_EMPTY and str(remark) != Constants.STRING_IS_NAN and row.get("isLabeled", None) == 1:
for col in range(self.ui.tableWidget_label_add.columnCount()):
item = self.ui.tableWidget_label_add.item(index, col)
item.setBackground(QColor(255, 200, 200))

View File

@ -188,12 +188,6 @@ class SettingWindow(QMainWindow):
Path(ConfigParams.ABD_RAW +
str(self.ui.spinBox_input_Abd_freq.value()) +
ConfigParams.ENDSWITH_TXT))))
self.ui.plainTextEdit_file_path_save.setPlainText(
str((Path(self.root_path) /
ConfigParams.PUBLIC_PATH_LABEL /
Path(str(self.sampID)) /
Path(ConfigParams.APPROXIMATELY_ALIGN_INFO +
ConfigParams.ENDSWITH_CSV))))
class MainWindow_approximately_align(QMainWindow):

View File

@ -3,12 +3,14 @@ from pathlib import Path
from traceback import format_exc
import matplotlib.pyplot as plt
from PySide6.QtCore import QCoreApplication
from PySide6.QtGui import QColor
from PySide6.QtWidgets import QMessageBox, QMainWindow, QApplication, QTableWidget, QTableWidgetItem
from matplotlib import gridspec
from matplotlib.backends.backend_qt import NavigationToolbar2QT
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
from numpy import array, int64, append, zeros, full, where, nan, arange, float64, isnan, place, count_nonzero, all as np_all
from numpy import array, int64, append, zeros, full, where, nan, arange, float64, isnan, place, count_nonzero, \
all as np_all, split
from overrides import overrides
from pandas import read_csv, DataFrame
from scipy.signal import resample, iirfilter, lfilter
@ -99,7 +101,7 @@ class SettingWindow(QMainWindow):
"Save": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_LABEL /
Path(str(self.sampID)))),
},
"Mode": "Undefined",
"Mode": "30s",
"DataPartNum": 0,
"CurrentDataIdx": 0,
"CurrentPartNum": 1,
@ -225,6 +227,33 @@ class MainWindow_bcg_quality_label(QMainWindow):
self.ui.pushButton_input_setting.clicked.connect(self.setting.show)
self.ui.pushButton_input.clicked.connect(self.__slot_btn_input__)
self.ui.pushButton_prev.clicked.connect(self.__slot_btn_move__)
self.ui.pushButton_next.clicked.connect(self.__slot_btn_move__)
self.ui.tableWidget_a1.cellDoubleClicked.connect(self.__slot_tablewidget_on_cell_double_clicked__)
self.ui.tableWidget_a2.cellDoubleClicked.connect(self.__slot_tablewidget_on_cell_double_clicked__)
self.ui.tableWidget_b1.cellDoubleClicked.connect(self.__slot_tablewidget_on_cell_double_clicked__)
self.ui.tableWidget_b2.cellDoubleClicked.connect(self.__slot_tablewidget_on_cell_double_clicked__)
self.ui.tableWidget_c.cellDoubleClicked.connect(self.__slot_tablewidget_on_cell_double_clicked__)
self.ui.tableWidget_f.cellDoubleClicked.connect(self.__slot_tablewidget_on_cell_double_clicked__)
self.ui.checkBox_highlight_longest_continuous.clicked.connect(self.__slot_checkBox_highlight_longest_continuous__)
self.ui.checkBox_display_afterfilter.clicked.connect(self.__slot_checkBox_display_afterfilter__)
self.ui.pushButton_invalid_signal_label.clicked.connect(self.__slot_btn_invalid_signal_label__)
self.ui.pushButton_Ctype_signal_label.clicked.connect(self.__slot_btn_Ctype_signal_label__)
self.ui.pushButton_a1.clicked.connect(self.__slot_btn_label__)
self.ui.pushButton_a2.clicked.connect(self.__slot_btn_label__)
self.ui.pushButton_b1.clicked.connect(self.__slot_btn_label__)
self.ui.pushButton_b2.clicked.connect(self.__slot_btn_label__)
self.ui.pushButton_c.clicked.connect(self.__slot_btn_label__)
self.ui.pushButton_f.clicked.connect(self.__slot_btn_label__)
self.ui.checkBox_allin.clicked.connect(self.__slot_checkBox__)
self.ui.checkBox_type1.clicked.connect(self.__slot_checkBox__)
self.ui.checkBox_type2.clicked.connect(self.__slot_checkBox__)
self.ui.checkBox_type3.clicked.connect(self.__slot_checkBox__)
self.ui.checkBox_type4.clicked.connect(self.__slot_checkBox__)
self.ui.checkBox_type5.clicked.connect(self.__slot_checkBox__)
self.ui.pushButton_prev.setShortcut(QCoreApplication.translate("MainWindow", ConfigParams.BCG_QUALITY_LABEL_BTN_PREV_SHORTCUT_KEY))
self.ui.pushButton_next.setShortcut(QCoreApplication.translate("MainWindow", ConfigParams.BCG_QUALITY_LABEL_BTN_NEXT_SHORTCUT_KEY))
@overrides
def closeEvent(self, event):
@ -260,7 +289,17 @@ class MainWindow_bcg_quality_label(QMainWindow):
sender = self.sender()
if sender == self.ui.pushButton_input:
if (sender == self.ui.pushButton_input or
sender == self.ui.pushButton_prev or
sender == self.ui.pushButton_next or
self.ui.tableWidget_a1 or
self.ui.tableWidget_a2 or
self.ui.tableWidget_b1 or
self.ui.tableWidget_b2 or
self.ui.tableWidget_c or
self.ui.tableWidget_f or
self.ui.checkBox_highlight_longest_continuous or
self.ui.checkBox_display_afterfilter):
try:
artifact_type_seq = array([])
artifact_type_seq = artifact_type_seq.astype(int64)
@ -413,10 +452,16 @@ class MainWindow_bcg_quality_label(QMainWindow):
self.change_tablewidget_mode()
self.update_tableWidget()
self.update_status()
ButtonState["Current"]["pushButton_input_setting"] = True
ButtonState["Current"]["pushButton_input"] = True
self.change_labelBtn_color()
ButtonState["Current"]["pushButton_input_setting"] = False
ButtonState["Current"]["pushButton_input"] = False
ButtonState["Current"]["pushButton_invalid_signal_label"] = True
ButtonState["Current"]["pushButton_Ctype_signal_label"] = True
if Config["Mode"] == "10s":
ButtonState["Current"]["pushButton_Ctype_signal_label"] = True
elif Config["Mode"] == "30s":
ButtonState["Current"]["pushButton_Ctype_signal_label"] = False
else:
raise ValueError("模式不存在")
ButtonState["Current"]["pushButton_prev"] = True
ButtonState["Current"]["pushButton_next"] = True
ButtonState["Current"]["pushButton_save"] = True
@ -431,6 +476,270 @@ class MainWindow_bcg_quality_label(QMainWindow):
PublicFunc.finish_operation(self, ButtonState)
def __slot_btn_move__(self):
sender = self.sender()
if sender == self.ui.pushButton_prev:
if Config["CurrentPartNum"] == 1:
PublicFunc.text_output(self.ui, Constants.BCG_QUALITY_LABEL_VIEWING_THE_FIRST_PART, Constants.MSGBOX_TYPE_INFO)
PublicFunc.msgbox_output(self, Constants.BCG_QUALITY_LABEL_VIEWING_THE_FIRST_PART, Constants.MSGBOX_TYPE_INFO)
return
Config["CurrentPartNum"] -= 1
if Config["Mode"] == "10s":
Config["CurrentDataIdx"] -= Config["InputConfig"]["UseFreq"] * 10
elif Config["Mode"] == "30s":
Config["CurrentDataIdx"] -= Config["InputConfig"]["UseFreq"] * 30
else:
raise ValueError("模式不存在")
while (self.ui.checkBox_examine_tobeLabeled.isChecked() and
self.data.df_label.at[
Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] != Constants.BCG_QUALITY_LABEL_TOBELABELED):
Config["CurrentPartNum"] -= 1
if Config["Mode"] == "10s":
Config["CurrentDataIdx"] -= Config["InputConfig"]["UseFreq"] * 10
elif Config["Mode"] == "30s":
Config["CurrentDataIdx"] -= Config["InputConfig"]["UseFreq"] * 30
if Config["CurrentPartNum"] == 0:
Config["CurrentPartNum"] = 1
Config["CurrentDataIdx"] = 0
PublicFunc.text_output(self.ui, Constants.BCG_QUALITY_LABEL_VIEWING_THE_FIRST_PART_UNLABELED,
Constants.MSGBOX_TYPE_INFO)
PublicFunc.msgbox_output(self, Constants.BCG_QUALITY_LABEL_VIEWING_THE_FIRST_PART_UNLABELED,
Constants.MSGBOX_TYPE_INFO)
break
elif sender == self.ui.pushButton_next:
if Config["CurrentPartNum"] == Config["DataPartNum"]:
PublicFunc.text_output(self.ui, Constants.BCG_QUALITY_LABEL_VIEWING_THE_LAST_PART, Constants.MSGBOX_TYPE_INFO)
PublicFunc.msgbox_output(self, Constants.BCG_QUALITY_LABEL_VIEWING_THE_LAST_PART, Constants.MSGBOX_TYPE_INFO)
return
Config["CurrentPartNum"] += 1
if Config["Mode"] == "10s":
Config["CurrentDataIdx"] += Config["InputConfig"]["UseFreq"] * 10
elif Config["Mode"] == "30s":
Config["CurrentDataIdx"] += Config["InputConfig"]["UseFreq"] * 30
while (self.ui.checkBox_examine_tobeLabeled.isChecked() and
self.data.df_label.at[
Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] != Constants.BCG_QUALITY_LABEL_TOBELABELED):
Config["CurrentPartNum"] += 1
if Config["Mode"] == "10s":
Config["CurrentDataIdx"] += Config["InputConfig"]["UseFreq"] * 10
elif Config["Mode"] == "30s":
Config["CurrentDataIdx"] += Config["InputConfig"]["UseFreq"] * 30
if Config["CurrentPartNum"] == Config["DataPartNum"] + 1:
Config["CurrentPartNum"] = Config["DataPartNum"]
if Config["Mode"] == "10s":
Config["CurrentDataIdx"] = (Config["DataPartNum"] - 1) * Config["InputConfig"]["UseFreq"] * 10
elif Config["Mode"] == "30s":
Config["CurrentDataIdx"] = (Config["DataPartNum"] - 1) * Config["InputConfig"]["UseFreq"] * 30
PublicFunc.text_output(self.ui, Constants.BCG_QUALITY_LABEL_VIEWING_THE_LAST_PART_UNLABELED,
Constants.MSGBOX_TYPE_INFO)
PublicFunc.msgbox_output(self, Constants.BCG_QUALITY_LABEL_VIEWING_THE_LAST_PART_UNLABELED,
Constants.MSGBOX_TYPE_INFO)
break
else:
raise ValueError("发射信号不存在")
# 更新备注内容
if not (str(self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_REMARK]) ==
Constants.STRING_IS_NAN):
self.ui.lineEdit_remark.setText(
str(self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_REMARK]))
else:
self.ui.lineEdit_remark.setText(Constants.STRING_IS_EMPTY)
# 更新按钮颜色
self.change_labelBtn_color()
if (self.data.df_label[
Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] != Constants.BCG_QUALITY_LABEL_TOBELABELED).all():
PublicFunc.text_output(self.ui, Constants.BCG_QUALITY_LABEL_LABELED_FINISHED,
Constants.MSGBOX_TYPE_INFO)
self.update_status()
self.update_tableWidget()
self.__plot__()
PublicFunc.text_output(self.ui, Constants.BCG_QUALITY_LABEL_VIEWING_PART + str(Config["CurrentPartNum"]),
Constants.MSGBOX_TYPE_INFO)
def __slot_tablewidget_on_cell_double_clicked__(self, row, column):
sender = self.sender()
if Config["Mode"] == "30s":
length = Config["InputConfig"]["UseFreq"] * 30
elif Config["Mode"] == "10s":
length = Config["InputConfig"]["UseFreq"] * 10
else:
raise ValueError("模式不存在")
if sender == self.ui.tableWidget_a1:
Config["CurrentPartNum"] = int(self.ui.tableWidget_a1.item(row, column).text())
Config["CurrentDataIdx"] = (Config["CurrentPartNum"] - 1) * length
elif sender == self.ui.tableWidget_a2:
Config["CurrentPartNum"] = int(self.ui.tableWidget_a2.item(row, column).text())
Config["CurrentDataIdx"] = (Config["CurrentPartNum"] - 1) * length
elif sender == self.ui.tableWidget_b1:
Config["CurrentPartNum"] = int(self.ui.tableWidget_b1.item(row, column).text())
Config["CurrentDataIdx"] = (Config["CurrentPartNum"] - 1) * length
elif sender == self.ui.tableWidget_b2:
Config["CurrentPartNum"] = int(self.ui.tableWidget_b2.item(row, column).text())
Config["CurrentDataIdx"] = (Config["CurrentPartNum"] - 1) * length
elif sender == self.ui.tableWidget_c:
Config["CurrentPartNum"] = int(self.ui.tableWidget_c.item(row, column).text())
Config["CurrentDataIdx"] = (Config["CurrentPartNum"] - 1) * length
elif sender == self.ui.tableWidget_f:
Config["CurrentPartNum"] = int(self.ui.tableWidget_f.item(row, column).text())
Config["CurrentDataIdx"] = (Config["CurrentPartNum"] - 1) * length
else:
raise ValueError("发射信号不存在")
# 更新备注内容
if not (str(self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_REMARK]) ==
Constants.STRING_IS_NAN):
self.ui.lineEdit_remark.setText(str(self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_REMARK]))
else:
self.ui.lineEdit_remark.setText(Constants.STRING_IS_EMPTY)
# 更新按钮颜色
self.change_labelBtn_color()
self.update_status()
self.__plot__()
PublicFunc.text_output(self.ui, Constants.BCG_QUALITY_LABEL_JUMP_PART + str(Config["CurrentPartNum"]),
Constants.MSGBOX_TYPE_INFO)
def __slot_btn_label__(self):
sender = self.sender()
if sender == self.ui.pushButton_a1:
if Config["Mode"] == "30s":
label = Constants.BCG_QUALITY_LABEL_30S_A1
elif Config["Mode"] == "10s":
label = Constants.BCG_QUALITY_LABEL_10S_A
else:
raise ValueError("模式不存在")
elif sender == self.ui.pushButton_a2:
label = Constants.BCG_QUALITY_LABEL_30S_A2
elif sender == self.ui.pushButton_b1:
if Config["Mode"] == "30s":
label = Constants.BCG_QUALITY_LABEL_30S_B1
elif Config["Mode"] == "10s":
label = Constants.BCG_QUALITY_LABEL_10S_B
else:
raise ValueError("模式不存在")
elif sender == self.ui.pushButton_b2:
label = Constants.BCG_QUALITY_LABEL_30S_B2
elif sender == self.ui.pushButton_c:
if Config["Mode"] == "30s":
label = Constants.BCG_QUALITY_LABEL_30S_C
elif Config["Mode"] == "10s":
label = Constants.BCG_QUALITY_LABEL_10S_C
else:
raise ValueError("模式不存在")
elif sender == self.ui.pushButton_f:
label = Constants.BCG_QUALITY_LABEL_TOBELABELED
else:
raise ValueError("发射信号不存在")
self.data.label[Config["CurrentPartNum"] - 1] = label
self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] = self.data.label
self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_REMARK] = (
self.ui.lineEdit_remark.text())
self.change_labelBtn_color()
self.update_tableWidget()
result = self.data.save(label)
if not result.status:
PublicFunc.text_output(self.ui, result.info, Constants.TIPS_TYPE_ERROR)
PublicFunc.msgbox_output(self, result.info, Constants.MSGBOX_TYPE_ERROR)
PublicFunc.finish_operation(self, ButtonState)
return
else:
PublicFunc.text_output(self.ui, result.info, Constants.TIPS_TYPE_INFO)
def __slot_btn_invalid_signal_label__(self):
reply = QMessageBox.question(self, Constants.QUESTION_TITLE,
Constants.BCG_QUALITY_LABEL_LABEL_ALL_TO_TYPE_C_QUESTION_CONTENT,
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
if Config["Mode"] == "30s":
self.data.label = full(self.data.label.shape, Constants.BCG_QUALITY_LABEL_30S_C).astype(str)
elif Config["Mode"] == "10s":
self.data.label = full(self.data.label.shape, Constants.BCG_QUALITY_LABEL_10S_C).astype(str)
else:
raise ValueError("模式不存在")
self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] = self.data.label
self.change_labelBtn_color()
self.update_tableWidget()
result = self.data.save("无效信号标注")
if not result.status:
PublicFunc.text_output(self.ui, result.info, Constants.TIPS_TYPE_ERROR)
PublicFunc.msgbox_output(self, result.info, Constants.MSGBOX_TYPE_ERROR)
PublicFunc.finish_operation(self, ButtonState)
return
else:
PublicFunc.text_output(self.ui, result.info, Constants.TIPS_TYPE_INFO)
def __slot_btn_Ctype_signal_label__(self):
reply = QMessageBox.question(self, Constants.QUESTION_TITLE,
Constants.BCG_QUALITY_LABEL_LABEL_ARTIFACT_TO_TYPE_C_QUESTION_CONTENT,
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
artifact_mask = self.data.artifact_mask[:Config["InputConfig"]["UseFreq"] * 10 *
int(len(self.data.BCG) // (Config["InputConfig"]["UseFreq"] * 10))]
sub_artifact_mask = split(artifact_mask, len(artifact_mask) // (Config["InputConfig"]["UseFreq"] * 10))
for index, array in enumerate(sub_artifact_mask):
if 1 in array or 2 in array or 3 in array or 4 in array or 5 in array:
self.data.label[index] = Constants.BCG_QUALITY_LABEL_10S_C
self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] = self.data.label
self.change_labelBtn_color()
self.update_tableWidget()
result = self.data.save("C类信号标注")
if not result.status:
PublicFunc.text_output(self.ui, result.info, Constants.TIPS_TYPE_ERROR)
PublicFunc.msgbox_output(self, result.info, Constants.MSGBOX_TYPE_ERROR)
PublicFunc.finish_operation(self, ButtonState)
return
else:
PublicFunc.text_output(self.ui, result.info, Constants.TIPS_TYPE_INFO)
def __slot_checkBox_highlight_longest_continuous__(self):
self.__plot__()
def __slot_checkBox_display_afterfilter__(self):
self.__plot__()
def __slot_checkBox__(self):
sender = self.sender()
if sender == self.ui.checkBox_allin:
if self.ui.checkBox_allin.isChecked():
self.ui.checkBox_type1.setChecked(True)
self.ui.checkBox_type2.setChecked(True)
self.ui.checkBox_type3.setChecked(True)
self.ui.checkBox_type4.setChecked(True)
self.ui.checkBox_type5.setChecked(True)
else:
self.ui.checkBox_type1.setChecked(False)
self.ui.checkBox_type2.setChecked(False)
self.ui.checkBox_type3.setChecked(False)
self.ui.checkBox_type4.setChecked(False)
self.ui.checkBox_type5.setChecked(False)
elif (sender == self.ui.checkBox_type1 or
sender == self.ui.checkBox_type2 or
sender == self.ui.checkBox_type3 or
sender == self.ui.checkBox_type4 or
sender == self.ui.checkBox_type5):
if (self.ui.checkBox_type1.isChecked() and
self.ui.checkBox_type2.isChecked() and
self.ui.checkBox_type3.isChecked() and
self.ui.checkBox_type4.isChecked() and
self.ui.checkBox_type5.isChecked()):
self.ui.checkBox_allin.setChecked(True)
else:
self.ui.checkBox_allin.setChecked(False)
else:
raise ValueError("发射信号不存在")
self.__plot__()
def update_status(self):
if Config["Mode"] == "30s":
hour = int(((Config["CurrentDataIdx"] + (Config["InputConfig"]["UseFreq"] * 30)) / int(Config["InputConfig"]["UseFreq"])) // 3600)
@ -479,9 +788,9 @@ class MainWindow_bcg_quality_label(QMainWindow):
for row, value in enumerate(label):
item = QTableWidgetItem(str(value).strip())
tableWidget.setItem(row, 0, item)
if (self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_REMARK][
value - 1] != Constants.STRING_IS_EMPTY and
self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_REMARK][value - 1] is not nan):
if (str(self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_REMARK][
value - 1]) != Constants.STRING_IS_EMPTY and
str(self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_REMARK][value - 1]) != Constants.STRING_IS_NAN):
item = tableWidget.item(row, 0)
item.setBackground(QColor(255, 200, 200))
else:
@ -517,9 +826,9 @@ class MainWindow_bcg_quality_label(QMainWindow):
for row, value in enumerate(label):
item = QTableWidgetItem(str(value).strip())
tableWidget.setItem(row, 0, item)
if (self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_REMARK][
value - 1] != Constants.STRING_IS_EMPTY and
self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_REMARK][value - 1] is not nan):
if (str(self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_REMARK][
value - 1]) != Constants.STRING_IS_EMPTY and
str(self.data.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_REMARK][value - 1]) != Constants.STRING_IS_NAN):
item = tableWidget.item(row, 0)
item.setBackground(QColor(255, 200, 200))
else:
@ -588,12 +897,48 @@ class MainWindow_bcg_quality_label(QMainWindow):
self.ui.tableWidget_b2.setHorizontalHeaderLabels(['b2'])
self.ui.tableWidget_c.setHorizontalHeaderLabels(['c'])
self.ui.tableWidget_f.setHorizontalHeaderLabels(['None'])
elif Config["Mode"] == "Undefined":
return False
else:
raise ValueError("模式不存在")
return True
def change_labelBtn_color(self):
if self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] == "a1":
self.ui.pushButton_a1.setStyleSheet(Constants.BCG_QUALITY_LABEL_LABELBTN_STYLE)
self.ui.pushButton_a2.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_b1.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_b2.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_c.setStyleSheet(Constants.STRING_IS_EMPTY)
elif self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] == "a2":
self.ui.pushButton_a1.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_a2.setStyleSheet(Constants.BCG_QUALITY_LABEL_LABELBTN_STYLE)
self.ui.pushButton_b1.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_b2.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_c.setStyleSheet(Constants.STRING_IS_EMPTY)
elif self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] == "b1":
self.ui.pushButton_a1.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_a2.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_b1.setStyleSheet(Constants.BCG_QUALITY_LABEL_LABELBTN_STYLE)
self.ui.pushButton_b2.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_c.setStyleSheet(Constants.STRING_IS_EMPTY)
elif self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] == "b2":
self.ui.pushButton_a1.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_a2.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_b1.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_b2.setStyleSheet(Constants.BCG_QUALITY_LABEL_LABELBTN_STYLE)
self.ui.pushButton_c.setStyleSheet(Constants.STRING_IS_EMPTY)
elif self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] == "c1":
self.ui.pushButton_a1.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_a2.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_b1.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_b2.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_c.setStyleSheet(Constants.BCG_QUALITY_LABEL_LABELBTN_STYLE)
elif self.data.df_label.at[Config["CurrentPartNum"] - 1, Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] == "f1":
self.ui.pushButton_a1.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_a2.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_b1.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_b2.setStyleSheet(Constants.STRING_IS_EMPTY)
self.ui.pushButton_c.setStyleSheet(Constants.STRING_IS_EMPTY)
class Data():
@ -635,8 +980,6 @@ class Data():
elif Config["Mode"] == "10s":
Config["Path"]["Save"] = str(
Path(Config["Path"]["Save"]) / Path(ConfigParams.SQ_LABEL_10S + ConfigParams.ENDSWITH_CSV))
elif Config["Mode"] == "Undefined":
return Result().failure(info=Constants.INPUT_FAILURE + Constants.FAILURE_REASON["Mode_Undefined"])
else:
raise ValueError("模式不存在")
@ -696,7 +1039,7 @@ class Data():
raise ValueError("模式不存在")
if not Path(Config["Path"]["Save"]).exists():
self.label = full(Config["DataPartNum"], Constants.BCG_QUALITY_LABEL_TOBELABELED)
self.label = full(Config["DataPartNum"], Constants.BCG_QUALITY_LABEL_TOBELABELED).astype(str)
self.df_label = DataFrame(columns=[Constants.BCG_QUALITY_LABEL_COLUMN_LABEL, Constants.BCG_QUALITY_LABEL_COLUMN_REMARK])
self.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_LABEL] = self.label
self.df_label[Constants.BCG_QUALITY_LABEL_COLUMN_REMARK] = Constants.STRING_IS_EMPTY
@ -740,6 +1083,28 @@ class Data():
return Result().success(info=Constants.PREPROCESS_FINISHED)
def save(self, label):
if (not Path(Config["Path"]["Save"]).parent.exists()) or (not Path(Config["Path"]["Save"]).parent.is_dir()):
Path(Config["Path"]["Save"]).parent.mkdir(parents=True, exist_ok=True)
if self.df_label is None:
return Result().failure(info=ConfigParams.RESP_QUALITY_LABEL + Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Data_Not_Exist"])
if Config["Mode"] == "30s":
filename = ConfigParams.SQ_LABEL_30S
elif Config["Mode"] == "10s":
filename = ConfigParams.SQ_LABEL_10S
else:
raise ValueError("模式不存在")
try:
self.df_label.to_csv(Config["Path"]["Save"], index=False, encoding=ConfigParams.GBK_ENCODING)
except Exception as e:
return Result().failure(info=filename + Constants.SAVE_FAILURE +
Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc())
return Result().success(info=filename + Constants.SAVE_FINISHED + "标签为:" + str(label))
@staticmethod
def wipe_industrialFrequencyNoise(data, fs):

View File

@ -262,6 +262,8 @@ class ConfigParams:
"UseFreq": 1000
}
}
BCG_QUALITY_LABEL_BTN_PREV_SHORTCUT_KEY: str = "A"
BCG_QUALITY_LABEL_BTN_NEXT_SHORTCUT_KEY: str = "D"
# 呼吸可用性及间期标注
RESP_QUALITY_LABEL_CONFIG_FILE_PATH: str = "./config/Config_resp_quality_label.yaml"

View File

@ -106,7 +106,6 @@ class Constants:
"Data_Length_not_Correct": "orgBcg和BCG长度不匹配",
"Artifact_Format_Not_Correct": "(体动长度或格式不正确)",
"Data_Length_Not_Correct": "(信号长度不正确)",
"Mode_Undefined": "(模式未选择)",
"Open_Data_Exception": "(打开数据异常)",
"Process_Exception": "(处理异常)",
@ -388,15 +387,34 @@ class Constants:
BCG_QUALITY_LABEL_PLOT_LABEL_SIGNAL: str = "BCG"
BCG_QUALITY_LABEL_PLOT_LABEL_ARTIFACT: str = "Artifact"
BCG_QUALITY_LABEL_PLOT_LABEL_LONGEST_CONTINUOUS: str = "Longest_Continuous"
BCG_QUALITY_LABEL_10S_A: str = "a"
BCG_QUALITY_LABEL_10S_B: str = "b"
BCG_QUALITY_LABEL_10S_C: str = "c"
BCG_QUALITY_LABEL_30S_A1: str = "a"
BCG_QUALITY_LABEL_30S_A2: str = "b"
BCG_QUALITY_LABEL_30S_B1: str = "c"
BCG_QUALITY_LABEL_30S_B2: str = "d"
BCG_QUALITY_LABEL_30S_C: str = "e"
BCG_QUALITY_LABEL_TOBELABELED: str = "f"
BCG_QUALITY_LABEL_10S_A: str = "a1"
BCG_QUALITY_LABEL_10S_B: str = "b1"
BCG_QUALITY_LABEL_10S_C: str = "c1"
BCG_QUALITY_LABEL_30S_A1: str = "a1"
BCG_QUALITY_LABEL_30S_A2: str = "a2"
BCG_QUALITY_LABEL_30S_B1: str = "b1"
BCG_QUALITY_LABEL_30S_B2: str = "b2"
BCG_QUALITY_LABEL_30S_C: str = "c1"
BCG_QUALITY_LABEL_TOBELABELED: str = "f1"
BCG_QUALITY_LABEL_VIEWING_THE_FIRST_PART: str = "你正在查看第1段信号"
BCG_QUALITY_LABEL_VIEWING_THE_LAST_PART: str = "你正在查看最后1段信号"
BCG_QUALITY_LABEL_VIEWING_THE_FIRST_PART_UNLABELED: str = "前面的片段都被打标将跳转至第1段信号"
BCG_QUALITY_LABEL_VIEWING_THE_LAST_PART_UNLABELED: str = "后面的片段都被打标将跳转至最后1段信号"
BCG_QUALITY_LABEL_LABELED_FINISHED: str = "该份数据打标已全部完成"
BCG_QUALITY_LABEL_VIEWING_PART: str = "正在查看信号段"
BCG_QUALITY_LABEL_JUMP_PART: str = "跳转到片段"
BCG_QUALITY_LABEL_LABEL_ALL_TO_TYPE_C_QUESTION_CONTENT: str = "你确定要将所有片段标记为类型C"
BCG_QUALITY_LABEL_LABEL_ARTIFACT_TO_TYPE_C_QUESTION_CONTENT: str = "你确定要将所有带有体动的片段标记为类型C"
BCG_QUALITY_LABEL_LABELBTN_STYLE: str = """
QPushButton {
background-color: orange; /* 设置背景颜色 */
padding: 10px; /* 设置内边距 */
border: 2px solid darkblue; /* 设置边框 */
border-radius: 10px; /* 设置圆角 */
}
QPushButton:hover {
background-color: yellow; /* 鼠标悬停时的背景颜色 */
}"""
# 呼吸可用性及间期标注
@ -467,43 +485,6 @@ class Constants:
SA_LABEL_LENGTH_LESS_THEN_10S: str = "当前标注的事件的持续时间小于10秒"
SA_LABEL_WRONG_ARGS: str = "起始时间和终止时间输入错误"
# 质量打标
BCG_QUALITY_LABEL_VIEWING_THE_FIRST_PART: str = "你正在查看第1段信号"
BCG_QUALITY_LABEL_VIEWING_THE_LAST_PART: str = "你正在查看最后1段信号"
BCG_QUALITY_LABEL_VIEWING_THE_FIRST_PART_UNLABELED: str = "前面的片段都被打标将跳转至第1段信号"
BCG_QUALITY_LABEL_VIEWING_THE_LAST_PART_UNLABELED: str = "后面的片段都被打标将跳转至最后1段信号"
BCG_QUALITY_LABEL_LABELED_FINISHED: str = "该份数据打标已全部完成"
BCG_QUALITY_LABEL_VIEWING_PART: str = "正在查看信号段"
BCG_QUALITY_LABEL_JUMP_PART: str = "跳转到片段"
BCG_QUALITY_LABEL_CLICKED_CHECKBOX_HIGHLIGHT_LONGEST_CONTINUOUS: str = "点击了<高亮最长连续>"
BCG_QUALITY_LABEL_CLICKED_CHECKBOX_DISPLAY_AFTERFILTER: str = "点击了<去除工频噪声>"
BCG_QUALITY_LABEL_CLICKED_CHECKBOX_EXAMINE_TOBOLABELED: str = "点击了<仅查未标片段>"
BCG_QUALITY_LABEL_LABEL_ALL_TO_TYPE_C_QUESTION_CONTENT: str = "你确定要将所有片段标记为类型C"
BCG_QUALITY_LABEL_LABEL_ALL_TO_TYPE_C: str = "已将所有片段标记为类型C"
BCG_QUALITY_LABEL_LABEL_ARTIFACT_TO_TYPE_C_QUESTION_CONTENT: str = "你确定要将所有带有体动的片段标记为类型C"
BCG_QUALITY_LABEL_LABEL_ARTIFACT_TO_TYPE_C: str = "已将所有带有体动的片段标记为类型C"
BCG_QUALITY_LABEL_LABELBTN_STYLE: str = """
QPushButton {
background-color: orange; /* 设置背景颜色 */
padding: 10px; /* 设置内边距 */
border: 2px solid darkblue; /* 设置边框 */
border-radius: 10px; /* 设置圆角 */
}
QPushButton:hover {
background-color: yellow; /* 鼠标悬停时的背景颜色 */
}"""
# 禁止实例化
def __new__(cls):
raise TypeError("Constants class cannot be instantiated")