Compare commits

..

No commits in common. "d0e179fb7cb3e8b8d0366b5808c1658ed7c19ba3" and "d3e7ababd8598ba4c6639995063ae134e94c7cbe" have entirely different histories.

4 changed files with 115 additions and 106 deletions

View File

@ -1,31 +1,49 @@
# -*- mode: python -*- from app.api import bp
# -*- coding: utf-8 -*- from app.api.auth import token_auth, token_permission_required
from app.models import NotesNotes, FormSemestre
from app.scodoc.sco_permissions import Permission
from flask import jsonify
from app import models
from app import db
import time
import random
import datetime
##############################################################################
#
# Gestion scolarite IUT
#
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Emmanuel Viennet emmanuel.viennet@viennet.net
#
##############################################################################
""" @bp.route("/create_note", methods=["GET"])
!!! ATTENTION !!! @token_auth.login_required
Fichier a utilisé uniquement à des fins de debug @token_permission_required(Permission.APIView)
""" def create_note():
note = NotesNotes()
db.session.add(note)
db.session.commit()
return jsonify(note.to_dict())
@bp.route("/change_value_note/<int:note_id>", methods=["GET"])
@token_auth.login_required
@token_permission_required(Permission.APIView)
def change_value_note(note_id: int):
note = NotesNotes.query.get_or_404(note_id)
note.value = 10
db.session.commit()
return jsonify(note.to_dict())
@bp.route(
"/change_date_note/<int:note_id>", methods=["GET"]
) # XXX TODO test avec notes_add() en plus
@token_auth.login_required
@token_permission_required(Permission.APIView)
def change_date_note(note_id: int):
formsemestre = FormSemestre.query.get_or_404(1)
date_debut = formsemestre.date_debut
date_fin = formsemestre.date_fin
note = NotesNotes.query.get_or_404(note_id)
note.date = date_debut + random.random() * (date_fin - date_debut)
db.session.commit()
return jsonify(note.to_dict())

View File

@ -7,11 +7,15 @@ import app
from app import models from app import models
from app.api import bp from app.api import bp
from app.api.auth import token_auth, token_permission_required from app.api.auth import token_auth, token_permission_required
from app.api.tools import calculate_median
from app.comp import res_sem from app.comp import res_sem
from app.comp.moy_mod import ModuleImplResults from app.comp.moy_mod import ModuleImplResults
from app.comp.res_compat import NotesTableCompat from app.comp.res_compat import NotesTableCompat
from app.models import Departement, FormSemestre, FormSemestreEtape, ModuleImpl from app.models import Departement, FormSemestre, FormSemestreEtape, Module, ModuleImpl
from app.scodoc import sco_evaluation_db
from app.scodoc.sco_bulletins import get_formsemestre_bulletin_etud_json from app.scodoc.sco_bulletins import get_formsemestre_bulletin_etud_json
from app.scodoc.sco_evaluation_recap import evaluations_recap_table
from app.scodoc.sco_evaluations import do_evaluation_etat_in_sem, do_evaluation_etat
from app.scodoc.sco_groups import get_etud_groups from app.scodoc.sco_groups import get_etud_groups
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
from app.scodoc.sco_utils import ModuleType from app.scodoc.sco_utils import ModuleType
@ -490,7 +494,6 @@ def etat_evals(formsemestre_id: int):
"description": null, "description": null,
"datetime_epreuve": null, "datetime_epreuve": null,
"heure_fin": "09:00:00", "heure_fin": "09:00:00",
"coefficient": "02.00"
"comptee": "oui", "comptee": "oui",
"inscrits": 16, "inscrits": 16,
"manquantes": 0, "manquantes": 0,
@ -498,9 +501,9 @@ def etat_evals(formsemestre_id: int):
"ATT": 0, "ATT": 0,
"EXC": 0, "EXC": 0,
"saisie_notes": { "saisie_notes": {
"datetime_debut": "2021-09-11T00:00:00+02:00", "datetime_debut": "Wed, 01 Jun 2022 10:37:59 GMT",
"datetime_fin": "2022-08-25T00:00:00+02:00", "datetime_fin": "Wed, 01 Jun 2022 13:18:09 GMT",
"datetime_mediane": "2022-03-19T00:00:00+01:00" "datetime_mediane": "Wed, 01 Jun 2022 12:38:57 GMT"
} }
}, },
{ {
@ -515,9 +518,9 @@ def etat_evals(formsemestre_id: int):
"ATT": 0, "ATT": 0,
"EXC": 0, "EXC": 0,
"saisie_notes": { "saisie_notes": {
"datetime_debut": "2021-09-11T00:00:00+02:00", "datetime_debut": "Wed, 01 Jun 2022 12:04:19 GMT",
"datetime_fin": "2022-08-25T00:00:00+02:00", "datetime_fin": "Wed, 01 Jun 2022 12:04:36 GMT",
"datetime_mediane": "2022-03-19T00:00:00+01:00" "datetime_mediane": "Wed, 01 Jun 2022 14:04:27 GMT"
} }
}, },
] ]
@ -559,11 +562,8 @@ def etat_evals(formsemestre_id: int):
eval["id"] = evaluation.id eval["id"] = evaluation.id
eval["description"] = evaluation.description eval["description"] = evaluation.description
eval["datetime_epreuve"] = ( eval["datetime_epreuve"] = evaluation.jour
evaluation.jour.isoformat() if evaluation.jour is not None else None
)
eval["heure_fin"] = evaluation.heure_fin.isoformat() eval["heure_fin"] = evaluation.heure_fin.isoformat()
eval["coefficient"] = evaluation.coefficient
eval["comptee"] = "oui" if eval_etat.is_complete else "non" eval["comptee"] = "oui" if eval_etat.is_complete else "non"
eval["inscrits"] = modimpl_results.nb_inscrits_module eval["inscrits"] = modimpl_results.nb_inscrits_module
eval["manquantes"] = len( eval["manquantes"] = len(
@ -582,10 +582,6 @@ def etat_evals(formsemestre_id: int):
evaluation_id=evaluation.id evaluation_id=evaluation.id
).all() ).all()
date_debut = None
date_fin = None
date_mediane = None
# Si il y a plus d'une note saisie pour l'évaluation # Si il y a plus d'une note saisie pour l'évaluation
if len(notes) >= 1: if len(notes) >= 1:
# Trie des notes en fonction de leurs dates # Trie des notes en fonction de leurs dates
@ -602,20 +598,19 @@ def etat_evals(formsemestre_id: int):
int((len(list_id_notes_sorted)) / 2) int((len(list_id_notes_sorted)) / 2)
] ]
date_mediane = ""
for n in notes_sorted: for n in notes_sorted:
if n.id == id_mediane: if n.id == id_mediane:
date_mediane = n.date date_mediane = n.date
else:
date_debut = None
date_fin = None
date_mediane = None
eval["saisie_notes"] = { eval["saisie_notes"] = {
"datetime_debut": date_debut.isoformat() "datetime_debut": date_debut,
if date_debut is not None "datetime_fin": date_fin,
else None, "datetime_mediane": date_mediane,
"datetime_fin": date_fin.isoformat()
if date_fin is not None
else None,
"datetime_mediane": date_mediane.isoformat()
if date_mediane is not None
else None,
} }
list_eval.append(eval) list_eval.append(eval)

