1

Ajoute le graphique variations vs total par personnage

This commit is contained in:
2025-12-03 21:50:28 +01:00
parent 3c20b74b1c
commit f9854a6949
7 changed files with 244 additions and 1 deletions

View File

@@ -5,10 +5,12 @@ from pathlib import Path
from lib.rebrickable.minifig_characters import (
aggregate_by_character,
aggregate_by_gender,
aggregate_variations_and_totals,
aggregate_character_spans,
aggregate_presence_by_year,
load_sets_enriched,
write_character_counts,
write_character_variations_totals,
write_gender_counts,
)
@@ -68,6 +70,55 @@ def test_aggregate_by_character_counts_unique_figs() -> None:
]
def test_aggregate_variations_and_totals_excludes_figurants() -> None:
"""Compter le total et les variations en excluant les figurants."""
aggregates = aggregate_variations_and_totals(
[
{
"set_num": "123-1",
"part_num": "head-a",
"known_character": "Owen Grady",
"fig_num": "fig-owen-1",
"gender": "male",
},
{
"set_num": "124-1",
"part_num": "head-b",
"known_character": "Owen Grady",
"fig_num": "fig-owen-1",
"gender": "male",
},
{
"set_num": "125-1",
"part_num": "head-c",
"known_character": "Owen Grady",
"fig_num": "fig-owen-2",
"gender": "male",
},
{
"set_num": "126-1",
"part_num": "head-d",
"known_character": "Ellie Sattler",
"fig_num": "fig-ellie-1",
"gender": "female",
},
{
"set_num": "127-1",
"part_num": "head-e",
"known_character": "Figurant",
"fig_num": "fig-guard-1",
"gender": "unknown",
},
],
excluded_characters=["Figurant"],
)
assert aggregates == [
{"known_character": "Owen Grady", "gender": "male", "variation_count": 2, "total_minifigs": 3},
{"known_character": "Ellie Sattler", "gender": "female", "variation_count": 1, "total_minifigs": 1},
]
def test_aggregate_by_gender_counts_unique_figs() -> None:
"""Compter les minifigs distinctes par genre."""
aggregates = aggregate_by_gender(
@@ -112,6 +163,19 @@ def test_write_gender_counts_outputs_csv(tmp_path: Path) -> None:
assert destination.read_text() == "gender,minifig_count\nmale,2\nfemale,1\n"
def test_write_character_variations_totals_outputs_csv(tmp_path: Path) -> None:
"""Écrit le CSV comparatif variations/total."""
destination = tmp_path / "variations.csv"
rows = [
{"known_character": "A", "gender": "male", "variation_count": 2, "total_minifigs": 3},
{"known_character": "B", "gender": "female", "variation_count": 1, "total_minifigs": 1},
]
write_character_variations_totals(destination, rows)
assert destination.read_text() == "known_character,gender,variation_count,total_minifigs\nA,male,2,3\nB,female,1,1\n"
def test_aggregate_presence_by_year_excludes_figurants(tmp_path: Path) -> None:
"""Calcule le total annuel en excluant les figurants."""
sets_path = tmp_path / "sets_enriched.csv"