affine affichege des bonus/malus

This commit is contained in:
Jean-Marie Place 2023-07-20 18:06:12 +02:00
parent fb5cdc2624
commit 2f05e081ee
2 changed files with 111 additions and 14 deletions

View File

@ -212,6 +212,34 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
else: else:
self.ue_std_rows(rows, ue, title_bg) self.ue_std_rows(rows, ue, title_bg)
@staticmethod
def affichage_bonus_malus(ue: dict) -> list:
fields_bmr = []
# lecture des bonus sport culture et malus (ou bonus autre) (0 si valeur non numérique)
try:
bonus_sc = float(ue.get("bonus", 0.0)) or 0
except ValueError:
bonus_sc = 0
try:
malus = float(ue.get("malus", 0.0)) or 0
except ValueError:
malus = 0
# Calcul de l affichage
if malus < 0:
if bonus_sc > 0:
fields_bmr.append(f"Bonus sport/culture: {bonus_sc}")
fields_bmr.append(f"Bonus autres: {-malus}")
else:
fields_bmr.append(f"Bonus: {-malus}")
elif malus > 0:
if bonus_sc > 0:
fields_bmr.append(f"Bonus: {bonus_sc}")
fields_bmr.append(f"Malus: {malus}")
else:
if bonus_sc > 0:
fields_bmr.append(f"Bonus: {bonus_sc}")
return fields_bmr
def ue_std_rows(self, rows: list, ue: dict, title_bg: tuple): def ue_std_rows(self, rows: list, ue: dict, title_bg: tuple):
"Lignes décrivant une UE standard dans la table de synthèse" "Lignes décrivant une UE standard dans la table de synthèse"
# 2eme ligne titre UE (bonus/malus/ects) # 2eme ligne titre UE (bonus/malus/ects)
@ -220,20 +248,7 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
else: else:
ects_txt = "" ects_txt = ""
# case Bonus/Malus/Rang "bmr" # case Bonus/Malus/Rang "bmr"
fields_bmr = [] fields_bmr = BulletinGeneratorStandardBUT.affichage_bonus_malus(ue)
try:
value = float(ue.get("bonus", 0.0))
if value != 0:
fields_bmr.append(f"Bonus: {ue['bonus']}")
except ValueError:
pass
try:
value = float(ue.get("malus", 0.0))
if value != 0:
fields_bmr.append(f"Malus: {ue['malus']}")
except ValueError:
pass
moy_ue = ue.get("moyenne", "-") moy_ue = ue.get("moyenne", "-")
if isinstance(moy_ue, dict): # UE non capitalisées if isinstance(moy_ue, dict): # UE non capitalisées
if self.preferences["bul_show_ue_rangs"]: if self.preferences["bul_show_ue_rangs"]:

View File

@ -0,0 +1,82 @@
"""Tests unitaires : bulletins de notes
Utiliser comme:
pytest tests/unit/test_bulletin_bonus.py
"""
from app.but.bulletin_but_pdf import BulletinGeneratorStandardBUT
def test_nobonus():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus({}) == []
def test_bonus_sport_nul():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus({"bonus": 0}) == []
def test_malus_nul():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus({"malus": 0}) == []
def test_bonus_et_malus_nuls():
assert (
BulletinGeneratorStandardBUT.affichage_bonus_malus({"bonus": 0, "malus": 0})
== []
)
def test_vrai_malus():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus({"malus": 0.1}) == [
"Malus: 0.1"
]
def test_bonus_sport_et_vrai_malus():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus(
{"malus": 0.12, "bonus": 0.23}
) == [
"Bonus: 0.23",
"Malus: 0.12",
]
def test_bonus_sport_seul():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus({"bonus": 0.5}) == [
"Bonus: 0.5"
]
def test_bonus_sport_nul_et_vrai_malus():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus(
{"bonus": 0, "malus": 0.5}
) == ["Malus: 0.5"]
def test_bonus_sport_et_malus_nul():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus(
{"bonus": 0.5, "malus": 0}
) == [
"Bonus: 0.5",
]
def test_faux_malus():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus({"malus": -0.6}) == [
"Bonus: 0.6"
]
def test_sport_nul_faux_malus():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus(
{"bonus": 0, "malus": -0.6}
) == ["Bonus: 0.6"]
def test_bonus_sport_et_faux_malus():
assert BulletinGeneratorStandardBUT.affichage_bonus_malus(
{"bonus": 0.3, "malus": -0.6}
) == [
"Bonus sport/culture: 0.3",
"Bonus autres: 0.6",
]