1

Ajoute le diagramme de longévité des personnages

This commit is contained in:
2025-12-02 11:01:01 +01:00
parent 4d37a654f2
commit f019deeef5
6 changed files with 210 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
"""Tests du diagramme de longévité des personnages."""
import matplotlib
from pathlib import Path
from lib.plots.minifig_character_spans import plot_character_spans
matplotlib.use("Agg")
def test_plot_character_spans(tmp_path: Path) -> None:
"""Génère le graphique de span des personnages."""
spans_path = tmp_path / "minifig_character_spans.csv"
destination = tmp_path / "figures" / "step23" / "minifig_character_spans.png"
spans_path.write_text(
"known_character,start_year,end_year,total_minifigs\n"
"Owen Grady,2020,2022,3\n"
"Figurant,2019,2020,2\n"
)
plot_character_spans(spans_path, destination)
assert destination.exists()
assert destination.stat().st_size > 0

View File

@@ -2,8 +2,13 @@
from pathlib import Path
from lib.rebrickable.minifig_characters import aggregate_by_character, write_character_counts
from lib.rebrickable.minifig_characters import aggregate_presence_by_year, write_presence_by_year, load_sets_enriched
from lib.rebrickable.minifig_characters import (
aggregate_by_character,
aggregate_character_spans,
aggregate_presence_by_year,
load_sets_enriched,
write_character_counts,
)
def test_aggregate_by_character_counts_unique_figs() -> None:
@@ -58,3 +63,26 @@ def test_aggregate_presence_by_year_excludes_figurants(tmp_path: Path) -> None:
{"known_character": "Owen Grady", "year": "2020", "minifig_count": "1"},
{"known_character": "Owen Grady", "year": "2021", "minifig_count": "0"},
]
def test_aggregate_character_spans_excludes_figurants(tmp_path: Path) -> None:
"""Calcule les bornes min/max par personnage."""
sets_path = tmp_path / "sets_enriched.csv"
sets_path.write_text(
"set_num,year\n"
"123-1,2020\n"
"124-1,2021\n"
"125-1,2022\n"
)
sets_years = load_sets_enriched(sets_path)
minifigs_rows = [
{"set_num": "123-1", "known_character": "Owen Grady", "fig_num": "fig-owen", "part_num": "head-a"},
{"set_num": "124-1", "known_character": "Owen Grady", "fig_num": "fig-owen", "part_num": "head-a"},
{"set_num": "125-1", "known_character": "Figurant", "fig_num": "fig-guard", "part_num": "head-b"},
]
spans = aggregate_character_spans(minifigs_rows, sets_years, excluded_characters=["Figurant"])
assert spans == [
{"known_character": "Owen Grady", "start_year": "2020", "end_year": "2021", "total_minifigs": "2"},
]