From 08ba8fe1a74876b783d4678e767f00352ab19969 2021-06-11 03:38:55 From: jespinoza Date: 2021-06-11 03:38:55 Subject: [PATCH] Add static images and fix template --- diff --git a/docker-compose.yml b/docker-compose.yml index 7f5a8c6..7dfc365 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3' services: web: @@ -6,15 +6,20 @@ services: build: . restart: always image: realtime - command: python manage.py runserver 0.0.0.0:8000 + # command: python manage.py runserver 0.0.0.0:8000 + # command: gunicorn realtime.wsgi:application --bind 0.0.0.0:8080 + command: daphne -b 0.0.0.0 -p 8080 realtime.asgi:application env_file: .env - ports: - - "8000:8000" + # ports: + # - "8081:8081" + # expose: + # - 8000 links: - redis - mongo volumes: - './:${APP_DIR}' + - './static:/static' depends_on: - redis - mongo @@ -37,9 +42,9 @@ services: redis: container_name: 'realtime_redis' - image: 'redis:3.2-alpine' + image: 'redis:5.0-alpine' volumes: - - 'redisdata:/data' + - '/data/dockers/realtime/redis:/data' mongo: container_name: 'realtime_mongo' @@ -48,8 +53,30 @@ services: ports: - '127.0.0.1:27017:27017' volumes: - - 'mongodata:/data/db' + - '/data/dockers/realtime/mongo:/data/db' + + #volumes: + # redisdata: + # mongodata: + + nginx: + image: nginx:1.15-alpine + volumes: + - ./static:/static + - ./nginx:/etc/nginx/conf.d + - ./certbot/conf:/etc/letsencrypt + - ./certbot/www:/var/www/certbot + ports: + - "8000:8000" + - "443:443" + depends_on: + - web + command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" + + certbot: + image: certbot/certbot:latest + volumes: + - ./certbot/conf:/etc/letsencrypt + - ./certbot/www:/var/www/certbot + entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'" -volumes: - redisdata: - mongodata: \ No newline at end of file diff --git a/plotter/consumers.py b/plotter/consumers.py index e3cb583..b83f4f0 100644 --- a/plotter/consumers.py +++ b/plotter/consumers.py @@ -90,7 +90,7 @@ class PlotConsumer(WebsocketConsumer): 'plot': plot }) if meta1: - if meta1['metadata']['type'] in ('pcolor',): + if meta1['metadata']['type'] in ('pcolor', 'image'): datas = DB.plot_data.find( {'plot': meta1['_id']}, ['time', 'data'], diff --git a/plotter/routing.py b/plotter/routing.py index 45c8498..92a0da6 100644 --- a/plotter/routing.py +++ b/plotter/routing.py @@ -1,9 +1,9 @@ -from django.conf.urls import url +from django.urls import re_path from . import consumers websocket_urlpatterns = [ - url(r'^ws/main/$', consumers.MainConsumer), - url(r'^ws/realtime/(?P[^/]+)/(?P[^/]+)/$', consumers.PlotConsumer), - url(r'^ws/database/(?P[^/]+)/(?P[^/]+)/$', consumers.PlotConsumer), -] \ No newline at end of file + re_path(r'^ws/main/$', consumers.MainConsumer.as_asgi()), + re_path(r'^ws/realtime/(?P[^/]+)/(?P[^/]+)/$', consumers.PlotConsumer.as_asgi()), + re_path(r'^ws/database/(?P[^/]+)/(?P[^/]+)/$', consumers.PlotConsumer.as_asgi()), +] diff --git a/plotter/templates/footer_igp.html b/plotter/templates/footer_igp.html index 891e33b..aabdaf9 100644 --- a/plotter/templates/footer_igp.html +++ b/plotter/templates/footer_igp.html @@ -39,7 +39,7 @@ - \ No newline at end of file + diff --git a/plotter/templates/home.html b/plotter/templates/home.html index bb74a6e..7373f66 100644 --- a/plotter/templates/home.html +++ b/plotter/templates/home.html @@ -37,8 +37,9 @@ {% endif %} {% endblock %} {% block script %} - {% endblock script %} \ No newline at end of file + {% endblock script %} diff --git a/plotter/views.py b/plotter/views.py index 490b1dd..63967e5 100644 --- a/plotter/views.py +++ b/plotter/views.py @@ -71,7 +71,7 @@ class SPCSetupForm(forms.Form): def main(request, tag=None): kwargs = {} - date = request.GET.get('date', datetime.utcnow().strftime('%d-%m-%Y')) + date = request.GET.get('date', datetime.now().strftime('%d-%m-%Y')) exps = ExpDetail.objects(date=datetime.strptime(date, '%d-%m-%Y')) tmp = {} @@ -167,7 +167,7 @@ def plot(request, code=None, plot=None): realtime = False date = request.GET.get('date', None) if date is None: - date = datetime.utcnow().strftime('%d-%m-%Y') + date = datetime.now().strftime('%d-%m-%Y') realtime = True exp = Experiment.objects.get(code=int(code)) detail = ExpDetail.objects.get(experiment=exp, date=datetime.strptime(date, '%d-%m-%Y')) @@ -235,4 +235,4 @@ def plot_overjro(request): data = skynoise_plot(date.year, date.month, date.day) response = HttpResponse(data.getvalue(), content_type='image/png') - return response \ No newline at end of file + return response diff --git a/realtime/routing.py b/realtime/routing.py deleted file mode 100644 index e441c24..0000000 --- a/realtime/routing.py +++ /dev/null @@ -1,11 +0,0 @@ -from channels.auth import AuthMiddlewareStack -from channels.routing import ProtocolTypeRouter, URLRouter -import plotter.routing - -application = ProtocolTypeRouter({ - 'websocket': AuthMiddlewareStack( - URLRouter( - plotter.routing.websocket_urlpatterns - ) - ), -}) \ No newline at end of file diff --git a/realtime/settings.py b/realtime/settings.py index 0dba516..b40fcf5 100644 --- a/realtime/settings.py +++ b/realtime/settings.py @@ -70,7 +70,7 @@ TEMPLATES = [ }, ] -WSGI_APPLICATION = 'realtime.wsgi.application' +# WSGI_APPLICATION = 'realtime.wsgi.application' # Database @@ -121,10 +121,13 @@ USE_TZ = True # https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = '/static/' #======================== YONG ================================ host = os.environ.get('HOST_REDIS', '127.0.0.1') +ASGI_APPLICATION = 'realtime.asgi.application' + CHANNEL_LAYERS = { "default": { 'BACKEND': 'channels_redis.core.RedisChannelLayer', @@ -134,4 +137,3 @@ CHANNEL_LAYERS = { }, } -ASGI_APPLICATION = "realtime.routing.application" diff --git a/requirements.txt b/requirements.txt index 33d092d..adcd31d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ requests simplejson numpy matplotlib -scipy \ No newline at end of file +scipy +gunicorn diff --git a/scripts/experiments.json b/scripts/experiments.json index b34cef9..39298b7 100644 --- a/scripts/experiments.json +++ b/scripts/experiments.json @@ -116,12 +116,16 @@ "name" : "JULIA Bistatic" }, { + "code" : 210, + "name" : "High Altitude Drift" + }, + { "code" : 230, "name" : "Valley Bottonside 150 Km" }, { "code" : 240, - "name" : "Simone Oyon" + "name" : "Simone Ancon" }, { "code" : 241, @@ -137,6 +141,6 @@ }, { "code" : 244, - "name" : "Simone Ancon" + "name" : "Simone Chaclacayo" } ] diff --git a/scripts/server.py b/scripts/server.py index 9100be4..9a4e351 100644 --- a/scripts/server.py +++ b/scripts/server.py @@ -44,7 +44,7 @@ def loaddata(): #============== funcion para modificar datos en la tabla ============== def update(buffer): - dt = datetime.utcfromtimestamp(buffer['time']) + dt = datetime.fromtimestamp(buffer['time']) interval = buffer['metadata'].pop('interval') tag = buffer['metadata'].pop('tag') if 'tag' in buffer['metadata'] else '' exp = Experiment.objects.get(code=buffer['code']) @@ -129,7 +129,10 @@ def main(): while True: - buffer = receiver.recv_json() + try: + buffer = receiver.recv_json() + except: + continue if not isinstance(buffer, dict): print('Invalid data received: {}').format(str(buffer)) continue diff --git a/utils/TimeTools.py b/utils/TimeTools.py index e74d553..2f08b32 100755 --- a/utils/TimeTools.py +++ b/utils/TimeTools.py @@ -119,7 +119,7 @@ class Time: Converts datetime to number of seconds respect to 1970. """ - dtime = dt(self.year, self.month, self.dom) + dtime = dt(self.year[0], self.month[0], self.dom[0]) return (dtime-dt(1970, 1, 1)).total_seconds() year = self.year