From c0474f109d8da33b9b0917ad9f513c7ca9b392c2 Mon Sep 17 00:00:00 2001 From: leonard_montalbano Date: Fri, 3 Jun 2022 16:20:59 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20de=20l'al=C3=A9atoire=20dans=20la=20sai?= =?UTF-8?q?sies=20des=20notes=20(prob=20avec=20les=20dates)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fakedatabase/create_test_api_database.py | 61 +++++++++++++++++-- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/tools/fakedatabase/create_test_api_database.py b/tools/fakedatabase/create_test_api_database.py index 3744fc10..41710890 100644 --- a/tools/fakedatabase/create_test_api_database.py +++ b/tools/fakedatabase/create_test_api_database.py @@ -195,21 +195,70 @@ def saisie_note_evaluations(formsemestre: FormSemestre, user: User): """ # Récupération des id des étudiants du semestre list_etudids = [etud.id for etud in formsemestre.etuds] - list_ues = formsemestre.query_ues() - def create_list_etudid_random_notes(): + def add_random_notes(evaluation_id, new_list_notes_eval=None, not_all=False): """ - Retourne une liste de tuple (etudid, note_random) + Permet d'ajouter des notes aléatoires à une évaluation """ - return [(etudid, random.uniform(0.0, 20.0)) for etudid in list_etudids] + if not_all: + percent = 80 / 100 + len_list_etudids = len(list_etudids) + new_list_etudids = random.sample( + list_etudids, k=int(percent * len_list_etudids) + ) + # new_list_etudids = [note.etudid for note in new_list_notes_eval] + list_tuple_notes = [ + (etudid, random.uniform(0.0, 20.0)) for etudid in new_list_etudids + ] + notes_add(user, evaluation_id, list_tuple_notes) + else: + list_tuple_notes = [ + (etudid, random.uniform(0.0, 20.0)) for etudid in list_etudids + ] + notes_add(user, evaluation_id, list_tuple_notes) + + def saisir_notes(evaluation_id: int, condition: int, list_notes_eval): + """ + Permet de saisir les notes de manière aléatoire suivant une condition + Définition des valeurs de condition : + 0 : all_notes_saisies + 1 : all_notes_manquantes + 2 : some_notes_manquantes + """ + if condition == 0 or condition == 2: + date_debut = formsemestre.date_debut + date_fin = formsemestre.date_fin + if condition == 0: + add_random_notes(evaluation_id) + for note in list_notes_eval: + note.date = date_debut + random.random() * (date_fin - date_debut) + db.session.add(note) + db.session.commit() + else: + percent = 80 / 100 + len_list_notes_eval = len(list_notes_eval) + new_list_notes_eval = random.sample( + list_notes_eval, k=int(percent * len_list_notes_eval) + ) + add_random_notes(evaluation_id, new_list_notes_eval, True) + for note in new_list_notes_eval: + note.date = date_debut + random.random() * (date_fin - date_debut) + db.session.add(note) + db.session.commit() + + list_ues = formsemestre.query_ues() for ue in list_ues: mods = ue.modules for mod in mods: moduleimpl = ModuleImpl.query.get_or_404(mod.id) for evaluation in moduleimpl.evaluations: - notes = create_list_etudid_random_notes() - notes_add(user, evaluation.id, notes) + # Récupération de toutes les notes de l'évaluation + notes_eval = models.NotesNotes.query.filter_by( + evaluation_id=evaluation.id + ).all() + condition_saisie_notes = random.randint(0, 2) + saisir_notes(evaluation.id, condition_saisie_notes, notes_eval) def init_test_database():