Administrator approval is now required for registering new accounts. If you are registering a new account, and are external to the University, please ask the repository owner to contact ServiceLine to request your account be approved. Repository owners must include the newly registered email address, and specific repository in the request for approval.

Commit 88e4a1da authored by Ed Rogers's avatar Ed Rogers
Browse files

Add basic plotting of results

parent 91f39ea4
......@@ -120,3 +120,16 @@ class HearingTest:
def mean_two_arrays(a: np.ndarray, b: np.ndarray):
return np.mean(np.array([a, b]), axis=0)
class HearingResults:
def __init__(self):
self._data = np.array((0,))
self.load_results()
self._counter = 0
def as_list(self):
return self._data.tolist()
def load_results(self):
self._data = np.loadtxt('data.csv', delimiter=',')
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import QMainWindow, QSizePolicy, QGridLayout
from PyQt5.QtWidgets import QMainWindow, QSizePolicy, QGridLayout, QWidget
import numpy as np
from HearingTest import HearingResults, HearingTest
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
......@@ -7,10 +9,11 @@ from matplotlib.figure import Figure
class HearingResultsCanvas(FigureCanvas):
def __init__(self, parent=None, results=None):
def __init__(self, parent=None, results: HearingResults=None):
self.setParent = parent
fig = Figure()
self.axes = fig.add_subplot(111)
fig.set_facecolor((0., 0., 0.))
FigureCanvas.__init__(self, fig)
FigureCanvas.setSizePolicy(self,
......@@ -19,25 +22,39 @@ class HearingResultsCanvas(FigureCanvas):
FigureCanvas.updateGeometry(self)
self.plot_results(results)
def plot_results(self, results):
# TODO implement plotting of results
pass
def plot_results(self, results: HearingResults):
results_list = results.as_list()
n = len(results_list)
pink = np.array((1., 0.7, 0.8))
for i, result in enumerate(results_list):
if n - i > 10:
color = pink
else:
reduction = (n - i) / 10
color = (pink[0], pink[1] * reduction, pink[2] * reduction)
print(color)
self.axes.plot(result, color=color)
spacing = (HearingTest.upper_lim - HearingTest.lower_lim) / 10
self.axes.set_ylim(HearingTest.lower_lim - spacing, HearingTest.upper_lim + spacing)
class ResultsWindow(QMainWindow):
def __init__(self, parent):
def __init__(self, parent, results):
QMainWindow.__init__(self)
self.parent = parent
self.results = None
self.results = results
self.setWindowTitle('Hearing Test Results')
self.resize(QSize(640, 480))
self.move(641, 0)
central_widget = QWidget(self)
grid_layout = QGridLayout(self)
self.setLayout(grid_layout)
central_widget.setLayout(grid_layout)
self.setCentralWidget(central_widget)
self.graph = HearingResultsCanvas()
self.graph = HearingResultsCanvas(self, results)
grid_layout.addWidget(self.graph, 0, 0)
self.show()
from PyQt5.QtCore import QSize
from PyQt5 import QtCore, Qt, QtGui
from PyQt5.QtWidgets import QMainWindow, QSizePolicy, QGridLayout, QWidget, QLabel, QTextEdit
from HearingTest import HearingTest
from HearingTest import HearingTest, HearingResults
import time
import numpy as np
import matplotlib
......@@ -147,7 +147,8 @@ class TestWindow(QMainWindow):
grid_layout.addWidget(self.graph, 2, 0)
grid_layout.addWidget(self.score_label, 3, 0)
self.results_window = ResultsWindow(self)
self.results = HearingResults()
self.results_window = ResultsWindow(self, self.results)
def keyPressEvent(self, event: QtGui.QKeyEvent):
if event.key() == Qt.Qt.Key_D:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment