Skip to content

Commit

Permalink
Added STP attribute, fixed layout, fixed minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkoev committed Dec 7, 2020
1 parent b0554ca commit 87c5371
Show file tree
Hide file tree
Showing 11 changed files with 510 additions and 221 deletions.
7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

24 changes: 18 additions & 6 deletions UI/MapTable.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import sys
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QTableWidget, QGridLayout, QWidget, QTableWidgetItem

from PyQt5.QtCore import QSize, Qt
from PyQt5.QtWidgets import QTableWidget, QGridLayout, QWidget, QTableWidgetItem, QApplication

def getBgColor(func_name: str):
colors_dict = {
"A1(t)": QColor(255, 255, 255),
"A2(t)": QColor(204, 255, 255),
"A3(t)": QColor(255, 255, 204),
"A4(t)": QColor(205, 255, 204),
"A5(t)": QColor(255, 204, 204),
}
return colors_dict[func_name]


class MapTable(QWidget):
def __init__(self, accumulator):
super().__init__()
self.acc = accumulator
self.setMinimumSize(QSize(1100, 800)) # Устанавливаем размеры
self.setWindowTitle("Map") # Устанавливаем заголовок окна
central_widget = QWidget(self) # Создаём центральный виджет
self.setMinimumSize(QSize(1100, 800))
self.setWindowTitle("Map")
central_widget = QWidget(self)

grid_layout = QGridLayout()
central_widget.setLayout(grid_layout)
Expand Down Expand Up @@ -40,6 +50,8 @@ def fillout(self):
max_value = value
max_key = key
self.table.setItem(i, j, QTableWidgetItem(str(max_key)))
self.table.item(i, j).setBackground(getBgColor(str(max_key)))
self.table.item(i, j).setToolTip(f"[{row[0][0]} = {row[0][1]}, {row[1][0]} = {row[1][1]}]")
j += 1
if j > 9:
i += 1
Expand Down
574 changes: 409 additions & 165 deletions UI/mainView.py

Large diffs are not rendered by default.

Binary file added UI/source/at.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UI/source/sys.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions model/OdeArgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self):
self.__tn = None
self.__At = None
self.timeline = None
self.__delta = 0

def set_s1(self, s1):
print('S1 is set to: ' + str(s1))
Expand All @@ -26,7 +27,7 @@ def get_timeline(self):
if self.get_t0() == self.get_tn():
self.timeline = np.linspace(0, self.get_tn(), 2, True)
else:
self.timeline = np.linspace(self.get_t0(), self.get_tn(), 45, True)
self.timeline = np.linspace(self.get_t0(), self.get_tn(),30)
return self.timeline

def get_s1(self):
Expand Down Expand Up @@ -115,4 +116,13 @@ def get_at(self, x, y):
return at_dictionary[self.__At]

def get_at_keys(self):
return ['A1(t)', 'A2(t)', 'A3(t)', 'A4(t)', 'A5(t)']
return ['A1(t)', 'A2(t)', 'A3(t)', 'A4(t)', 'A5(t)']

def set_STP(self, delta):
print(f"set STP to {delta}")
if delta < 0 or delta > 1:
raise Exception('Delta is set ' + delta + ', when valid range is [0 - 1]')
self.__delta = delta

def get_STP(self):
return self.__delta
27 changes: 14 additions & 13 deletions src/OdeSolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
from model.OdeArgs import OdeArgs


# function that returns dz/dt


class OdeSolve():
class OdeSolve:

def __init__(self, args: OdeArgs):
self.__s1 = args.get_s1()
Expand All @@ -21,21 +18,22 @@ def __init__(self, args: OdeArgs):
self.__result = None
self.__timeline = args.get_timeline()
self.__At = lambda x, y: args.get_at(x, y)
self.__delta = args.get_STP()

def model45(self, z, t):
print(f'Model initialized with z = {z}, t = {t}')
print(f'Model initialized with z = {z}, t = {t}, stp = {self.stp(t)}')
x = z[0]
y = z[1]

dxdt = self.__At(x, y) * ((self.__s1 * x ** self.__alp1 + self.__s2 * y ** self.__alp2) - self.__gam1 * x)
dydt = (1 - self.__At(x, y)) * ((self.__s1 * x ** self.__alp1 + self.__s2 * y ** self.__alp2) - self.__gam2 * y)
return [dxdt, dydt]
k1 = self.__At(x, y) * self.stp(t) * \
((self.__s1 * x ** self.__alp1 + self.__s2 * y ** self.__alp2) - self.__gam1 * x)
k2 = (1 - self.__At(x, y)) * self.stp(t) * \
((self.__s1 * x ** self.__alp1 + self.__s2 * y ** self.__alp2) - self.__gam2 * y)
return [k1, k2]

