ScoDoc-PE/app/scodoc/sco_export_results.py

356 lines
13 KiB
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
2021-01-01 17:51:08 +01:00
# Copyright (c) 1999 - 2021 Emmanuel Viennet. All rights reserved.
2020-09-26 16:19:37 +02:00
#
# 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
#
##############################################################################
"""Export d'une table avec les résultats de tous les étudiants
"""
2021-02-03 22:00:41 +01:00
from types import ListType
2020-09-26 16:19:37 +02:00
import app.scodoc.notesdb as ndb
import app.scodoc.sco_utils as scu
from app.scodoc.notes_log import log
from app.scodoc import html_sco_header
from app.scodoc import sco_bac
from app.scodoc import sco_codes_parcours
from app.scodoc import sco_core
from app.scodoc import sco_formations
from app.scodoc import sco_preferences
from app.scodoc import sco_pvjury
from app.scodoc import sco_etud
from app.scodoc import VERSION
from app.scodoc.gen_tables import GenTable
from app.scodoc.sco_codes_parcours import NO_SEMESTRE_ID
2020-09-26 16:19:37 +02:00
def _build_results_table(context, start_date=None, end_date=None, types_parcours=[]):
"""Construit une table avec les résultats de jury de TOUS les étudiants
de TOUS les semestres ScoDoc de ce département entre les dates indiquées
(c'est à dire commençant APRES ou à start_date et terminant avant ou à end_date)
Les dates sont des chaines iso.
"""
formsemestre_ids = get_set_formsemestre_id_dates(context, start_date, end_date)
# Décisions de jury de tous les semestres:
dpv_by_sem = {}
for formsemestre_id in formsemestre_ids:
dpv_by_sem[formsemestre_id] = sco_pvjury.dict_pvjury(
context, formsemestre_id, with_parcours_decisions=True
)
semlist = [dpv["formsemestre"] for dpv in dpv_by_sem.values() if dpv]
semlist_parcours = []
for sem in semlist:
sem["formation"] = sco_formations.formation_list(
context, args={"formation_id": sem["formation_id"]}
2020-09-26 16:19:37 +02:00
)[0]
sem["parcours"] = sco_codes_parcours.get_parcours_from_code(
sem["formation"]["type_parcours"]
)
if sem["parcours"].TYPE_PARCOURS in types_parcours:
semlist_parcours.append(sem)
formsemestre_ids_parcours = [sem["formsemestre_id"] for sem in semlist_parcours]
# Ensemble des étudiants
etuds_infos = (
{}
) # etudid : { formsemestre_id d'inscription le plus recent dans les dates considérées, etud }
for formsemestre_id in formsemestre_ids_parcours:
2021-06-13 23:37:14 +02:00
nt = sco_core.get_notes_cache(context).get_NotesTable(
2020-09-26 16:19:37 +02:00
context, formsemestre_id
) # > get_etudids
etudids = nt.get_etudids()
for etudid in etudids:
if etudid not in etuds_infos: # pas encore traité ?
etud = sco_etud.get_etud_info(etudid=etudid, filled=True)[0]
2020-09-26 16:19:37 +02:00
for sem in etud["sems"]: # le plus récent d'abord
if sem["formsemestre_id"] in formsemestre_ids_parcours:
etuds_infos[etudid] = {
"recent_formsemestre_id": sem["formsemestre_id"],
"etud": etud,
}
break
# sanity check
assert etudid in etuds_infos
# Construit la table (semblable à pvjury_table)
rows, titles, columns_ids = _build_results_list(context, dpv_by_sem, etuds_infos)
tab = GenTable(
rows=rows,
titles=titles,
columns_ids=columns_ids,
2021-02-04 20:02:44 +01:00
filename=scu.make_filename("scodoc-results-%s-%s" % (start_date, end_date)),
2020-09-26 16:19:37 +02:00
caption="Résultats ScoDoc de %s à %s" % (start_date, end_date),
2021-02-04 20:02:44 +01:00
origin="Généré par %s le " % VERSION.SCONAME + scu.timedate_human_repr() + "",
2020-09-26 16:19:37 +02:00
html_class="table_leftalign",
html_sortable=True,
2021-06-13 19:12:20 +02:00
preferences=sco_preferences.SemPreferences(
context,
),
2020-09-26 16:19:37 +02:00
)
return tab, semlist
def _build_results_list(context, dpv_by_sem, etuds_infos):
"""Construit la table (semblable à pvjury_table)
Returns:
rows, titles, columns_ids
"""
titles = {
"anneescolaire": "Année",
"periode": "Période",
"sid": "Semestre",
"etudid": "etudid",
"code_nip": "NIP",
"nom": "Nom",
"prenom": "Prénom",
"civilite_str": "Civ.",
2020-09-26 16:19:37 +02:00
"nom_usuel": "Nom usuel",
"bac": "Bac",
"parcours": "Parcours",
"devenir": "Devenir",
}
columns_ids = [
"anneescolaire",
"periode",
"sid",
"code_nip",
"civilite_str",
2020-09-26 16:19:37 +02:00
"nom",
# 'nom_usuel', # inutile ?
"prenom",
"bac",
"parcours",
]
# Recherche la liste des indices de semestres à considérer
all_idx = set()
for etudid in etuds_infos:
# la décision de jury à considérer pour cet étudiant:
e = dpv_by_sem[etuds_infos[etudid]["recent_formsemestre_id"]]["decisions_dict"][
etudid
]
all_idx |= set(e["parcours_decisions"].keys())
sem_ids = sorted(all_idx)
# ajoute les titres des colonnes résultats de semestres
for i in sem_ids:
if i != NO_SEMESTRE_ID:
titles[i] = "S%d" % i
else:
titles[i] = "S" # pas très parlant ?
columns_ids += [i]
columns_ids += ["devenir"]
# Construit la liste:
rows = []
for etudid in etuds_infos:
etud = etuds_infos[etudid]["etud"]
bac = sco_bac.Baccalaureat(etud["bac"], etud["specialite"])
dpv = dpv_by_sem[etuds_infos[etudid]["recent_formsemestre_id"]]
dec = dpv["decisions_dict"][etudid]
l = {
"etudid": etudid,
"code_nip": etud["code_nip"],
"nom": etud["nom"],
"nom_usuel": etud["nom_usuel"],
"prenom": etud["prenom"],
"civilite_str": etud["civilite_str"],
2021-06-15 12:34:33 +02:00
"_nom_target": "%s/ficheEtud?etudid=%s" % (scu.ScoURL(), etudid),
2020-09-26 16:19:37 +02:00
"_nom_td_attrs": 'id="%s" class="etudinfo"' % etudid,
"bac": bac.abbrev(),
"parcours": dec["parcours"],
}
for sem in reversed(etud["sems"]):
r = l.copy()
dpv = dpv_by_sem.get(sem["formsemestre_id"], None)
if dpv: # semestre à inclure dans ce rapport
dec = dpv["decisions_dict"].get(etudid, None)
if dec and dec["decision_sem"]:
code = dec["decision_sem"]["code"]
if dec["validation_parcours"]:
r["devenir"] = "Diplôme obtenu"
else:
r["devenir"] = dec["autorisations_descr"]
else:
code = "-"
r[sem["semestre_id"]] = code
r["periode"] = sem["periode"]
2021-02-04 20:02:44 +01:00
r["anneescolaire"] = scu.annee_scolaire_debut(
2020-09-26 16:19:37 +02:00
int(sem["annee_debut"]), sem["mois_debut_ord"]
)
r["sid"] = "{} {} {}".format(
2021-06-15 12:34:33 +02:00
sem["sem_id_txt"], scu.get_dept_id(), sem["modalite"]
2020-09-26 16:19:37 +02:00
)
rows.append(r)
return rows, titles, columns_ids
def get_set_formsemestre_id_dates(context, start_date, end_date):
2021-01-01 18:40:47 +01:00
"""Ensemble des formsemestre_id entre ces dates"""
2021-02-03 22:00:41 +01:00
s = ndb.SimpleDictFetch(
2020-09-26 16:19:37 +02:00
context,
"SELECT formsemestre_id FROM notes_formsemestre WHERE date_debut >= %(start_date)s AND date_fin <= %(end_date)s",
{"start_date": start_date, "end_date": end_date},
)
return {x["formsemestre_id"] for x in s}
def scodoc_table_results(
context, start_date="", end_date="", types_parcours=[], format="html", REQUEST=None
):
"""Page affichant la table des résultats
Les dates sont en dd/mm/yyyy (datepicker javascript)
2021-01-01 18:40:47 +01:00
types_parcours est la liste des types de parcours à afficher
2020-09-26 16:19:37 +02:00
(liste de chaines, eg ['100', '210'] )
"""
log("scodoc_table_results: start_date=%s" % (start_date,)) # XXX
if not types_parcours:
types_parcours = []
if not isinstance(types_parcours, ListType):
types_parcours = [types_parcours]
if start_date:
2021-02-03 22:00:41 +01:00
start_date_iso = ndb.DateDMYtoISO(start_date)
2020-09-26 16:19:37 +02:00
if end_date:
2021-02-03 22:00:41 +01:00
end_date_iso = ndb.DateDMYtoISO(end_date)
2020-09-26 16:19:37 +02:00
types_parcours = [int(x) for x in types_parcours if x]
if start_date and end_date:
tab, semlist = _build_results_table(
context, start_date_iso, end_date_iso, types_parcours
)
2021-05-11 11:48:32 +02:00
tab.base_url = "%s?start_date=%s&end_date=%s&types_parcours=%s" % (
2020-09-26 16:19:37 +02:00
REQUEST.URL0,
start_date,
end_date,
2021-05-11 11:48:32 +02:00
"&types_parcours=".join([str(x) for x in types_parcours]),
2020-09-26 16:19:37 +02:00
)
if format != "html":
return tab.make_page(
context, format=format, with_html_headers=False, REQUEST=REQUEST
)
tab_html = tab.html()
nb_rows = tab.get_nb_rows()
else:
tab = None
nb_rows = 0
tab_html = ""
semlist = []
# affiche la liste des semestres utilisés:
info_sems = ["<ul>"]
menu_options = []
type_parcours_set = set()
for sem in sorted(semlist, key=lambda x: x["dateord"]):
if sem["parcours"].TYPE_PARCOURS in types_parcours:
selected = "selected"
else:
selected = ""
if sem["parcours"].TYPE_PARCOURS not in type_parcours_set:
type_parcours_set.add(sem["parcours"].TYPE_PARCOURS)
menu_options.append(
'<option value="%s" %s>%s</option>'
% (sem["parcours"].TYPE_PARCOURS, selected, sem["parcours"].__doc__)
)
if sem["parcours"].TYPE_PARCOURS in types_parcours:
info_sems.append(
'<li><a class="stdlink" href="formsemestre_status?formsemestre_id=%(formsemestre_id)s">%(titremois)s</a></li>'
% sem
)
info_sems.append("</ul>")
H = [
2021-06-13 19:12:20 +02:00
html_sco_header.sco_header(
context,
2020-09-26 16:19:37 +02:00
REQUEST,
page_title="Export résultats",
init_qtip=True,
javascripts=html_sco_header.BOOTSTRAP_MULTISELECT_JS
+ ["js/etud_info.js", "js/export_results.js"],
cssstyles=html_sco_header.BOOTSTRAP_MULTISELECT_CSS,
),
# XXX
"""
<h2>Table des résultats de tous les semestres</h2>
<p class="warning">Développement en cours / attention !</p>
""",
_DATE_FORM.format(
start_date=start_date,
end_date=end_date,
menu_options="\n".join(menu_options),
),
"""<div>
<h4>%d étudiants dans les %d semestres de cette période</h4>
</div>
"""
% (nb_rows, len(semlist)),
tab_html,
"""<div><h4>Semestres pris en compte:</h4>
""",
"\n".join(info_sems),
"""</div>""",
2021-06-13 18:29:53 +02:00
html_sco_header.sco_footer(context, REQUEST),
2020-09-26 16:19:37 +02:00
]
return "\n".join(H)
# Formulaire pour saisie dates et sélection parcours
_DATE_FORM = """
<form method="get">
<div><b>Choisir les dates :</b>
<div>Début: <input type="text" name="start_date" size="10" value="{start_date}" class="datepicker"/> </div>
<div>Fin: <input type="text" name="end_date" size="10" value="{end_date}" class="datepicker"/></div>
<input type="submit" name="" value=" OK " width=100/>
</div>
<div>
<b>Types de parcours :</b>
<select name="types_parcours" id="parcours_sel" class="multiselect" multiple="multiple">
{menu_options}
</select>
<input type="submit" name="" value=" charger " width=100/>
</form>
"""
# ------- debug
"""
# /opt/scodoc/bin/zopectl debug
from debug import *
from app.scodoc.sco_export_results import *
2020-09-26 16:19:37 +02:00
context = go_dept(app, 'RT').Notes
etudid = 'EID27764'
etud = sco_etud.get_etud_info( etudid=etudid, filled=True)[0]
2020-09-26 16:19:37 +02:00
start_date='2015-08-15'
end_date='2017-08-31'
formsemestre_ids = get_set_formsemestre_id_dates(context, start_date, end_date)
dpv_by_sem = {}
for formsemestre_id in formsemestre_ids:
dpv_by_sem[formsemestre_id] = sco_pvjury.dict_pvjury(context, formsemestre_id, with_parcours_decisions=True)
semlist = [ dpv['formsemestre'] for dpv in dpv_by_sem.values() ]
"""