ScoDoc/app/scodoc/sco_cost_formation.py

196 lines
6.2 KiB
Python

# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
# Copyright (c) 1999 - 2023 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
#
##############################################################################
"""Rapports estimation coût de formation basé sur le programme pédagogique
et les nombres de groupes.
(coût théorique en heures équivalent TD)
"""
from flask import request
from app.models import FormSemestre
from app.scodoc.gen_tables import GenTable
from app.scodoc import sco_preferences
import app.scodoc.sco_utils as scu
import sco_version
def formsemestre_table_estim_cost(
formsemestre_id,
n_group_td=1,
n_group_tp=1,
coef_tp=1,
coef_cours=1.5,
):
"""
Rapports estimation coût de formation basé sur le programme pédagogique
et les nombres de groupes.
Coût théorique en heures équivalent TD.
Attention: ne prend en compte que les modules utilisés dans ce semestre.
Attention: prend en compte _tous_ les modules utilisés dans ce semestre, ce qui
peut conduire à une sur-estimation du coût s'il y a des modules optionnels
(dans ce cas, retoucher le tableau excel exporté).
"""
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
rows = []
for modimpl in formsemestre.modimpls:
rows.append(
{
"code": modimpl.module.code or "",
"titre": modimpl.module.titre,
"heures_cours": modimpl.module.heures_cours or 0.0,
"heures_td": (modimpl.module.heures_td or 0.0) * n_group_td,
"heures_tp": (modimpl.module.heures_tp or 0.0) * n_group_tp,
}
)
# calcul des heures:
for row in rows:
row["HeqTD"] = (
row["heures_td"]
+ coef_cours * row["heures_cours"]
+ coef_tp * row["heures_tp"]
)
sum_cours = sum([t["heures_cours"] for t in rows])
sum_td = sum([t["heures_td"] for t in rows])
sum_tp = sum([t["heures_tp"] for t in rows])
sum_heqtd = sum_td + coef_cours * sum_cours + coef_tp * sum_tp
assert abs(sum([t["HeqTD"] for t in rows]) - sum_heqtd) < 0.01, "%s != %s" % (
sum([t["HeqTD"] for t in rows]),
sum_heqtd,
)
rows.append(
{
"code": "TOTAL SEMESTRE",
"heures_cours": sum_cours,
"heures_td": sum_td,
"heures_tp": sum_tp,
"HeqTD": sum_heqtd,
"_table_part": "foot",
}
)
titles = {
"code": "Code",
"titre": "Titre",
"heures_cours": "Cours",
"heures_td": "TD",
"heures_tp": "TP",
"HeqTD": "HeqTD",
}
tab = GenTable(
titles=titles,
columns_ids=(
"code",
"titre",
"heures_cours",
"heures_td",
"heures_tp",
"HeqTD",
),
rows=rows,
html_sortable=True,
preferences=sco_preferences.SemPreferences(formsemestre_id),
html_class="table_leftalign table_listegroupe",
xls_before_table=[
[formsemestre.titre_annee()],
[
f"Formation {formsemestre.formation.titre} version {formsemestre.formation.version}"
],
[],
["", "TD", "TP"],
["Nombre de groupes", n_group_td, n_group_tp],
[],
[],
],
html_caption="""<div class="help">
Estimation du coût de formation basé sur le programme pédagogique
et les nombres de groupes.<br>
Coût théorique en heures équivalent TD.<br>
Attention: ne prend en compte que les modules utilisés dans ce semestre.<br>
Attention: prend en compte <em>tous les modules</em> utilisés dans ce semestre, ce qui
peut conduire à une sur-estimation du coût s'il y a des modules optionnels
(dans ce cas, retoucher le tableau excel exporté).
</div>
""",
origin=f"""Généré par {sco_version.SCONAME} le {scu.timedate_human_repr()}""",
filename=f"EstimCout-S{formsemestre.semestre_id}",
)
return tab
def formsemestre_estim_cost(
formsemestre_id,
n_group_td=1,
n_group_tp=1,
coef_tp=1,
coef_cours=1.5,
fmt="html",
):
"""Page (formulaire) estimation coûts"""
n_group_td = int(n_group_td)
n_group_tp = int(n_group_tp)
coef_tp = float(coef_tp)
coef_cours = float(coef_cours)
tab = formsemestre_table_estim_cost(
formsemestre_id,
n_group_td=n_group_td,
n_group_tp=n_group_tp,
coef_tp=coef_tp,
coef_cours=coef_cours,
)
h = """
<form name="f" method="get" action="%s">
<input type="hidden" name="formsemestre_id" value="%s"></input>
Nombre de groupes de TD: <input type="text" name="n_group_td" value="%s" onchange="document.f.submit()"/><br>
Nombre de groupes de TP: <input type="text" name="n_group_tp" value="%s" onchange="document.f.submit()"/>
&nbsp;Coefficient heures TP: <input type="text" name="coef_tp" value="%s" onchange="document.f.submit()"/>
<br>
</form>
""" % (
request.base_url,
formsemestre_id,
n_group_td,
n_group_tp,
coef_tp,
)
tab.html_before_table = h
tab.base_url = "%s?formsemestre_id=%s&n_group_td=%s&n_group_tp=%s&coef_tp=%s" % (
request.base_url,
formsemestre_id,
n_group_td,
n_group_tp,
coef_tp,
)
return tab.make_page(fmt=fmt)