def calc(self):
print('calc method is initialized')
# initial condition
z0 = [self.__k1, self.__k2]
print(f"timeline is: {self.__timeline}")
#print(f"timeline is: {self.__timeline}")
self.__result = odeint(self.model45, z0, self.__timeline)
print("===================result===================")
print(self.__result)
Expand All @@ -46,9 +44,12 @@ def getTimeline(self):
return self.__timeline

def buildPlot(self):
plt.plot(self.__timeline, self.__result[:, 0], 'b-', label=r'$\frac{dx}{dt}=3 \; \exp(-t)$')
plt.plot(self.__timeline, self.__result[:, 1], 'r--', label=r'$\frac{dy}{dt}=-y+3$')
plt.plot(self.__timeline, self.__result[:, 0], 'b-', label='K1')
plt.plot(self.__timeline, self.__result[:, 1], 'r--', label='K2')
plt.ylabel('response')
plt.xlabel('time')
plt.legend(loc='best')
plt.show()

# Calculate scientific and technical progress
stp = lambda self, t: np.exp(t * self.__delta)
35 changes: 19 additions & 16 deletions view/MapTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, ui):
super().__init__(OdeArgs(), ui)
self.ui = ui
self.chbCount = 0
self.disableAllGamAlp()
self.__disableValuesOnStart()
self.ui.S1_2.textChanged[str].connect(self.onS1Change)
self.ui.S2_2.textChanged[str].connect(self.onS2Change)
self.ui.alp1_2.textChanged[str].connect(self.onAlp1Change)
Expand All @@ -24,15 +24,15 @@ def __init__(self, ui):
self.ui.K1_2.textChanged[str].connect(self.onK1Change)
self.ui.K2_2.textChanged[str].connect(self.onK2Change)
self.ui.tn_2.textChanged[str].connect(self.onTnChange)
self.ui.t0_2.setDisabled(True)
self.ui.STP_2.textChanged[str].connect(self.onSTPChange)
self.ui.alp1_chb.stateChanged.connect(self.onChb)
self.ui.alp2_chb.stateChanged.connect(self.onChb)
self.ui.gam2_chb.stateChanged.connect(self.onChb)
self.ui.gam1_chb.stateChanged.connect(self.onChb)
self.ui.calc_mapper.setDisabled(True)
self.ui.STP_checkbox_2.stateChanged.connect(self.onSTPCheckbox)
self.ui.calc_mapper.clicked.connect(self.onCalc)
self.ui.build_map.clicked.connect(self.onBuildMap)
self.ui.build_map.setDisabled(True)

self.alp_gam_array = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
self.__set_fixed_arguments_list = []
self.map_accumulator = []
Expand All @@ -45,7 +45,7 @@ def onChb(self, state):
if self.chbCount == 2:
self.enableNotSelected()
else:
self.disableAllGamAlp()
self.__disableValuesOnStart()

def onTnChange(self, text):
self.onChange(text, self.args.set_t0)
Expand All @@ -54,6 +54,7 @@ def onTnChange(self, text):
def onCalc(self):
__result = 0
self.map_accumulator.clear()
self.ui.map_table.clear()
self.__redraw_table()
self.__calculate()
for argument in self.__set_fixed_arguments_list:
Expand All @@ -76,11 +77,23 @@ def enableNotSelected(self):
self.__set_fixed_arguments_list.append(checkbox["set"])
self.__fixed_arguments_names.append(checkbox["name"])

def disableAllGamAlp(self):
def __disableValuesOnStart(self):
self.ui.STP_2.setDisabled(True)
self.ui.gam2_2.setDisabled(True)
self.ui.gam1_2.setDisabled(True)
self.ui.alp2_2.setDisabled(True)
self.ui.alp1_2.setDisabled(True)
self.ui.t0_2.setDisabled(True)
self.ui.calc_mapper.setDisabled(True)
self.ui.build_map.setDisabled(True)

def onSTPChange(self, text):
self.onChange(text, self.args.set_STP)

def onSTPCheckbox(self, state):
if state == Qt.Checked:
self.ui.STP_2.setDisabled(False)
else: self.ui.STP_2.setDisabled(True)

def __calculate(self, ):
__row = 0
Expand Down Expand Up @@ -128,13 +141,3 @@ def onBuildMap(self):
print(e)


