forked from ScoDoc/ScoDoc
76 lines
3.0 KiB
Python
76 lines
3.0 KiB
Python
|
# -*- mode: python -*-
|
||
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
##############################################################################
|
||
|
#
|
||
|
# Gestion scolarite IUT
|
||
|
#
|
||
|
# Copyright (c) 1999 - 2021 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
|
||
|
#
|
||
|
##############################################################################
|
||
|
|
||
|
"""Fonctions de calcul des moyennes de modules (modules, ressources ou SAÉ)
|
||
|
|
||
|
Rappel: pour éviter les confusions, on appelera *poids* les coefficients d'une
|
||
|
évaluation dans un module, et *coefficients* ceux utilisés pour le calcul de la
|
||
|
moyenne générale d'une UE.
|
||
|
"""
|
||
|
import numpy as np
|
||
|
import pandas as pd
|
||
|
|
||
|
from app import db
|
||
|
from app import models
|
||
|
|
||
|
|
||
|
def df_load_evaluations_poids(moduleimpl_id: int, default_poids=1.0) -> pd.DataFrame:
|
||
|
"""Charge poids des évaluations d'un module et retourne un dataframe
|
||
|
rows = evaluations, columns = UE, value = poids (float).
|
||
|
Les valeurs manquantes (évaluations sans coef vers des UE) sont
|
||
|
remplies par default_poids.
|
||
|
"""
|
||
|
modimpl = models.ModuleImpl.query.get(moduleimpl_id)
|
||
|
evaluations = models.Evaluation.query.filter_by(moduleimpl_id=moduleimpl_id).all()
|
||
|
ues = modimpl.formsemestre.query_ues().all()
|
||
|
ue_ids = [ue.id for ue in ues]
|
||
|
evaluation_ids = [evaluation.id for evaluation in evaluations]
|
||
|
df = pd.DataFrame(columns=ue_ids, index=evaluation_ids, dtype=float)
|
||
|
for eval_poids in models.EvaluationUEPoids.query.join(
|
||
|
models.EvaluationUEPoids.evaluation
|
||
|
).filter_by(moduleimpl_id=moduleimpl_id):
|
||
|
df[eval_poids.ue_id][eval_poids.evaluation_id] = eval_poids.poids
|
||
|
if default_poids is not None:
|
||
|
df.fillna(value=default_poids, inplace=True)
|
||
|
return df
|
||
|
|
||
|
|
||
|
def check_moduleimpl_conformity(
|
||
|
moduleimpl, evals_poids: pd.DataFrame, modules_coefficients: pd.DataFrame
|
||
|
) -> bool:
|
||
|
"""Vérifie que les évaluations de ce moduleimpl sont bien conformes
|
||
|
au PN.
|
||
|
Un module est dit *conforme* si et seulement si la somme des poids de ses
|
||
|
évaluations vers une UE de coefficient non nul est non nulle.
|
||
|
"""
|
||
|
module_evals_poids = evals_poids.transpose().sum(axis=1).to_numpy() != 0
|
||
|
check = all(
|
||
|
(modules_coefficients[moduleimpl.module.id].to_numpy() != 0)
|
||
|
== module_evals_poids
|
||
|
)
|
||
|
return check
|