From 05372eef6884765f9ee1760dde8db3fe37be745c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Thu, 16 Mar 2023 11:00:07 +0100 Subject: [PATCH] Repartition now logs groups' assigned toughness Closes #5 --- repartir_taches/entrypoint.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/repartir_taches/entrypoint.py b/repartir_taches/entrypoint.py index ee405e0..7224032 100644 --- a/repartir_taches/entrypoint.py +++ b/repartir_taches/entrypoint.py @@ -2,6 +2,7 @@ import argparse import typing as t import random from pathlib import Path +from collections import defaultdict import logging import jinja2 as j2 @@ -179,6 +180,32 @@ def export_latex(config: Config, groupes: list[list[str]]) -> str: return template.render(**env) +def log_assignment_toughness(config: Config): + """Prints each group's assigned tasks toughness""" + + grp_tough: dict[int, int] = defaultdict(int) + + def explore_tasks(task: Task | Category): + if isinstance(task, Task): + assert task.assigned is not None + for grp in task.assigned: + grp_tough[grp] += task.tough + else: + for child in task.tasks: + explore_tasks(child) + + explore_tasks(config.taches) + + grp_ids = list(grp_tough.keys()) + grp_ids.sort() + tough_lines = [] + for grp_id in grp_ids: + tough_lines.append(f"{grp_id+1:2d} : {grp_tough[grp_id]:3d}") + out_str = "Répartition des pénibilités :\n" + "\n".join(tough_lines) + + logger.info(out_str) + + def repartition(config: Config) -> list[Group]: """Crée des groupes et assigne des tâches""" groupes: list[Group] = constituer_groupes(config.choristes) @@ -255,6 +282,8 @@ def main() -> None: logger.critical("Échec de répartition des tâches.") raise exn from exn + log_assignment_toughness(config) + if args.to_intermed: intermed = intermed_file.IntermedFile.from_assignment(config, groupes) intermed.sanity_check()