This repository has been archived by the owner on Jan 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requester_ws.py
57 lines (42 loc) · 1.58 KB
/
requester_ws.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
48
49
50
51
52
53
54
55
56
import zmq
import json
import socket
from threading import Thread
import time as ttime
import pandas as pd
import matplotlib.pyplot as plt
plt.ion()
context = zmq.Context()
sender = context.socket(zmq.PUSH)
sender.connect("tcp://xf08id-srv2:5559")
# Create SUBSCRIBER to get information from 'gateway'
subscriber = context.socket(zmq.SUB)
subscriber.connect("tcp://xf08id-srv2:5562")
hostname_filter = socket.gethostname()
subscriber.setsockopt_string(zmq.SUBSCRIBE, hostname_filter)
def recv_function():
while True:
message = subscriber.recv().decode('utf-8')
message = message[len(hostname_filter):]
data = json.loads(message)
if data['type'] == 'spectroscopy':
if data['processing_ret']['type'] == 'interpolate':
interp_data = pd.DataFrame.from_dict(json.loads(data['processing_ret']['data']))
interp_data = interp_data.sort_values('energy')
#plt.figure()
#plt.plot(interp_data['energy'], interp_data['i0']/interp_data['it'])
#plt.figure()
#plt.plot(interp_data['energy'], interp_data['iff']/interp_data['i0'])
# plot on interpolation plot and generate log
recv_thread = Thread(target = recv_function)
recv_thread.start()
dic = {'uid': '61d3b7f0-9c9d-4e19-b08c-6229c2473123',
'requester': hostname_filter,
'type': 'spectroscopy',
'processing_info': {'type': 'interpolate',
'interp_base': 'i0'
}
}
#sender.send_string(json.dumps(dic))
#while True:
# pass