MonScoDocEssai/app/comp/moy_ue.py

56 lines
2.1 KiB
Python
Raw Normal View History

# -*- 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:
"""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.
Unspecified coefs (not defined in db) are set to zero.
"""
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)
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)
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
df.fillna(value=0, inplace=True)
return df