-
Notifications
You must be signed in to change notification settings - Fork 0
/
BiodataConsumer.py
47 lines (37 loc) · 1.29 KB
/
BiodataConsumer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from Vicarious.Consumers.Consumer import Consumer
import sys,time
from collections import deque
class BiodataConsumer():
def __init__(self, host, port, table, player):
self.consumer = Consumer(host,int(port), self)
self.table = table
self.player = player
self.peaksPerMin = deque([], 1000)
self.lastValue = None
def run(self):
"""
Thread run method. Waits on data to come in and then once received, sends it to :func:`processData`
"""
while(True):
self.consumer.waitData()
data = self.consumer.getData()
if data != None:
self.processData(float(data))
def processData(self, value):
"""
Evaluates the peaks per min based on the ``value`` and sends both the (possibly) new peaks per min value
and the ``value`` through to the ``Player`` object
"""
if value == 0.0 and self.lastValue > 0.0: #reached a peak, add to list
self.peaksPerMin.append(time.time())
# Prune any peaks > 60 secs
if len(self.peaksPerMin) > 0:
if time.time() - self.peaksPerMin[0] >= 60.0:
self.peaksPerMin.popleft()
self.player.threshValue = value
self.player.peaksPerMin = len(self.peaksPerMin)
self.lastValue = value
def main(host,port):
chart = BiodataConsumer(host,port)
chart.run()
if __name__ == '__main__': main(sys.argv[1],int(sys.argv[2]))