diff --git a/Serveur/ApiExamAI/admin.py b/Serveur/ApiExamAI/admin.py index 8c38f3f..b85a2fb 100644 --- a/Serveur/ApiExamAI/admin.py +++ b/Serveur/ApiExamAI/admin.py @@ -1,3 +1,24 @@ from django.contrib import admin +from .models import Surveillance, Eleve +from django.utils.text import Truncator -# Register your models here. + +class EleveAdmin(admin.ModelAdmin): + list_display = ('idul', 'dateCo', 'apercu_clee') + list_filter = ('idul', 'dateCo',) + date_hierarchy = 'dateCo' + ordering = ('dateCo', ) + search_fields = ('idul', 'dateCo') + + def apercu_clee(self, eleve): + """ + Retourne les 40 premiers caractères du contenu de l'article, + suivi de points de suspension si le texte est plus long. + """ + return Truncator(eleve.clee).chars(40, truncate='...') + + # En-tête de notre colonne + apercu_clee.short_description = 'Aperçu de la clée publique' + + +admin.site.register(Eleve, EleveAdmin) diff --git a/Serveur/ApiExamAI/migrations/0001_initial.py b/Serveur/ApiExamAI/migrations/0001_initial.py new file mode 100644 index 0000000..e4b646e --- /dev/null +++ b/Serveur/ApiExamAI/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 2.1.2 on 2018-11-10 23:25 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Eleve', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('idul', models.CharField(max_length=7)), + ('clee', models.IntegerField()), + ('secretPartage', models.IntegerField()), + ('dateCo', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Date de connection')), + ('suspect', models.IntegerField()), + ('photo', models.ImageField(upload_to='')), + ], + options={ + 'verbose_name': 'eleve', + 'ordering': ['idul'], + }, + ), + ] diff --git a/Serveur/ApiExamAI/migrations/0002_auto_20181111_1420.py b/Serveur/ApiExamAI/migrations/0002_auto_20181111_1420.py new file mode 100644 index 0000000..a35f2ea --- /dev/null +++ b/Serveur/ApiExamAI/migrations/0002_auto_20181111_1420.py @@ -0,0 +1,48 @@ +# Generated by Django 2.1.2 on 2018-11-11 19:20 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('ApiExamAI', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Surveillance', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('suspect', models.IntegerField(default=0)), + ('photo', models.ImageField(default=None, upload_to='')), + ], + options={ + 'verbose_name': 'eleve', + 'ordering': ['suspect'], + }, + ), + migrations.RemoveField( + model_name='eleve', + name='photo', + ), + migrations.RemoveField( + model_name='eleve', + name='secretPartage', + ), + migrations.RemoveField( + model_name='eleve', + name='suspect', + ), + migrations.AlterField( + model_name='eleve', + name='dateCo', + field=models.DateTimeField(auto_now_add=True, verbose_name='Date de connection'), + ), + migrations.AddField( + model_name='eleve', + name='surveille', + field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.PROTECT, to='ApiExamAI.Surveillance'), + ), + ] diff --git a/Serveur/ApiExamAI/migrations/0003_remove_eleve_surveille.py b/Serveur/ApiExamAI/migrations/0003_remove_eleve_surveille.py new file mode 100644 index 0000000..f6a7566 --- /dev/null +++ b/Serveur/ApiExamAI/migrations/0003_remove_eleve_surveille.py @@ -0,0 +1,17 @@ +# Generated by Django 2.1.2 on 2018-11-12 01:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('ApiExamAI', '0002_auto_20181111_1420'), + ] + + operations = [ + migrations.RemoveField( + model_name='eleve', + name='surveille', + ), + ] diff --git a/Serveur/ApiExamAI/models.py b/Serveur/ApiExamAI/models.py index 71a8362..a849a86 100644 --- a/Serveur/ApiExamAI/models.py +++ b/Serveur/ApiExamAI/models.py @@ -1,3 +1,39 @@ from django.db import models +from django.utils import timezone -# Create your models here. + +class Surveillance(models.Model): + suspect = models.IntegerField(default=0) + photo = models.ImageField(upload_to="photos/", default=None) + + class Meta: + verbose_name = "surveillance" + ordering = ['suspect'] + + def __str__(self): + return self.suspect + + +class Eleve(models.Model): + idul = models.CharField(max_length=7) + clee = models.IntegerField() + dateCo = models.DateTimeField(auto_now_add=True, + verbose_name="Date de connection") + # default=timezone.now, + #surveille = models.OneToOneField(Surveillance, on_delete=models.PROTECT, null=True) + # PROTECT ou CASCADE ou SET_NULL + + class Meta: + verbose_name = "eleve" + ordering = ['idul'] + + def __str__(self): + return self.idul + + +""" +>> > article = Article(titre="Bonjour", auteur="Maxime") +>> > for article in Article.objects.filter(auteur="Maxime"): +>> > Article.objects.filter(titre__contains="crêpe") +>> > Article.objects.filter(date__lt=timezone.now()) +""" diff --git a/Serveur/ApiExamAI/templates/ApiExamAI/Acceuil_eleve.html b/Serveur/ApiExamAI/templates/ApiExamAI/Acceuil_eleve.html new file mode 100644 index 0000000..9556db9 --- /dev/null +++ b/Serveur/ApiExamAI/templates/ApiExamAI/Acceuil_eleve.html @@ -0,0 +1,5 @@ +{% extends "base.html"%} +{% block title %} Recherche d'eleve {% endblock title %} +{% block content %} +

