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