From a2077e640ac99c3e2e1118472dcb5bdbc4d34aa7 Mon Sep 17 00:00:00 2001 From: Antoine Van Elstraete Date: Wed, 11 Mar 2026 20:31:16 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20count=5Fday=5Ftypes=20=E2=80=94=20compt?= =?UTF-8?q?e=20les=20jours=20par=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/business/time_calc.py | 8 ++++++++ tests/test_time_calc.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/app/business/time_calc.py b/app/business/time_calc.py index 63c4260..10a5834 100644 --- a/app/business/time_calc.py +++ b/app/business/time_calc.py @@ -23,3 +23,11 @@ def work_minutes_reference(day_type: str) -> int: def week_balance_minutes(actual_minutes: int, reference_minutes: int) -> int: return actual_minutes - reference_minutes + + +def count_day_types(entries: list) -> dict[str, int]: + """Retourne un dict {day_type: count} pour une liste d'entrées, sans les zéros.""" + counts: dict[str, int] = {} + for entry in entries: + counts[entry.day_type] = counts.get(entry.day_type, 0) + 1 + return counts diff --git a/tests/test_time_calc.py b/tests/test_time_calc.py index 87f24c6..872df05 100644 --- a/tests/test_time_calc.py +++ b/tests/test_time_calc.py @@ -40,3 +40,32 @@ def test_week_balance_positive(): def test_week_balance_negative(): assert week_balance_minutes(2200, 2325) == -125 + + +from app.business.time_calc import count_day_types +from app.models import WorkEntry +from datetime import date + + +def test_count_day_types_basic(): + entries = [ + WorkEntry(date=date(2025, 1, 2), day_type="WORK"), + WorkEntry(date=date(2025, 1, 3), day_type="WORK"), + WorkEntry(date=date(2025, 1, 6), day_type="TT"), + WorkEntry(date=date(2025, 1, 7), day_type="GARDE"), + ] + result = count_day_types(entries) + assert result == {"WORK": 2, "TT": 1, "GARDE": 1} + + +def test_count_day_types_empty(): + assert count_day_types([]) == {} + + +def test_count_day_types_single_type(): + entries = [ + WorkEntry(date=date(2025, 2, 1), day_type="RTT"), + WorkEntry(date=date(2025, 2, 2), day_type="RTT"), + ] + result = count_day_types(entries) + assert result == {"RTT": 2}