##// END OF EJS Templates
Fix publish to web_server
Juan C. Espinoza -
r1114:f58248fe43e5
parent child
Show More
@@ -82,9 +82,10 class Data(object):
82 Object to hold data to be plotted
82 Object to hold data to be plotted
83 '''
83 '''
84
84
85 def __init__(self, plottypes, throttle_value):
85 def __init__(self, plottypes, throttle_value, exp_code):
86 self.plottypes = plottypes
86 self.plottypes = plottypes
87 self.throttle = throttle_value
87 self.throttle = throttle_value
88 self.exp_code = exp_code
88 self.ended = False
89 self.ended = False
89 self.localtime = False
90 self.localtime = False
90 self.__times = []
91 self.__times = []
@@ -215,17 +216,24 class Data(object):
215 Convert data to json
216 Convert data to json
216 '''
217 '''
217
218
218 ret = {}
219 data = {}
219 tm = self.times[-1]
220 tm = self.times[-1]
220
221
221 for key, value in self.data:
222 for key in self.data:
222 if key in ('spc', 'cspc'):
223 if key in ('spc', 'cspc'):
223 ret[key] = roundFloats(self.data[key].to_list())
224 data[key] = roundFloats(self.data[key].tolist())
224 else:
225 else:
225 ret[key] = roundFloats(self.data[key][tm].to_list())
226 data[key] = roundFloats(self.data[key][tm].tolist())
226
227
227 ret['timestamp'] = tm
228 ret = {'data': data}
229 ret['exp_code'] = self.exp_code
230 ret['time'] = tm
228 ret['interval'] = self.interval
231 ret['interval'] = self.interval
232 ret['ymin'] = self.heights[0]
233 ret['ymax'] = self.heights[-1]
234 ret['ystep'] = self.heights[1] - self.heights[0]
235
236 return json.dumps(ret)
229
237
230 @property
238 @property
231 def times(self):
239 def times(self):
@@ -476,7 +484,8 class ReceiverData(ProcessingUnit):
476 class PlotterReceiver(ProcessingUnit, Process):
484 class PlotterReceiver(ProcessingUnit, Process):
477
485
478 throttle_value = 5
486 throttle_value = 5
479 __attrs__ = ['server', 'plottypes', 'realtime', 'localtime', 'throttle']
487 __attrs__ = ['server', 'plottypes', 'realtime', 'localtime', 'throttle',
488 'exp_code', 'web_server']
480
489
481 def __init__(self, **kwargs):
490 def __init__(self, **kwargs):
482
491
@@ -487,30 +496,25 class PlotterReceiver(ProcessingUnit, Process):
487 self.isWebConfig = False
496 self.isWebConfig = False
488 self.connections = 0
497 self.connections = 0
489 server = kwargs.get('server', 'zmq.pipe')
498 server = kwargs.get('server', 'zmq.pipe')
490 plot_server = kwargs.get('plot_server', 'zmq.web')
499 web_server = kwargs.get('web_server', None)
491 if 'tcp://' in server:
500 if 'tcp://' in server:
492 address = server
501 address = server
493 else:
502 else:
494 address = 'ipc:///tmp/%s' % server
503 address = 'ipc:///tmp/%s' % server
495
496 if 'tcp://' in plot_server:
497 plot_address = plot_server
498 else:
499 plot_address = 'ipc:///tmp/%s' % plot_server
500
501 self.address = address
504 self.address = address
502 self.plot_address = plot_address
505 self.web_address = web_server
503 self.plottypes = [s.strip() for s in kwargs.get('plottypes', '').split(',') if s]
506 self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')]
504 self.realtime = kwargs.get('realtime', False)
507 self.realtime = kwargs.get('realtime', False)
505 self.localtime = kwargs.get('localtime', True)
508 self.localtime = kwargs.get('localtime', True)
506 self.throttle_value = kwargs.get('throttle', 5)
509 self.throttle_value = kwargs.get('throttle', 5)
510 self.exp_code = kwargs.get('exp_code', None)
507 self.sendData = self.initThrottle(self.throttle_value)
511 self.sendData = self.initThrottle(self.throttle_value)
508 self.dates = []
512 self.dates = []
509 self.setup()
513 self.setup()
510
514
511 def setup(self):
515 def setup(self):
512
516
513 self.data = Data(self.plottypes, self.throttle_value)
517 self.data = Data(self.plottypes, self.throttle_value, self.exp_code)
514 self.isConfig = True
518 self.isConfig = True
515
519
516 def event_monitor(self, monitor):
520 def event_monitor(self, monitor):
@@ -560,9 +564,13 class PlotterReceiver(ProcessingUnit, Process):
560 self.receiver.bind(self.address)
564 self.receiver.bind(self.address)
561 monitor = self.receiver.get_monitor_socket()
565 monitor = self.receiver.get_monitor_socket()
562 self.sender = self.context.socket(zmq.PUB)
566 self.sender = self.context.socket(zmq.PUB)
563 if self.realtime:
567 if self.web_address:
568 log.success(
569 'Sending to web: {}'.format(self.web_address),
570 self.name
571 )
564 self.sender_web = self.context.socket(zmq.PUB)
572 self.sender_web = self.context.socket(zmq.PUB)
565 self.sender_web.connect(self.plot_address)
573 self.sender_web.connect(self.web_address)
566 time.sleep(1)
574 time.sleep(1)
567
575
568 if 'server' in self.kwargs:
576 if 'server' in self.kwargs:
@@ -610,27 +618,10 class PlotterReceiver(ProcessingUnit, Process):
610 else:
618 else:
611 if self.realtime:
619 if self.realtime:
612 self.send(self.data)
620 self.send(self.data)
613 # self.sender_web.send_string(self.data.jsonify())
621 if self.web_address:
622 self.sender_web.send(self.data.jsonify())
614 else:
623 else:
615 self.sendData(self.send, self.data, coerce=coerce)
624 self.sendData(self.send, self.data, coerce=coerce)
616 coerce = False
625 coerce = False
617
626
618 return
627 return
619
620 def sendToWeb(self):
621
622 if not self.isWebConfig:
623 context = zmq.Context()
624 sender_web_config = context.socket(zmq.PUB)
625 if 'tcp://' in self.plot_address:
626 dum, address, port = self.plot_address.split(':')
627 conf_address = '{}:{}:{}'.format(dum, address, int(port)+1)
628 else:
629 conf_address = self.plot_address + '.config'
630 sender_web_config.bind(conf_address)
631 time.sleep(1)
632 for kwargs in self.operationKwargs.values():
633 if 'plot' in kwargs:
634 log.success('[Sending] Config data to web for {}'.format(kwargs['code'].upper()))
635 sender_web_config.send_string(json.dumps(kwargs))
636 self.isWebConfig = True
General Comments 0
You need to be logged in to leave comments. Login now