@@ -2,6 +2,11 | |||
|
2 | 2 | RUN mkdir /app |
|
3 | 3 | WORKDIR /app |
|
4 | 4 | ADD requirements.txt ./requirements.txt |
|
5 | RUN pip install -r requirements.txt | |
|
5 | RUN apt-get clean && apt-get update && apt-get install -y --no-install-recommends \ | |
|
6 | g++ \ | |
|
7 | gcc \ | |
|
8 | && pip install -r requirements.txt \ | |
|
9 | && apt-get purge -y --auto-remove gcc g++\ | |
|
10 | && rm -rf /var/lib/apt/lists/* | |
|
6 | 11 | COPY . /app/ |
|
7 | 12 | No newline at end of file |
@@ -2,26 +2,34 version: '2' | |||
|
2 | 2 | |
|
3 | 3 | services: |
|
4 | 4 | web: |
|
5 | container_name: 'realtime_web' | |
|
5 | 6 | build: . |
|
6 | 7 | image: realtime |
|
7 | 8 | command: python manage.py runserver 0.0.0.0:8000 |
|
9 | env_file: .env | |
|
8 | 10 | ports: |
|
9 | 11 | - "8000:8000" |
|
10 | 12 | links: |
|
11 | 13 | - redis |
|
12 | 14 | - mongo |
|
15 | volumes: | |
|
16 | - './:/app' | |
|
13 | 17 | depends_on: |
|
14 | 18 | - redis |
|
15 | 19 | - mongo |
|
16 | 20 | |
|
17 | 21 | zmq_server: |
|
22 | container_name: 'zmq_server' | |
|
18 | 23 | image: 'realtime' |
|
19 | 24 | ports: |
|
20 | 25 | - '127.0.0.1:4444:4444' |
|
21 | command: 'python scripts/server.py' | |
|
26 | command: 'python -u scripts/server.py' | |
|
27 | env_file: .env | |
|
22 | 28 | links: |
|
23 | 29 | - redis |
|
24 | 30 | - mongo |
|
31 | volumes: | |
|
32 | - './:/app' | |
|
25 | 33 | depends_on: |
|
26 | 34 | - web |
|
27 | 35 |
@@ -1,8 +1,8 | |||
|
1 | ||
|
1 | import os | |
|
2 | 2 | import json |
|
3 | 3 | import numpy as np |
|
4 | 4 | from datetime import datetime |
|
5 | import mongoengine | |
|
5 | ||
|
6 | 6 | from pymongo import MongoClient |
|
7 | 7 | |
|
8 | 8 | from models import Experiment, Data |
@@ -11,10 +11,8 from channels.handler import AsgiHandler | |||
|
11 | 11 | from channels.auth import channel_session_user |
|
12 | 12 | from channels import Group |
|
13 | 13 | |
|
14 | from profilehooks import profile | |
|
15 | ||
|
16 | # mongoengine.connect('dbplots') | |
|
17 | CLIENT = MongoClient('mongo:27017') | |
|
14 | host = os.environ.get('HOST_MONGO', 'localhost') | |
|
15 | CLIENT = MongoClient('{}:27017'.format(host)) | |
|
18 | 16 | DB = CLIENT['dbplots'] |
|
19 | 17 | |
|
20 | 18 | # Connected to websocket.connect |
@@ -40,8 +38,8 def ws_message(message, code, plot): | |||
|
40 | 38 | datas = DB.data.find({'experiment': e['_id']}, ['time', 'data']).sort('time', 1) |
|
41 | 39 | dum = [(d['time'], d['data'][plot]) for d in datas] |
|
42 | 40 | e['time'] = [d[0] for d in dum] |
|
43 |
dum = |
|
|
44 |
e[plot] = |
|
|
41 | dum = [d[1] for d in dum] | |
|
42 | e[plot] = map(list, zip(*dum)) | |
|
45 | 43 | e.pop('date', None) |
|
46 | 44 | e.pop('_id', None) |
|
47 | 45 | message.reply_channel.send({'text': json.dumps(e)}) |
@@ -1,6 +1,7 | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | from __future__ import unicode_literals |
|
3 | 3 | |
|
4 | import os | |
|
4 | 5 | from datetime import datetime |
|
5 | 6 | |
|
6 | 7 | from django import forms |
@@ -12,7 +13,9 from bootstrap3_datetime.widgets import DateTimePicker | |||
|
12 | 13 | |
|
13 | 14 | from pymongo import MongoClient |
|
14 | 15 | |
|
15 | CLIENT = MongoClient('mongo:27017') | |
|
16 | host = os.environ.get('HOST_MONGO', 'localhost') | |
|
17 | ||
|
18 | CLIENT = MongoClient('{}:27017'.format(host)) | |
|
16 | 19 | DB = CLIENT['dbplots'] |
|
17 | 20 | |
|
18 | 21 | # Forms |
@@ -44,9 +47,13 def main(request, code=None, plot=None): | |||
|
44 | 47 | if plot is not None: |
|
45 | 48 | initial['plot'] = plot |
|
46 | 49 | |
|
50 | print 'hola' | |
|
47 | 51 | codes = DB.experiment.find().distinct('code') |
|
52 | print codes | |
|
48 | 53 | exps = [DB.experiment.find_one({'code': c}, ['name']) for c in codes] |
|
54 | print exps | |
|
49 | 55 | names = [q['name'] for q in exps] |
|
56 | print names | |
|
50 | 57 | form = SearchForm( |
|
51 | 58 | initial = initial, |
|
52 | 59 | exp_choices = [(e[0], e[1]) for e in zip(codes, names)] |
@@ -59,8 +66,10 def main(request, code=None, plot=None): | |||
|
59 | 66 | 'form': form, |
|
60 | 67 | } |
|
61 | 68 | |
|
62 | if codes: | |
|
69 | if code and codes: | |
|
63 | 70 | kwargs['title'] = [t[1] for t in zip(codes, names) if t[0]==int(code)][0] |
|
71 | else: | |
|
72 | kwargs['title'] = 'JRO' | |
|
64 | 73 | |
|
65 | 74 | if plot == 'rti': |
|
66 | 75 | return render(request, 'rti.html', kwargs) |
@@ -122,11 +122,13 USE_TZ = True | |||
|
122 | 122 | |
|
123 | 123 | STATIC_URL = '/static/' |
|
124 | 124 | |
|
125 | host = os.environ.get('HOST_REDIS', 'localhost') | |
|
126 | ||
|
125 | 127 | CHANNEL_LAYERS = { |
|
126 | 128 | "default": { |
|
127 | 129 | "BACKEND": "asgi_redis.RedisChannelLayer", |
|
128 | 130 | "CONFIG": { |
|
129 |
"hosts": [( |
|
|
131 | "hosts": [(host, 6379)], | |
|
130 | 132 | }, |
|
131 | 133 | "ROUTING": "realtime.routing.channel_routing", |
|
132 | 134 | }, |
@@ -2,7 +2,7 asgi-redis==1.4.3 | |||
|
2 | 2 | Django==1.11.7 |
|
3 | 3 | django-bootstrap3==9.1.0 |
|
4 | 4 | django-bootstrap3-datetimepicker-2==2.5.0 |
|
5 |
|
|
|
5 | channels==1.1.8 | |
|
6 | 6 | mongoengine==0.15.0 |
|
7 | 7 | numpy==1.13.3 |
|
8 | 8 | pymongo==3.5.1 |
@@ -12,15 +12,21 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "realtime.settings") | |||
|
12 | 12 | |
|
13 | 13 | from plotter.models import Experiment, Data |
|
14 | 14 | |
|
15 | mongoengine.connect('dbplots', host='mongo', port=27017) | |
|
15 | ||
|
16 | host_mongo = os.environ.get('HOST_MONGO', 'localhost') | |
|
17 | mongoengine.connect('dbplots', host=host_mongo, port=27017) | |
|
18 | ||
|
19 | ||
|
20 | host_redis = os.environ.get('HOST_REDIS', 'localhost') | |
|
21 | channel = asgi_redis.RedisChannelLayer(hosts=[(host_redis, 6379)]) | |
|
16 | 22 | |
|
17 | 23 | context = zmq.Context() |
|
18 | 24 | receiver = context.socket(zmq.SUB) |
|
19 | 25 | |
|
20 |
receiver.bind("tcp:// |
|
|
26 | receiver.bind("tcp://0.0.0.0:4444") | |
|
21 | 27 | receiver.setsockopt(zmq.SUBSCRIBE, '') |
|
22 | 28 | |
|
23 | channel = asgi_redis.RedisChannelLayer(hosts=[('redis', 6379)]) | |
|
29 | ||
|
24 | 30 | |
|
25 | 31 | def update_db(buffer): |
|
26 | 32 | dt = datetime.utcfromtimestamp(buffer['time']) |
@@ -52,7 +58,7 def update_db(buffer): | |||
|
52 | 58 | new = False |
|
53 | 59 | |
|
54 | 60 | return new |
|
55 |
print ' |
|
|
61 | print 'Starting...' | |
|
56 | 62 | while True: |
|
57 | 63 | buffer = receiver.recv_json() |
|
58 | 64 | if 'xrange' not in buffer: |
General Comments 0
You need to be logged in to leave comments.
Login now