test for part 2 added, minor ui changes

This commit is contained in:
Вадим Силаев 2022-12-04 09:33:18 +03:00
parent d6f8f6f13f
commit 46b5845387
2 changed files with 40 additions and 6 deletions

View File

@ -1,6 +1,8 @@
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import random import random
from numpy import tanh
def get_point(part, num): def get_point(part, num):
if part == 1: if part == 1:
@ -38,8 +40,13 @@ def get_point(part, num):
vol[2][num].append(random.random() * 100) vol[2][num].append(random.random() * 100)
cur[2][num].append(random.random() * 100) cur[2][num].append(random.random() * 100)
elif part == 4: elif part == 4:
vol[3][num].append(random.random() * 100) vol[3][num].append(random.random() * 50 - 25)
cur[3][num].append(random.random() * 100) if experiment % 3 == 0:
cur[3][num].append((83 * tanh(15.5 / 83 * vol[3][num][-1]) + 1.7 * vol[3][num][-1]) * (0.98 + random.random() / 25))
elif experiment % 3 == 1:
cur[3][num].append((44 * tanh(8.7 / 44 * vol[3][num][-1]) + 0.9 * vol[3][num][-1]) * (0.98 + random.random() / 25))
else:
cur[3][num].append((22 * tanh(4.4 / 22 * vol[3][num][-1]) + 0.5 * vol[3][num][-1]) * (0.98 + random.random() / 25))
def update_plot(part, num): def update_plot(part, num):
for i in range(10): for i in range(10):
@ -48,8 +55,10 @@ def update_plot(part, num):
def saveplot(part): def saveplot(part):
plt.figure(figsize=(8, 6)) plt.figure(figsize=(8, 6))
for i in range(len(vol[part - 1])): for i in range(len(vol[part - 1])):
plt.scatter(cur[part - 1][i], vol[part - 1][i], marker='o') plt.scatter(vol[part - 1][i], cur[part - 1][i], marker='o')
plt.grid() plt.grid()
plt.xlabel('Напряжение, В')
plt.ylabel('Ток, мкА')
plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200) plt.savefig('tmpplots/tmpplot' + str(part) + '.jpg', dpi=200)
plt.close() plt.close()
@ -63,12 +72,18 @@ def empty_plot(part):
plt.close() plt.close()
def plus_plot(part): def plus_plot(part):
global experiment
vol[part - 1].append([]) vol[part - 1].append([])
cur[part - 1].append([]) cur[part - 1].append([])
experiment += 1
def minus_plot(part): def minus_plot(part):
vol[part - 1].pop() vol[part - 1].pop()
cur[part - 1].pop() cur[part - 1].pop()
if len(vol[part - 1]) == 0:
vol[part - 1].append([])
cur[part - 1].append([])
vol = [[], [], [[]], [[]]] vol = [[], [], [[]], [[]]]
cur = [[], [], [[]], [[]]] cur = [[], [], [[]], [[]]]
experiment = 0

View File

@ -216,6 +216,7 @@ class Part2(QtWidgets.QWidget):
super().__init__() super().__init__()
self.n = 0 self.n = 0
self.num = 0 self.num = 0
self.i = 0
self.hint_open = False self.hint_open = False
self.started = False self.started = False
self.q = QtGui.QScreen.availableGeometry(QtWidgets.QApplication.primaryScreen()) self.q = QtGui.QScreen.availableGeometry(QtWidgets.QApplication.primaryScreen())
@ -230,6 +231,11 @@ class Part2(QtWidgets.QWidget):
self.points.setGeometry(QtCore.QRect(7.5 * h - 150, 3 * h - 80, 300, 20)) self.points.setGeometry(QtCore.QRect(7.5 * h - 150, 3 * h - 80, 300, 20))
self.points.setText('Измеренных точек в текущей серии: ' + str(self.n)) self.points.setText('Измеренных точек в текущей серии: ' + str(self.n))
self.current = QtWidgets.QLabel(self)
self.current.setGeometry(QtCore.QRect(7.5 * h - 150, 3 * h - 120, 300, 20))
self.current.setText('Текущий ток разряда: ' + str(self.i))
self.current.setStyleSheet('color: green;')
self.disclaimer = QtWidgets.QLabel(self) self.disclaimer = QtWidgets.QLabel(self)
self.disclaimer.setText('<html><p align=\"left\"><span style=\" font-size:10pt; font-weight:600;\">Не ' self.disclaimer.setText('<html><p align=\"left\"><span style=\" font-size:10pt; font-weight:600;\">Не '
'забудьте прочитать методику<\p><p align=\"left\"><span style=\" font-size:10pt; ' 'забудьте прочитать методику<\p><p align=\"left\"><span style=\" font-size:10pt; '
@ -298,14 +304,27 @@ class Part2(QtWidgets.QWidget):
self.start_btn.clicked.connect(self.start_stop) self.start_btn.clicked.connect(self.start_stop)
self.delete_btn.clicked.connect(self.delete) self.delete_btn.clicked.connect(self.delete)
self.hint_btn.clicked.connect(self.hint) self.hint_btn.clicked.connect(self.hint)
self.save_btn.clicked.connect(self.savefile) self.save_btn.clicked.connect(self.save_file)
timer = QtCore.QTimer(self) timer = QtCore.QTimer(self)
timer.timeout.connect(self.upd_plot) timer.timeout.connect(self.upd_plot)
timer.start(500) timer.start(500)
timer2 = QtCore.QTimer(self)
timer2.timeout.connect(self.cur_check)
timer2.start(1000)
@QtCore.Slot() @QtCore.Slot()
def savefile(self): def cur_check(self):
if plots.experiment % 3 == 0:
self.i = 5
elif plots.experiment % 3 == 1:
self.i = 3
else:
self.i = 1.5
self.current.setText('Текущий ток разряда: ' + str(self.i) + 'мА')
def save_file(self):
file, check = QtWidgets.QFileDialog.getSaveFileName(None, "Сохранить график 2", file, check = QtWidgets.QFileDialog.getSaveFileName(None, "Сохранить график 2",
r"C:\Users\Vadim\Desktop\plot2.jpg", "Images (*.png *.jpg)") r"C:\Users\Vadim\Desktop\plot2.jpg", "Images (*.png *.jpg)")
if check: if check: