diff --git a/statapp/constants.py b/statapp/constants.py new file mode 100644 index 0000000..2903c42 --- /dev/null +++ b/statapp/constants.py @@ -0,0 +1,20 @@ +# +# Copyright (c) 2023 Maxim Slipenko, Eugene Lazurenko. +# +# This file is part of Statapp +# (see https://github.com/shizand/statapp). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +NUMBERS_PRECISION = 5 diff --git a/statapp/correlation_analysis.py b/statapp/correlation_analysis.py index 2fcc8f1..a266a3f 100644 --- a/statapp/correlation_analysis.py +++ b/statapp/correlation_analysis.py @@ -23,6 +23,7 @@ from PySide2.QtGui import QIcon from PySide2.QtWidgets import QDialog, QHeaderView from statapp.calculations import correlationAnalysis +from statapp.constants import NUMBERS_PRECISION from statapp.mathtex_header_view import MathTexHeaderView from statapp.models.correlation_analysis_model import CorrelationAnalysisModel from statapp.ui.ui_correlation_analysis_window import Ui_CorrelationAnalysisWindow @@ -36,7 +37,7 @@ class CorrelationAnalysisWindow(QDialog): self.ui.setupUi(self) res = correlationAnalysis(data) - self.model = CorrelationAnalysisModel(res.round(2)) + self.model = CorrelationAnalysisModel(res.round(NUMBERS_PRECISION)) self.ui.tableView.setModel(self.model) self.ui.tableView.setVerticalHeader( MathTexHeaderView(self.ui.tableView) diff --git a/statapp/linear_polynom_window.py b/statapp/linear_polynom_window.py index fc7b09e..6d040c0 100644 --- a/statapp/linear_polynom_window.py +++ b/statapp/linear_polynom_window.py @@ -23,7 +23,7 @@ from statapp.calculations import linearPolynom from statapp.mathtex_header_view import MathTexHeaderView from statapp.models.regression_result_model import RegressionResultModel from statapp.ui.ui_linear_polynom_window import Ui_LinearPolynomWindow -from statapp.utils import addIcon +from statapp.utils import addIcon, FloatDelegate class LinearPolynomWindow(QDialog): @@ -36,6 +36,7 @@ class LinearPolynomWindow(QDialog): result = linearPolynom(data) self.model = RegressionResultModel(result) + self.ui.tableView.setItemDelegate(FloatDelegate()) self.ui.tableView.setModel(self.model) self.ui.tableView.setVerticalHeader(MathTexHeaderView(self.ui.tableView)) header = self.ui.tableView.horizontalHeader() diff --git a/statapp/main_window.py b/statapp/main_window.py index f83b475..b38132b 100644 --- a/statapp/main_window.py +++ b/statapp/main_window.py @@ -23,6 +23,7 @@ from PySide2.QtCore import Slot from PySide2.QtWidgets import QMainWindow, QMessageBox from statapp.calculations import generateXValues, generateYValues +from statapp.constants import NUMBERS_PRECISION from statapp.generate_factor_window import GenerateFactorWindow from statapp.linear_polynom_window import LinearPolynomWindow from statapp.mathtex_header_view import MathTexHeaderView @@ -32,7 +33,7 @@ from statapp.about_window import AboutWindow from statapp.models.fileslc_model import FileSLCModel from statapp.squared_polynom_window import SquaredPolynomWindow from statapp.ui.ui_main_window import Ui_MainWindow -from statapp.utils import buildMessageBox, addIcon +from statapp.utils import buildMessageBox, addIcon, FloatDelegate from statapp.variance_analysis import VarianceAnalysisWindow from statapp.correlation_analysis import CorrelationAnalysisWindow @@ -62,6 +63,7 @@ class MainWindow(QMainWindow): self.isDataChanged = False self.model = InputValuesModel() self.fileModel = FileSLCModel() + self.ui.tableView.setItemDelegate(FloatDelegate()) self.ui.tableView.setModel(self.model) self.ui.tableView.setHorizontalHeader( MathTexHeaderView(self.ui.tableView, orientation=QtCore.Qt.Horizontal) @@ -150,7 +152,7 @@ class MainWindow(QMainWindow): if gw.exec(): y = generateYValues(gw.mat, gw.deviation, gw.count) - self.model.updateAllData(y.round(2)) + self.model.updateAllData(y.round(NUMBERS_PRECISION)) self.isDataChanged = True @Slot() @@ -161,7 +163,7 @@ class MainWindow(QMainWindow): data = self.model.getData() y = self.model.getY() xValues = generateXValues(gfw.mat, gfw.deviation, gfw.typeConnection, y) - data = np.concatenate((data, xValues.round(2)), axis=1) + data = np.concatenate((data, xValues.round(NUMBERS_PRECISION)), axis=1) self.model.updateAllData(data) self.isDataChanged = True diff --git a/statapp/models/fileslc_model.py b/statapp/models/fileslc_model.py index 36f8dfa..9e286e4 100644 --- a/statapp/models/fileslc_model.py +++ b/statapp/models/fileslc_model.py @@ -20,6 +20,7 @@ import numpy as np from PySide2.QtWidgets import QFileDialog, QMessageBox +from statapp.constants import NUMBERS_PRECISION from statapp.utils import buildMessageBox @@ -57,7 +58,7 @@ class FileSLCModel: None, "Сохранить файл", "", "Text Files (*.txt);;CSV Files (*.csv)" ) if self.fileName: - np.savetxt(self.fileName, data, delimiter=",", fmt='%10.5f') + np.savetxt(self.fileName, data, delimiter=",", fmt=f"%.{NUMBERS_PRECISION}f") return True return False diff --git a/statapp/squared_polynom_window.py b/statapp/squared_polynom_window.py index 37475b1..ce0d63b 100644 --- a/statapp/squared_polynom_window.py +++ b/statapp/squared_polynom_window.py @@ -23,7 +23,7 @@ from statapp.calculations import squaredPolynom from statapp.mathtex_header_view import MathTexHeaderView from statapp.models.regression_result_model import RegressionResultModel from statapp.ui.ui_squared_polynom_window import Ui_SquaredPolynomWindow -from statapp.utils import addIcon +from statapp.utils import addIcon, FloatDelegate class SquaredPolynomWindow(QDialog): @@ -36,6 +36,7 @@ class SquaredPolynomWindow(QDialog): result = squaredPolynom(data) self.model = RegressionResultModel(result) + self.ui.tableView.setItemDelegate(FloatDelegate()) self.ui.tableView.setModel(self.model) self.ui.tableView.setVerticalHeader(MathTexHeaderView(self.ui.tableView)) header = self.ui.tableView.horizontalHeader() diff --git a/statapp/ui/generate_factor_window.ui b/statapp/ui/generate_factor_window.ui index 147b4ae..75155b9 100644 --- a/statapp/ui/generate_factor_window.ui +++ b/statapp/ui/generate_factor_window.ui @@ -71,6 +71,9 @@ 12 + + 5 + 1000000.000000000000000 @@ -83,6 +86,9 @@ 12 + + 5 + 1000000.000000000000000 diff --git a/statapp/ui/generate_window.ui b/statapp/ui/generate_window.ui index 8abb447..cce6dda 100644 --- a/statapp/ui/generate_window.ui +++ b/statapp/ui/generate_window.ui @@ -44,6 +44,9 @@ + + 5 + 1000000.000000000000000 @@ -68,6 +71,9 @@ + + 5 + 1000000.000000000000000 diff --git a/statapp/ui/ui_generate_factor_window.py b/statapp/ui/ui_generate_factor_window.py index 727b1b7..94d324b 100644 --- a/statapp/ui/ui_generate_factor_window.py +++ b/statapp/ui/ui_generate_factor_window.py @@ -71,6 +71,7 @@ class Ui_GenerateFactorWindow(object): self.matSpinBox = QDoubleSpinBox(GenerateFactorWindow) self.matSpinBox.setObjectName(u"matSpinBox") self.matSpinBox.setFont(font) + self.matSpinBox.setDecimals(5) self.matSpinBox.setMaximum(1000000.000000000000000) self.gridLayout.addWidget(self.matSpinBox, 1, 1, 1, 1) @@ -78,6 +79,7 @@ class Ui_GenerateFactorWindow(object): self.deviationSpinBox = QDoubleSpinBox(GenerateFactorWindow) self.deviationSpinBox.setObjectName(u"deviationSpinBox") self.deviationSpinBox.setFont(font) + self.deviationSpinBox.setDecimals(5) self.deviationSpinBox.setMaximum(1000000.000000000000000) self.gridLayout.addWidget(self.deviationSpinBox, 2, 1, 1, 1) diff --git a/statapp/ui/ui_generate_window.py b/statapp/ui/ui_generate_window.py index c3fbe49..8514030 100644 --- a/statapp/ui/ui_generate_window.py +++ b/statapp/ui/ui_generate_window.py @@ -62,6 +62,7 @@ class Ui_GenerateWindow(object): self.matSpinBox = QDoubleSpinBox(GenerateWindow) self.matSpinBox.setObjectName(u"matSpinBox") + self.matSpinBox.setDecimals(5) self.matSpinBox.setMaximum(1000000.000000000000000) self.gridLayout.addWidget(self.matSpinBox, 1, 1, 1, 1) @@ -80,6 +81,7 @@ class Ui_GenerateWindow(object): self.deviationSpinBox = QDoubleSpinBox(GenerateWindow) self.deviationSpinBox.setObjectName(u"deviationSpinBox") + self.deviationSpinBox.setDecimals(5) self.deviationSpinBox.setMaximum(1000000.000000000000000) self.gridLayout.addWidget(self.deviationSpinBox, 2, 1, 1, 1) diff --git a/statapp/utils.py b/statapp/utils.py index 9d1e83c..5039d6d 100644 --- a/statapp/utils.py +++ b/statapp/utils.py @@ -22,7 +22,9 @@ import sys from PySide2.QtCore import QSize from PySide2.QtGui import QIcon -from PySide2.QtWidgets import QMessageBox +from PySide2.QtWidgets import QMessageBox, QDoubleSpinBox, QStyledItemDelegate + +from statapp.constants import NUMBERS_PRECISION def resourcePath(relative): @@ -58,3 +60,19 @@ def buildMessageBox(title, text, icon, buttons, defaultButton): msgBox.setDefaultButton(defaultButton) return msgBox + + +class FloatDelegate(QStyledItemDelegate): + def __init__(self, parent=None): + QStyledItemDelegate.__init__(self, parent=parent) + + def createEditor(self, parent, option, index): + editor = QDoubleSpinBox(parent) + editor.setDecimals(NUMBERS_PRECISION) + editor.setMaximum(10**8) + editor.setMinimum(-10**8) + return editor + + def displayText(self, value, locale): + # Грязный хак, скорее всего нужно было использовать locale + return f'{value:.{NUMBERS_PRECISION}f}' diff --git a/statapp/variance_analysis.py b/statapp/variance_analysis.py index 75609af..2ca5b47 100644 --- a/statapp/variance_analysis.py +++ b/statapp/variance_analysis.py @@ -20,10 +20,11 @@ from PySide2.QtWidgets import QDialog, QHeaderView from statapp.calculations import varianceAnalysis +from statapp.constants import NUMBERS_PRECISION from statapp.mathtex_header_view import MathTexHeaderView from statapp.models.variance_analysis_model import VarianceAnalysisModel from statapp.ui.ui_variance_analysis_window import Ui_VarianceAnalysisWindow -from statapp.utils import addIcon +from statapp.utils import addIcon, FloatDelegate class VarianceAnalysisWindow(QDialog): @@ -33,7 +34,8 @@ class VarianceAnalysisWindow(QDialog): self.ui.setupUi(self) res = varianceAnalysis(data) - self.model = VarianceAnalysisModel(res.round(2)) + self.model = VarianceAnalysisModel(res.round(NUMBERS_PRECISION)) + self.ui.tableView.setItemDelegate(FloatDelegate()) self.ui.tableView.setModel(self.model) self.ui.tableView.setVerticalHeader( MathTexHeaderView(self.ui.tableView)