diff --git a/simulators/camera/cameraVISSimulator.py b/simulators/camera/cameraVISSimulator.py index 1c22767..0f4df08 100644 --- a/simulators/camera/cameraVISSimulator.py +++ b/simulators/camera/cameraVISSimulator.py @@ -10,6 +10,7 @@ sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) from utils.DeviceSim import DeviceSim from utils.StatusManager import StatusManager + #(EP) class CameraVISSimulator(Device, StatusManager): class CameraVISSimulator(DeviceSim, StatusManager): status = {"status" : "VALID"} @@ -21,7 +22,7 @@ class CameraVISSimulator(DeviceSim, StatusManager): super().__init__(argv) self.setDevice("CameraVIS") self.setStatusManager("cameraVISSimulator", argv) - + self.cameraVISPrint("COUCOU CECI EST UN TEST") def cameraVISPrint(self, string: str): if DEBUG_FILE: print("cameraVISSimulator : " + string) diff --git a/simulators/utils/DeviceSim.py b/simulators/utils/DeviceSim.py index ef090ef..753c7fe 100644 --- a/simulators/utils/DeviceSim.py +++ b/simulators/utils/DeviceSim.py @@ -4,7 +4,6 @@ import select import abc import sys from . import settings - DEBUG_FILE = True ''' @@ -70,9 +69,10 @@ class DeviceSim(object): print(str(e)) print(self.name, "No connection established") self.log(self.name, "No connection established") + return False self.connections.append({"connection": connection, "address": address}) - + self.log(self.name, "Connection successfully established") return True def close(self, connection_address): @@ -93,6 +93,7 @@ class DeviceSim(object): co["connection"].send(bytes(message, "UTF-8")) #self.forceLog(self.name, "Message sent [" + message + "] to " + str(co["address"])) self.forceLog(self.name, "Message sent to " + str(co["address"]) +" : [" + message + "]") + self.log(self.name, "Message sent to " + str(co["address"]) +" : [" + message + "]") except Exception as e: if (settings.DEBUG): print(self.name, "Could not send message on socket "+ str(co["address"]) +" : " + message + " -> " + str(e)) @@ -128,6 +129,7 @@ class DeviceSim(object): #(EP) return ("DISCONNECTED") raise Exception("DISCONNECTED") self.forceLog(self.name, "Message received on " + str(co["address"]) +" : [" + ret + "]") + self.log(self.name, "Message received on " + str(co["address"]) + " : [" + ret + "]") except Exception as e: if (settings.DEBUG): print(self.name, "Socket not readable : " + str(e)) @@ -172,6 +174,7 @@ class DeviceSim(object): return (0) def listen(self): + if (self.ip is None or self.port is None): self.log(self.name, "Ip or Port not initialized") # (EP) It's a serious bug, so raise exception !!! @@ -179,6 +182,7 @@ class DeviceSim(object): raise Exception(self.name +" has no ip or port") try: + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.settimeout(1) diff --git a/src/dashboard/templates/dashboard/index.html b/src/dashboard/templates/dashboard/index.html index 0766dff..e32b9f8 100644 --- a/src/dashboard/templates/dashboard/index.html +++ b/src/dashboard/templates/dashboard/index.html @@ -114,7 +114,7 @@
  • - +

    Tele & Inst

    html5 diff --git a/src/dashboard/templates/dashboard/observation_status.html b/src/dashboard/templates/dashboard/observation_status.html new file mode 100644 index 0000000..0f3d3fc --- /dev/null +++ b/src/dashboard/templates/dashboard/observation_status.html @@ -0,0 +1,238 @@ + + +{% extends "base.html" %} +{% load staticfiles%} + +{% block title %} + Observation System Status : +{% endblock %} + +{% block content %} + + + + + + + + + + + {% block environnment %} +
    + +
    + {% endblock %} +
    + + +
    + +
    +

    +
      +
      + {% for log in object.cagire_logs.all %} +
    • {{log.created}} : {{log.message}}
    • {% endfor %} +
    + +
    +
    +

    +
      +
      + {% for log in cagire_logs %} +
    • {{log.created}} : {{log.message}}
    • {% endfor %} +
    +
    +
    +

    +
      +
      + {% for log in ddrago_r_logs %} +
    • {{log.created}} : {{log.message}}
    • {% endfor %} +
    + +
    +
    +

    +
      +
      + {% for log in ddrago_b_logs %} +
    • {{log.created}} : {{log.message}}
    • {% endfor %} +
    +
    +
    +
    + + + +
    + +{% endblock %} + diff --git a/src/dashboard/templates/dashboard/observation_status_env.html b/src/dashboard/templates/dashboard/observation_status_env.html new file mode 100644 index 0000000..28e1146 --- /dev/null +++ b/src/dashboard/templates/dashboard/observation_status_env.html @@ -0,0 +1,89 @@ +{% load static %} + + +

    Current site time : {{ t.hour }}h {{ t.minute }}min {{ t.second }}s

    +
    + +
    + + {% if isDay %} +
    + +
    The Sun is Up
    +
    + {% else %} +
    + +
    The Sun is Down
    +
    + {% endif %} + + +
    + +
    + {% if weather_status.rain > 10 %} +
    + +
    Raining
    +
    + {% elif weather_status.cloud >= 1 %} +
    + +
    The sky is Cloudy
    +
    + {% else %} +
    + +
    The sky is Clear
    +
    + {% endif %} + + +
    + +
    + + {% if weather_status.wind >= 60 %} +
    + +
    The Wind is too strong : {{ weather_status.wind }}km/h
    +
    + {% else %} +
    + +
    The Wind is acceptable : {{ weather_status.wind }}km/h
    +
    + {% endif %} + + +
    +
    \ No newline at end of file diff --git a/src/dashboard/templates/dashboard/retrieve_observation_status.html b/src/dashboard/templates/dashboard/retrieve_observation_status.html new file mode 100644 index 0000000..26fabb3 --- /dev/null +++ b/src/dashboard/templates/dashboard/retrieve_observation_status.html @@ -0,0 +1,106 @@ + + + + + +
    + +

    +
    +

    TELESCOPE

    +
      +
      + {% for log in telescope_logs %} +
    • {{log.created}} : {{log.message}}
    • {% endfor %} +
    + +
    +

    +
    +

    CAGIRE

    +
      +
      + {% for log in cagire_logs %} +
    • {{log.created}} : {{log.message}}
    • {% endfor %} +
    +
    +

    +
    +

    +
      +
      + {% for log in ddrago_r_logs %} +
    • {{log.created}} : {{log.message}}
    • {% endfor %} +
    + +
    +

    +
    +

    DDRAGO BLUE

    +
      +
      + {% for log in ddrago_b_logs %} +
    • {{log.created}} : {{log.message}}
    • {% endfor %} +
    +
    +
    + + diff --git a/src/dashboard/urls.py b/src/dashboard/urls.py index 2b6902c..bdea015 100644 --- a/src/dashboard/urls.py +++ b/src/dashboard/urls.py @@ -13,4 +13,8 @@ urlpatterns = [ name="system_retrieve_logs"), url(r'^schedule$', views.schedule, name="schedule"), url(r'^quotas$', views.quotas, name="quotas"), + url(r'^observation_status/retrieve_env', views.retrieve_env, name='retrieve_env'), + url(r'^retrieve_env_navbar', views.retrieve_env_navbar, name='retrieve_env_navbar'), + + #url(r'^retrieve_observation_status$', views.retrieve_observation_status, name="retrieve_observation_status"), ] diff --git a/src/dashboard/views.py b/src/dashboard/views.py index 79ad00a..514c3ba 100644 --- a/src/dashboard/views.py +++ b/src/dashboard/views.py @@ -1,15 +1,39 @@ +from django.http import HttpResponse from django.shortcuts import render, redirect from django.core import urlresolvers from django.contrib.auth.decorators import login_required -from common.models import Log - +import datetime +from common.models import Log, WeatherWatch +from django.core import serializers import utils.Logger as l log = l.setupLogger("dashboard", "dashboard") + + @login_required def index(request): return render(request, 'dashboard/index.html') +#@login_required +#def observation_status(request): + # return render(request, 'dashboard/observation_status.html') + +@login_required +def retrieve_env(request): + weather_status = WeatherWatch.objects.latest('updated') + t = datetime.datetime.now() + datetime.timedelta(hours=-7) #temporary method to demonstrate the day/night display + isDay = False + if t.hour > 5 and t.hour < 20: + isDay = True + return render(request, 'dashboard/observation_status_env.html', locals()) + +@login_required +def retrieve_env_navbar(request): + if request.is_ajax(): + weather_status = WeatherWatch.objects.latest('updated') + weather = serializers.serialize('json', [weather_status]) + return HttpResponse(weather, content_type="application/json") + @login_required def users(request): url_ = urlresolvers.reverse('admin:auth_user_changelist') diff --git a/src/devices/Device.py b/src/devices/Device.py index 4ed7077..7a67a6d 100644 --- a/src/devices/Device.py +++ b/src/devices/Device.py @@ -6,6 +6,7 @@ import select import utils.Logger as L import time import os +from common.models import Log DEBUG_FILE = True RECONNECT_TIMEOUT_SECONDS = 20 @@ -76,6 +77,7 @@ class DeviceController(): return False # (EP) NON, 0 = false !!! #return (0) + Log.objects.create(agent=self.name, message='Message send : ' + message) return True def isError(self, message: str): @@ -142,6 +144,7 @@ class DeviceController(): return (0) def log(self, device_name: str, message: str): + Log.objects.create(agent=self.name, message=message) if DEBUG_FILE and settings.DEBUG: self.logger.info("From device : " + device_name + " -> " + message) return (0) diff --git a/src/devices/urls.py b/src/devices/urls.py new file mode 100644 index 0000000..acadaa4 --- /dev/null +++ b/src/devices/urls.py @@ -0,0 +1,11 @@ +from django.conf.urls import url +from . import views + + +urlpatterns = [ +url(r'^observation_status$', views.observation_status, name="observation_status"), +url(r'^update_cagire_logs$', views.update_cagire_logs, name="update_cagire_logs"), +url(r'^update_telescope_logs$', views.update_telescope_logs, name="update_telescope_logs"), +url(r'^update_ddrago_r_logs$', views.update_ddrago_r_logs, name="update_ddrago_r_logs"), +url(r'^update_ddrago_b_logs$', views.update_ddrago_b_logs, name="update_ddrago_b_logs"), +] \ No newline at end of file diff --git a/src/devices/views.py b/src/devices/views.py index 91ea44a..eba5ada 100644 --- a/src/devices/views.py +++ b/src/devices/views.py @@ -1,3 +1,54 @@ from django.shortcuts import render +from common.models import Log +from django.http import HttpResponse +from django.core import urlresolvers +from django.core import serializers +from django.contrib.auth.decorators import login_required +MAX_LOGS_LINES = 200 # Create your views here. +@login_required +def update_cagire_logs(request): + if request.is_ajax(): + cagire_logs = Log.objects.filter(agent='CameraNIR').order_by('-created')[:MAX_LOGS_LINES] + logs = serializers.serialize('json', cagire_logs) + return HttpResponse(logs, content_type="application/json") + #return render("dashboard/observation_status.html", logs, content_type="application/json") + + +@login_required +def update_telescope_logs(request): + if request.is_ajax(): + telescope_logs = Log.objects.filter(agent='Telescope').order_by('-created')[:MAX_LOGS_LINES] + logs = serializers.serialize('json', telescope_logs) + return HttpResponse(logs, content_type="application/json") + +@login_required +def update_ddrago_r_logs(request): + if request.is_ajax(): + ddrago_r_logs = Log.objects.filter(agent='CameraVIS').order_by('-created')[:MAX_LOGS_LINES] + logs = serializers.serialize('json', ddrago_r_logs) + return HttpResponse(logs, content_type="application/json") + +@login_required +def update_ddrago_b_logs(request): + if request.is_ajax(): + ddrago_b_logs = Log.objects.filter(agent='CameraVIS').order_by('-created')[:MAX_LOGS_LINES] + logs = serializers.serialize('json', ddrago_b_logs) + return HttpResponse(logs, content_type="application/json") + + +@login_required +def observation_status(request): + ''' + Called by the dashboard system page with ajax request every seconds, to get the logs and print them + ''' + if request.is_ajax(): + telescope_logs = Log.objects.filter(agent='Telescope').order_by('-created') + cagire_logs = Log.objects.filter(agent='CameraNIR').order_by('-created') + ddrago_b_logs = Log.objects.filter(agent='CameraVIS').order_by('-created') + ddrago_r_logs = Log.objects.filter(agent='CameraVIS').order_by('-created') + logs = telescope_logs + cagire_logs + ddrago_r_logs + ddrago_b_logs + return render('dashboard/observation_status.html', {logs: object}) + else: + return render(request, "dashboard/observation_status.html") \ No newline at end of file diff --git a/src/misc/static/js/observation_status.js b/src/misc/static/js/observation_status.js new file mode 100755 index 0000000..cac69f0 --- /dev/null +++ b/src/misc/static/js/observation_status.js @@ -0,0 +1,122 @@ +var LOGS_REFRESH_FREQUENCE = 2000; //in milliseconds + +var show_cagire = false; +var show_telescope = false; +var show_ddrago_b = false; +var show_ddrago_r = false; +var interval_cagire =-1; +var interval_ddrago_r=-1; +var interval_ddrago_b=-1; +var interval_telescope=-1; + +jQuery(document).ready(function(){ + +$("#Telescope_button").click(function () { + show_telescope= !show_telescope; + + if (show_telescope) + { + $("#telescope_list").show(); + interval_telescope = setInterval(function() {ajax_request("telescope", "telescope_list");}, LOGS_REFRESH_FREQUENCE); + } + else { $("#telescope_list").hide(); + if (interval_telescope !== -1){clearInterval(interval_telescope);} + } + +}); + +$("#Cagire_button").click(function () { + show_cagire = !show_cagire; + + + if (show_cagire) + { + $("#cagire_list").show(); + interval_cagire = setInterval(function() {ajax_request("cagire", "cagire_list");}, LOGS_REFRESH_FREQUENCE); + } + else { + $("#cagire_list").hide(); + if (interval_cagire !== -1){clearInterval(interval_cagire);} + } + +}); + +$("#ddrago_r_button").click(function () { + show_ddrago_r= !show_ddrago_r; + + if (show_ddrago_r) + { + $("#ddrago_r_list").show(); + interval_ddrago_r = setInterval(function() {ajax_request("ddrago_r", "ddrago_r_list");}, LOGS_REFRESH_FREQUENCE); + } + else { + $("#ddrago_r_list").hide(); + if (interval_ddrago_r !== -1){clearInterval(interval_ddrago_r);} + } +}); + +$("#ddrago_b_button").click(function () { + show_ddrago_b= !show_ddrago_b; + + if (show_ddrago_b) + { + $("#ddrago_b_list").show(); + interval_ddrago_b = setInterval(function() {ajax_request("ddrago_b", "ddrago_b_list");}, LOGS_REFRESH_FREQUENCE); + } + else { $("#ddrago_b_list").hide(); + if (interval_ddrago_b !== -1){clearInterval(interval_ddrago_b);} + } +}); + + /* + function retriving logs for tools with show variable equal True, called every LOGS_REFRESH_FREQUENCE + */ + +function ajax_request(cam, id_list){ + var cagire_url ="/devices/update_cagire_logs"; + var telescope_url ="/devices/update_telescope_logs"; + var ddrago_r_url ="/devices/update_ddrago_r_logs"; + var ddrago_b_url ="/devices/update_ddrago_b_logs"; + var url_txt = ""; + if (cam === 'cagire') + url_txt = cagire_url; + else if (cam === "telescope") + url_txt = telescope_url; + else if (cam === "ddrago_r") + url_txt = ddrago_r_url; + else if (cam === "ddrago_b") + url_txt = ddrago_b_url; + $.ajax({ + url: url_txt, + type: 'get', + dataType: 'text', + success: function(data) + { + var obj = JSON.parse(data); + if (obj) { + var listDiv = document.getElementById(id_list); + listDiv.innerHTML = ''; + for (var tmp in obj) { + var li = document.createElement('li'); + li.innerHTML = obj[tmp]['fields']['created'] + ": " + obj[tmp]['fields']['message']; // Use innerHTML to set the text + listDiv.appendChild(li); + } + } + }, + error: function() + { + console.log('Ajax error: GET request failed\n'); + } + + }); + + } + + +}); + + $(window).unload(function(){ + alert("bye") + if (interval_cagire != -1){clearInterval(interval_cagire);} + if (interval_telescope !== -1){clearInterval(interval_telescope);} +}); diff --git a/src/misc/static/media/cloud.png b/src/misc/static/media/cloud.png new file mode 100644 index 0000000..7d1bc79 Binary files /dev/null and b/src/misc/static/media/cloud.png differ diff --git a/src/misc/static/media/moon.png b/src/misc/static/media/moon.png new file mode 100644 index 0000000..ddd7ef1 Binary files /dev/null and b/src/misc/static/media/moon.png differ diff --git a/src/misc/static/media/no_wind.png b/src/misc/static/media/no_wind.png new file mode 100644 index 0000000..b7bc0ca Binary files /dev/null and b/src/misc/static/media/no_wind.png differ diff --git a/src/misc/static/media/rain.png b/src/misc/static/media/rain.png new file mode 100644 index 0000000..1c07a4a Binary files /dev/null and b/src/misc/static/media/rain.png differ diff --git a/src/misc/static/media/rain.svg b/src/misc/static/media/rain.svg new file mode 100644 index 0000000..35bdaca --- /dev/null +++ b/src/misc/static/media/rain.svg @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/misc/static/media/rain_new.png b/src/misc/static/media/rain_new.png new file mode 100644 index 0000000..f9d2c1d Binary files /dev/null and b/src/misc/static/media/rain_new.png differ diff --git a/src/misc/static/media/rising_sun.png b/src/misc/static/media/rising_sun.png new file mode 100644 index 0000000..c402c7e Binary files /dev/null and b/src/misc/static/media/rising_sun.png differ diff --git a/src/misc/static/media/sun.png b/src/misc/static/media/sun.png new file mode 100644 index 0000000..dacfa9d Binary files /dev/null and b/src/misc/static/media/sun.png differ diff --git a/src/misc/static/media/white_cloud.png b/src/misc/static/media/white_cloud.png new file mode 100644 index 0000000..538c164 Binary files /dev/null and b/src/misc/static/media/white_cloud.png differ diff --git a/src/misc/static/media/white_moon.png b/src/misc/static/media/white_moon.png new file mode 100644 index 0000000..8517a0e Binary files /dev/null and b/src/misc/static/media/white_moon.png differ diff --git a/src/misc/static/media/white_moon_new.png b/src/misc/static/media/white_moon_new.png new file mode 100644 index 0000000..8517a0e Binary files /dev/null and b/src/misc/static/media/white_moon_new.png differ diff --git a/src/misc/static/media/white_rising_sun.png b/src/misc/static/media/white_rising_sun.png new file mode 100644 index 0000000..719fd9a Binary files /dev/null and b/src/misc/static/media/white_rising_sun.png differ diff --git a/src/misc/static/media/white_rising_sun_new.png b/src/misc/static/media/white_rising_sun_new.png new file mode 100644 index 0000000..66b7f17 Binary files /dev/null and b/src/misc/static/media/white_rising_sun_new.png differ diff --git a/src/misc/static/media/white_sun.png b/src/misc/static/media/white_sun.png new file mode 100644 index 0000000..83a2a40 Binary files /dev/null and b/src/misc/static/media/white_sun.png differ diff --git a/src/misc/static/media/white_windsock_nowind.png b/src/misc/static/media/white_windsock_nowind.png new file mode 100644 index 0000000..fbdfbbd Binary files /dev/null and b/src/misc/static/media/white_windsock_nowind.png differ diff --git a/src/misc/static/media/white_windsock_nowind_new.png b/src/misc/static/media/white_windsock_nowind_new.png new file mode 100644 index 0000000..d5c8dbc Binary files /dev/null and b/src/misc/static/media/white_windsock_nowind_new.png differ diff --git a/src/misc/static/media/white_windsock_windy.png b/src/misc/static/media/white_windsock_windy.png new file mode 100644 index 0000000..645b2c6 Binary files /dev/null and b/src/misc/static/media/white_windsock_windy.png differ diff --git a/src/misc/static/media/wind.png b/src/misc/static/media/wind.png new file mode 100644 index 0000000..ddac3ce Binary files /dev/null and b/src/misc/static/media/wind.png differ diff --git a/src/misc/templates/base.html b/src/misc/templates/base.html index ac223f3..000d0b4 100644 --- a/src/misc/templates/base.html +++ b/src/misc/templates/base.html @@ -34,7 +34,16 @@ - +
    @@ -43,30 +52,24 @@ - - + + + + @@ -91,7 +94,69 @@
    - + + + diff --git a/src/pyros/settings.py b/src/pyros/settings.py index 06b5643..a9fd6c7 100644 --- a/src/pyros/settings.py +++ b/src/pyros/settings.py @@ -126,11 +126,11 @@ LOGIN_URL = "/" "$ pyros.py simulator_development" will automatically set them to "True" ''' # FOR SIMULATOR (TODO: remove because not used) -SIMULATOR = False +SIMULATOR = True # FOR SIMULATOR (and TESTS) -CELERY_TEST = False +CELERY_TEST = True -# CELERY_TEST = False ==> DEFAULT (NORMAL) RUN MODE, use pyros (normal) database +# CELERY_TEST = True ==> DEFAULT (NORMAL) RUN MODE, use pyros (normal) database if not CELERY_TEST: if not MYSQL: DATABASES = { @@ -149,7 +149,7 @@ if not CELERY_TEST: } } -# CELERY_TEST = False ==> 'TEST' RUN MODE, use pyros_test database +# CELERY_TEST = True ==> 'TEST' RUN MODE, use pyros_test database else: DATABASES = { 'default': { diff --git a/src/pyros/urls.py b/src/pyros/urls.py index 3af0ce8..9d5ac2c 100644 --- a/src/pyros/urls.py +++ b/src/pyros/urls.py @@ -29,6 +29,7 @@ urlpatterns = [ urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^dashboard/', include('dashboard.urls')), + url(r'^devices/', include('devices.urls')), url(r'^scheduler/', include('scheduler.urls')), url(r'^alert_manager/', include('alert_manager.urls')), url(r'^analyzer/', include('analyzer.urls')), -- libgit2 0.21.2