mirror of
https://github.com/shizand/statapp.git
synced 2024-12-23 12:12:59 +03:00
fix: Добавлена обработка ошибок (#98)
Closes #83 Closes #96 Closes #97 Добавлена обобщенная обработка на большинство методов. Один из вариантов временно (а может и постоянно) решить проблемы.
This commit is contained in:
parent
1c88acf772
commit
c36e1aa733
@ -3,5 +3,5 @@
|
|||||||
<component name="Black">
|
<component name="Black">
|
||||||
<option name="sdkName" value="Poetry (statapp)" />
|
<option name="sdkName" value="Poetry (statapp)" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="statapp" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Poetry (statapp) (2)" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<module type="PYTHON_MODULE" version="4">
|
<module type="PYTHON_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$" />
|
||||||
<orderEntry type="jdk" jdkName="statapp" jdkType="Python SDK" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
@ -24,4 +24,5 @@ disable=
|
|||||||
missing-docstring,
|
missing-docstring,
|
||||||
too-many-public-methods,
|
too-many-public-methods,
|
||||||
too-few-public-methods,
|
too-few-public-methods,
|
||||||
too-many-arguments
|
too-many-arguments,
|
||||||
|
broad-except
|
||||||
|
@ -33,7 +33,7 @@ from statapp.about_window import AboutWindow
|
|||||||
from statapp.models.fileslc_model import FileSLCModel
|
from statapp.models.fileslc_model import FileSLCModel
|
||||||
from statapp.polynoms.squared_polynom_window import SquaredPolynomWindow
|
from statapp.polynoms.squared_polynom_window import SquaredPolynomWindow
|
||||||
from statapp.ui.ui_main_window import Ui_MainWindow
|
from statapp.ui.ui_main_window import Ui_MainWindow
|
||||||
from statapp.utils import buildMessageBox, addIcon, FloatDelegate
|
from statapp.utils import buildMessageBox, addIcon, FloatDelegate, onError
|
||||||
from statapp.variance_analysis import VarianceAnalysisWindow
|
from statapp.variance_analysis import VarianceAnalysisWindow
|
||||||
from statapp.correlation_analysis import CorrelationAnalysisWindow
|
from statapp.correlation_analysis import CorrelationAnalysisWindow
|
||||||
from statapp.polynoms.transform_polynom_window import TransformPolynomWindow
|
from statapp.polynoms.transform_polynom_window import TransformPolynomWindow
|
||||||
@ -103,71 +103,86 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_openfileaction_triggered(self):
|
def on_openfileaction_triggered(self):
|
||||||
currentData = self.model.getData()
|
try:
|
||||||
data = np.array([])
|
currentData = self.model.getData()
|
||||||
if currentData.size > 1:
|
data = np.array([])
|
||||||
file = ''
|
if currentData.size > 1:
|
||||||
if self.fileModel.fileName:
|
file = ''
|
||||||
file = '\nФайл сохранения: ' + self.fileModel.fileName
|
if self.fileModel.fileName:
|
||||||
|
file = '\nФайл сохранения: ' + self.fileModel.fileName
|
||||||
|
|
||||||
msgBox = buildMessageBox \
|
msgBox = buildMessageBox \
|
||||||
('Сохранение данных',
|
('Сохранение данных',
|
||||||
"Сохранить данные?" + file,
|
"Сохранить данные?" + file,
|
||||||
QMessageBox.Question,
|
QMessageBox.Question,
|
||||||
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
|
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
|
||||||
QMessageBox.Cancel)
|
QMessageBox.Cancel)
|
||||||
|
|
||||||
reply = msgBox.exec_()
|
reply = msgBox.exec_()
|
||||||
if reply == QMessageBox.StandardButton.Yes:
|
if reply == QMessageBox.StandardButton.Yes:
|
||||||
self.fileModel.saveFile(self.model.getData())
|
self.fileModel.saveFile(self.model.getData())
|
||||||
|
|
||||||
data = self.fileModel.loadFile()
|
data = self.fileModel.loadFile()
|
||||||
if data is not None and data.shape[0] > 0:
|
if data is not None and data.shape[0] > 0:
|
||||||
self.model.updateAllData(data)
|
self.model.updateAllData(data)
|
||||||
self.isDataChanged = False
|
self.isDataChanged = False
|
||||||
elif reply == QMessageBox.StandardButton.Cancel:
|
elif reply == QMessageBox.StandardButton.Cancel:
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
data = self.fileModel.loadFile()
|
||||||
|
if data is not None and data.shape[0] > 0:
|
||||||
|
self.model.updateAllData(data)
|
||||||
|
self.isDataChanged = False
|
||||||
else:
|
else:
|
||||||
data = self.fileModel.loadFile()
|
data = self.fileModel.loadFile()
|
||||||
if data is not None and data.shape[0] > 0:
|
if data is not None and data.shape[0] > 0:
|
||||||
self.model.updateAllData(data)
|
self.model.updateAllData(data)
|
||||||
self.isDataChanged = False
|
self.isDataChanged = False
|
||||||
else:
|
except Exception as error:
|
||||||
data = self.fileModel.loadFile()
|
onError(error)
|
||||||
if data is not None and data.shape[0] > 0:
|
|
||||||
self.model.updateAllData(data)
|
|
||||||
self.isDataChanged = False
|
|
||||||
|
|
||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_savefileaction_triggered(self):
|
def on_savefileaction_triggered(self):
|
||||||
self.isDataChanged = not self.fileModel.saveFile(self.model.getData())
|
try:
|
||||||
|
self.isDataChanged = not self.fileModel.saveFile(self.model.getData())
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_closefileaction_triggered(self):
|
def on_closefileaction_triggered(self):
|
||||||
self.fileModel.closeFile()
|
try:
|
||||||
self.isDataChanged = False
|
self.fileModel.closeFile()
|
||||||
|
self.isDataChanged = False
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_generateYaction_triggered(self):
|
def on_generateYaction_triggered(self):
|
||||||
gw = GenerateWindow()
|
try:
|
||||||
|
gw = GenerateWindow()
|
||||||
|
|
||||||
if gw.exec():
|
if gw.exec():
|
||||||
y = generateYValues(gw.mat, gw.deviation, gw.count)
|
y = generateYValues(gw.mat, gw.deviation, gw.count)
|
||||||
self.model.updateAllData(y.round(NUMBERS_PRECISION))
|
self.model.updateAllData(y.round(NUMBERS_PRECISION))
|
||||||
self.isDataChanged = True
|
self.isDataChanged = True
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_generateXaction_triggered(self):
|
def on_generateXaction_triggered(self):
|
||||||
gfw = GenerateFactorWindow()
|
try:
|
||||||
|
gfw = GenerateFactorWindow()
|
||||||
|
|
||||||
if gfw.exec():
|
if gfw.exec():
|
||||||
data = self.model.getData()
|
data = self.model.getData()
|
||||||
y = self.model.getY()
|
y = self.model.getY()
|
||||||
xValues = generateXValues(gfw.mat, gfw.deviation, gfw.typeConnection, y)
|
xValues = generateXValues(gfw.mat, gfw.deviation, gfw.typeConnection, y)
|
||||||
data = np.concatenate((data, xValues.round(NUMBERS_PRECISION)), axis=1)
|
data = np.concatenate((data, xValues.round(NUMBERS_PRECISION)), axis=1)
|
||||||
self.model.updateAllData(data)
|
self.model.updateAllData(data)
|
||||||
self.isDataChanged = True
|
self.isDataChanged = True
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_aboutmenuaction_triggered(self):
|
def on_aboutmenuaction_triggered(self):
|
||||||
@ -176,28 +191,43 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_varianceAnalysisAction_triggered(self):
|
def on_varianceAnalysisAction_triggered(self):
|
||||||
dw = VarianceAnalysisWindow(self.model.getData())
|
try:
|
||||||
dw.exec()
|
dw = VarianceAnalysisWindow(self.model.getData())
|
||||||
|
dw.exec()
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_correlationAnalisisAction_triggered(self):
|
def on_correlationAnalisisAction_triggered(self):
|
||||||
dw = CorrelationAnalysisWindow(self.model.getData())
|
try:
|
||||||
dw.exec()
|
dw = CorrelationAnalysisWindow(self.model.getData())
|
||||||
|
dw.exec()
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_linearPolynomAction_triggered(self):
|
def on_linearPolynomAction_triggered(self):
|
||||||
dw = LinearPolynomWindow(self.model.getData())
|
try:
|
||||||
dw.exec()
|
dw = LinearPolynomWindow(self.model.getData())
|
||||||
|
dw.exec()
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_squaredPolynomAction_triggered(self):
|
def on_squaredPolynomAction_triggered(self):
|
||||||
dw = SquaredPolynomWindow(self.model.getData())
|
try:
|
||||||
dw.exec()
|
dw = SquaredPolynomWindow(self.model.getData())
|
||||||
|
dw.exec()
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
@Slot()
|
@Slot()
|
||||||
def on_transformPolynomAction_triggered(self):
|
def on_transformPolynomAction_triggered(self):
|
||||||
dw = TransformPolynomWindow(self.model.getData())
|
try:
|
||||||
dw.exec()
|
dw = TransformPolynomWindow(self.model.getData())
|
||||||
|
dw.exec()
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
if self.isDataChanged:
|
if self.isDataChanged:
|
||||||
|
@ -28,7 +28,7 @@ from statapp.models.prediction_table_model import PreditionTableModel
|
|||||||
from statapp.models.transform_polynom_model import TransformPolynomModel, TRANSFORMS
|
from statapp.models.transform_polynom_model import TransformPolynomModel, TRANSFORMS
|
||||||
from statapp.polynoms.polynom_window import MplCanvas
|
from statapp.polynoms.polynom_window import MplCanvas
|
||||||
from statapp.ui.ui_polynom_window import Ui_PolynomWindow
|
from statapp.ui.ui_polynom_window import Ui_PolynomWindow
|
||||||
from statapp.utils import addIcon
|
from statapp.utils import addIcon, onError
|
||||||
|
|
||||||
|
|
||||||
class TransformPolynomWindow(QDialog):
|
class TransformPolynomWindow(QDialog):
|
||||||
@ -41,8 +41,11 @@ class TransformPolynomWindow(QDialog):
|
|||||||
|
|
||||||
self.data = data
|
self.data = data
|
||||||
result = linearPolynom(data)
|
result = linearPolynom(data)
|
||||||
|
try:
|
||||||
|
predictionResult = prediction(data, result)
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
predictionResult = prediction(data, result)
|
|
||||||
self.predictionModel = PreditionTableModel(predictionResult)
|
self.predictionModel = PreditionTableModel(predictionResult)
|
||||||
self.ui.predictionTableView.setModel(self.predictionModel)
|
self.ui.predictionTableView.setModel(self.predictionModel)
|
||||||
header = self.ui.predictionTableView.horizontalHeader()
|
header = self.ui.predictionTableView.horizontalHeader()
|
||||||
@ -90,7 +93,10 @@ class TransformPolynomWindow(QDialog):
|
|||||||
tr = self.model.data(self.model.createIndex(j, 0), Qt.DisplayRole)
|
tr = self.model.data(self.model.createIndex(j, 0), Qt.DisplayRole)
|
||||||
data[i][j] = TRANSFORMS[tr](data[i][j])
|
data[i][j] = TRANSFORMS[tr](data[i][j])
|
||||||
|
|
||||||
self.rebuildData(data)
|
try:
|
||||||
|
self.rebuildData(data)
|
||||||
|
except Exception as error:
|
||||||
|
onError(error)
|
||||||
|
|
||||||
def rebuildData(self, data):
|
def rebuildData(self, data):
|
||||||
result = linearPolynom(data)
|
result = linearPolynom(data)
|
||||||
|
@ -59,8 +59,19 @@ def buildMessageBox(title, text, icon, buttons, defaultButton):
|
|||||||
msgBox.setStandardButtons(buttons)
|
msgBox.setStandardButtons(buttons)
|
||||||
msgBox.setDefaultButton(defaultButton)
|
msgBox.setDefaultButton(defaultButton)
|
||||||
|
|
||||||
|
addIcon(msgBox)
|
||||||
|
|
||||||
return msgBox
|
return msgBox
|
||||||
|
|
||||||
|
def onError(errorName: Exception):
|
||||||
|
msgBox = buildMessageBox \
|
||||||
|
('Ошибка',
|
||||||
|
"Упс.. Произошла ошибка:\n" + str(errorName),
|
||||||
|
QMessageBox.Critical,
|
||||||
|
QMessageBox.Ok,
|
||||||
|
QMessageBox.Ok)
|
||||||
|
|
||||||
|
msgBox.exec_()
|
||||||
|
|
||||||
class FloatDelegate(QStyledItemDelegate):
|
class FloatDelegate(QStyledItemDelegate):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user