From 6a325ba95ba68f1c559b99e0505e914323278932 Mon Sep 17 00:00:00 2001 From: Yorusora <2944763079@qq.com> Date: Fri, 23 May 2025 10:25:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func/Module_SA_label.py | 2 +- func/Module_approximately_align.py | 6 - func/Module_bcg_quality_label.py | 399 +++++++++++++++++- func/utils/ConfigParams.py | 2 + func/utils/Constants.py | 75 ++-- ui/MainWindow/MainWindow_bcg_quality_label.py | 21 +- ui/MainWindow/MainWindow_bcg_quality_label.ui | 28 +- ui/setting/bcg_quality_label_input_setting.py | 1 + ui/setting/bcg_quality_label_input_setting.ui | 3 + 9 files changed, 423 insertions(+), 114 deletions(-) diff --git a/func/Module_SA_label.py b/func/Module_SA_label.py index 1e51b97..0e32da6 100644 --- a/func/Module_SA_label.py +++ b/func/Module_SA_label.py @@ -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)) diff --git a/func/Module_approximately_align.py b/func/Module_approximately_align.py index 298cf75..3b8a84e 100644 --- a/func/Module_approximately_align.py +++ b/func/Module_approximately_align.py @@ -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): diff --git a/func/Module_bcg_quality_label.py b/func/Module_bcg_quality_label.py index 3c6ab0e..9fa62be 100644 --- a/func/Module_bcg_quality_label.py +++ b/func/Module_bcg_quality_label.py @@ -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): diff --git a/func/utils/ConfigParams.py b/func/utils/ConfigParams.py index ee06548..a45c944 100644 --- a/func/utils/ConfigParams.py +++ b/func/utils/ConfigParams.py @@ -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" diff --git a/func/utils/Constants.py b/func/utils/Constants.py index 7300484..a6907e6 100644 --- a/func/utils/Constants.py +++ b/func/utils/Constants.py @@ -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") diff --git a/ui/MainWindow/MainWindow_bcg_quality_label.py b/ui/MainWindow/MainWindow_bcg_quality_label.py index df857d5..dec5d33 100644 --- a/ui/MainWindow/MainWindow_bcg_quality_label.py +++ b/ui/MainWindow/MainWindow_bcg_quality_label.py @@ -312,19 +312,6 @@ class Ui_MainWindow_bcg_quality_label(object): self.verticalLayout_2.addItem(self.verticalSpacer_3) - self.horizontalLayout_3 = QHBoxLayout() - self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") - self.pushButton_save = QPushButton(self.groupBox_left) - self.pushButton_save.setObjectName(u"pushButton_save") - sizePolicy.setHeightForWidth(self.pushButton_save.sizePolicy().hasHeightForWidth()) - self.pushButton_save.setSizePolicy(sizePolicy) - self.pushButton_save.setFont(font1) - - self.horizontalLayout_3.addWidget(self.pushButton_save) - - - self.verticalLayout_2.addLayout(self.horizontalLayout_3) - self.groupBox_4 = QGroupBox(self.groupBox_left) self.groupBox_4.setObjectName(u"groupBox_4") self.verticalLayout_6 = QVBoxLayout(self.groupBox_4) @@ -345,8 +332,7 @@ class Ui_MainWindow_bcg_quality_label(object): self.verticalLayout_2.setStretch(5, 1) self.verticalLayout_2.setStretch(6, 6) self.verticalLayout_2.setStretch(7, 1) - self.verticalLayout_2.setStretch(8, 2) - self.verticalLayout_2.setStretch(9, 5) + self.verticalLayout_2.setStretch(8, 5) self.gridLayout.addWidget(self.groupBox_left, 0, 0, 1, 1) @@ -530,8 +516,8 @@ class Ui_MainWindow_bcg_quality_label(object): self.checkBox_type4.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u7c7b\u578b4", None)) self.checkBox_type5.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u7c7b\u578b5", None)) self.groupBox_function.setTitle(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u529f\u80fd", None)) - self.pushButton_invalid_signal_label.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u65e0\u6548\u4fe1\u53f7\u6253\u6807", None)) - self.pushButton_Ctype_signal_label.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"C\u7c7b\u4fe1\u53f7\u6253\u6807", None)) + self.pushButton_invalid_signal_label.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u65e0\u6548\u4fe1\u53f7\u6807\u6ce8", None)) + self.pushButton_Ctype_signal_label.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"C\u7c7b\u4fe1\u53f7\u6807\u6ce8", None)) self.groupBox_operation.setTitle(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u64cd\u4f5c", None)) self.pushButton_prev.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"<(A)", None)) self.checkBox_examine_tobeLabeled.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u4ec5\u67e5\u672a\u6807\u7247\u6bb5", None)) @@ -539,7 +525,6 @@ class Ui_MainWindow_bcg_quality_label(object): self.pushButton_next.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u">(D)", None)) self.label.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u8f93\u5165\u5907\u6ce8", None)) self.checkBox_display_afterfilter.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u53bb\u9664\u5de5\u9891\u566a\u58f0", None)) - self.pushButton_save.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u5bfc\u51fa\u6807\u7b7e", None)) self.groupBox_4.setTitle(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u65e5\u5fd7", None)) self.groupBox_right.setTitle(QCoreApplication.translate("MainWindow_bcg_quality_label", u"\u6807\u7b7e\u8bb0\u5f55", None)) self.pushButton_b1.setText(QCoreApplication.translate("MainWindow_bcg_quality_label", u"b1", None)) diff --git a/ui/MainWindow/MainWindow_bcg_quality_label.ui b/ui/MainWindow/MainWindow_bcg_quality_label.ui index e196086..5be4fb4 100644 --- a/ui/MainWindow/MainWindow_bcg_quality_label.ui +++ b/ui/MainWindow/MainWindow_bcg_quality_label.ui @@ -42,7 +42,7 @@ BCG的质量标注 - + @@ -359,7 +359,7 @@ - 无效信号打标 + 无效信号标注 @@ -377,7 +377,7 @@ - C类信号打标 + C类信号标注 @@ -533,28 +533,6 @@ - - - - - - - 0 - 0 - - - - - 12 - - - - 导出标签 - - - - - diff --git a/ui/setting/bcg_quality_label_input_setting.py b/ui/setting/bcg_quality_label_input_setting.py index 735b15c..a9b6c22 100644 --- a/ui/setting/bcg_quality_label_input_setting.py +++ b/ui/setting/bcg_quality_label_input_setting.py @@ -113,6 +113,7 @@ class Ui_MainWindow_bcg_quality_label_input_setting(object): self.radioButton_30s_mode = QRadioButton(self.groupBox_display_mode) self.radioButton_30s_mode.setObjectName(u"radioButton_30s_mode") self.radioButton_30s_mode.setFont(font) + self.radioButton_30s_mode.setChecked(True) self.horizontalLayout.addWidget(self.radioButton_30s_mode) diff --git a/ui/setting/bcg_quality_label_input_setting.ui b/ui/setting/bcg_quality_label_input_setting.ui index c3bf273..47c971e 100644 --- a/ui/setting/bcg_quality_label_input_setting.ui +++ b/ui/setting/bcg_quality_label_input_setting.ui @@ -152,6 +152,9 @@ 30s模式 + + true +