diff --git a/func/Module_detect_Jpeak.py b/func/Module_detect_Jpeak.py index 0cf45e7..e873336 100644 --- a/func/Module_detect_Jpeak.py +++ b/func/Module_detect_Jpeak.py @@ -357,14 +357,17 @@ class MainWindow_detect_Jpeak(QMainWindow): total_rows = len(DataFrame(self.data.peak.reshape(-1))) chunk_size = Params.DETECT_JPEAK_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) - chunk = DataFrame(self.data.peak.reshape(-1)).iloc[start:end] - result = self.data.save(chunk) - progress = int((end / total_rows) * 100) - self.progressbar.setValue(progress) - QApplication.processEvents() + try: + with open(Config["Path"]["Save"], 'w') as f: + for start in range(0, total_rows, chunk_size): + end = min(start + chunk_size, total_rows) + chunk = DataFrame(self.data.peak.reshape(-1)).iloc[start:end] + result = self.data.save(chunk) + progress = int((end / total_rows) * 100) + self.progressbar.setValue(progress) + QApplication.processEvents() + except FileNotFoundError as e: + result = Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) if not result.status: PublicFunc.text_output(self.ui, "(1/1)" + result.info, Constants.TIPS_TYPE_ERROR) @@ -474,8 +477,6 @@ class Data: chunk.to_csv(Config["Path"]["Save"], mode='a', index=False, header=False) except PermissionError as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Permission_Denied"]) - except FileNotFoundError as e: - return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) except Exception as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc()) diff --git a/func/Module_detect_Rpeak.py b/func/Module_detect_Rpeak.py index 06c56d6..cb55adc 100644 --- a/func/Module_detect_Rpeak.py +++ b/func/Module_detect_Rpeak.py @@ -353,14 +353,17 @@ class MainWindow_detect_Rpeak(QMainWindow): total_rows = len(DataFrame(self.data.peak.reshape(-1))) 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) - chunk = DataFrame(self.data.peak.reshape(-1)).iloc[start:end] - result = self.data.save(chunk) - progress = int((end / total_rows) * 100) - self.progressbar.setValue(progress) - QApplication.processEvents() + try: + with open(Config["Path"]["Save"], 'w') as f: + for start in range(0, total_rows, chunk_size): + end = min(start + chunk_size, total_rows) + chunk = DataFrame(self.data.peak.reshape(-1)).iloc[start:end] + result = self.data.save(chunk) + progress = int((end / total_rows) * 100) + self.progressbar.setValue(progress) + QApplication.processEvents() + except FileNotFoundError as e: + result = Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) if not result.status: PublicFunc.text_output(self.ui, "(1/1)" + result.info, Constants.TIPS_TYPE_ERROR) @@ -464,8 +467,6 @@ class Data: chunk.to_csv(Config["Path"]["Save"], mode='a', index=False, header=False) except PermissionError as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Permission_Denied"]) - except FileNotFoundError as e: - return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) except Exception as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc()) diff --git a/func/Module_precisely_align.py b/func/Module_precisely_align.py index 65b1126..1eb1967 100644 --- a/func/Module_precisely_align.py +++ b/func/Module_precisely_align.py @@ -841,14 +841,17 @@ class MainWindow_precisely_align(QMainWindow): total_rows = len(DataFrame(self.data.res_orgBcg.reshape(-1))) chunk_size = Params.PRECISELY_ALIGN_SAVE_CHUNK_SIZE - with open(Config["Path"]["Save_OrgBCG"], 'w') as f: - for start in range(0, total_rows, chunk_size): - end = min(start + chunk_size, total_rows) - chunk = DataFrame(self.data.res_orgBcg.reshape(-1)).iloc[start:end] - result = self.data.save_res_orgBcg(chunk) - progress = int((end / total_rows) * 100) - self.progressbar.setValue(progress) - QApplication.processEvents() + try: + with open(Config["Path"]["Save_OrgBCG"], 'w') as f: + for start in range(0, total_rows, chunk_size): + end = min(start + chunk_size, total_rows) + chunk = DataFrame(self.data.res_orgBcg.reshape(-1)).iloc[start:end] + result = self.data.save_res_orgBcg(chunk) + progress = int((end / total_rows) * 100) + self.progressbar.setValue(progress) + QApplication.processEvents() + except FileNotFoundError as e: + result = Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) if not result.status: PublicFunc.text_output(self.ui, "(2/6)" + result.info, Constants.TIPS_TYPE_ERROR) @@ -863,14 +866,17 @@ class MainWindow_precisely_align(QMainWindow): total_rows = len(DataFrame(self.data.res_BCG.reshape(-1))) chunk_size = Params.PRECISELY_ALIGN_SAVE_CHUNK_SIZE - with open(Config["Path"]["Save_BCG"], 'w') as f: - for start in range(0, total_rows, chunk_size): - end = min(start + chunk_size, total_rows) - chunk = DataFrame(self.data.res_BCG.reshape(-1)).iloc[start:end] - result = self.data.save_res_BCG(chunk) - progress = int((end / total_rows) * 100) - self.progressbar.setValue(progress) - QApplication.processEvents() + try: + with open(Config["Path"]["Save_BCG"], 'w') as f: + for start in range(0, total_rows, chunk_size): + end = min(start + chunk_size, total_rows) + chunk = DataFrame(self.data.res_BCG.reshape(-1)).iloc[start:end] + result = self.data.save_res_BCG(chunk) + progress = int((end / total_rows) * 100) + self.progressbar.setValue(progress) + QApplication.processEvents() + except FileNotFoundError as e: + result = Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) if not result.status: PublicFunc.text_output(self.ui, "(3/6)" + result.info, Constants.TIPS_TYPE_ERROR) @@ -885,14 +891,17 @@ class MainWindow_precisely_align(QMainWindow): total_rows = len(DataFrame(self.data.cut_ECG.reshape(-1))) chunk_size = Params.PRECISELY_ALIGN_SAVE_CHUNK_SIZE - with open(Config["Path"]["Save_ECG"], 'w') as f: - for start in range(0, total_rows, chunk_size): - end = min(start + chunk_size, total_rows) - chunk = DataFrame(self.data.cut_ECG.reshape(-1)).iloc[start:end] - result = self.data.save_cut_ECG(chunk) - progress = int((end / total_rows) * 100) - self.progressbar.setValue(progress) - QApplication.processEvents() + try: + with open(Config["Path"]["Save_ECG"], 'w') as f: + for start in range(0, total_rows, chunk_size): + end = min(start + chunk_size, total_rows) + chunk = DataFrame(self.data.cut_ECG.reshape(-1)).iloc[start:end] + result = self.data.save_cut_ECG(chunk) + progress = int((end / total_rows) * 100) + self.progressbar.setValue(progress) + QApplication.processEvents() + except FileNotFoundError as e: + result = Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) if not result.status: PublicFunc.text_output(self.ui, "(4/6)" + result.info, Constants.TIPS_TYPE_ERROR) @@ -907,14 +916,17 @@ class MainWindow_precisely_align(QMainWindow): total_rows = len(DataFrame(self.data.cut_Jpeak.reshape(-1))) chunk_size = Params.PRECISELY_ALIGN_SAVE_PEAK_CHUNK_SIZE - with open(Config["Path"]["Save_Jpeak"], 'w') as f: - for start in range(0, total_rows, chunk_size): - end = min(start + chunk_size, total_rows) - chunk = DataFrame(self.data.cut_Jpeak.reshape(-1)).iloc[start:end] - result = self.data.save_Jpeak(chunk) - progress = int((end / total_rows) * 100) - self.progressbar.setValue(progress) - QApplication.processEvents() + try: + with open(Config["Path"]["Save_Jpeak"], 'w') as f: + for start in range(0, total_rows, chunk_size): + end = min(start + chunk_size, total_rows) + chunk = DataFrame(self.data.cut_Jpeak.reshape(-1)).iloc[start:end] + result = self.data.save_Jpeak(chunk) + progress = int((end / total_rows) * 100) + self.progressbar.setValue(progress) + QApplication.processEvents() + except FileNotFoundError as e: + result = Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) if not result.status: PublicFunc.text_output(self.ui, "(5/6)" + result.info, Constants.TIPS_TYPE_ERROR) @@ -929,14 +941,17 @@ class MainWindow_precisely_align(QMainWindow): total_rows = len(DataFrame(self.data.cut_Rpeak.reshape(-1))) chunk_size = Params.PRECISELY_ALIGN_SAVE_PEAK_CHUNK_SIZE - with open(Config["Path"]["Save_Rpeak"], 'w') as f: - for start in range(0, total_rows, chunk_size): - end = min(start + chunk_size, total_rows) - chunk = DataFrame(self.data.cut_Rpeak.reshape(-1)).iloc[start:end] - result = self.data.save_Rpeak(chunk) - progress = int((end / total_rows) * 100) - self.progressbar.setValue(progress) - QApplication.processEvents() + try: + with open(Config["Path"]["Save_Rpeak"], 'w') as f: + for start in range(0, total_rows, chunk_size): + end = min(start + chunk_size, total_rows) + chunk = DataFrame(self.data.cut_Rpeak.reshape(-1)).iloc[start:end] + result = self.data.save_Rpeak(chunk) + progress = int((end / total_rows) * 100) + self.progressbar.setValue(progress) + QApplication.processEvents() + except FileNotFoundError as e: + result = Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) if not result.status: PublicFunc.text_output(self.ui, "(6/6)" + result.info, Constants.TIPS_TYPE_ERROR) @@ -1906,8 +1921,6 @@ class Data: DataFrame(save_data).to_csv(Config["Path"]["Save_AlignInfo"], index=False, header=False) except PermissionError as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Permission_Denied"]) - except FileNotFoundError as e: - return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) except Exception as e: return Result().failure(info=Constants.PRECISELY_ALIGN_SAVING_ALIGNINFO_FAILURE + Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc()) @@ -1931,8 +1944,6 @@ class Data: chunk.to_csv(Config["Path"]["Save_OrgBCG"], mode='a', index=False, header=False) except PermissionError as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Permission_Denied"]) - except FileNotFoundError as e: - return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) except Exception as e: return Result().failure(info=Constants.PRECISELY_ALIGN_SAVING_RES_ORGBCG_FAILURE + Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc()) @@ -1951,8 +1962,6 @@ class Data: chunk.to_csv(Config["Path"]["Save_BCG"], mode='a', index=False, header=False) except PermissionError as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Permission_Denied"]) - except FileNotFoundError as e: - return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) except Exception as e: return Result().failure(info=Constants.PRECISELY_ALIGN_SAVING_RES_BCG_FAILURE + Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc()) @@ -1971,8 +1980,6 @@ class Data: chunk.to_csv(Config["Path"]["Save_ECG"], mode='a', index=False, header=False) except PermissionError as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Permission_Denied"]) - except FileNotFoundError as e: - return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) except Exception as e: return Result().failure(info=Constants.PRECISELY_ALIGN_SAVING_CUT_ECG_FAILURE + Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc()) @@ -1991,8 +1998,6 @@ class Data: chunk.to_csv(Config["Path"]["Save_Jpeak"], mode='a', index=False, header=False) except PermissionError as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Permission_Denied"]) - except FileNotFoundError as e: - return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) except Exception as e: return Result().failure(info=Constants.PRECISELY_ALIGN_SAVING_CUT_JPEAK_FAILURE + Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc()) @@ -2011,8 +2016,6 @@ class Data: chunk.to_csv(Config["Path"]["Save_Rpeak"], mode='a', index=False, header=False) except PermissionError as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Permission_Denied"]) - except FileNotFoundError as e: - return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) except Exception as e: return Result().failure(info=Constants.PRECISELY_ALIGN_SAVING_CUT_RPEAK_FAILURE + Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc()) diff --git a/func/Module_preprocess.py b/func/Module_preprocess.py index 36e8e80..97ba67a 100644 --- a/func/Module_preprocess.py +++ b/func/Module_preprocess.py @@ -366,14 +366,17 @@ class MainWindow_preprocess(QMainWindow): total_rows = len(DataFrame(self.data.processed_data.reshape(-1))) 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) - chunk = DataFrame(self.data.processed_data.reshape(-1)).iloc[start:end] - result = self.data.save(chunk) - progress = int((end / total_rows) * 100) - self.progressbar.setValue(progress) - QApplication.processEvents() + try: + with open(Config["Path"]["Save"], 'w') as f: + for start in range(0, total_rows, chunk_size): + end = min(start + chunk_size, total_rows) + chunk = DataFrame(self.data.processed_data.reshape(-1)).iloc[start:end] + result = self.data.save(chunk) + progress = int((end / total_rows) * 100) + self.progressbar.setValue(progress) + QApplication.processEvents() + except FileNotFoundError as e: + result = Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) if not result.status: PublicFunc.text_output(self.ui, "(1/1)" + result.info, Constants.TIPS_TYPE_ERROR) @@ -494,8 +497,6 @@ class Data: chunk.to_csv(Config["Path"]["Save"], mode='a', index=False, header=False, float_format='%.4f') except PermissionError as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Permission_Denied"]) - except FileNotFoundError as e: - return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_File_Not_Found"]) except Exception as e: return Result().failure(info=Constants.SAVE_FAILURE + Constants.FAILURE_REASON["Save_Exception"] + "\n" + format_exc())