1

Compare la répartition des genres minifigs vs personnages

This commit is contained in:
2025-12-03 22:55:05 +01:00
parent e5dbf7bbaa
commit 996e4cb9ff
8 changed files with 142 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ from pathlib import Path
from lib.rebrickable.minifig_characters import (
aggregate_by_character,
aggregate_by_gender,
aggregate_characters_by_gender,
aggregate_new_character_sets,
aggregate_new_characters_by_year,
aggregate_variations_and_totals,
@@ -12,6 +13,7 @@ from lib.rebrickable.minifig_characters import (
aggregate_presence_by_year,
load_sets_enriched,
write_character_counts,
write_character_gender_counts,
write_new_character_sets_csv,
write_new_character_sets_markdown,
write_new_characters_by_year,
@@ -143,6 +145,23 @@ def test_aggregate_by_gender_counts_unique_figs() -> None:
]
def test_aggregate_characters_by_gender_unique_characters() -> None:
"""Compter les personnages distincts par genre (ignorer unknown)."""
aggregates = aggregate_characters_by_gender(
[
{"known_character": "A", "gender": "male"},
{"known_character": "A", "gender": "male"},
{"known_character": "B", "gender": "female"},
{"known_character": "C", "gender": "unknown"},
]
)
assert aggregates == [
{"gender": "female", "character_count": "1"},
{"gender": "male", "character_count": "1"},
]
def test_aggregate_new_characters_by_year_limits_range(tmp_path: Path) -> None:
"""Compter les nouveaux personnages par année en respectant la plage."""
sets_path = tmp_path / "sets_enriched.csv"
@@ -268,6 +287,19 @@ def test_write_character_variations_totals_outputs_csv(tmp_path: Path) -> None:
assert destination.read_text() == "known_character,gender,variation_count,total_minifigs\nA,male,2,3\nB,female,1,1\n"
def test_write_character_gender_counts_outputs_csv(tmp_path: Path) -> None:
"""Écrit le CSV des comptes de personnages par genre."""
destination = tmp_path / "character_gender.csv"
rows = [
{"gender": "female", "character_count": "2"},
{"gender": "male", "character_count": "3"},
]
write_character_gender_counts(destination, rows)
assert destination.read_text() == "gender,character_count\nfemale,2\nmale,3\n"
def test_write_new_characters_by_year_outputs_csv(tmp_path: Path) -> None:
"""Écrit le CSV des nouveaux personnages par année."""
destination = tmp_path / "new_characters.csv"

View File

@@ -4,6 +4,7 @@ import matplotlib
from pathlib import Path
from lib.plots.minifig_gender_share import plot_minifig_gender_share
from lib.plots.minifig_gender_share import plot_character_gender_share
matplotlib.use("Agg")
@@ -24,3 +25,19 @@ def test_plot_minifig_gender_share(tmp_path: Path) -> None:
assert destination.exists()
assert destination.stat().st_size > 0
def test_plot_character_gender_share(tmp_path: Path) -> None:
"""Génère le graphique de répartition par genre au niveau personnages."""
counts_path = tmp_path / "character_gender.csv"
destination = tmp_path / "figures" / "step25" / "minifig_character_gender_share.png"
counts_path.write_text(
"gender,character_count\n"
"male,3\n"
"female,2\n"
)
plot_character_gender_share(counts_path, destination)
assert destination.exists()
assert destination.stat().st_size > 0