Taper dans la barre de recherche pour trouver un eleve

+{% endblock content %} diff --git a/Serveur/ApiExamAI/templates/ApiExamAI/Aide.html b/Serveur/ApiExamAI/templates/ApiExamAI/Aide.html new file mode 100644 index 0000000..b36e3fa --- /dev/null +++ b/Serveur/ApiExamAI/templates/ApiExamAI/Aide.html @@ -0,0 +1,7 @@ +{% extends "base.html"%} +{% block title %} Page d'aide {% endblock title %} +{% block content %} +

Expliquons comment ca marche

+

ici

+

plop

+{% endblock content %} diff --git a/Serveur/ApiExamAI/templates/ApiExamAI/eleve.html b/Serveur/ApiExamAI/templates/ApiExamAI/eleve.html index 03730ea..39089ec 100644 --- a/Serveur/ApiExamAI/templates/ApiExamAI/eleve.html +++ b/Serveur/ApiExamAI/templates/ApiExamAI/eleve.html @@ -1,3 +1,7 @@ {% extends "base.html"%} -

Surveillance en cours

-

Le {{date}} élève {{ idul }}

\ No newline at end of file +{% block title %} Surveillance de {{idul}} en cours {% endblock title %} +{% block content %} +

Surveillance en cours

+

Le {{date}} élève {{ idul }}

+

plop

+{% endblock content %} diff --git a/Serveur/ApiExamAI/templates/ApiExamAI/stats.html b/Serveur/ApiExamAI/templates/ApiExamAI/stats.html new file mode 100644 index 0000000..5e8b11f --- /dev/null +++ b/Serveur/ApiExamAI/templates/ApiExamAI/stats.html @@ -0,0 +1,3 @@ +{% extends 'base.html' %} +{% block title %} Statistiques {% endblock title %} +{% block content %} Les stats sont affichées ici{% endblock content %} diff --git a/Serveur/ApiExamAI/urls.py b/Serveur/ApiExamAI/urls.py index c39cf43..1db2f9a 100644 --- a/Serveur/ApiExamAI/urls.py +++ b/Serveur/ApiExamAI/urls.py @@ -2,8 +2,11 @@ from . import views urlpatterns = [ - path('accueil', views.home), - path('eleve/', views.view_eleve), - path('articles//', views.list_articles), - re_path(r'(?P^[A-Z]{5}\d{0,2}$)', views.view_eleve, name='eleve') -] \ No newline at end of file + path('accueil', views.home, name='Acceuil'), + path('Acceuil_eleve', views.Acceuil_eleve, name="Acceuil_eleve"), + path('statistiques', views.stats, name='stats'), + path('connection-', views.connection, name='connection'), + path('Aide', views.Aide, name="Aide"), + re_path(r'^eleve/(?P[A-Z]{5}\d{0,2}$)', + views.view_eleve, name='eleve') +] diff --git a/Serveur/ApiExamAI/views.py b/Serveur/ApiExamAI/views.py index 65af966..3f6f427 100644 --- a/Serveur/ApiExamAI/views.py +++ b/Serveur/ApiExamAI/views.py @@ -1,27 +1,38 @@ -from django.shortcuts import render -from django.http import HttpResponse -from django.http import Http404 -from django.shortcuts import redirect +from django.http import HttpResponse, Http404 +from django.shortcuts import render, redirect, get_object_or_404 from datetime import datetime +from Crypto.PublicKey import RSA +from . import models -def list_articles(request, year, month): - if month > 12: - #return redirect(view_eleve, idul='PISNE') - return redirect('eleve', idul='PISNE') - #return redirect("https://www.djangoproject.com") - else : - return HttpResponse( - "Vous avez demandé {0} et {1} !".format(year,month)) - def home(request): return HttpResponse("""

Bienvenue ExamAi !

Api : getInfos ou plop

