mirror of
https://github.com/shizand/statapp.git
synced 2024-12-23 12:12:59 +03:00
parent
a3f7c1ac0b
commit
86346b9c5b
@ -1,5 +1,30 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
DIRECT_LINK = 0
|
||||||
|
INDIRECT_LINK = 1
|
||||||
|
|
||||||
|
def generate_x_values(mean, std, typeConnection, y):
|
||||||
|
yMean = np.mean(y)
|
||||||
|
values = []
|
||||||
|
for cur_y in y:
|
||||||
|
k = np.abs(cur_y / yMean)
|
||||||
|
if k > 1:
|
||||||
|
k = 2 - 1 / k
|
||||||
|
if typeConnection == INDIRECT_LINK:
|
||||||
|
k = 1 / k
|
||||||
|
if std == 0:
|
||||||
|
k = 1
|
||||||
|
|
||||||
|
x = np.random.normal(mean * (k ** 3), std * k)
|
||||||
|
values.append(x)
|
||||||
|
# if (x > gfw.mat and cur_y > yMat) or (x < gfw.mat and cur_y < yMat):
|
||||||
|
# dd = np.append(dd, 1)
|
||||||
|
# else:
|
||||||
|
# dd = np.append(dd, 0)
|
||||||
|
|
||||||
|
# x_arr = x_arr.reshape(len(x_arr), 1)
|
||||||
|
|
||||||
|
return np.array(values)
|
||||||
|
|
||||||
def variance_analysis(data):
|
def variance_analysis(data):
|
||||||
return np.array([
|
return np.array([
|
||||||
|
@ -3,8 +3,9 @@ from PySide2.QtCore import Slot, QLocale, QSize
|
|||||||
from PySide2.QtGui import QIcon
|
from PySide2.QtGui import QIcon
|
||||||
from PySide2.QtWidgets import QMainWindow, QMessageBox, QApplication
|
from PySide2.QtWidgets import QMainWindow, QMessageBox, QApplication
|
||||||
|
|
||||||
|
from statapp.calculations import generate_x_values
|
||||||
from statapp.generate_factor_window import GenerateFactorWindow, INDIRECT_LINK
|
from statapp.generate_factor_window import GenerateFactorWindow, INDIRECT_LINK
|
||||||
from statapp.models.data_model import DataModel
|
from statapp.models.input_values_model import InputValuesModel
|
||||||
from statapp.generate_window import GenerateWindow
|
from statapp.generate_window import GenerateWindow
|
||||||
from statapp.about_window import AboutWindow
|
from statapp.about_window import AboutWindow
|
||||||
from statapp.models.fileslc_model import FileSLCModel
|
from statapp.models.fileslc_model import FileSLCModel
|
||||||
@ -25,7 +26,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.setWindowIcon(icon)
|
self.setWindowIcon(icon)
|
||||||
|
|
||||||
self.isDataChanged = False
|
self.isDataChanged = False
|
||||||
self.model = DataModel()
|
self.model = InputValuesModel()
|
||||||
self.fileModel = FileSLCModel()
|
self.fileModel = FileSLCModel()
|
||||||
self.ui.tableView.setModel(self.model)
|
self.ui.tableView.setModel(self.model)
|
||||||
|
|
||||||
@ -81,36 +82,13 @@ class MainWindow(QMainWindow):
|
|||||||
def on_generateXaction_triggered(self):
|
def on_generateXaction_triggered(self):
|
||||||
gfw = GenerateFactorWindow()
|
gfw = GenerateFactorWindow()
|
||||||
|
|
||||||
# dd = np.array([])
|
|
||||||
|
|
||||||
if gfw.exec():
|
if gfw.exec():
|
||||||
y = self.model.getY()
|
|
||||||
yMat = np.mean(y)
|
|
||||||
|
|
||||||
x_arr = np.array([])
|
|
||||||
|
|
||||||
for cur_y in y:
|
|
||||||
k = np.abs(cur_y / yMat)
|
|
||||||
if k > 1:
|
|
||||||
k = 2 - 1 / k
|
|
||||||
if gfw.typeConnection == INDIRECT_LINK:
|
|
||||||
k = 1 / k
|
|
||||||
if gfw.deviation == 0:
|
|
||||||
k = 1
|
|
||||||
|
|
||||||
x = np.random.normal(gfw.mat * (k ** 3), gfw.deviation * k, size=1)
|
|
||||||
x_arr = np.append(x_arr, x)
|
|
||||||
# if (x > gfw.mat and cur_y > yMat) or (x < gfw.mat and cur_y < yMat):
|
|
||||||
# dd = np.append(dd, 1)
|
|
||||||
# else:
|
|
||||||
# dd = np.append(dd, 0)
|
|
||||||
|
|
||||||
data = self.model.getData()
|
data = self.model.getData()
|
||||||
|
y = self.model.getY()
|
||||||
|
x_arr = generate_x_values(gfw.mat, gfw.deviation, gfw.typeConnection, y)
|
||||||
x_arr = x_arr.reshape(len(x_arr), 1).round(2)
|
x_arr = x_arr.reshape(len(x_arr), 1).round(2)
|
||||||
# dd = dd.reshape(len(dd), 1)
|
# dd = dd.reshape(len(dd), 1)
|
||||||
data = np.concatenate((data, x_arr), axis=1)
|
data = np.concatenate((data, x_arr), axis=1)
|
||||||
# data = np.concatenate((data, dd), axis=1)
|
|
||||||
self.model.updateAllData(data)
|
self.model.updateAllData(data)
|
||||||
self.isDataChanged = True
|
self.isDataChanged = True
|
||||||
|
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
import numpy as np
|
|
||||||
from PySide2 import QtCore
|
|
||||||
from PySide2.QtCore import Qt
|
|
||||||
|
|
||||||
|
|
||||||
class DataModel(QtCore.QAbstractTableModel):
|
|
||||||
def __init__(self, data=np.array([[]], dtype=np.float32)):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self._data = data
|
|
||||||
|
|
||||||
def updateAllData(self, data):
|
|
||||||
self.layoutAboutToBeChanged.emit()
|
|
||||||
self._data = data
|
|
||||||
self.layoutChanged.emit()
|
|
||||||
|
|
||||||
def rowCount(self, index):
|
|
||||||
return self._data.shape[0]
|
|
||||||
|
|
||||||
def columnCount(self, index):
|
|
||||||
return self._data.shape[1]
|
|
||||||
|
|
||||||
def headerData(self, section: int, orientation: Qt.Orientation, role: int = ...):
|
|
||||||
if role == Qt.DisplayRole:
|
|
||||||
# if orientation == Qt.Orientation.Horizontal:
|
|
||||||
|
|
||||||
if section == 0:
|
|
||||||
return 'Y'
|
|
||||||
|
|
||||||
return f'X{section}'
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
def flags(self, index):
|
|
||||||
return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable
|
|
||||||
|
|
||||||
def setData(self, index, value, role):
|
|
||||||
if role == Qt.EditRole:
|
|
||||||
try:
|
|
||||||
value = float(value)
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
self._data[index.row(), index.column()] = value
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def getData(self):
|
|
||||||
return self._data
|
|
||||||
|
|
||||||
def getY(self):
|
|
||||||
return self._data[:, 0]
|
|
||||||
|
|
||||||
|
|
||||||
def data(self, index, role):
|
|
||||||
if role == Qt.DisplayRole or role == Qt.EditRole:
|
|
||||||
# ?
|
|
||||||
return float(self._data[index.row(), index.column()])
|
|
||||||
|
|
||||||
return None
|
|
30
statapp/models/editable_table_model.py
Normal file
30
statapp/models/editable_table_model.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import numpy as np
|
||||||
|
from PySide2.QtCore import Qt
|
||||||
|
|
||||||
|
from statapp.models.ro_table_model import ROTableModel
|
||||||
|
|
||||||
|
|
||||||
|
class EditableTableModel(ROTableModel):
|
||||||
|
def __init__(self, data=np.array([[]], dtype=np.float32)):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self._data = data
|
||||||
|
|
||||||
|
def flags(self, index):
|
||||||
|
return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable
|
||||||
|
|
||||||
|
def setData(self, index, value, role):
|
||||||
|
if role == Qt.EditRole:
|
||||||
|
try:
|
||||||
|
value = float(value)
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
self._data[index.row(), index.column()] = value
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def data(self, index, role):
|
||||||
|
if role == Qt.DisplayRole or role == Qt.EditRole:
|
||||||
|
return float(self._data[index.row(), index.column()])
|
||||||
|
|
||||||
|
return None
|
16
statapp/models/input_values_model.py
Normal file
16
statapp/models/input_values_model.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import numpy as np
|
||||||
|
from PySide2.QtCore import Qt, QModelIndex
|
||||||
|
|
||||||
|
from statapp.models.editable_table_model import EditableTableModel
|
||||||
|
from statapp.models.utils import yx_header
|
||||||
|
|
||||||
|
|
||||||
|
class InputValuesModel(EditableTableModel):
|
||||||
|
def __init__(self, data=np.array([[]], dtype=np.float32)):
|
||||||
|
super().__init__(data)
|
||||||
|
|
||||||
|
def getHorizontalHeader(self):
|
||||||
|
return yx_header(self.rowCount(QModelIndex()))
|
||||||
|
|
||||||
|
def getY(self):
|
||||||
|
return self._data[:, 0]
|
@ -43,10 +43,6 @@ class ROTableModel(QtCore.QAbstractTableModel):
|
|||||||
def getData(self):
|
def getData(self):
|
||||||
return self._data
|
return self._data
|
||||||
|
|
||||||
def getY(self):
|
|
||||||
return self._data[:, 0]
|
|
||||||
|
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
return float(self._data[index.row(), index.column()])
|
return float(self._data[index.row(), index.column()])
|
||||||
|
2
statapp/models/utils.py
Normal file
2
statapp/models/utils.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
def yx_header(count):
|
||||||
|
return ['Y'] + [f'X{i}' for i in range(1, count)]
|
@ -1,6 +1,7 @@
|
|||||||
from PySide2.QtCore import QModelIndex
|
from PySide2.QtCore import QModelIndex
|
||||||
|
|
||||||
from statapp.models.ro_table_model import ROTableModel
|
from statapp.models.ro_table_model import ROTableModel
|
||||||
|
from statapp.models.utils import yx_header
|
||||||
|
|
||||||
|
|
||||||
class VarianceAnalysisModel(ROTableModel):
|
class VarianceAnalysisModel(ROTableModel):
|
||||||
@ -11,4 +12,4 @@ class VarianceAnalysisModel(ROTableModel):
|
|||||||
return ['Мат. ожидание', 'Среднекв. отклонение', 'Минимум', 'Максимум']
|
return ['Мат. ожидание', 'Среднекв. отклонение', 'Минимум', 'Максимум']
|
||||||
|
|
||||||
def getVerticalHeader(self):
|
def getVerticalHeader(self):
|
||||||
return ['Y'] + [f'X{i}' for i in range(1, self.rowCount(QModelIndex()))]
|
return yx_header(self.rowCount(QModelIndex()))
|
||||||
|
Loading…
Reference in New Issue
Block a user