2021-11-12 22:17:46 +01:00
|
|
|
# -*- 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 d'UE
|
|
|
|
"""
|
|
|
|
import numpy as np
|
|
|
|
import pandas as pd
|
|
|
|
|
|
|
|
from app import db
|
|
|
|
from app import models
|
|
|
|
|
|
|
|
|
2021-11-17 10:28:51 +01:00
|
|
|
def df_load_ue_coefs(formation_id: int, semestre_idx: int) -> pd.DataFrame:
|
2021-11-12 22:17:46 +01:00
|
|
|
"""Load coefs of all modules in formation and returns a DataFrame
|
2021-11-17 10:28:51 +01:00
|
|
|
rows = UEs, columns = modules, value = coef.
|
|
|
|
On considère toutes les UE et modules du semestre.
|
2021-11-12 22:17:46 +01:00
|
|
|
Unspecified coefs (not defined in db) are set to zero.
|
2021-11-18 22:46:18 +01:00
|
|
|
Si semestre_idx None, prend toutes les UE de la formation.
|
2021-11-12 22:17:46 +01:00
|
|
|
"""
|
2021-11-17 10:28:51 +01:00
|
|
|
ues = models.UniteEns.query.filter_by(formation_id=formation_id)
|
|
|
|
modules = models.Module.query.filter_by(formation_id=formation_id)
|
2021-11-18 22:46:18 +01:00
|
|
|
if semestre_idx is not None:
|
|
|
|
ues = ues.filter_by(semestre_idx=semestre_idx)
|
|
|
|
modules = modules.filter_by(semestre_id=semestre_idx)
|
2021-11-12 22:17:46 +01:00
|
|
|
ue_ids = [ue.id for ue in ues]
|
|
|
|
module_ids = [module.id for module in modules]
|
2021-11-17 10:28:51 +01:00
|
|
|
df = pd.DataFrame(columns=module_ids, index=ue_ids, dtype=float)
|
2021-11-12 22:17:46 +01:00
|
|
|
for mod_coef in (
|
|
|
|
db.session.query(models.ModuleUECoef)
|
|
|
|
.filter(models.UniteEns.formation_id == formation_id)
|
|
|
|
.filter(models.ModuleUECoef.ue_id == models.UniteEns.id)
|
|
|
|
):
|
2021-11-17 10:28:51 +01:00
|
|
|
df[mod_coef.module_id][mod_coef.ue_id] = mod_coef.coef
|
2021-11-12 22:17:46 +01:00
|
|
|
df.fillna(value=0, inplace=True)
|
2021-11-18 22:46:18 +01:00
|
|
|
return df, ues, modules
|