You've already forked etude_lego_jurassic_world
Complète l’étape 26 avec l’évolution minifigs/set
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from lib.rebrickable.minifig_parts_correlation import build_correlation_rows
|
||||
from lib.rebrickable.minifig_parts_correlation import build_correlation_rows, build_minifigs_per_year
|
||||
|
||||
|
||||
def write_csv(path: Path, content: str) -> None:
|
||||
@@ -68,3 +68,56 @@ def test_build_correlation_rows_merges_filtered_and_catalog(tmp_path: Path) -> N
|
||||
{"scope": "catalog", "set_num": "124-1", "num_parts": "150", "minifig_count": "1"},
|
||||
{"scope": "catalog", "set_num": "200-1", "num_parts": "100", "minifig_count": "3"},
|
||||
]
|
||||
|
||||
|
||||
def test_build_minifigs_per_year_computes_averages(tmp_path: Path) -> None:
|
||||
"""Calcule les moyennes annuelles minifigs/set pour filtrés et catalogue."""
|
||||
filtered_counts_path = tmp_path / "minifig_counts_by_set.csv"
|
||||
write_csv(
|
||||
filtered_counts_path,
|
||||
"set_num,set_id,name,year,minifig_count\n"
|
||||
"123-1,123,Set A,2020,2\n"
|
||||
"124-1,124,Set B,2020,1\n"
|
||||
"125-1,125,Set C,2021,3\n",
|
||||
)
|
||||
all_sets_path = tmp_path / "sets.csv"
|
||||
write_csv(
|
||||
all_sets_path,
|
||||
"set_num,name,year,theme_id,num_parts\n"
|
||||
"123-1,Set A,2020,1,300\n"
|
||||
"124-1,Set B,2020,1,150\n"
|
||||
"125-1,Set C,2021,1,100\n"
|
||||
"200-1,Set D,2020,1,50\n",
|
||||
)
|
||||
inventories_path = tmp_path / "inventories.csv"
|
||||
write_csv(
|
||||
inventories_path,
|
||||
"id,version,set_num\n"
|
||||
"10,1,123-1\n"
|
||||
"20,1,124-1\n"
|
||||
"30,1,125-1\n"
|
||||
"40,1,200-1\n",
|
||||
)
|
||||
inventory_minifigs_path = tmp_path / "inventory_minifigs.csv"
|
||||
write_csv(
|
||||
inventory_minifigs_path,
|
||||
"inventory_id,fig_num,quantity\n"
|
||||
"10,fig-a,2\n"
|
||||
"20,fig-b,1\n"
|
||||
"30,fig-c,3\n"
|
||||
"40,fig-d,4\n",
|
||||
)
|
||||
|
||||
rows = build_minifigs_per_year(
|
||||
filtered_counts_path,
|
||||
all_sets_path,
|
||||
inventories_path,
|
||||
inventory_minifigs_path,
|
||||
)
|
||||
|
||||
assert rows == [
|
||||
{"scope": "filtered", "year": "2020", "average_minifigs_per_set": "1.500", "set_count": "2"},
|
||||
{"scope": "filtered", "year": "2021", "average_minifigs_per_set": "3.000", "set_count": "1"},
|
||||
{"scope": "catalog", "year": "2020", "average_minifigs_per_set": "2.333", "set_count": "3"},
|
||||
{"scope": "catalog", "year": "2021", "average_minifigs_per_set": "3.000", "set_count": "1"},
|
||||
]
|
||||
|
||||
27
tests/test_minifig_parts_timeline_plot.py
Normal file
27
tests/test_minifig_parts_timeline_plot.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""Tests du graphique d'évolution minifigs/set."""
|
||||
|
||||
import matplotlib
|
||||
from pathlib import Path
|
||||
|
||||
from lib.plots.minifig_parts_timeline import plot_minifigs_per_set_timeline
|
||||
|
||||
|
||||
matplotlib.use("Agg")
|
||||
|
||||
|
||||
def test_plot_minifigs_per_set_timeline(tmp_path: Path) -> None:
|
||||
"""Génère la courbe minifigs/set."""
|
||||
timeline_path = tmp_path / "minifigs_per_set_timeline.csv"
|
||||
destination = tmp_path / "figures" / "step26" / "minifigs_per_set_timeline.png"
|
||||
timeline_path.write_text(
|
||||
"scope,year,average_minifigs_per_set,set_count\n"
|
||||
"filtered,2020,1.500,2\n"
|
||||
"filtered,2021,2.000,1\n"
|
||||
"catalog,2020,1.000,3\n"
|
||||
"catalog,2021,2.500,2\n"
|
||||
)
|
||||
|
||||
plot_minifigs_per_set_timeline(timeline_path, destination)
|
||||
|
||||
assert destination.exists()
|
||||
assert destination.stat().st_size > 0
|
||||
Reference in New Issue
Block a user