15 Commits

Author SHA1 Message Date
  maxime 2637ede5b5 gflouhreluigh eeuilgfhguloiedhgomiuedtlhgioume 5 months ago
  maxime c1dc68c70c rehgfigbhimodhlegouijthikujrtghuijklrfbgiulrdhgikjudhuiglvdflk 5 months ago
  Alban Gruin 59603dd755 Correction de l’indentation 5 months ago
  maxime 3701af7ca4 Response 5 months ago
  Alexandre FICHE b44cf720c8 remodification de la normalisation 5 months ago
  Alexandre FICHE 1e212a0591 modification de la normalisation 5 months ago
  Alban Gruin 016042c6a1 Correction de la normalisation et d’autres petits trucs 5 months ago
  Alexandre FICHE 1f04e53c6a ajout de la normalisation 5 months ago
  maxime de047d4597 Supression de import obsolètes 5 months ago
  maxime 4a89dbac59 Supression de import obsolètes 5 months ago
  maxime 5e2451e3ca Merge remote-tracking branch 'origin/master' into maxime/master 5 months ago
  maxime 9af9cbfaff Mise en place des channels layers 5 months ago
  maxime f3bd604d78 Corrections mineurs 5 months ago
  maxime 443238dd09 Suppression du callback pour les nouveaux capteurs pour les websockets 5 months ago
  maxime 6aae77989c Corrections mineurs 5 months ago

+ 8
- 37
gange/consumers.py View File

@@ -2,53 +2,22 @@ from channels.generic.websocket import WebsocketConsumer
2 2
 from asgiref.sync import async_to_sync
3 3
 import json
4 4
 
5
-from .models import Bulle, Capteur, Todo
6
-
7 5
 
8 6
 class FrontendConsumer(WebsocketConsumer):
9 7
     def connect(self):
10
-        async_to_sync(self.channel_layer.group_add)(
11
-            'message_to_websocket',
12
-            self.channel_name
13
-        )
14 8
         self.accept()
9
+        async_to_sync(self.channel_layer.add_group)('new_value')
15 10
 
16 11
     def disconnect(self, code):
17 12
         pass
18 13
 
19 14
     def receive(self, text_data=None, bytes_data=None):
15
+        print(text_data)
20 16
         text_data_json = json.loads(text_data)
21
-
22
-        try:
23
-            bulle = Bulle.objects.get(pk=text_data_json['id'])
24
-            capteur = Capteur.objects.filter(bulle=bulle)
25
-            todo = Todo.objects.filter(bulle=bulle)
26
-        except:
27
-            self.send(text_data=json.dumps({
28
-                'error': 'not found'
29
-            }))
30
-            return
31
-
32
-        if capteur.count() == 1:
33
-            self.send(text_data=json.dumps({
34
-                'type': 'details',
35
-                'max': capteur[0].val_max,
36
-                'min': capteur[0].val_min,
37
-                'name': capteur[0].nom,
38
-                'unite': capteur[0].unite
39
-            }))
40
-        elif todo.count() == 1:
41
-            self.send(text_data=json.dumps({
42
-                'type': 'details',
43
-                'titre': todo[0].titre,
44
-                'description': todo[0].description,
45
-                'complete': todo[0].complete,
46
-                'priorite': todo[0].priorite
47
-            }))
48
-        else:
49
-            self.send(text_data=json.dumps({
50
-                'error': 'not found'
51
-            }))
17
+        print(text_data_json['id'])
18
+        self.send(text_data=json.dumps({
19
+            'response': 'merci'
20
+        }))
52 21
 
53 22
     def new_value(self, event):
54 23
         self.send(text_data=json.dumps({
@@ -57,3 +26,5 @@ class FrontendConsumer(WebsocketConsumer):
57 26
             'value': event['value']
58 27
         }))
59 28
 
29
+    def new_sensor(self, event):
30
+        pass

+ 1
- 1
gange/models.py View File

