ScoDoc/app/scodoc/sco_compute_moy.py

103 lines
3.7 KiB
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
2023-01-02 13:16:27 +01:00
# Copyright (c) 1999 - 2023 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
#
##############################################################################
2023-02-20 21:04:29 +01:00
"""Calcul des moyennes de module (restes de fonctions ScoDoc 7)
2020-09-26 16:19:37 +02:00
"""
2023-02-20 21:04:29 +01:00
from app.models import ModuleImpl
import app.scodoc.notesdb as ndb
2020-09-26 16:19:37 +02:00
2023-02-20 21:04:29 +01:00
def moduleimpl_has_expression(modimpl: ModuleImpl):
"""True if we should use a user-defined expression
En ScoDoc 9, utilisé pour afficher un avertissement, l'expression elle même
n'est plus supportée.
"""
return (
modimpl.computation_expr
and modimpl.computation_expr.strip()
and modimpl.computation_expr.strip()[0] != "#"
)
2020-09-26 16:19:37 +02:00
def formsemestre_expressions_use_abscounts(formsemestre_id):
2020-09-26 16:19:37 +02:00
"""True si les notes de ce semestre dépendent des compteurs d'absences.
2021-10-16 19:20:36 +02:00
Cela n'est normalement pas le cas, sauf si des formules utilisateur
utilisent ces compteurs.
2020-09-26 16:19:37 +02:00
"""
# check presence of 'nbabs' in expressions
ab = "nb_abs" # chaine recherchée
2021-06-15 13:59:56 +02:00
cnx = ndb.GetDBConnexion()
2020-09-26 16:19:37 +02:00
# 1- moyennes d'UE:
elist = formsemestre_ue_computation_expr_list(
cnx, {"formsemestre_id": formsemestre_id}
)
for e in elist:
expr = e["computation_expr"].strip()
if expr and expr[0] != "#" and ab in expr:
return True
# 2- moyennes de modules
2023-02-20 21:04:29 +01:00
# #sco9 il n'y a plus d'expressions
# for mod in sco_moduleimpl.moduleimpl_list(formsemestre_id=formsemestre_id):
# if moduleimpl_has_expression(mod) and ab in mod["computation_expr"]:
# return True
2020-09-26 16:19:37 +02:00
return False
_formsemestre_ue_computation_exprEditor = ndb.EditableTable(
2020-09-26 16:19:37 +02:00
"notes_formsemestre_ue_computation_expr",
"notes_formsemestre_ue_computation_expr_id",
(
"notes_formsemestre_ue_computation_expr_id",
"formsemestre_id",
"ue_id",
"computation_expr",
),
html_quote=False, # does nt automatically quote
)
formsemestre_ue_computation_expr_create = _formsemestre_ue_computation_exprEditor.create
formsemestre_ue_computation_expr_delete = _formsemestre_ue_computation_exprEditor.delete
formsemestre_ue_computation_expr_list = _formsemestre_ue_computation_exprEditor.list
formsemestre_ue_computation_expr_edit = _formsemestre_ue_computation_exprEditor.edit
def get_ue_expression(formsemestre_id, ue_id, html_quote=False):
"""Returns UE expression (formula), or None if no expression has been defined"""
cnx = ndb.GetDBConnexion()
2020-09-26 16:19:37 +02:00
el = formsemestre_ue_computation_expr_list(
cnx, {"formsemestre_id": formsemestre_id, "ue_id": ue_id}
)
if not el:
return None
else:
expr = el[0]["computation_expr"].strip()
if expr and expr[0] != "#":
if html_quote:
expr = ndb.quote_html(expr)
2020-09-26 16:19:37 +02:00
return expr
else:
return None