feat: добавлена возможность ввода чисел до 5 знаков (#87)

Closes #82
This commit is contained in:
Maxim Slipenko 2023-11-25 14:21:05 +03:00 committed by GitHub
parent 2f5988a2eb
commit dc7c4875d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 72 additions and 10 deletions

20
statapp/constants.py Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
#
NUMBERS_PRECISION = 5

View File

@ -23,6 +23,7 @@ from PySide2.QtGui import QIcon
from PySide2.QtWidgets import QDialog, QHeaderView from PySide2.QtWidgets import QDialog, QHeaderView
from statapp.calculations import correlationAnalysis from statapp.calculations import correlationAnalysis
from statapp.constants import NUMBERS_PRECISION
from statapp.mathtex_header_view import MathTexHeaderView from statapp.mathtex_header_view import MathTexHeaderView
from statapp.models.correlation_analysis_model import CorrelationAnalysisModel from statapp.models.correlation_analysis_model import CorrelationAnalysisModel
from statapp.ui.ui_correlation_analysis_window import Ui_CorrelationAnalysisWindow from statapp.ui.ui_correlation_analysis_window import Ui_CorrelationAnalysisWindow
@ -36,7 +37,7 @@ class CorrelationAnalysisWindow(QDialog):
self.ui.setupUi(self) self.ui.setupUi(self)
res = correlationAnalysis(data) 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.setModel(self.model)
self.ui.tableView.setVerticalHeader( self.ui.tableView.setVerticalHeader(
MathTexHeaderView(self.ui.tableView) MathTexHeaderView(self.ui.tableView)

View File

@ -23,7 +23,7 @@ from statapp.calculations import linearPolynom
from statapp.mathtex_header_view import MathTexHeaderView from statapp.mathtex_header_view import MathTexHeaderView
from statapp.models.regression_result_model import RegressionResultModel from statapp.models.regression_result_model import RegressionResultModel
from statapp.ui.ui_linear_polynom_window import Ui_LinearPolynomWindow from statapp.ui.ui_linear_polynom_window import Ui_LinearPolynomWindow
from statapp.utils import addIcon from statapp.utils import addIcon, FloatDelegate
class LinearPolynomWindow(QDialog): class LinearPolynomWindow(QDialog):
@ -36,6 +36,7 @@ class LinearPolynomWindow(QDialog):
result = linearPolynom(data) result = linearPolynom(data)
self.model = RegressionResultModel(result) self.model = RegressionResultModel(result)
self.ui.tableView.setItemDelegate(FloatDelegate())
self.ui.tableView.setModel(self.model) self.ui.tableView.setModel(self.model)
self.ui.tableView.setVerticalHeader(MathTexHeaderView(self.ui.tableView)) self.ui.tableView.setVerticalHeader(MathTexHeaderView(self.ui.tableView))
header = self.ui.tableView.horizontalHeader() header = self.ui.tableView.horizontalHeader()

View File

@ -23,6 +23,7 @@ from PySide2.QtCore import Slot
from PySide2.QtWidgets import QMainWindow, QMessageBox from PySide2.QtWidgets import QMainWindow, QMessageBox
from statapp.calculations import generateXValues, generateYValues from statapp.calculations import generateXValues, generateYValues
from statapp.constants import NUMBERS_PRECISION
from statapp.generate_factor_window import GenerateFactorWindow from statapp.generate_factor_window import GenerateFactorWindow
from statapp.linear_polynom_window import LinearPolynomWindow from statapp.linear_polynom_window import LinearPolynomWindow
from statapp.mathtex_header_view import MathTexHeaderView 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.models.fileslc_model import FileSLCModel
from statapp.squared_polynom_window import SquaredPolynomWindow from statapp.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 from statapp.utils import buildMessageBox, addIcon, FloatDelegate
from statapp.variance_analysis import VarianceAnalysisWindow from statapp.variance_analysis import VarianceAnalysisWindow
from statapp.correlation_analysis import CorrelationAnalysisWindow from statapp.correlation_analysis import CorrelationAnalysisWindow
@ -62,6 +63,7 @@ class MainWindow(QMainWindow):
self.isDataChanged = False self.isDataChanged = False
self.model = InputValuesModel() self.model = InputValuesModel()
self.fileModel = FileSLCModel() self.fileModel = FileSLCModel()
self.ui.tableView.setItemDelegate(FloatDelegate())
self.ui.tableView.setModel(self.model) self.ui.tableView.setModel(self.model)
self.ui.tableView.setHorizontalHeader( self.ui.tableView.setHorizontalHeader(
MathTexHeaderView(self.ui.tableView, orientation=QtCore.Qt.Horizontal) MathTexHeaderView(self.ui.tableView, orientation=QtCore.Qt.Horizontal)
@ -150,7 +152,7 @@ class MainWindow(QMainWindow):
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(2)) self.model.updateAllData(y.round(NUMBERS_PRECISION))
self.isDataChanged = True self.isDataChanged = True
@Slot() @Slot()
@ -161,7 +163,7 @@ class MainWindow(QMainWindow):
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(2)), 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

View File

@ -20,6 +20,7 @@
import numpy as np import numpy as np
from PySide2.QtWidgets import QFileDialog, QMessageBox from PySide2.QtWidgets import QFileDialog, QMessageBox
from statapp.constants import NUMBERS_PRECISION
from statapp.utils import buildMessageBox from statapp.utils import buildMessageBox
@ -57,7 +58,7 @@ class FileSLCModel:
None, "Сохранить файл", "", "Text Files (*.txt);;CSV Files (*.csv)" None, "Сохранить файл", "", "Text Files (*.txt);;CSV Files (*.csv)"
) )
if self.fileName: 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 True
return False return False

View File

@ -23,7 +23,7 @@ from statapp.calculations import squaredPolynom
from statapp.mathtex_header_view import MathTexHeaderView from statapp.mathtex_header_view import MathTexHeaderView
from statapp.models.regression_result_model import RegressionResultModel from statapp.models.regression_result_model import RegressionResultModel
from statapp.ui.ui_squared_polynom_window import Ui_SquaredPolynomWindow from statapp.ui.ui_squared_polynom_window import Ui_SquaredPolynomWindow
from statapp.utils import addIcon from statapp.utils import addIcon, FloatDelegate
class SquaredPolynomWindow(QDialog): class SquaredPolynomWindow(QDialog):
@ -36,6 +36,7 @@ class SquaredPolynomWindow(QDialog):
result = squaredPolynom(data) result = squaredPolynom(data)
self.model = RegressionResultModel(result) self.model = RegressionResultModel(result)
self.ui.tableView.setItemDelegate(FloatDelegate())
self.ui.tableView.setModel(self.model) self.ui.tableView.setModel(self.model)
self.ui.tableView.setVerticalHeader(MathTexHeaderView(self.ui.tableView)) self.ui.tableView.setVerticalHeader(MathTexHeaderView(self.ui.tableView))
header = self.ui.tableView.horizontalHeader() header = self.ui.tableView.horizontalHeader()

View File

@ -71,6 +71,9 @@
<pointsize>12</pointsize> <pointsize>12</pointsize>
</font> </font>
</property> </property>
<property name="decimals">
<number>5</number>
</property>
<property name="maximum"> <property name="maximum">
<double>1000000.000000000000000</double> <double>1000000.000000000000000</double>
</property> </property>
@ -83,6 +86,9 @@
<pointsize>12</pointsize> <pointsize>12</pointsize>
</font> </font>
</property> </property>
<property name="decimals">
<number>5</number>
</property>
<property name="maximum"> <property name="maximum">
<double>1000000.000000000000000</double> <double>1000000.000000000000000</double>
</property> </property>

View File

@ -44,6 +44,9 @@
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QDoubleSpinBox" name="matSpinBox"> <widget class="QDoubleSpinBox" name="matSpinBox">
<property name="decimals">
<number>5</number>
</property>
<property name="maximum"> <property name="maximum">
<double>1000000.000000000000000</double> <double>1000000.000000000000000</double>
</property> </property>
@ -68,6 +71,9 @@
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QDoubleSpinBox" name="deviationSpinBox"> <widget class="QDoubleSpinBox" name="deviationSpinBox">
<property name="decimals">
<number>5</number>
</property>
<property name="maximum"> <property name="maximum">
<double>1000000.000000000000000</double> <double>1000000.000000000000000</double>
</property> </property>

View File

@ -71,6 +71,7 @@ class Ui_GenerateFactorWindow(object):
self.matSpinBox = QDoubleSpinBox(GenerateFactorWindow) self.matSpinBox = QDoubleSpinBox(GenerateFactorWindow)
self.matSpinBox.setObjectName(u"matSpinBox") self.matSpinBox.setObjectName(u"matSpinBox")
self.matSpinBox.setFont(font) self.matSpinBox.setFont(font)
self.matSpinBox.setDecimals(5)
self.matSpinBox.setMaximum(1000000.000000000000000) self.matSpinBox.setMaximum(1000000.000000000000000)
self.gridLayout.addWidget(self.matSpinBox, 1, 1, 1, 1) self.gridLayout.addWidget(self.matSpinBox, 1, 1, 1, 1)
@ -78,6 +79,7 @@ class Ui_GenerateFactorWindow(object):
self.deviationSpinBox = QDoubleSpinBox(GenerateFactorWindow) self.deviationSpinBox = QDoubleSpinBox(GenerateFactorWindow)
self.deviationSpinBox.setObjectName(u"deviationSpinBox") self.deviationSpinBox.setObjectName(u"deviationSpinBox")
self.deviationSpinBox.setFont(font) self.deviationSpinBox.setFont(font)
self.deviationSpinBox.setDecimals(5)
self.deviationSpinBox.setMaximum(1000000.000000000000000) self.deviationSpinBox.setMaximum(1000000.000000000000000)
self.gridLayout.addWidget(self.deviationSpinBox, 2, 1, 1, 1) self.gridLayout.addWidget(self.deviationSpinBox, 2, 1, 1, 1)

View File

@ -62,6 +62,7 @@ class Ui_GenerateWindow(object):
self.matSpinBox = QDoubleSpinBox(GenerateWindow) self.matSpinBox = QDoubleSpinBox(GenerateWindow)
self.matSpinBox.setObjectName(u"matSpinBox") self.matSpinBox.setObjectName(u"matSpinBox")
self.matSpinBox.setDecimals(5)
self.matSpinBox.setMaximum(1000000.000000000000000) self.matSpinBox.setMaximum(1000000.000000000000000)
self.gridLayout.addWidget(self.matSpinBox, 1, 1, 1, 1) self.gridLayout.addWidget(self.matSpinBox, 1, 1, 1, 1)
@ -80,6 +81,7 @@ class Ui_GenerateWindow(object):
self.deviationSpinBox = QDoubleSpinBox(GenerateWindow) self.deviationSpinBox = QDoubleSpinBox(GenerateWindow)
self.deviationSpinBox.setObjectName(u"deviationSpinBox") self.deviationSpinBox.setObjectName(u"deviationSpinBox")
self.deviationSpinBox.setDecimals(5)
self.deviationSpinBox.setMaximum(1000000.000000000000000) self.deviationSpinBox.setMaximum(1000000.000000000000000)
self.gridLayout.addWidget(self.deviationSpinBox, 2, 1, 1, 1) self.gridLayout.addWidget(self.deviationSpinBox, 2, 1, 1, 1)

View File

@ -22,7 +22,9 @@ import sys
from PySide2.QtCore import QSize from PySide2.QtCore import QSize
from PySide2.QtGui import QIcon 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): def resourcePath(relative):
@ -58,3 +60,19 @@ def buildMessageBox(title, text, icon, buttons, defaultButton):
msgBox.setDefaultButton(defaultButton) msgBox.setDefaultButton(defaultButton)
return msgBox 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}'

