forked from ScoDoc/ScoDoc
correction bug génération date random pour tests unitaires
This commit is contained in:
parent
d3e7ababd8
commit
25422b7f81
@ -47,6 +47,14 @@ class NotesNotes(db.Model):
|
|||||||
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
||||||
uid = db.Column(db.Integer, db.ForeignKey("user.id"))
|
uid = db.Column(db.Integer, db.ForeignKey("user.id"))
|
||||||
|
|
||||||
|
def __init__(self, etudid, evaluation_id, value, comment, date, uid):
|
||||||
|
self.etudid = etudid
|
||||||
|
self.evaluation_id = evaluation_id
|
||||||
|
self.value = value
|
||||||
|
self.comment = comment
|
||||||
|
self.date = date
|
||||||
|
self.uid = uid
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return {
|
return {
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
FLASK_DEBUG=1
|
FLASK_DEBUG=1
|
||||||
|
|
||||||
2) En tant qu'utilisateur scodoc, lancer:
|
2) En tant qu'utilisateur scodoc, lancer:
|
||||||
tools/create_database.sh SCODOC_TEST_API
|
tools/create_database.sh SCODOC_TEST_API_EVAL
|
||||||
flask db upgrade
|
flask db upgrade
|
||||||
flask sco-db-init --erase
|
flask sco-db-init --erase
|
||||||
flask init-test-database
|
flask init-test-database
|
||||||
@ -24,11 +24,19 @@
|
|||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from app.auth.models import Role, User
|
from app.auth.models import Role, User
|
||||||
from app import models
|
from app import models
|
||||||
from app.models import Departement, Formation, FormSemestre, Identite, ModuleImpl
|
from app.models import (
|
||||||
|
Departement,
|
||||||
|
Formation,
|
||||||
|
FormSemestre,
|
||||||
|
Identite,
|
||||||
|
ModuleImpl,
|
||||||
|
NotesNotes,
|
||||||
|
)
|
||||||
from app import db
|
from app import db
|
||||||
from app.scodoc import (
|
from app.scodoc import (
|
||||||
sco_cache,
|
sco_cache,
|
||||||
@ -189,35 +197,21 @@ def create_evaluations(formsemestre: FormSemestre):
|
|||||||
evaluation_id = sco_evaluation_db.do_evaluation_create(**args)
|
evaluation_id = sco_evaluation_db.do_evaluation_create(**args)
|
||||||
|
|
||||||
|
|
||||||
def saisie_note_evaluations(formsemestre: FormSemestre, user: User):
|
def saisie_notes_evaluations(formsemestre: FormSemestre, user: User):
|
||||||
"""
|
"""
|
||||||
Saisie les notes des evaluations d'un semestre
|
Saisie les notes des evaluations d'un semestre
|
||||||
"""
|
"""
|
||||||
# Récupération des id des étudiants du semestre
|
etuds = formsemestre.etuds
|
||||||
list_etudids = [etud.id for etud in formsemestre.etuds]
|
list_etuds = []
|
||||||
|
for etu in etuds:
|
||||||
|
list_etuds.append(etu)
|
||||||
|
|
||||||
def add_random_notes(evaluation_id, new_list_notes_eval=None, not_all=False):
|
date_debut = formsemestre.date_debut
|
||||||
"""
|
date_fin = formsemestre.date_fin
|
||||||
Permet d'ajouter des notes aléatoires à une évaluation
|
|
||||||
"""
|
|
||||||
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):
|
list_ues = formsemestre.query_ues()
|
||||||
|
|
||||||
|
def saisir_notes(evaluation_id: int, condition: int):
|
||||||
"""
|
"""
|
||||||
Permet de saisir les notes de manière aléatoire suivant une condition
|
Permet de saisir les notes de manière aléatoire suivant une condition
|
||||||
Définition des valeurs de condition :
|
Définition des valeurs de condition :
|
||||||
@ -226,39 +220,41 @@ def saisie_note_evaluations(formsemestre: FormSemestre, user: User):
|
|||||||
2 : some_notes_manquantes
|
2 : some_notes_manquantes
|
||||||
"""
|
"""
|
||||||
if condition == 0 or condition == 2:
|
if condition == 0 or condition == 2:
|
||||||
date_debut = formsemestre.date_debut
|
|
||||||
date_fin = formsemestre.date_fin
|
|
||||||
if condition == 0:
|
if condition == 0:
|
||||||
add_random_notes(evaluation_id)
|
for etu in list_etuds:
|
||||||
for note in list_notes_eval:
|
note = NotesNotes(
|
||||||
note.date = date_debut + random.random() * (date_fin - date_debut)
|
etu.id,
|
||||||
|
evaluation_id,
|
||||||
|
random.uniform(0, 20),
|
||||||
|
"",
|
||||||
|
date_debut + random.random() * (date_fin - date_debut),
|
||||||
|
user.id,
|
||||||
|
)
|
||||||
db.session.add(note)
|
db.session.add(note)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
else:
|
else:
|
||||||
percent = 80 / 100
|
percent = 80 / 100
|
||||||
len_list_notes_eval = len(list_notes_eval)
|
len_etuds = len(list_etuds)
|
||||||
new_list_notes_eval = random.sample(
|
new_list_etuds = random.sample(list_etuds, k=int(percent * len_etuds))
|
||||||
list_notes_eval, k=int(percent * len_list_notes_eval)
|
for etu in new_list_etuds:
|
||||||
|
note = NotesNotes(
|
||||||
|
etu.id,
|
||||||
|
evaluation_id,
|
||||||
|
random.uniform(0, 20),
|
||||||
|
"",
|
||||||
|
date_debut + random.random() * (date_fin - date_debut),
|
||||||
|
user.id,
|
||||||
)
|
)
|
||||||
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.add(note)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
list_ues = formsemestre.query_ues()
|
|
||||||
|
|
||||||
for ue in list_ues:
|
for ue in list_ues:
|
||||||
mods = ue.modules
|
mods = ue.modules
|
||||||
for mod in mods:
|
for mod in mods:
|
||||||
moduleimpl = ModuleImpl.query.get_or_404(mod.id)
|
moduleimpl = ModuleImpl.query.get_or_404(mod.id)
|
||||||
for evaluation in moduleimpl.evaluations:
|
for evaluation in moduleimpl.evaluations:
|
||||||
# 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)
|
condition_saisie_notes = random.randint(0, 2)
|
||||||
saisir_notes(evaluation.id, condition_saisie_notes, notes_eval)
|
saisir_notes(evaluation.id, condition_saisie_notes)
|
||||||
|
|
||||||
|
|
||||||
def init_test_database():
|
def init_test_database():
|
||||||
@ -274,7 +270,7 @@ def init_test_database():
|
|||||||
formsemestre = create_formsemestre(formation, user_lecteur)
|
formsemestre = create_formsemestre(formation, user_lecteur)
|
||||||
create_evaluations(formsemestre)
|
create_evaluations(formsemestre)
|
||||||
inscrit_etudiants(etuds, formsemestre)
|
inscrit_etudiants(etuds, formsemestre)
|
||||||
saisie_note_evaluations(formsemestre, user_lecteur)
|
saisie_notes_evaluations(formsemestre, user_lecteur)
|
||||||
# à compléter
|
# à compléter
|
||||||
# - groupes
|
# - groupes
|
||||||
# - absences
|
# - absences
|
||||||
|
Loading…
Reference in New Issue
Block a user