优化<冗余数据切割和标签映射>的代码
删去了<冗余数据切割和标签映射>的自动最大化
This commit is contained in:
@ -64,7 +64,7 @@ class MainWindow_cut_PSG(QMainWindow):
|
||||
"Path": {
|
||||
"InputFolder": str(Path(self.root_path) / ConfigParams.PUBLIC_PATH_PSG_TEXT / Path(str(self.sampID))),
|
||||
"SaveFolder": str(Path(self.root_path) / ConfigParams.PUBLIC_PATH_PSG_ALIGNED / Path(str(self.sampID))),
|
||||
"InputAlignInfo": str(Path(self.root_path) / ConfigParams.PUBLIC_PATH_LABEL / Path(str(self.sampID)) / (ConfigParams.CUT_PSG_SAVE_ECG_ALIGNINFO_FILENAME + ConfigParams.ENDSWITH_TXT))
|
||||
"InputAlignInfo": str(Path(self.root_path) / ConfigParams.PUBLIC_PATH_LABEL / Path(str(self.sampID)))
|
||||
}
|
||||
})
|
||||
|
||||
@ -108,7 +108,7 @@ class MainWindow_cut_PSG(QMainWindow):
|
||||
def __slot_btn_execute__(self):
|
||||
PublicFunc.__disableAllButton__(self, ButtonState)
|
||||
|
||||
self.data = Data()
|
||||
self.data = Data(self.root_path, self.sampID)
|
||||
Config["ECGFreq"] = self.ui.spinBox_ECGFreq.value()
|
||||
|
||||
# 检查文件是否存在并获取其数据采样率
|
||||
@ -185,7 +185,7 @@ class MainWindow_cut_PSG(QMainWindow):
|
||||
|
||||
class Data:
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, root_path, sampID):
|
||||
self.alignInfo = None
|
||||
|
||||
self.raw = {key: array([]) for key in Config["ChannelInput"]}
|
||||
@ -194,6 +194,9 @@ class Data:
|
||||
self.SALabel = None
|
||||
self.startTime = None
|
||||
|
||||
self.root_path = root_path
|
||||
self.sampID = sampID
|
||||
|
||||
def get_file_and_freq(self):
|
||||
try:
|
||||
for file_path in Path(Config["Path"]["InputFolder"]).glob('*'):
|
||||
@ -206,22 +209,41 @@ class Data:
|
||||
freq = int(freq_str)
|
||||
self.freq[key] = freq
|
||||
except ValueError:
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE + Constants.CUT_PSG_FAILURE_REASON["Filename_Format_not_Correct"])
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE +
|
||||
Constants.FAILURE_REASON["Filename_Format_not_Correct"])
|
||||
for value in self.freq.values():
|
||||
if value == 0:
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE + Constants.CUT_PSG_FAILURE_REASON["Filename_Format_not_Correct"])
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE +
|
||||
Constants.FAILURE_REASON["Filename_Format_not_Correct"])
|
||||
if not any((Config["LabelInput"]["SA Label"] + Config["EndWith"]["SA Label"]) in str(file) for file in Path(Config["Path"]["InputFolder"]).glob('*')):
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE + Constants.CUT_PSG_FAILURE_REASON["File_not_Exist"])
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE +
|
||||
Constants.FAILURE_REASON["File_not_Exist"])
|
||||
if not any((Config["StartTime"] + Config["EndWith"]["StartTime"]) in str(file) for file in Path(Config["Path"]["InputFolder"]).glob('*')):
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE + Constants.CUT_PSG_FAILURE_REASON["File_not_Exist"])
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE +
|
||||
Constants.FAILURE_REASON["File_not_Exist"])
|
||||
if not Path(Config["Path"]["InputAlignInfo"]).exists():
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE + Constants.CUT_PSG_FAILURE_REASON["File_not_Exist"])
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE +
|
||||
Constants.FAILURE_REASON["File_not_Exist"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE + Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE["Get_File_and_Freq_Excepetion"] + "\n" + format_exc())
|
||||
return Result().failure(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FAILURE +
|
||||
Constants.FAILURE_REASON["Get_File_and_Freq_Excepetion"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.CUT_PSG_GET_FILE_AND_FREQ_FINISHED)
|
||||
|
||||
def open_file(self):
|
||||
path = str(Path(self.root_path) / ConfigParams.PUBLIC_PATH_PSG_TEXT / Path(str(self.sampID)))
|
||||
for value in Config["ChannelInput"].values():
|
||||
result = PublicFunc.examine_file(path, value)
|
||||
if not result.status:
|
||||
return result
|
||||
|
||||
if Path(Config["Path"]["InputAlignInfo"]).is_file():
|
||||
Config["Path"]["InputAlignInfo"] = str(Path(Config["Path"]["InputAlignInfo"]).parent)
|
||||
|
||||
Config["Path"]["InputAlignInfo"] = str(
|
||||
Path(Config["Path"]["InputAlignInfo"]) / Path(
|
||||
ConfigParams.PRECISELY_ALIGN_INFO + ConfigParams.ENDSWITH_TXT))
|
||||
|
||||
try:
|
||||
for key in Config["ChannelInput"].keys():
|
||||
self.raw[key] = read_csv(Path(Config["Path"]["InputFolder"]) / Path((Config["ChannelInput"][key] + str(self.freq[key]) + Config["EndWith"][key])),
|
||||
@ -237,7 +259,8 @@ class Data:
|
||||
header=None).to_numpy().reshape(-1)
|
||||
self.alignInfo = literal_eval(self.alignInfo[0])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.INPUT_FAILURE + Constants.CUT_PSG_FAILURE_REASON["Read_Data_Exception"] + "\n" + format_exc())
|
||||
return Result().failure(info=Constants.INPUT_FAILURE +
|
||||
Constants.FAILURE_REASON["Open_Data_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.INPUT_FINISHED)
|
||||
|
||||
@ -255,9 +278,11 @@ class Data:
|
||||
# 切割信号
|
||||
self.raw[key] = self.raw[key][start_index_cut:end_index_cut]
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.CUT_PSG_CUT_DATA_FAILURE + Constants.CUT_PSG_FAILURE_REASON["Cut_Data_Length_not_Correct"])
|
||||
return Result().failure(info=Constants.CUT_PSG_CUT_DATA_FAILURE +
|
||||
Constants.FAILURE_REASON["Cut_Data_Length_not_Correct"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.CUT_PSG_CUT_DATA_FAILURE + Constants.CUT_PSG_FAILURE_REASON["Cut_Data_Exception"] + "\n" + format_exc())
|
||||
return Result().failure(info=Constants.CUT_PSG_CUT_DATA_FAILURE +
|
||||
Constants.FAILURE_REASON["Cut_Data_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.CUT_PSG_CUT_DATA_FINISHED)
|
||||
|
||||
@ -269,7 +294,8 @@ class Data:
|
||||
self.SALabel["Duration"] = self.SALabel["Duration"].astype(str)
|
||||
self.SALabel["Duration"] = self.SALabel["Duration"].str.replace(r' \(.*?\)', '', regex=True)
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.CUT_PSG_ALIGN_LABEL_FAILURE + Constants.CUT_PSG_FAILURE_REASON["Align_Label_SALabel_Format_not_Correct"])
|
||||
return Result().failure(info=Constants.CUT_PSG_ALIGN_LABEL_FAILURE +
|
||||
Constants.FAILURE_REASON["Align_Label_SALabel_Format_not_Correct"])
|
||||
|
||||
try:
|
||||
# 获取记录开始时间
|
||||
@ -290,14 +316,16 @@ class Data:
|
||||
self.SALabel = self.SALabel[self.SALabel["Start"] < ECG_length]
|
||||
self.SALabel.loc[self.SALabel["End"] >= ECG_length, "End"] = ECG_length - 1
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.CUT_PSG_ALIGN_LABEL_FAILURE + Constants.CUT_PSG_FAILURE_REASON["Align_Label_Exception"] + "\n" + format_exc())
|
||||
return Result().failure(info=Constants.CUT_PSG_ALIGN_LABEL_FAILURE +
|
||||
Constants.FAILURE_REASON["Align_Label_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.CUT_PSG_ALIGN_LABEL_FINISHED)
|
||||
|
||||
def save(self):
|
||||
for raw in self.raw.values():
|
||||
if len(raw) == 0:
|
||||
return Result().failure(info=Constants.SAVING_FAILURE + Constants.CUT_PSG_FAILURE_REASON["Save_Data_not_Exist"])
|
||||
return Result().failure(info=Constants.SAVING_FAILURE +
|
||||
Constants.FAILURE_REASON["Data_not_Exist"])
|
||||
|
||||
try:
|
||||
for key, raw in self.raw.items():
|
||||
@ -307,7 +335,8 @@ class Data:
|
||||
index=False,
|
||||
encoding="gbk")
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.SAVING_FAILURE + Constants.CUT_PSG_FAILURE_REASON["Save_Exception"] + "\n" + format_exc())
|
||||
return Result().failure(info=Constants.SAVING_FAILURE +
|
||||
Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.SAVING_FINISHED)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user