Commit 8ffbc4ad423462be75c94c4cb854d4db68b03f5d
1 parent
e9ac5444
Exists in
master
Split class series into separate module, as part of attempt to declutter main
Showing
2 changed files
with
46 additions
and
41 deletions
Show diff stats
robots/little_john/telemetry/code/monitor/version1/main.py
... | ... | @@ -21,6 +21,7 @@ import logging |
21 | 21 | |
22 | 22 | from serialselect import selectserial |
23 | 23 | from colours import * |
24 | +from series import Series | |
24 | 25 | |
25 | 26 | logging.basicConfig(format='%(levelname)s:\t%(message)s', level=logging.DEBUG) |
26 | 27 | logging.info("Logging system active") |
... | ... | @@ -38,47 +39,6 @@ else: |
38 | 39 | os='Other' |
39 | 40 | logging.info('OS = ' + os) |
40 | 41 | |
41 | -class Series: | |
42 | - def __init__(self, points=300, title="Series title", xname="x-axis name", yname="y-axis name"): | |
43 | - """Set up an object to store a 2D data series""" | |
44 | - # Proposal: | |
45 | - # In order to neatly handle multiple lines on the same graph | |
46 | - # a series is not so much a set of 2D data points, but a number | |
47 | - # of series sharing an x axis. For example | |
48 | - # (time, temperature) | |
49 | - # (time, xaccel, yaccel, zaccel) | |
50 | - # The latter seta of points much be of like nature and share an axis | |
51 | - # (time, temperature, xaccel) | |
52 | - # would be a meaningless thing to plot on a single graph anyway | |
53 | - | |
54 | - self.title = title | |
55 | - self.xname = xname | |
56 | - self.yname = yname | |
57 | - self.xlimits = (0, 100) | |
58 | - self.ylimits = (-100, 100) | |
59 | - self.data = [] | |
60 | - self.points = points | |
61 | - | |
62 | - def addpoint(self, point): | |
63 | - """Add a point to the dataset, and remove the oldest, if necessary""" | |
64 | - self.data.append(point) | |
65 | - if len(self.data) > self.points: | |
66 | - del self.data[0] | |
67 | - self.autoscale(0) | |
68 | - | |
69 | - def autoscale(self, axis): # axis=0 is x, 1 is y | |
70 | - minval = self.data[0][axis] | |
71 | - maxval = self.data[0][axis] | |
72 | - for value in self.data: | |
73 | - if value[axis] < minval: | |
74 | - minval = value[axis] | |
75 | - if value[axis] > maxval: | |
76 | - maxval = value[axis] | |
77 | - if axis == 0: | |
78 | - self.xlimits = (minval, maxval) | |
79 | - else: | |
80 | - self.ylimits = (minval, maxval) | |
81 | - | |
82 | 42 | class Plot(pyglet.window.Window): |
83 | 43 | def __init__(self, series): |
84 | 44 | """Setup a the details of a plot, and create a corresponding window""" | ... | ... |
robots/little_john/telemetry/code/monitor/version1/series.py
0 → 100644
... | ... | @@ -0,0 +1,45 @@ |
1 | +# Class to store data for a live graph | |
2 | +# Written as a telemetry tool by: | |
3 | +# The UoN Robot Wars Project, 2018 | |
4 | + | |
5 | + | |
6 | +class Series: | |
7 | + def __init__(self, points=300, title="Series title", xname="x-axis name", yname="y-axis name"): | |
8 | + """Set up an object to store a 2D data series""" | |
9 | + # Proposal: | |
10 | + # In order to neatly handle multiple lines on the same graph | |
11 | + # a series is not so much a set of 2D data points, but a number | |
12 | + # of series sharing an x axis. For example | |
13 | + # (time, temperature) | |
14 | + # (time, xaccel, yaccel, zaccel) | |
15 | + # The latter seta of points much be of like nature and share an axis | |
16 | + # (time, temperature, xaccel) | |
17 | + # would be a meaningless thing to plot on a single graph anyway | |
18 | + | |
19 | + self.title = title | |
20 | + self.xname = xname | |
21 | + self.yname = yname | |
22 | + self.xlimits = (0, 100) | |
23 | + self.ylimits = (-100, 100) | |
24 | + self.data = [] | |
25 | + self.points = points | |
26 | + | |
27 | + def addpoint(self, point): | |
28 | + """Add a point to the dataset, and remove the oldest, if necessary""" | |
29 | + self.data.append(point) | |
30 | + if len(self.data) > self.points: | |
31 | + del self.data[0] | |
32 | + self.autoscale(0) | |
33 | + | |
34 | + def autoscale(self, axis): # axis=0 is x, 1 is y | |
35 | + minval = self.data[0][axis] | |
36 | + maxval = self.data[0][axis] | |
37 | + for value in self.data: | |
38 | + if value[axis] < minval: | |
39 | + minval = value[axis] | |
40 | + if value[axis] > maxval: | |
41 | + maxval = value[axis] | |
42 | + if axis == 0: | |
43 | + self.xlimits = (minval, maxval) | |
44 | + else: | |
45 | + self.ylimits = (minval, maxval) | ... | ... |