View File

@ -47,14 +47,6 @@ 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,

View File

@ -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_EVAL tools/create_database.sh SCODOC_TEST_API
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,19 +24,11 @@
""" """
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 ( from app.models import Departement, Formation, FormSemestre, Identite, ModuleImpl
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,
@ -197,21 +189,35 @@ 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_notes_evaluations(formsemestre: FormSemestre, user: User): def saisie_note_evaluations(formsemestre: FormSemestre, user: User):
""" """
Saisie les notes des evaluations d'un semestre Saisie les notes des evaluations d'un semestre
""" """
etuds = formsemestre.etuds # Récupération des id des étudiants du semestre
list_etuds = [] list_etudids = [etud.id for etud in formsemestre.etuds]
for etu in etuds:
list_etuds.append(etu)
date_debut = formsemestre.date_debut def add_random_notes(evaluation_id, new_list_notes_eval=None, not_all=False):
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)
list_ues = formsemestre.query_ues() def saisir_notes(evaluation_id: int, condition: int, list_notes_eval):
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 :
@ -220,41 +226,39 @@ def saisie_notes_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:
for etu in list_etuds: add_random_notes(evaluation_id)
note = NotesNotes( for note in list_notes_eval:
etu.id, note.date = date_debut + random.random() * (date_fin - date_debut)
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_etuds = len(list_etuds) len_list_notes_eval = len(list_notes_eval)
new_list_etuds = random.sample(list_etuds, k=int(percent * len_etuds)) new_list_notes_eval = random.sample(
for etu in new_list_etuds: list_notes_eval, k=int(percent * len_list_notes_eval)
note = NotesNotes( )
etu.id, add_random_notes(evaluation_id, new_list_notes_eval, True)
evaluation_id, for note in new_list_notes_eval:
random.uniform(0, 20), note.date = date_debut + random.random() * (date_fin - date_debut)
"",
date_debut + random.random() * (date_fin - date_debut),
user.id,
)
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) saisir_notes(evaluation.id, condition_saisie_notes, notes_eval)
def init_test_database(): def init_test_database():
@ -270,7 +274,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_notes_evaluations(formsemestre, user_lecteur) saisie_note_evaluations(formsemestre, user_lecteur)
# à compléter # à compléter
# - groupes # - groupes
# - absences # - absences