View File

@ -20,10 +20,11 @@
from PySide2.QtWidgets import QDialog, QHeaderView from PySide2.QtWidgets import QDialog, QHeaderView
from statapp.calculations import varianceAnalysis from statapp.calculations import varianceAnalysis
from statapp.constants import NUMBERS_PRECISION
from statapp.mathtex_header_view import MathTexHeaderView from statapp.mathtex_header_view import MathTexHeaderView
from statapp.models.variance_analysis_model import VarianceAnalysisModel from statapp.models.variance_analysis_model import VarianceAnalysisModel
from statapp.ui.ui_variance_analysis_window import Ui_VarianceAnalysisWindow from statapp.ui.ui_variance_analysis_window import Ui_VarianceAnalysisWindow
from statapp.utils import addIcon from statapp.utils import addIcon, FloatDelegate
class VarianceAnalysisWindow(QDialog): class VarianceAnalysisWindow(QDialog):
@ -33,7 +34,8 @@ class VarianceAnalysisWindow(QDialog):
self.ui.setupUi(self) self.ui.setupUi(self)
res = varianceAnalysis(data) 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.setModel(self.model)
self.ui.tableView.setVerticalHeader( self.ui.tableView.setVerticalHeader(
MathTexHeaderView(self.ui.tableView) MathTexHeaderView(self.ui.tableView)