@@ -14,7 +14,7 @@ class Bulle(models.Model):
14 14
     )
15 15
 
16 16
     def __str__(self):
17
-        return "{} ({})".format(groupe, utilisations)
17
+        return "{} ({})".format(self.groupe, self.utilisations)
18 18
 
19 19
 
20 20
 class BulleModel(models.Model):

+ 8
- 0
gange/normalisation.py View File

@@ -0,0 +1,8 @@
1
+from .models import Bulle
2
+from django.db.models import Sum
3
+def normal():
4
+    b = Bulle.objects.order_by("utilisations")
5
+    somme_util = Bulle.objects.aggregate(Sum("utilisation"))
6
+    for bulle in b:
7
+        bulle.normaliser = b.utilisation/somme_util*10
8
+    return b

+ 0
- 1779
gange/static/main.js
File diff suppressed because it is too large
View File


+ 0
- 70
gange/static/style.css View File

@@ -1,70 +0,0 @@
1
-@import url('https://fonts.googleapis.com/css?family=Bitter|Bungee|Maven+Pro:900');
2
-
3
-body, html {
4
-	height:100%;
5
-	min-height:100%;
6
-	margin:0;
7
-	padding:0;
8
-	overflow: hidden;
9
-}
10
-
11
-#base {
12
-	position: relative;
13
-}
14
-
15
-#info {
16
-	position: absolute;
17
-	top: 0;
18
-	bottom: 0;
19
-	right: 0;
20
-	left: 0;
21
-	margin: auto;
22
-	width: 60%;
23
-	height: 60%;
24
-	border-style: solid;
25
-	border-color: rgb(0, 0, 0);
26
-  	border-width: 20px 20px 20px 20px;
27
-	
28
-}
29
-
30
-#text {
31
-	width: 70%;
32
-	margin: auto;
33
-	text-align: center;
34
-}
35
-
36
-#warning {
37
-	text-align: center;
38
-	font-size: 64px;
39
-}
40
-
41
-
42
-p {
43
-	font-family: 'Bitter', serif;
44
-	font-size: 20px;
45
-	text-align: justify;
46
-	color: white;
47
-	text-align: center;
48
-}
49
-
50
-button:hover {
51
-	background-color: rgb(210, 210, 210);
52
-	color: black;
53
-}
54
-
55
-button {
56
-	text-align: center;
57
-	margin-right: 0;
58
-	background-color: black;
59
-	color: white;
60
-	border: 2px solid #e7e7e7;
61
-	padding: 16px 32px;
62
-	text-align: center;
63
-	text-decoration: none;
64
-	display: inline-block;
65
-	font-size: 16px;
66
-	margin: 4px 2px;
67
-	-webkit-transition-duration: 0.4s; /* Safari */
68
-	transition-duration: 0.5s;
69
-	cursor: pointer;
70
-}

+ 9
- 9
gange/templates/gange/index.html View File

@@ -1,9 +1,9 @@
1
-{% load static %}
2
-
3
-<DOCTYPE html>
4
-<head>
5
-	<link rel="stylesheet" type="text/css" href="{% static "style.css" %}">
6
-</head>
7
-<body>
8
-	<script src='{% static "main.js" %}'></script>
9
-</body>
1
+<html>
2
+  <head>
3
+    <title>Coucou</title>
4
+  </head>
5
+  <body>
6
+  Cette page est une
7
+  page toute simple
8
+  </body>
9
+</html>

+ 1
- 1
gange/urls.py View File

@@ -3,5 +3,5 @@ from . import views
3 3
 
4 4
 urlpatterns = [
5 5
     path("", views.index, name="index"),
6
-    path("api/newvalue", views.new_value, name="newvalue"),
6
+    path("api/newvalue/", views.new_value, name="newvalue"),
7 7
 ]

+ 5
- 17
gange/views.py View File

@@ -1,28 +1,26 @@
1 1
 from django.shortcuts import render, get_object_or_404
