1、优化了异常处理
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
from gc import collect
|
||||
from pathlib import Path
|
||||
from traceback import format_exc
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
from PySide6.QtWidgets import QMessageBox, QMainWindow, QApplication
|
||||
@ -334,8 +335,8 @@ class MainWindow_approximately_align(QMainWindow):
|
||||
result = self.DrawPicByEpoch(*args, **kwargs)
|
||||
elif sender == self.ui.pushButton_EP100:
|
||||
result = self.DrawPicByEpoch(*args, **kwargs)
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE)
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE + "\n" + format_exc())
|
||||
|
||||
if result is None:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE)
|
||||
@ -670,8 +671,8 @@ class MainWindow_approximately_align(QMainWindow):
|
||||
ax3.set_title("ABD")
|
||||
|
||||
self.fig.canvas.draw()
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE)
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE + "\n" + format_exc())
|
||||
# 返回图片以便存到QPixImage
|
||||
return Result().success(info=Constants.DRAWING_FINISHED)
|
||||
|
||||
@ -720,8 +721,8 @@ class MainWindow_approximately_align(QMainWindow):
|
||||
ax3.set_title("ABD")
|
||||
|
||||
self.fig.canvas.draw()
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE)
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE + "\n" + format_exc())
|
||||
# 返回图片以便存到QPixImage
|
||||
return Result().success(info=Constants.DRAWING_FINISHED)
|
||||
|
||||
@ -744,8 +745,8 @@ class MainWindow_approximately_align(QMainWindow):
|
||||
ax4.set_title("The Correlation of ABD and Reverse orgBcg")
|
||||
|
||||
self.fig.canvas.draw()
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE)
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE + "\n" + format_exc())
|
||||
# 返回图片以便存到QPixImage
|
||||
return Result().success(info=Constants.DRAWING_FINISHED)
|
||||
|
||||
@ -778,8 +779,8 @@ class MainWindow_approximately_align(QMainWindow):
|
||||
ax3.set_title("ABD")
|
||||
|
||||
self.fig.canvas.draw()
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE)
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE + "\n" + format_exc())
|
||||
# 返回图片以便存到QPixImage
|
||||
return Result().success(info=Constants.DRAWING_FINISHED)
|
||||
|
||||
@ -838,8 +839,8 @@ class MainWindow_approximately_align(QMainWindow):
|
||||
ax6.set_ylim((10, 50))
|
||||
|
||||
self.fig.canvas.draw()
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE)
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.DRAWING_FAILURE + "\n" + format_exc())
|
||||
# 返回图片以便存到QPixImage
|
||||
return Result().success(info=Constants.DRAWING_FINISHED)
|
||||
|
||||
@ -870,8 +871,8 @@ class Data:
|
||||
self.raw_Abd = read_csv(Config["Path"]["Input_Abd"],
|
||||
encoding=ConfigParams.UTF8_ENCODING,
|
||||
header=None).to_numpy().reshape(-1)
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.INPUT_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Read_Data_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.INPUT_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Read_Data_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.INPUT_FINISHED)
|
||||
|
||||
@ -882,8 +883,8 @@ class Data:
|
||||
# 保存到csv中
|
||||
df = DataFrame({"pos": [pos], "epoch": [epoch], "ApplyFrequency": [ApplyFrequency]})
|
||||
df.to_csv(Path(Config["Path"]["Save"]), mode="w", header=True, index=False)
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.SAVING_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Save_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.SAVING_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Save_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.SAVING_FINISHED)
|
||||
|
||||
@ -895,8 +896,8 @@ class Data:
|
||||
self.processed_orgBcg = resample(self.raw_orgBcg, int(Config["orgBcg_minutes"] * 60 * Config["ApplyFrequency"]))
|
||||
self.processed_Tho = resample(self.raw_Tho, int(Config["PSG_minutes"] * 60 * Config["ApplyFrequency"]))
|
||||
self.processed_Abd = resample(self.raw_Abd, int(Config["PSG_minutes"] * 60 * Config["ApplyFrequency"]))
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_ONLY_ALIGN_RESAMPLE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Only_Resample_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_ONLY_ALIGN_RESAMPLE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Only_Resample_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.APPROXIMATELY_ONLY_ALIGN_RESAMPLE_FINISHED)
|
||||
|
||||
@ -923,8 +924,8 @@ class Data:
|
||||
Config["Filter"]["BandPassHigh"],
|
||||
Config["InputConfig"]["AbdFreq"],
|
||||
Config["Filter"]["BandPassOrder"])
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_RESP_GET_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Resp_Get_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_RESP_GET_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Resp_Get_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.APPROXIMATELY_RESP_GET_FINISHED)
|
||||
|
||||
@ -951,8 +952,8 @@ class Data:
|
||||
# 用repeat完成
|
||||
self.processed_orgBcg = repeat(self.processed_orgBcg, int(Config["TempFrequency"] / Config["InputConfig"]["orgBcgFreq"]), axis=0)
|
||||
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_PRE_ALIGN_RESAMPLE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Pre_Resample_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_PRE_ALIGN_RESAMPLE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Pre_Resample_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.APPROXIMATELY_PRE_ALIGN_RESAMPLE_FINISHED)
|
||||
|
||||
@ -972,8 +973,8 @@ class Data:
|
||||
self.processed_orgBcg = self.processed_orgBcg - convolve(self.processed_orgBcg,
|
||||
ones(int(4 * temp_frequency)) / int(4 * temp_frequency),
|
||||
mode='same')
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_DELETE_BASE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Delete_Base_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_DELETE_BASE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Delete_Base_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.APPROXIMATELY_DELETE_BASE_FINISHED)
|
||||
|
||||
@ -986,8 +987,8 @@ class Data:
|
||||
self.processed_Abd = (self.processed_Abd - mean(self.processed_Abd)) / std(self.processed_Abd)
|
||||
if Config["orgBcgConfig"]["orgBcgZScore"]:
|
||||
self.processed_orgBcg = (self.processed_orgBcg - mean(self.processed_orgBcg)) / std(self.processed_orgBcg)
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_STANDARDIZE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Standardize_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_STANDARDIZE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Standardize_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.APPROXIMATELY_STANDARDIZE_FINISHED)
|
||||
|
||||
@ -999,8 +1000,8 @@ class Data:
|
||||
self.processed_Tho = self.processed_Tho[::int(temp_frequency / Config["ApplyFrequency"])]
|
||||
self.processed_Abd = self.processed_Abd[::int(temp_frequency / Config["ApplyFrequency"])]
|
||||
self.processed_orgBcg = self.processed_orgBcg[::int(temp_frequency / Config["ApplyFrequency"])]
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_ALIGN_RESAMPLE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Resample_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_ALIGN_RESAMPLE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Resample_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.APPROXIMATELY_ALIGN_RESAMPLE_FINISHED)
|
||||
|
||||
@ -1024,8 +1025,8 @@ class Data:
|
||||
tho_relate2 = - tho_relate
|
||||
|
||||
result = {"tho_relate": tho_relate, "tho_relate2": tho_relate2}
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_CORRELATION_CALCULATE1_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Calculate_Correlation1_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_CORRELATION_CALCULATE1_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Calculate_Correlation1_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.APPROXIMATELY_CORRELATION_CALCULATE1_FINISHED, data=result)
|
||||
|
||||
@ -1050,8 +1051,8 @@ class Data:
|
||||
abd_relate2 = - abd_relate
|
||||
|
||||
result = {"abd_relate": abd_relate, "abd_relate2": abd_relate2}
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_CORRELATION_CALCULATE2_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Calculate_Correlation2_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_CORRELATION_CALCULATE2_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Calculate_Correlation2_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.APPROXIMATELY_CORRELATION_CALCULATE2_FINISHED, data=result)
|
||||
|
||||
@ -1067,8 +1068,8 @@ class Data:
|
||||
bias = pre - len(self.processed_orgBcg) + 1
|
||||
|
||||
result = {"tho_max": tho_max, "tho_max2": tho_max2, "abd_max": abd_max, "abd_max2": abd_max2, "bias": bias}
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_MAXVALUE_POS_CALCULATE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Calculate_Maxvalue_Pos_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_MAXVALUE_POS_CALCULATE_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Calculate_Maxvalue_Pos_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.APPROXIMATELY_MAXVALUE_POS_CALCULATE_FINISHED, data=result)
|
||||
|
||||
@ -1080,8 +1081,8 @@ class Data:
|
||||
(len(self.processed_orgBcg) + Config["pos"]) // 30 // Config["ApplyFrequency"] - 1)
|
||||
|
||||
result = {"epoch_min": epoch_min, "epoch_max": epoch_max}
|
||||
except Exception:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_EPOCH_GET_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Get_Epoch_Exception"])
|
||||
except Exception as e:
|
||||
return Result().failure(info=Constants.APPROXIMATELY_EPOCH_GET_FAILURE + Constants.APPROXIMATELY_ALIGN_FAILURE_REASON["Get_Epoch_Exception"] + "\n" + format_exc())
|
||||
|
||||
return Result().success(info=Constants.APPROXIMATELY_EPOCH_GET_FINISHED, data=result)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user