##// END OF EJS Templates
New template, clean code, workig for realtime
Juan C. Espinoza -
r21:dc5f8680b6e1
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
@@ -3,7 +3,7
3 import os
3 import os
4 import json
4 import json
5
5
6 from datetime import datetime
6 from datetime import datetime, timedelta
7
7
8 from pymongo import MongoClient
8 from pymongo import MongoClient
9
9
@@ -16,21 +16,26 CLIENT = MongoClient('{}:27017'.format(host))
16 DB = CLIENT['dbplots']
16 DB = CLIENT['dbplots']
17
17
18 # Connected to websocket.connect
18 # Connected to websocket.connect
19 def ws_connect(message, code=None, plot=None):
19 def ws_connect(message, id, code, plot):
20 message.reply_channel.send({'accept': True})
20
21 if plot == 'main':
21 if id == 'main':
22 Group('main').add(message.reply_channel)
22 Group('main').add(message.reply_channel)
23 print('New main connection')
23 print('New main connection')
24 elif id == 'realtime':
25 Group('{}_{}'.format(code, plot)).add(message.reply_channel)
26 print('New connection from: {}, Group: {}_{}'.format(message.content['client'][0], code, plot))
24 else:
27 else:
25 pk = message.content['query_string'].decode().split('=')[1]
28 print('New connection from: {}, history, id: {}'.format(message.content['client'][0], id))
26 Group('{}_{}'.format(pk, plot)).add(message.reply_channel)
29 message.reply_channel.send({
27 print('New connection from: {}, Group: {}_{}'.format(message.content['client'][0], pk, plot))
30 'accept': True
31 })
28
32
29 def ws_message(message, code, plot):
33 def ws_message(message, id, code, plot):
30 # Accept the incoming connection
34 # Accept the incoming connection
31 dt = datetime.strptime(str(json.loads(message.content['text'])['date']), '%d/%m/%Y')
35 dt = datetime.strptime(str(json.loads(message.content['text'])['date']), '%d/%m/%Y')
36 exp0 = DB.exp_meta.find_one({'code': int(code), 'date': dt-timedelta(days=1)})
32 exp = DB.exp_meta.find_one({'code': int(code), 'date': dt})
37 exp = DB.exp_meta.find_one({'code': int(code), 'date': dt})
33
38 print('New request for id={}'.format(id))
34 if exp and plot in exp['plots']:
39 if exp and plot in exp['plots']:
35 if plot == 'spc':
40 if plot == 'spc':
36 datas = DB.exp_data.find({'expmeta': exp['_id']}, ['time', 'data']).sort('time', -1).limit(1)[0]
41 datas = DB.exp_data.find({'expmeta': exp['_id']}, ['time', 'data']).sort('time', -1).limit(1)[0]
@@ -39,12 +44,32 def ws_message(message, code, plot):
39 exp['rti'] = datas['data']['rti']
44 exp['rti'] = datas['data']['rti']
40 exp['noise'] = datas['data']['noise']
45 exp['noise'] = datas['data']['noise']
41 else:
46 else:
42 datas = DB.exp_data.find({'expmeta': exp['_id']}, ['time', 'data']).sort('time', 1)
47 last = DB.exp_data.find_one({'expmeta': exp['_id']}, ['time'], sort=[('time', -1)])
48 if exp0:
49 datas = DB.exp_data.find(
50 {
51 'expmeta': {'$in': [exp0['_id'], exp['_id']]},
52 'time': {'$gt': last['time']-12*60*60}
53 },
54 ['time', 'data'],
55 sort=[('time', 1)],
56 limit=720
57 )
58 else:
59 datas = DB.exp_data.find(
60 {
61 'expmeta': exp['_id'],
62 'time': {'$gt': last['time']-12*60*60}
63 },
64 ['time', 'data'],
65 sort=[('time', 1)],
66 limit=720
67 )
43 dum = [(d['time'], d['data'][plot]) for d in datas]
68 dum = [(d['time'], d['data'][plot]) for d in datas]
44 exp['time'] = [d[0] for d in dum]
69 exp['time'] = [d[0] for d in dum]
45 dum = [d[1] for d in dum]
70 dum = [d[1] for d in dum]
46 exp[plot] = [t for t in map(list, zip(*dum))]
71 exp[plot] = [t for t in map(list, zip(*dum))]
47 print([datetime.fromtimestamp(t) for t in exp['time']])
72
48 exp.pop('date', None)
73 exp.pop('date', None)
49 exp.pop('_id', None)
74 exp.pop('_id', None)
50 message.reply_channel.send({'text': json.dumps(exp)})
75 message.reply_channel.send({'text': json.dumps(exp)})
@@ -52,5 +77,5 def ws_message(message, code, plot):
52 message.reply_channel.send({'text': json.dumps({'interval': 0})})
77 message.reply_channel.send({'text': json.dumps({'interval': 0})})
53
78
54 # Connected to websocket.disconnect
79 # Connected to websocket.disconnect
55 def ws_disconnect(message, code, plot):
80 def ws_disconnect(message, id, code, plot):
56 Group('{}_{}'.format(code, plot)).discard(message.reply_channel)
81 Group('{}_{}'.format(code, plot)).discard(message.reply_channel)
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (2050 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed, binary diff hidden
NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now