2 2
 from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotAllowed
3 3
 from django.views.decorators.csrf import csrf_exempt
4
-from asgiref.sync import async_to_sync
5
-import channels.layers
6 4
 
7 5
 from .models import Bulle, Valeur, Capteur
8 6
 
9 7
 
10 8
 def index(request):
11
-    return render(request, "gange/index.html", {})
9
+    return HttpResponse("Hello, world. You're at the polls index.")
12 10
     """context = {}
13 11
     return render(request, 'gange/index.html', context)"""
14 12
 
15 13
 
16 14
 @csrf_exempt
17
-def new_value(request):
15
+def new_value(request, capteur_id, capteur_new_value):
18 16
     if request.method == "POST":
19
-        sensor_id = request.POST.get("sensor_id", "")
20
-        new_value = request.POST.get("value", "")
17
+        sensor_id = requests.POST.get("sensor_id", "")
18
+        new_value = requests.POST.get("value", "")
21 19
 
22 20
         errors = ""
23 21
         if not sensor_id.isdigit():
24 22
             errors += "Invalid sensor_id\n"
25
-        if "value" not in request.POST:
23
+        if "value" not in requests.POST:
26 24
             errors += "No value provided\n"
27 25
         if len(errors) > 0:
28 26
             return HttpResponseBadRequest(errors)
@@ -30,15 +28,5 @@ def new_value(request):
30 28
         sensor = get_object_or_404(Capteur, pk=sensor_id)
31 29
         value = Valeur(valeur=new_value, capteur=sensor)
32 30
         value.save()
33
-
34
-        async_to_sync(channels.layers.get_channel_layer().group_send)(
35
-            'message_to_websocket',
36
-            {
37
-                'type': 'new.value',
38
-                'id': sensor_id,
39
-                'value': new_value
40
-            }
41
-        )
42
-
43 31
         return HttpResponse("ok")
44 32
     return HttpResponseNotAllowed()

+ 3
- 19
pa1furet/settings.py View File

@@ -25,7 +25,7 @@ SECRET_KEY = '5c7oi9-tfv=v%f19561fzmhqtx*25_w$9%y7k_-%i%%^9u0=l)'
25 25
 # SECURITY WARNING: don't run with debug turned on in production!
26 26
 DEBUG = True
27 27
 
28
-ALLOWED_HOSTS = ["192.168.2.4"]
28
+ALLOWED_HOSTS = []
29 29
 
30 30
 
31 31
 # Application definition
@@ -77,12 +77,8 @@ WSGI_APPLICATION = 'pa1furet.wsgi.application'
77 77
 
78 78
 DATABASES = {
79 79
     'default': {
80
-        'ENGINE': 'django.db.backends.postgresql_psycopg2',
81
-        'NAME': 'maxime',
82
-        'USER': 'maxime',
83
-        'PASSWORD': "maxime",
84
-        'HOST': '10.0.0.134',
85
-        'PORT': '5432'
80
+        'ENGINE': 'django.db.backends.sqlite3',
81
+        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
86 82
     }
87 83
 }
88 84
 
@@ -125,17 +121,5 @@ USE_TZ = True
125 121
 
126 122
 STATIC_URL = '/static/'
127 123
 
128
-STATIC_ROOT = os.path.join(BASE_DIR, "static")
129
-
130
-
131 124
 # Channels
132 125
 ASGI_APPLICATION = "pa1furet.routing.application"
133
-
134
-CHANNEL_LAYERS = {
135
-    "default": {
136
-        "BACKEND": "channels_redis.core.RedisChannelLayer",
137
-        "CONFIG": {
138
-            "hosts": [("10.0.0.134", 6379)]
139
-        }
140
-    }
141
-}

+ 0
- 1
requirements.txt View File

@@ -1,3 +1,2 @@
1 1
 django==2.1.4
2 2
 channels==2.1.5
3
-channels_redis==2.3.2