@@ -60,12 +60,17 class throttle(object): | |||||
60 | def __call__(self, fn): |
|
60 | def __call__(self, fn): | |
61 | @wraps(fn) |
|
61 | @wraps(fn) | |
62 | def wrapper(*args, **kwargs): |
|
62 | def wrapper(*args, **kwargs): | |
63 | now = datetime.datetime.now() |
|
63 | coerce = kwargs.pop('coerce', None) | |
64 | time_since_last_call = now - self.time_of_last_call |
|
64 | if coerce: | |
65 | time_left = self.throttle_period - time_since_last_call |
|
65 | self.time_of_last_call = datetime.datetime.now() | |
|
66 | return fn(*args, **kwargs) | |||
|
67 | else: | |||
|
68 | now = datetime.datetime.now() | |||
|
69 | time_since_last_call = now - self.time_of_last_call | |||
|
70 | time_left = self.throttle_period - time_since_last_call | |||
66 |
|
71 | |||
67 | if time_left > datetime.timedelta(seconds=0): |
|
72 | if time_left > datetime.timedelta(seconds=0): | |
68 | return |
|
73 | return | |
69 |
|
74 | |||
70 | self.time_of_last_call = datetime.datetime.now() |
|
75 | self.time_of_last_call = datetime.datetime.now() | |
71 | return fn(*args, **kwargs) |
|
76 | return fn(*args, **kwargs) | |
@@ -104,6 +109,9 class Data(object): | |||||
104 | ret = numpy.swapaxes(ret, 0, 1) |
|
109 | ret = numpy.swapaxes(ret, 0, 1) | |
105 | return ret |
|
110 | return ret | |
106 |
|
111 | |||
|
112 | def __contains__(self, key): | |||
|
113 | return key in self.data | |||
|
114 | ||||
107 | def setup(self): |
|
115 | def setup(self): | |
108 | ''' |
|
116 | ''' | |
109 | Configure object |
|
117 | Configure object | |
@@ -564,26 +572,30 class PlotterReceiver(ProcessingUnit, Process): | |||||
564 |
|
572 | |||
565 | while True: |
|
573 | while True: | |
566 | dataOut = self.receiver.recv_pyobj() |
|
574 | dataOut = self.receiver.recv_pyobj() | |
567 | tm = dataOut.utctime |
|
575 | if not dataOut.flagNoData: | |
568 | if dataOut.useLocalTime: |
|
576 | if dataOut.type == 'Parameters': | |
569 |
|
|
577 | tm = dataOut.utctimeInit | |
570 |
|
|
578 | else: | |
571 | dt = datetime.datetime.fromtimestamp(tm).date() |
|
579 | tm = dataOut.utctime | |
572 | else: |
|
580 | if dataOut.useLocalTime: | |
573 | if self.localtime: |
|
581 | if not self.localtime: | |
574 |
tm |
|
582 | tm += time.timezone | |
575 |
dt = datetime.datetime. |
|
583 | dt = datetime.datetime.fromtimestamp(tm).date() | |
576 |
|
|
584 | else: | |
577 |
if |
|
585 | if self.localtime: | |
578 | if self.data: |
|
586 | tm -= time.timezone | |
579 | self.data.ended = True |
|
587 | dt = datetime.datetime.utcfromtimestamp(tm).date() | |
580 | self.send(self.data) |
|
588 | coerce = False | |
581 |
|
|
589 | if dt not in self.dates: | |
582 |
self.data |
|
590 | if self.data: | |
583 |
self.dat |
|
591 | self.data.ended = True | |
584 |
|
592 | self.send(self.data) | ||
585 | self.data.update(dataOut) |
|
593 | coerce = True | |
|
594 | self.data.setup() | |||
|
595 | self.dates.append(dt) | |||
586 |
|
596 | |||
|
597 | self.data.update(dataOut) | |||
|
598 | ||||
587 | if dataOut.finished is True: |
|
599 | if dataOut.finished is True: | |
588 | self.connections -= 1 |
|
600 | self.connections -= 1 | |
589 | if self.connections == 0 and dt in self.dates: |
|
601 | if self.connections == 0 and dt in self.dates: | |
@@ -594,9 +606,9 class PlotterReceiver(ProcessingUnit, Process): | |||||
594 | if self.realtime: |
|
606 | if self.realtime: | |
595 | self.send(self.data) |
|
607 | self.send(self.data) | |
596 | # self.sender_web.send_string(self.data.jsonify()) |
|
608 | # self.sender_web.send_string(self.data.jsonify()) | |
597 | else: |
|
609 | else: | |
598 | if not sended: |
|
610 | self.sendData(self.send, self.data, coerce=coerce) | |
599 | self.sendData(self.send, self.data) |
|
611 | coerce = False | |
600 |
|
612 | |||
601 | return |
|
613 | return | |
602 |
|
614 |
General Comments 0
You need to be logged in to leave comments.
Login now