""") -def view_eleve(request, idul): - #return HttpResponse("Vous avez demandé l'eleve {0} !".format(idul)) + +def Acceuil_eleve(request): + return render(request, 'ApiExamAI/Acceuil_eleve.html') + + +def view_eleve(request, idul="AAAAA"): + # return HttpResponse("Vous avez demandé l'eleve {0} !".format(idul)) date = datetime.now() - #eturn render(request, 'ApiExamAI/eleve.html', date) + # return render(request, 'ApiExamAI/eleve.html', date) return render(request, 'ApiExamAI/eleve.html', locals()) + + +def stats(request): + return render(request, 'ApiExamAI/stats.html') + + +def Aide(request): + return render(request, 'ApiExamAI/Aide.html') + + +def connection(request, idul): + eleve = models.Eleve(idul=idul) + eleve.clee = RSA.generate(4096).publickey() + #eleve.surveille.suspect = 0 + # public_key.encrypt(TrucQuonVeutSecuriser) diff --git a/Serveur/Serveur/settings.py b/Serveur/Serveur/settings.py index 857a1cb..e445f94 100644 --- a/Serveur/Serveur/settings.py +++ b/Serveur/Serveur/settings.py @@ -15,7 +15,7 @@ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - +MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ @@ -56,8 +56,8 @@ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ - os.path.join(BASE_DIR, 'templates'), - ], + os.path.join(BASE_DIR, 'templates'), + ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -121,3 +121,6 @@ # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, "static"), +) diff --git a/Serveur/ApiExamAI/templates/ApiExamAI/base.html b/Serveur/templates/base.html similarity index 66% rename from Serveur/ApiExamAI/templates/ApiExamAI/base.html rename to Serveur/templates/base.html index 338c3ae..0e924d4 100644 --- a/Serveur/ApiExamAI/templates/ApiExamAI/base.html +++ b/Serveur/templates/base.html @@ -1,3 +1,4 @@ +{% load static %} @@ -9,9 +10,9 @@ @@ -20,4 +21,4 @@ - \ No newline at end of file + diff --git a/detectSound/plop.py b/detectSound/plop.py index 831718c..5505929 100644 --- a/detectSound/plop.py +++ b/detectSound/plop.py @@ -1,34 +1,33 @@ +from pygame import mixer import speech_recognition as sr from gtts import gTTS -#quiet the endless 'insecurerequest' warning +# quiet the endless 'insecurerequest' warning import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) -from pygame import mixer mixer.init() while (True == True): -# obtain audio from the microphone - r = sr.Recognizer() - with sr.Microphone() as source: - #print("Please wait. Calibrating microphone...") - # listen for 1 second and create the ambient noise energy level - r.adjust_for_ambient_noise(source, duration=1) - print("Say something!") - audio = r.listen(source,phrase_time_limit=5) + # obtain audio from the microphone + r = sr.Recognizer() + with sr.Microphone() as source: + #print("Please wait. Calibrating microphone...") + # listen for 1 second and create the ambient noise energy level + r.adjust_for_ambient_noise(source, duration=1) + print("Say something!") + audio = r.listen(source, phrase_time_limit=5) # recognize speech using Sphinx/Google - try: - #response = r.recognize_sphinx(audio) - response = r.recognize_google(audio) - print("I think you said '" + response + "'") - tts = gTTS(text="I think you said "+str(response), lang='en') - tts.save("response.mp3") - mixer.music.load('response.mp3') - mixer.music.play() - + try: + #response = r.recognize_sphinx(audio) + response = r.recognize_google(audio) + print("I think you said '" + response + "'") + tts = gTTS(text="I think you said "+str(response), lang='en') + tts.save("response.mp3") + mixer.music.load('response.mp3') + mixer.music.play() - except sr.UnknownValueError: - print("Sphinx could not understand audio") - except sr.RequestError as e: - print("Sphinx error; {0}".format(e)) + except sr.UnknownValueError: + print("Sphinx could not understand audio") + except sr.RequestError as e: + print("Sphinx error; {0}".format(e)) diff --git a/detectSound/test.py b/detectSound/test.py index 1d42fe9..a171ad3 100644 --- a/detectSound/test.py +++ b/detectSound/test.py @@ -1,31 +1,42 @@ +"""PyAudio example: Record a few seconds of audio and save to a WAVE file.""" + import pyaudio import wave -import sys -print("plop") -pa = pyaudio.PyAudio() -print(pa.get_default_input_device_info()) -CHUNK = 1024 -if len(sys.argv) < 2: - print("Plays a wave file.\n\nUsage: %s filename.wav" % sys.argv[0]) - sys.exit(-1) +CHUNK = 1024 +FORMAT = pyaudio.paInt16 +CHANNELS = 2 +RATE = 44100 +RECORD_SECONDS = 5 +WAVE_OUTPUT_FILENAME = "output.wav" -wf = wave.open(sys.argv[1], 'rb') +pa = pyaudio.PyAudio() +print('plop', pyaudio.pa.__file__) +print('nb', pa.get_device_count()) +pa.get_default_input_device_info() +stream = pa.open(format=FORMAT, + channels=CHANNELS, + rate=RATE, + input=True, + frames_per_buffer=CHUNK) -p = pyaudio.PyAudio() +print("* recording") -stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), - channels=wf.getnchannels(), - rate=wf.getframerate(), - output=True) +frames = [] -data = wf.readframes(CHUNK) +for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): + data = stream.read(CHUNK) + frames.append(data) -while data != '': - stream.write(data) - data = wf.readframes(CHUNK) +print("* done recording") stream.stop_stream() stream.close() - -p.terminate() +pa.terminate() + +wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb') +wf.setnchannels(CHANNELS) +wf.setsampwidth(p.get_sample_size(FORMAT)) +wf.setframerate(RATE) +wf.writeframes(b''.join(frames)) +wf.close()