新增脚本filename_regulation_generator.py,有命名规范需要修改时,只需要修改ConfigParams.py的Filename类里面的变量的值,之后直接运行脚本filename_regulation_generator.py即可获取最新版本的数据结构化输入和输出命名规范.html
This commit is contained in:
@ -15,8 +15,9 @@ from pandas import read_csv, DataFrame
|
||||
from scipy.signal import find_peaks
|
||||
from yaml import dump, load, FullLoader
|
||||
|
||||
from func.utils.ConfigParams import Filename, Params
|
||||
from func.utils.PublicFunc import PublicFunc
|
||||
from func.utils.Constants import Constants, ConfigParams
|
||||
from func.utils.Constants import Constants
|
||||
from func.Filters.Preprocessing import data_preprocess_for_label_check
|
||||
from func.utils.Result import Result
|
||||
|
||||
@ -69,11 +70,11 @@ class SettingWindow(QMainWindow):
|
||||
self.ui.pushButton_cancel.clicked.connect(self.close)
|
||||
|
||||
def __read_config__(self):
|
||||
if not Path(ConfigParams.LABEL_CHECK_CONFIG_FILE_PATH).exists():
|
||||
with open(ConfigParams.LABEL_CHECK_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(ConfigParams.LABEL_CHECK_CONFIG_NEW_CONTENT, f)
|
||||
if not Path(Params.LABEL_CHECK_CONFIG_FILE_PATH).exists():
|
||||
with open(Params.LABEL_CHECK_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(Params.LABEL_CHECK_CONFIG_NEW_CONTENT, f)
|
||||
|
||||
with open(ConfigParams.LABEL_CHECK_CONFIG_FILE_PATH, "r") as f:
|
||||
with open(Params.LABEL_CHECK_CONFIG_FILE_PATH, "r") as f:
|
||||
file_config = load(f.read(), Loader=FullLoader)
|
||||
Config.update(file_config)
|
||||
self.config = file_config
|
||||
@ -81,13 +82,13 @@ class SettingWindow(QMainWindow):
|
||||
if self.mode == "BCG":
|
||||
Config.update({
|
||||
"Path": {
|
||||
"Input_Signal": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Input_Peak": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Input_Approximately_Align": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_LABEL /
|
||||
"Input_Signal": str((Path(self.root_path) / Filename.PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Input_Peak": str((Path(self.root_path) / Filename.PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Input_Approximately_Align": str((Path(self.root_path) / Filename.PATH_LABEL /
|
||||
Path(str(self.sampID)))),
|
||||
"Save": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
"Save": str((Path(self.root_path) / Filename.PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID))))
|
||||
},
|
||||
"Mode": self.mode
|
||||
@ -95,13 +96,13 @@ class SettingWindow(QMainWindow):
|
||||
elif self.mode == "ECG":
|
||||
Config.update({
|
||||
"Path": {
|
||||
"Input_Signal": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Input_Peak": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Input_Approximately_Align": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_LABEL /
|
||||
"Input_Signal": str((Path(self.root_path) / Filename.PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Input_Peak": str((Path(self.root_path) / Filename.PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)))),
|
||||
"Input_Approximately_Align": str((Path(self.root_path) / Filename.PATH_LABEL /
|
||||
Path(str(self.sampID)))),
|
||||
"Save": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
"Save": str((Path(self.root_path) / Filename.PATH_PSG_TEXT /
|
||||
Path(str(self.sampID))))
|
||||
},
|
||||
"Mode": self.mode
|
||||
@ -147,7 +148,7 @@ class SettingWindow(QMainWindow):
|
||||
# 保存配置到文件
|
||||
self.config["InputConfig"]["Freq"] = self.ui.spinBox_input_freq_signal.value()
|
||||
|
||||
with open(ConfigParams.LABEL_CHECK_CONFIG_FILE_PATH, "w") as f:
|
||||
with open(Params.LABEL_CHECK_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(self.config, f)
|
||||
|
||||
self.close()
|
||||
@ -159,47 +160,47 @@ class SettingWindow(QMainWindow):
|
||||
if self.mode == "BCG":
|
||||
self.ui.plainTextEdit_file_path_input_signal.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
Filename.PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.BCG_FILTER +
|
||||
Path(Filename.BCG_FILTER +
|
||||
str(self.ui.spinBox_input_freq_signal.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
self.ui.plainTextEdit_file_path_input_peak.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
Filename.PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.JPEAK_REVISE +
|
||||
Path(Filename.JPEAK_REVISE +
|
||||
str(self.ui.spinBox_input_freq_signal.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
self.ui.plainTextEdit_file_path_save.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
Filename.PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.JPEAK_REVISE_CORRECTED +
|
||||
Path(Filename.JPEAK_REVISE_CORRECTED +
|
||||
str(self.ui.spinBox_input_freq_signal.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
elif self.mode == "ECG":
|
||||
self.ui.plainTextEdit_file_path_input_signal.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
Filename.PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.ECG_FILTER +
|
||||
Path(Filename.ECG_FILTER +
|
||||
str(self.ui.spinBox_input_freq_signal.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
self.ui.plainTextEdit_file_path_input_peak.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
Filename.PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.RPEAK_FINAL +
|
||||
Path(Filename.RPEAK_FINAL +
|
||||
str(self.ui.spinBox_input_freq_signal.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
self.ui.plainTextEdit_file_path_save.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
Filename.PATH_PSG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.RPEAK_FINAL_CORRECTED +
|
||||
Path(Filename.RPEAK_FINAL_CORRECTED +
|
||||
str(self.ui.spinBox_input_freq_signal.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
else:
|
||||
raise ValueError("模式不存在")
|
||||
|
||||
@ -281,11 +282,11 @@ class MainWindow_label_check(QMainWindow):
|
||||
self.fig.subplots_adjust(top=0.98, bottom=0.05, right=0.98, left=0.1, hspace=0, wspace=0)
|
||||
self.ax0 = self.fig.add_subplot(self.gs[0])
|
||||
self.ax0.grid(True)
|
||||
self.ax0.xaxis.set_major_formatter(ConfigParams.FORMATTER)
|
||||
self.ax0.xaxis.set_major_formatter(Params.FORMATTER)
|
||||
self.ax0.tick_params(axis='x', colors=Constants.PLOT_COLOR_WHITE)
|
||||
self.ax1 = self.fig.add_subplot(self.gs[1], sharex=self.ax0, sharey=self.ax0)
|
||||
self.ax1.grid(True)
|
||||
self.ax1.xaxis.set_major_formatter(ConfigParams.FORMATTER)
|
||||
self.ax1.xaxis.set_major_formatter(Params.FORMATTER)
|
||||
|
||||
PublicFunc.__resetAllButton__(self, ButtonState)
|
||||
|
||||
@ -638,12 +639,12 @@ class MainWindow_label_check(QMainWindow):
|
||||
if self.ax0 is not None:
|
||||
self.ax0.clear()
|
||||
self.ax0.grid(True)
|
||||
self.ax0.xaxis.set_major_formatter(ConfigParams.FORMATTER)
|
||||
self.ax0.xaxis.set_major_formatter(Params.FORMATTER)
|
||||
self.ax0.tick_params(axis='x', colors=Constants.PLOT_COLOR_WHITE)
|
||||
if self.ax1 is not None:
|
||||
self.ax1.clear()
|
||||
self.ax1.grid(True)
|
||||
self.ax1.xaxis.set_major_formatter(ConfigParams.FORMATTER)
|
||||
self.ax1.xaxis.set_major_formatter(Params.FORMATTER)
|
||||
|
||||
def on_xlim_change(self, event_ax):
|
||||
try:
|
||||
@ -835,24 +836,24 @@ class MainWindow_label_check(QMainWindow):
|
||||
if self.figToolbar.rect_patch_ax0 is None:
|
||||
if self.is_left_button_pressed:
|
||||
self.figToolbar.rect_patch_ax0 = patches.Rectangle((0, 0), 1, 1, fill=True,
|
||||
alpha=ConfigParams.LABEL_CHECK_LABEL_TRANSPARENCY,
|
||||
color=Constants.PLOT_COLOR_PINK)
|
||||
alpha=Params.LABEL_CHECK_LABEL_TRANSPARENCY,
|
||||
color=Constants.PLOT_COLOR_PINK)
|
||||
elif self.is_right_button_pressed:
|
||||
self.figToolbar.rect_patch_ax0 = patches.Rectangle((0, 0), 1, 1, fill=True,
|
||||
alpha=ConfigParams.LABEL_CHECK_LABEL_TRANSPARENCY,
|
||||
color=Constants.PLOT_COLOR_RED)
|
||||
alpha=Params.LABEL_CHECK_LABEL_TRANSPARENCY,
|
||||
color=Constants.PLOT_COLOR_RED)
|
||||
self.ax0.add_patch(self.figToolbar.rect_patch_ax0)
|
||||
|
||||
# 如果矩形patch不存在,则创建一个新的
|
||||
if self.figToolbar.rect_patch_ax1 is None:
|
||||
if self.is_left_button_pressed:
|
||||
self.figToolbar.rect_patch_ax1 = patches.Rectangle((0, 0), 1, 1, fill=True,
|
||||
alpha=ConfigParams.LABEL_CHECK_LABEL_TRANSPARENCY,
|
||||
color=Constants.PLOT_COLOR_PINK)
|
||||
alpha=Params.LABEL_CHECK_LABEL_TRANSPARENCY,
|
||||
color=Constants.PLOT_COLOR_PINK)
|
||||
elif self.is_right_button_pressed:
|
||||
self.figToolbar.rect_patch_ax1 = patches.Rectangle((0, 0), 1, 1, fill=True,
|
||||
alpha=ConfigParams.LABEL_CHECK_LABEL_TRANSPARENCY,
|
||||
color=Constants.PLOT_COLOR_RED)
|
||||
alpha=Params.LABEL_CHECK_LABEL_TRANSPARENCY,
|
||||
color=Constants.PLOT_COLOR_RED)
|
||||
self.ax1.add_patch(self.figToolbar.rect_patch_ax1)
|
||||
|
||||
# 更新矩形patch的位置和大小
|
||||
@ -883,13 +884,13 @@ class Data:
|
||||
|
||||
def open_file(self):
|
||||
if Config["Mode"] == "BCG":
|
||||
signal = ConfigParams.BCG_FILTER
|
||||
peak = ConfigParams.JPEAK_REVISE
|
||||
save = ConfigParams.JPEAK_REVISE_CORRECTED
|
||||
signal = Filename.BCG_FILTER
|
||||
peak = Filename.JPEAK_REVISE
|
||||
save = Filename.JPEAK_REVISE_CORRECTED
|
||||
elif Config["Mode"] == "ECG":
|
||||
signal = ConfigParams.ECG_FILTER
|
||||
peak = ConfigParams.RPEAK_FINAL
|
||||
save = ConfigParams.RPEAK_FINAL_CORRECTED
|
||||
signal = Filename.ECG_FILTER
|
||||
peak = Filename.RPEAK_FINAL
|
||||
save = Filename.RPEAK_FINAL_CORRECTED
|
||||
else:
|
||||
raise ValueError("模式不存在")
|
||||
if Path(Config["Path"]["Input_Signal"]).is_file():
|
||||
@ -901,7 +902,7 @@ class Data:
|
||||
if Path(Config["Path"]["Save"]).is_file():
|
||||
Config["Path"]["Save"] = str(Path(Config["Path"]["Save"]).parent)
|
||||
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input_Signal"], signal, ConfigParams.ENDSWITH_TXT)
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input_Signal"], signal, Params.ENDSWITH_TXT)
|
||||
if result.status:
|
||||
Config["Path"]["Input_Signal"] = result.data["path"]
|
||||
Config["InputConfig"]["Freq"] = result.data["freq"]
|
||||
@ -909,12 +910,12 @@ class Data:
|
||||
return result
|
||||
|
||||
Config["Path"]["Input_Peak"] = str(
|
||||
Path(Config["Path"]["Input_Peak"]) / Path(peak + str(Config["InputConfig"]["Freq"]) + ConfigParams.ENDSWITH_TXT))
|
||||
Path(Config["Path"]["Input_Peak"]) / Path(peak + str(Config["InputConfig"]["Freq"]) + Params.ENDSWITH_TXT))
|
||||
Config["Path"]["Input_Approximately_Align"] = str(
|
||||
Path(Config["Path"]["Input_Approximately_Align"]) / Path(
|
||||
ConfigParams.APPROXIMATELY_ALIGN_INFO + ConfigParams.ENDSWITH_CSV))
|
||||
Filename.APPROXIMATELY_ALIGN_INFO + Params.ENDSWITH_CSV))
|
||||
Config["Path"]["Save"] = str(
|
||||
Path(Config["Path"]["Save"]) / Path(save + str(Config["InputConfig"]["Freq"]) + ConfigParams.ENDSWITH_TXT))
|
||||
Path(Config["Path"]["Save"]) / Path(save + str(Config["InputConfig"]["Freq"]) + Params.ENDSWITH_TXT))
|
||||
|
||||
if not Path(Config["Path"]["Input_Peak"]).exists():
|
||||
return Result().failure(info=Constants.INPUT_FAILURE + "\n" +
|
||||
@ -923,16 +924,16 @@ class Data:
|
||||
Constants.FAILURE_REASON["Path_Not_Exist"])
|
||||
if not Path(Config["Path"]["Input_Approximately_Align"]).exists():
|
||||
return Result().failure(info=Constants.INPUT_FAILURE + "\n" +
|
||||
ConfigParams.APPROXIMATELY_ALIGN_INFO + ":" +
|
||||
Filename.APPROXIMATELY_ALIGN_INFO + ":" +
|
||||
Config["Path"]["Input_Approximately_Align"] +
|
||||
Constants.FAILURE_REASON["Path_Not_Exist"])
|
||||
|
||||
try:
|
||||
self.raw_data = read_csv(Config["Path"]["Input_Signal"],
|
||||
encoding=ConfigParams.UTF8_ENCODING,
|
||||
encoding=Params.UTF8_ENCODING,
|
||||
header=None).to_numpy().reshape(-1)
|
||||
self.original_peak = read_csv(Config["Path"]["Input_Peak"],
|
||||
encoding=ConfigParams.UTF8_ENCODING,
|
||||
encoding=Params.UTF8_ENCODING,
|
||||
header=None).to_numpy().reshape(-1)
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.INPUT_FAILURE +
|
||||
@ -967,7 +968,7 @@ class Data:
|
||||
return Result().success(info=Constants.ARCHIVE_NOT_EXIST)
|
||||
else:
|
||||
self.corrected_peak = read_csv(Config["Path"]["Save"],
|
||||
encoding=ConfigParams.UTF8_ENCODING,
|
||||
encoding=Params.UTF8_ENCODING,
|
||||
header=None).to_numpy().reshape(-1)
|
||||
return Result().success(info=Constants.ARCHIVE_EXIST)
|
||||
|
||||
@ -1017,19 +1018,19 @@ class CustomNavigationToolbar(NavigationToolbar2QT):
|
||||
super().__init__(canvas, parent)
|
||||
# 初始化画框工具栏
|
||||
self.action_Label_Multiple = QAction(Constants.LABEL_CHECK_ACTION_LABEL_MULTIPLE_NAME, self)
|
||||
self.action_Label_Multiple.setFont(QFont(ConfigParams.FONT, 14))
|
||||
self.action_Label_Multiple.setFont(QFont(Params.FONT, 14))
|
||||
self.action_Label_Multiple.setCheckable(True)
|
||||
self.action_Label_Multiple.setShortcut(QCoreApplication.translate(
|
||||
"MainWindow",
|
||||
ConfigParams.LABEL_CHECK_ACTION_LABEL_MULTIPLE_SHORTCUT_KEY))
|
||||
Params.LABEL_CHECK_ACTION_LABEL_MULTIPLE_SHORTCUT_KEY))
|
||||
self.insertAction(self._actions['pan'], self.action_Label_Multiple)
|
||||
|
||||
self._actions['pan'].setShortcut(QCoreApplication.translate(
|
||||
"MainWindow",
|
||||
ConfigParams.ACTION_PAN_SHORTCUT_KEY))
|
||||
Params.ACTION_PAN_SHORTCUT_KEY))
|
||||
self._actions['zoom'].setShortcut(QCoreApplication.translate(
|
||||
"MainWindow",
|
||||
ConfigParams.ACTION_ZOOM_SHORTCUT_KEY))
|
||||
Params.ACTION_ZOOM_SHORTCUT_KEY))
|
||||
|
||||
# 用于存储事件连接ID
|
||||
self.cid_mouse_press = None
|
||||
|
||||
Reference in New Issue
Block a user