Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Добавлена обработка ошибок #98

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/stat.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ disable=
missing-docstring,
too-many-public-methods,
too-few-public-methods,
too-many-arguments
too-many-arguments,
broad-except
144 changes: 87 additions & 57 deletions statapp/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from statapp.models.fileslc_model import FileSLCModel
from statapp.polynoms.squared_polynom_window import SquaredPolynomWindow
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.correlation_analysis import CorrelationAnalysisWindow
from statapp.polynoms.transform_polynom_window import TransformPolynomWindow
Expand Down Expand Up @@ -103,71 +103,86 @@ def setEnabledMainActions(self, enabled):

@Slot()
def on_openfileaction_triggered(self):
currentData = self.model.getData()
data = np.array([])
if currentData.size > 1:
file = ''
if self.fileModel.fileName:
file = '\nФайл сохранения: ' + self.fileModel.fileName

msgBox = buildMessageBox \
('Сохранение данных',
"Сохранить данные?" + file,
QMessageBox.Question,
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
QMessageBox.Cancel)

reply = msgBox.exec_()
if reply == QMessageBox.StandardButton.Yes:
self.fileModel.saveFile(self.model.getData())

data = self.fileModel.loadFile()
if data is not None and data.shape[0] > 0:
self.model.updateAllData(data)
self.isDataChanged = False
elif reply == QMessageBox.StandardButton.Cancel:
return
try:
currentData = self.model.getData()
data = np.array([])
if currentData.size > 1:
file = ''
if self.fileModel.fileName:
file = '\nФайл сохранения: ' + self.fileModel.fileName

msgBox = buildMessageBox \
('Сохранение данных',
"Сохранить данные?" + file,
QMessageBox.Question,
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
QMessageBox.Cancel)

reply = msgBox.exec_()
if reply == QMessageBox.StandardButton.Yes:
self.fileModel.saveFile(self.model.getData())

data = self.fileModel.loadFile()
if data is not None and data.shape[0] > 0:
self.model.updateAllData(data)
self.isDataChanged = False
elif reply == QMessageBox.StandardButton.Cancel:
return
else:
data = self.fileModel.loadFile()
if data is not None and data.shape[0] > 0:
self.model.updateAllData(data)
self.isDataChanged = False
else:
data = self.fileModel.loadFile()
if data is not None and data.shape[0] > 0:
self.model.updateAllData(data)
self.isDataChanged = False
else:
data = self.fileModel.loadFile()
if data is not None and data.shape[0] > 0:
self.model.updateAllData(data)
self.isDataChanged = False
except Exception as error:
onError(error)


@Slot()
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()
def on_closefileaction_triggered(self):
self.fileModel.closeFile()
self.isDataChanged = False
try:
self.fileModel.closeFile()
self.isDataChanged = False
except Exception as error:
onError(error)

@Slot()
def on_generateYaction_triggered(self):
gw = GenerateWindow()
try:
gw = GenerateWindow()

if gw.exec():
y = generateYValues(gw.mat, gw.deviation, gw.count)
self.model.updateAllData(y.round(NUMBERS_PRECISION))
self.isDataChanged = True
if gw.exec():
y = generateYValues(gw.mat, gw.deviation, gw.count)
self.model.updateAllData(y.round(NUMBERS_PRECISION))
self.isDataChanged = True
except Exception as error:
onError(error)

@Slot()
def on_generateXaction_triggered(self):
gfw = GenerateFactorWindow()

if gfw.exec():
data = self.model.getData()
y = self.model.getY()
xValues = generateXValues(gfw.mat, gfw.deviation, gfw.typeConnection, y)
data = np.concatenate((data, xValues.round(NUMBERS_PRECISION)), axis=1)
self.model.updateAllData(data)
self.isDataChanged = True
try:
gfw = GenerateFactorWindow()

if gfw.exec():
data = self.model.getData()
y = self.model.getY()
xValues = generateXValues(gfw.mat, gfw.deviation, gfw.typeConnection, y)
data = np.concatenate((data, xValues.round(NUMBERS_PRECISION)), axis=1)
self.model.updateAllData(data)
self.isDataChanged = True
except Exception as error:
onError(error)

@Slot()
def on_aboutmenuaction_triggered(self):
Expand All @@ -176,28 +191,43 @@ def on_aboutmenuaction_triggered(self):

@Slot()
def on_varianceAnalysisAction_triggered(self):
dw = VarianceAnalysisWindow(self.model.getData())
dw.exec()
try:
dw = VarianceAnalysisWindow(self.model.getData())
dw.exec()
except Exception as error:
onError(error)

@Slot()
def on_correlationAnalisisAction_triggered(self):
dw = CorrelationAnalysisWindow(self.model.getData())
dw.exec()
try:
dw = CorrelationAnalysisWindow(self.model.getData())
dw.exec()
except Exception as error:
onError(error)

@Slot()
def on_linearPolynomAction_triggered(self):
dw = LinearPolynomWindow(self.model.getData())
dw.exec()
try:
dw = LinearPolynomWindow(self.model.getData())
dw.exec()
except Exception as error:
onError(error)

@Slot()
def on_squaredPolynomAction_triggered(self):
dw = SquaredPolynomWindow(self.model.getData())
dw.exec()
try:
dw = SquaredPolynomWindow(self.model.getData())
dw.exec()
except Exception as error:
onError(error)

@Slot()
def on_transformPolynomAction_triggered(self):
dw = TransformPolynomWindow(self.model.getData())
dw.exec()
try:
dw = TransformPolynomWindow(self.model.getData())
dw.exec()
except Exception as error:
onError(error)

def closeEvent(self, event):
if self.isDataChanged:
Expand Down
12 changes: 9 additions & 3 deletions statapp/polynoms/transform_polynom_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from statapp.models.transform_polynom_model import TransformPolynomModel, TRANSFORMS
from statapp.polynoms.polynom_window import MplCanvas
from statapp.ui.ui_polynom_window import Ui_PolynomWindow
from statapp.utils import addIcon
from statapp.utils import addIcon, onError


class TransformPolynomWindow(QDialog):
Expand All @@ -41,8 +41,11 @@ def __init__(self, data):

self.data = data
result = linearPolynom(data)
try:
predictionResult = prediction(data, result)
except Exception as error:
onError(error)

predictionResult = prediction(data, result)
self.predictionModel = PreditionTableModel(predictionResult)
self.ui.predictionTableView.setModel(self.predictionModel)
header = self.ui.predictionTableView.horizontalHeader()
Expand Down Expand Up @@ -90,7 +93,10 @@ def on_data_changed(self):
tr = self.model.data(self.model.createIndex(j, 0), Qt.DisplayRole)
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):
result = linearPolynom(data)
Expand Down
11 changes: 11 additions & 0 deletions statapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,19 @@ def buildMessageBox(title, text, icon, buttons, defaultButton):
msgBox.setStandardButtons(buttons)
msgBox.setDefaultButton(defaultButton)

addIcon(msgBox)

return msgBox

def onError(errorName: Exception):
msgBox = buildMessageBox \
('Ошибка',
"Упс.. Произошла ошибка:\n" + str(errorName),
QMessageBox.Critical,
QMessageBox.Ok,
QMessageBox.Ok)

msgBox.exec_()

class FloatDelegate(QStyledItemDelegate):
def __init__(self, parent=None):
Expand Down
Loading