新增脚本filename_regulation_generator.py,有命名规范需要修改时,只需要修改ConfigParams.py的Filename类里面的变量的值,之后直接运行脚本filename_regulation_generator.py即可获取最新版本的数据结构化输入和输出命名规范.html
This commit is contained in:
@ -11,8 +11,9 @@ from overrides import overrides
|
||||
from pandas import read_csv, DataFrame
|
||||
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.utils.Result import Result
|
||||
from func.utils.detect_Rpeak import preprocess, Rpeak_Detection, get_method
|
||||
|
||||
@ -59,20 +60,20 @@ class SettingWindow(QMainWindow):
|
||||
self.ui.pushButton_cancel.clicked.connect(self.close)
|
||||
|
||||
def __read_config__(self):
|
||||
if not Path(ConfigParams.DETECT_RPEAK_CONFIG_FILE_PATH).exists():
|
||||
with open(ConfigParams.DETECT_RPEAK_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(ConfigParams.DETECT_RPEAK_CONFIG_NEW_CONTENT, f)
|
||||
if not Path(Params.DETECT_RPEAK_CONFIG_FILE_PATH).exists():
|
||||
with open(Params.DETECT_RPEAK_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(Params.DETECT_RPEAK_CONFIG_NEW_CONTENT, f)
|
||||
|
||||
with open(ConfigParams.DETECT_RPEAK_CONFIG_FILE_PATH, "r") as f:
|
||||
with open(Params.DETECT_RPEAK_CONFIG_FILE_PATH, "r") as f:
|
||||
file_config = load(f.read(), Loader=FullLoader)
|
||||
Config.update(file_config)
|
||||
self.config = file_config
|
||||
|
||||
Config.update({
|
||||
"Path": {
|
||||
"Input": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_PSG_TEXT /
|
||||
"Input": str((Path(self.root_path) / Filename.PATH_PSG_TEXT /
|
||||
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))))
|
||||
}
|
||||
})
|
||||
@ -91,7 +92,7 @@ class SettingWindow(QMainWindow):
|
||||
# 保存配置到文件
|
||||
self.config["InputConfig"]["Freq"] = self.ui.spinBox_input_freq.value()
|
||||
|
||||
with open(ConfigParams.DETECT_RPEAK_CONFIG_FILE_PATH, "w") as f:
|
||||
with open(Params.DETECT_RPEAK_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(self.config, f)
|
||||
|
||||
self.close()
|
||||
@ -102,18 +103,18 @@ class SettingWindow(QMainWindow):
|
||||
def __update_ui__(self):
|
||||
self.ui.plainTextEdit_file_path_input.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.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 +
|
||||
Path(Filename.RPEAK_FINAL +
|
||||
str(self.ui.spinBox_input_freq.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
|
||||
|
||||
class MainWindow_detect_Rpeak(QMainWindow):
|
||||
@ -166,11 +167,11 @@ class MainWindow_detect_Rpeak(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)
|
||||
self.ax1.grid(True)
|
||||
self.ax1.xaxis.set_major_formatter(ConfigParams.FORMATTER)
|
||||
self.ax1.xaxis.set_major_formatter(Params.FORMATTER)
|
||||
|
||||
PublicFunc.__resetAllButton__(self, ButtonState)
|
||||
|
||||
@ -351,7 +352,7 @@ class MainWindow_detect_Rpeak(QMainWindow):
|
||||
PublicFunc.progressbar_update(self, 1, 1, Constants.SAVING_DATA, 0)
|
||||
|
||||
total_rows = len(DataFrame(self.data.peak.reshape(-1)))
|
||||
chunk_size = ConfigParams.DETECT_RPEAK_SAVE_CHUNK_SIZE
|
||||
chunk_size = Params.DETECT_RPEAK_SAVE_CHUNK_SIZE
|
||||
with open(Config["Path"]["Save"], 'w') as f:
|
||||
for start in range(0, total_rows, chunk_size):
|
||||
end = min(start + chunk_size, total_rows)
|
||||
@ -376,10 +377,10 @@ class MainWindow_detect_Rpeak(QMainWindow):
|
||||
self.ax0.clear()
|
||||
self.ax1.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)
|
||||
self.ax1.grid(True)
|
||||
self.ax1.xaxis.set_major_formatter(ConfigParams.FORMATTER)
|
||||
self.ax1.xaxis.set_major_formatter(Params.FORMATTER)
|
||||
|
||||
def update_ui_comboBox_method(self, method_list):
|
||||
self.ui.comboBox_method.clear()
|
||||
@ -399,18 +400,18 @@ class Data:
|
||||
if Path(Config["Path"]["Input"]).is_file():
|
||||
Config["Path"]["Input"] = str(Path(Config["Path"]["Input"]).parent)
|
||||
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input"], ConfigParams.ECG_FILTER, ConfigParams.ENDSWITH_TXT)
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input"], Filename.ECG_FILTER, Params.ENDSWITH_TXT)
|
||||
if result.status:
|
||||
Config["Path"]["Input"] = result.data["path"]
|
||||
Config["InputConfig"]["Freq"] = result.data["freq"]
|
||||
Config["Path"]["Save"] = str(
|
||||
Path(Config["Path"]["Save"]) / Path(ConfigParams.RPEAK_FINAL + str(Config["InputConfig"]["Freq"]) + ConfigParams.ENDSWITH_TXT))
|
||||
Path(Config["Path"]["Save"]) / Path(Filename.RPEAK_FINAL + str(Config["InputConfig"]["Freq"]) + Params.ENDSWITH_TXT))
|
||||
else:
|
||||
return result
|
||||
|
||||
try:
|
||||
self.raw_data = read_csv(Config["Path"]["Input"],
|
||||
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 +
|
||||
|
||||
Reference in New Issue
Block a user