forked from ScoDoc/ScoDoc
Compare commits
3 Commits
d3e7ababd8
...
d0e179fb7c
Author | SHA1 | Date | |
---|---|---|---|
|
d0e179fb7c | ||
|
d245030b65 | ||
|
25422b7f81 |
@ -1,49 +1,31 @@
|
||||
from app.api import bp
|
||||
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
|
||||
# -*- mode: python -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# 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"])
|
||||
@token_auth.login_required
|
||||
@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())
|
||||
"""
|
||||
!!! ATTENTION !!!
|
||||
Fichier a utilisé uniquement à des fins de debug
|
||||
"""
|
||||
|
@ -7,15 +7,11 @@ import app
|
||||
from app import models
|
||||
from app.api import bp
|
||||
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.moy_mod import ModuleImplResults
|
||||
from app.comp.res_compat import NotesTableCompat
|
||||
from app.models import Departement, FormSemestre, FormSemestreEtape, Module, ModuleImpl
|
||||
from app.scodoc import sco_evaluation_db
|
||||
from app.models import Departement, FormSemestre, FormSemestreEtape, ModuleImpl
|
||||
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_permissions import Permission
|
||||
from app.scodoc.sco_utils import ModuleType
|
||||
@ -494,6 +490,7 @@ def etat_evals(formsemestre_id: int):
|
||||
"description": null,
|
||||
"datetime_epreuve": null,
|
||||
"heure_fin": "09:00:00",
|
||||
"coefficient": "02.00"
|
||||
"comptee": "oui",
|
||||
"inscrits": 16,
|
||||
"manquantes": 0,
|
||||
@ -501,9 +498,9 @@ def etat_evals(formsemestre_id: int):
|
||||
"ATT": 0,
|
||||
"EXC": 0,
|
||||
"saisie_notes": {
|
||||
"datetime_debut": "Wed, 01 Jun 2022 10:37:59 GMT",
|
||||
"datetime_fin": "Wed, 01 Jun 2022 13:18:09 GMT",
|
||||
"datetime_mediane": "Wed, 01 Jun 2022 12:38:57 GMT"
|
||||
"datetime_debut": "2021-09-11T00:00:00+02:00",
|
||||
"datetime_fin": "2022-08-25T00:00:00+02:00",
|
||||
"datetime_mediane": "2022-03-19T00:00:00+01:00"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -518,9 +515,9 @@ def etat_evals(formsemestre_id: int):
|
||||
"ATT": 0,
|
||||
"EXC": 0,
|
||||
"saisie_notes": {
|
||||
"datetime_debut": "Wed, 01 Jun 2022 12:04:19 GMT",
|
||||
"datetime_fin": "Wed, 01 Jun 2022 12:04:36 GMT",
|
||||
"datetime_mediane": "Wed, 01 Jun 2022 14:04:27 GMT"
|
||||
"datetime_debut": "2021-09-11T00:00:00+02:00",
|
||||
"datetime_fin": "2022-08-25T00:00:00+02:00",
|
||||
"datetime_mediane": "2022-03-19T00:00:00+01:00"
|
||||
}
|
||||
},
|
||||
]
|
||||
@ -562,8 +559,11 @@ def etat_evals(formsemestre_id: int):
|
||||
|
||||
eval["id"] = evaluation.id
|
||||
eval["description"] = evaluation.description
|
||||
eval["datetime_epreuve"] = evaluation.jour
|
||||
eval["datetime_epreuve"] = (
|
||||
evaluation.jour.isoformat() if evaluation.jour is not None else None
|
||||
)
|
||||
eval["heure_fin"] = evaluation.heure_fin.isoformat()
|
||||
eval["coefficient"] = evaluation.coefficient
|
||||
eval["comptee"] = "oui" if eval_etat.is_complete else "non"
|
||||
eval["inscrits"] = modimpl_results.nb_inscrits_module
|
||||
eval["manquantes"] = len(
|
||||
@ -582,6 +582,10 @@ def etat_evals(formsemestre_id: int):
|
||||
evaluation_id=evaluation.id
|
||||
).all()
|
||||
|
||||
date_debut = None
|
||||
date_fin = None
|
||||
date_mediane = None
|
||||
|
||||
# Si il y a plus d'une note saisie pour l'évaluation
|
||||
if len(notes) >= 1:
|
||||
# Trie des notes en fonction de leurs dates
|
||||
@ -598,19 +602,20 @@ def etat_evals(formsemestre_id: int):
|
||||
int((len(list_id_notes_sorted)) / 2)
|
||||
]
|
||||
|
||||
date_mediane = ""
|
||||
for n in notes_sorted:
|
||||
if n.id == id_mediane:
|
||||
date_mediane = n.date
|
||||
else:
|
||||
date_debut = None
|
||||
date_fin = None
|
||||
date_mediane = None
|
||||
|
||||
eval["saisie_notes"] = {
|
||||
"datetime_debut": date_debut,
|
||||
"datetime_fin": date_fin,
|
||||
"datetime_mediane": date_mediane,
|
||||
"datetime_debut": date_debut.isoformat()
|
||||
if date_debut is not None
|
||||
else None,
|
||||
"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)
|
||||
|
@ -47,6 +47,14 @@ class NotesNotes(db.Model):
|
||||
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
||||
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):
|
||||
return {
|
||||
"id": self.id,
|
||||
|
@ -10,7 +10,7 @@
|
||||
FLASK_DEBUG=1
|
||||
|
||||
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 sco-db-init --erase
|
||||
flask init-test-database
|
||||
@ -24,11 +24,19 @@
|
||||
"""
|
||||
import datetime
|
||||
import random
|
||||
import time
|
||||
import sys
|
||||
|
||||
from app.auth.models import Role, User
|
||||
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.scodoc import (
|
||||
sco_cache,
|
||||
@ -189,35 +197,21 @@ def create_evaluations(formsemestre: FormSemestre):
|
||||
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
|
||||
"""
|
||||
# Récupération des id des étudiants du semestre
|
||||
list_etudids = [etud.id for etud in formsemestre.etuds]
|
||||
etuds = 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):
|
||||
"""
|
||||
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)
|
||||
date_debut = formsemestre.date_debut
|
||||
date_fin = formsemestre.date_fin
|
||||
|
||||
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
|
||||
Définition des valeurs de condition :
|
||||
@ -226,39 +220,41 @@ def saisie_note_evaluations(formsemestre: FormSemestre, user: User):
|
||||
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)
|
||||
for etu in list_etuds:
|
||||
note = NotesNotes(
|
||||
etu.id,
|
||||
evaluation_id,
|
||||
random.uniform(0, 20),
|
||||
"",
|
||||
date_debut + random.random() * (date_fin - date_debut),
|
||||
user.id,
|
||||
)
|
||||
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)
|
||||
len_etuds = len(list_etuds)
|
||||
new_list_etuds = random.sample(list_etuds, k=int(percent * len_etuds))
|
||||
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.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:
|
||||
# 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)
|
||||
saisir_notes(evaluation.id, condition_saisie_notes)
|
||||
|
||||
|
||||
def init_test_database():
|
||||
@ -274,7 +270,7 @@ def init_test_database():
|
||||
formsemestre = create_formsemestre(formation, user_lecteur)
|
||||
create_evaluations(formsemestre)
|
||||
inscrit_etudiants(etuds, formsemestre)
|
||||
saisie_note_evaluations(formsemestre, user_lecteur)
|
||||
saisie_notes_evaluations(formsemestre, user_lecteur)
|
||||
# à compléter
|
||||
# - groupes
|
||||
# - absences
|
||||
|
Loading…
Reference in New Issue
Block a user