class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
24 changes: 20 additions & 4 deletions view/PlotTab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# from UI.mainView import Ui_MainWindow
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QTableWidgetItem

from model.OdeArgs import OdeArgs
Expand All @@ -9,12 +10,10 @@
class PlotTab(Tab):
def __init__(self, ui):
super().__init__(OdeArgs(), ui)
print(type(ui))
self.ui.pushButton.setEnabled(False)
self.ui.pushButton_2.setEnabled(False)
self.__disableValuesOnStart()
self.ui.pushButton.clicked.connect(self.onCalc)
self.ui.pushButton_2.clicked.connect(self.onBuildPlot)
self.ui.pushButton_3.clicked.connect(self.onExportClick)
# self.ui.pushButton_3.clicked.connect(self.onExportClick)
self.ui.S1.textChanged[str].connect(self.onS1Change)
self.ui.S2.textChanged[str].connect(self.onS2Change)
self.ui.alp1.textChanged[str].connect(self.onAlp1Change)
Expand All @@ -25,6 +24,9 @@ def __init__(self, ui):
self.ui.K2.textChanged[str].connect(self.onK2Change)
self.ui.t0.textChanged[str].connect(self.onT0Change)
self.ui.tn.textChanged[str].connect(self.onTnChange)
self.ui.STP.textChanged[str].connect(self.onSTPChange)
self.ui.STP_checkbox.stateChanged.connect(self.onSTPCheckbox)


def onBuildPlot(self):
try:
Expand Down Expand Up @@ -58,3 +60,17 @@ def onCalc(self):
self.ui.pushButton_2.setEnabled(True)
self.ui.tableWidget.setHorizontalHeaderLabels(['t', 'K1', 'K2', 'K1+K2'])
self.ui.tableWidget.resizeColumnsToContents()

def __disableValuesOnStart(self):
self.ui.pushButton.setDisabled(True)
self.ui.pushButton_2.setDisabled(True)
self.ui.STP.setDisabled(True)

def onSTPChange(self, text):
self.onChange(text, self.args.set_STP)

def onSTPCheckbox(self, state):
if state == Qt.Checked:
self.ui.STP.setEnabled(True)
else:
self.ui.STP.setDisabled(True)
20 changes: 10 additions & 10 deletions view/Tab.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from PyQt5 import QtGui

from model.OdeArgs import OdeArgs


class Tab:
def __init__(self, args: OdeArgs, ui):
self.args = args
self.ui = ui
self.ui.label_24.setPixmap(QtGui.QPixmap("../UI/source/sys.png"))
self.ui.label_25.setPixmap(QtGui.QPixmap("../UI/source/at.png"))
self.ui.label_26.setPixmap(QtGui.QPixmap("../UI/source/sys.png"))
self.ui.label_27.setPixmap(QtGui.QPixmap("../UI/source/at.png"))


def onS1Change(self, text):
Expand Down Expand Up @@ -37,25 +43,19 @@ def onChange(self, text, func):
func(float(text))
self.checkOnEdit()
except BaseException as e:
print('Error on value parsing: ',e)
print('Error on value parsing: ', e)

def checkOnEdit(self):
args = [self.args.get_tn(), self.args.get_t0(), self.args.get_s1(), self.args.get_s2(), self.args.get_k1(),
self.args.get_k2(), self.args.get_alp2(), self.args.get_alp1(), self.args.get_gam1(),
self.args.get_gam2()]
self.args.get_gam2(), self.args.get_STP()]
_i = 0
for arg in args:
if arg is not None:
_i = _i + 1

if _i == 10:
print('trace')
print(self.__class__.__name__)
print('==============================')
if _i == len(args):
if self.__class__.__name__ == "MapTab":
self.ui.calc_mapper.setEnabled(True)
else:
self.ui.pushButton.setEnabled(True)



self.ui.pushButton.setEnabled(True)
6 changes: 1 addition & 5 deletions view/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt5 import QtWidgets
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import QTableWidgetItem

Expand All @@ -12,12 +12,8 @@
class App(QtWidgets.QMainWindow, mainView.Ui_MainWindow):

def __init__(self):
# Это здесь нужно для доступа к переменным, методам
# и т.д. в файле design.py
super().__init__()
self.setupUi(self) # Это нужно для инициализации нашего дизайна
self.args = OdeArgs.OdeArgs()
self.plotTab = PlotTab(self)
self.mapTab = MapTab(self)
self.setMinimumSize(QSize(920, 1080))

0 comments on commit 87c5371

Please sign in to comment.