Merge pull request 'affine affichege des bonus/malus' (#674) from jmplace/ScoDoc-Lille:bonus_malus into sco96

Reviewed-on: https://scodoc.org/git/ScoDoc/ScoDoc/pulls/674
This commit is contained in:
Emmanuel Viennet 2023-07-21 09:26:50 +02:00
commit 0d0c9da6b3
2 changed files with 111 additions and 14 deletions

View File

@ -212,6 +212,34 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
else:
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):
"Lignes décrivant une UE standard dans la table de synthèse"
# 2eme ligne titre UE (bonus/malus/ects)
@ -220,20 +248,7 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
else:
ects_txt = ""
# case Bonus/Malus/Rang "bmr"
fields_bmr = []
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
fields_bmr = BulletinGeneratorStandardBUT.affichage_bonus_malus(ue)
moy_ue = ue.get("moyenne", "-")
if isinstance(moy_ue, dict): # UE non capitalisées
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",
]