1

Ajoute la heatmap annuelle des personnages

This commit is contained in:
2025-12-02 01:54:49 +01:00
parent 3e1cf940e3
commit dbfa46a99f
7 changed files with 194 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
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
def test_aggregate_by_character_counts_unique_figs() -> None:
@@ -35,3 +36,25 @@ def test_write_character_counts_outputs_csv(tmp_path: Path) -> None:
write_character_counts(destination, rows)
assert destination.read_text() == "known_character,minifig_count\nA,2\nB,1\n"
def test_aggregate_presence_by_year_excludes_figurants(tmp_path: Path) -> None:
"""Calcule la présence annuelle en excluant les figurants."""
sets_path = tmp_path / "sets_enriched.csv"
sets_path.write_text(
"set_num,year\n"
"123-1,2020\n"
"124-1,2021\n"
)
minifigs_rows = [
{"set_num": "123-1", "known_character": "Owen Grady", "fig_num": "fig-owen", "part_num": "head-a"},
{"set_num": "124-1", "known_character": "Figurant", "fig_num": "fig-guard", "part_num": "head-b"},
]
sets_years = load_sets_enriched(sets_path)
presence = aggregate_presence_by_year(minifigs_rows, sets_years, excluded_characters=["Figurant"])
assert presence == [
{"known_character": "Owen Grady", "year": "2020", "present": "1"},
{"known_character": "Owen Grady", "year": "2021", "present": "0"},
]

View File

@@ -0,0 +1,26 @@
"""Tests du graphique de présence annuelle des personnages."""
import matplotlib
from pathlib import Path
from lib.plots.minifig_characters import plot_character_year_presence
matplotlib.use("Agg")
def test_plot_character_year_presence(tmp_path: Path) -> None:
"""Génère la heatmap binaire personnage × année."""
presence_path = tmp_path / "minifig_characters_year_presence.csv"
destination = tmp_path / "figures" / "step22" / "minifig_characters_timeline.png"
presence_path.write_text(
"known_character,year,present\n"
"Owen Grady,2020,1\n"
"Owen Grady,2021,0\n"
"Figurant,2020,1\n"
)
plot_character_year_presence(presence_path, destination)
assert destination.exists()
assert destination.stat().st_size > 0