新增脚本filename_regulation_generator.py,有命名规范需要修改时,只需要修改ConfigParams.py的Filename类里面的变量的值,之后直接运行脚本filename_regulation_generator.py即可获取最新版本的数据结构化输入和输出命名规范.html
This commit is contained in:
@ -12,8 +12,9 @@ from pandas import read_csv, DataFrame
|
||||
from scipy.signal import resample
|
||||
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 Butterworth_for_BCG_PreProcess, Butterworth_for_ECG_PreProcess
|
||||
from func.utils.Result import Result
|
||||
|
||||
@ -62,11 +63,11 @@ class SettingWindow(QMainWindow):
|
||||
self.ui.pushButton_cancel.clicked.connect(self.close)
|
||||
|
||||
def __read_config__(self):
|
||||
if not Path(ConfigParams.PREPROCESS_CONFIG_FILE_PATH).exists():
|
||||
with open(ConfigParams.PREPROCESS_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(ConfigParams.PREPROCESS_CONFIG_NEW_CONTENT, f)
|
||||
if not Path(Params.PREPROCESS_CONFIG_FILE_PATH).exists():
|
||||
with open(Params.PREPROCESS_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(Params.PREPROCESS_CONFIG_NEW_CONTENT, f)
|
||||
|
||||
with open(ConfigParams.PREPROCESS_CONFIG_FILE_PATH, "r") as f:
|
||||
with open(Params.PREPROCESS_CONFIG_FILE_PATH, "r") as f:
|
||||
file_config = load(f.read(), Loader=FullLoader)
|
||||
Config.update(file_config)
|
||||
self.config = file_config
|
||||
@ -74,9 +75,9 @@ class SettingWindow(QMainWindow):
|
||||
if self.mode == "BCG":
|
||||
Config.update({
|
||||
"Path": {
|
||||
"Input": str((Path(self.root_path) / ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
"Input": str((Path(self.root_path) / Filename.PATH_ORGBCG_TEXT /
|
||||
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
|
||||
@ -84,9 +85,9 @@ class SettingWindow(QMainWindow):
|
||||
elif self.mode == "ECG":
|
||||
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))))
|
||||
},
|
||||
"Mode": self.mode
|
||||
@ -111,7 +112,7 @@ class SettingWindow(QMainWindow):
|
||||
self.config["InputConfig"]["Freq"] = self.ui.spinBox_input_freq.value()
|
||||
self.config["OutputConfig"]["Freq"] = self.ui.spinBox_output_freq.value()
|
||||
|
||||
with open(ConfigParams.PREPROCESS_CONFIG_FILE_PATH, "w") as f:
|
||||
with open(Params.PREPROCESS_CONFIG_FILE_PATH, "w") as f:
|
||||
dump(self.config, f)
|
||||
|
||||
self.close()
|
||||
@ -123,33 +124,33 @@ class SettingWindow(QMainWindow):
|
||||
if self.mode == "BCG":
|
||||
self.ui.plainTextEdit_file_path_input.setPlainText(
|
||||
str((Path(self.root_path) /
|
||||
ConfigParams.PUBLIC_PATH_ORGBCG_TEXT /
|
||||
Filename.PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.ORGBCG_RAW +
|
||||
Path(Filename.ORGBCG_RAW +
|
||||
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_ORGBCG_TEXT /
|
||||
Filename.PATH_ORGBCG_TEXT /
|
||||
Path(str(self.sampID)) /
|
||||
Path(ConfigParams.BCG_FILTER +
|
||||
Path(Filename.BCG_FILTER +
|
||||
str(self.ui.spinBox_output_freq.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
elif self.mode == "ECG":
|
||||
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_RAW +
|
||||
Path(Filename.ECG_RAW +
|
||||
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.ECG_FILTER +
|
||||
Path(Filename.ECG_FILTER +
|
||||
str(self.ui.spinBox_output_freq.value()) +
|
||||
ConfigParams.ENDSWITH_TXT))))
|
||||
Params.ENDSWITH_TXT))))
|
||||
else:
|
||||
raise ValueError("模式不存在")
|
||||
|
||||
@ -205,7 +206,7 @@ class MainWindow_preprocess(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)
|
||||
|
||||
PublicFunc.__resetAllButton__(self, ButtonState)
|
||||
|
||||
@ -364,7 +365,7 @@ class MainWindow_preprocess(QMainWindow):
|
||||
PublicFunc.progressbar_update(self, 1, 1, Constants.SAVING_DATA, 0)
|
||||
|
||||
total_rows = len(DataFrame(self.data.processed_data.reshape(-1)))
|
||||
chunk_size = ConfigParams.PREPROCESS_SAVE_CHUNK_SIZE
|
||||
chunk_size = Params.PREPROCESS_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)
|
||||
@ -389,7 +390,7 @@ class MainWindow_preprocess(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)
|
||||
|
||||
|
||||
class Data:
|
||||
@ -400,28 +401,28 @@ class Data:
|
||||
|
||||
def open_file(self):
|
||||
if Config["Mode"] == "BCG":
|
||||
signal = ConfigParams.ORGBCG_RAW
|
||||
save = ConfigParams.BCG_FILTER
|
||||
signal = Filename.ORGBCG_RAW
|
||||
save = Filename.BCG_FILTER
|
||||
elif Config["Mode"] == "ECG":
|
||||
signal = ConfigParams.ECG_RAW
|
||||
save = ConfigParams.ECG_FILTER
|
||||
signal = Filename.ECG_RAW
|
||||
save = Filename.ECG_FILTER
|
||||
else:
|
||||
raise ValueError("模式不存在")
|
||||
if Path(Config["Path"]["Input"]).is_file():
|
||||
Config["Path"]["Input"] = str(Path(Config["Path"]["Input"]).parent)
|
||||
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input"], signal, ConfigParams.ENDSWITH_TXT)
|
||||
result = PublicFunc.examine_file(Config["Path"]["Input"], signal, 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(save + str(Config["OutputConfig"]["Freq"]) + ConfigParams.ENDSWITH_TXT))
|
||||
Path(Config["Path"]["Save"]) / Path(save + str(Config["OutputConfig"]["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