You've already forked etude_lego_jurassic_world
Ajoute l’étape 28 des palettes perceptuelles
This commit is contained in:
84
tests/test_set_color_swatches_perceptual.py
Normal file
84
tests/test_set_color_swatches_perceptual.py
Normal file
@@ -0,0 +1,84 @@
|
||||
"""Tests des palettes perceptuelles par set."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from lib.rebrickable.set_color_swatches_perceptual import build_perceptual_swatches
|
||||
|
||||
|
||||
def write_csv(path: Path, content: str) -> None:
|
||||
"""Écrit un CSV brut."""
|
||||
path.write_text(content)
|
||||
|
||||
|
||||
def test_build_perceptual_swatches_diversifies_buckets(tmp_path: Path) -> None:
|
||||
"""Sélectionne des couleurs variées par teinte en priorité."""
|
||||
colors_path = tmp_path / "colors_by_set.csv"
|
||||
write_csv(
|
||||
colors_path,
|
||||
"set_num,set_id,year,color_rgb,is_translucent,color_name,quantity_total,quantity_non_spare,quantity_minifig,quantity_non_minifig\n"
|
||||
"123-1,123,2020,FF0000,false,Red,10,10,0,10\n"
|
||||
"123-1,123,2020,00FF00,false,Green,8,8,0,8\n"
|
||||
"123-1,123,2020,0000FF,false,Blue,6,6,0,6\n"
|
||||
"123-1,123,2020,FFFF00,false,Yellow,5,5,0,5\n"
|
||||
"123-1,123,2020,FF00FF,false,Magenta,4,4,0,4\n"
|
||||
"123-1,123,2020,00FFFF,false,Cyan,3,3,0,3\n",
|
||||
)
|
||||
sets_lookup = {"123-1": {"name": "Set A", "year": 2020, "set_id": "123"}}
|
||||
rows = build_perceptual_swatches(
|
||||
[
|
||||
{
|
||||
"set_num": "123-1",
|
||||
"set_id": "123",
|
||||
"year": "2020",
|
||||
"color_rgb": "FF0000",
|
||||
"color_name": "Red",
|
||||
"quantity_non_minifig": "10",
|
||||
},
|
||||
{
|
||||
"set_num": "123-1",
|
||||
"set_id": "123",
|
||||
"year": "2020",
|
||||
"color_rgb": "00FF00",
|
||||
"color_name": "Green",
|
||||
"quantity_non_minifig": "8",
|
||||
},
|
||||
{
|
||||
"set_num": "123-1",
|
||||
"set_id": "123",
|
||||
"year": "2020",
|
||||
"color_rgb": "0000FF",
|
||||
"color_name": "Blue",
|
||||
"quantity_non_minifig": "6",
|
||||
},
|
||||
{
|
||||
"set_num": "123-1",
|
||||
"set_id": "123",
|
||||
"year": "2020",
|
||||
"color_rgb": "FFFF00",
|
||||
"color_name": "Yellow",
|
||||
"quantity_non_minifig": "5",
|
||||
},
|
||||
{
|
||||
"set_num": "123-1",
|
||||
"set_id": "123",
|
||||
"year": "2020",
|
||||
"color_rgb": "FF00FF",
|
||||
"color_name": "Magenta",
|
||||
"quantity_non_minifig": "4",
|
||||
},
|
||||
{
|
||||
"set_num": "123-1",
|
||||
"set_id": "123",
|
||||
"year": "2020",
|
||||
"color_rgb": "00FFFF",
|
||||
"color_name": "Cyan",
|
||||
"quantity_non_minifig": "3",
|
||||
},
|
||||
],
|
||||
sets_lookup,
|
||||
top_n=5,
|
||||
)
|
||||
|
||||
ranks = [row["rank"] for row in rows if row["set_num"] == "123-1"]
|
||||
assert ranks == ["1", "2", "3", "4", "5"]
|
||||
assert len({row["color_name"] for row in rows}) == 5
|
||||
28
tests/test_set_color_swatches_perceptual_plot.py
Normal file
28
tests/test_set_color_swatches_perceptual_plot.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Tests du graphique de palettes perceptuelles par set."""
|
||||
|
||||
import matplotlib
|
||||
from pathlib import Path
|
||||
|
||||
from lib.plots.set_color_swatches_perceptual import plot_set_color_swatches_perceptual
|
||||
|
||||
|
||||
matplotlib.use("Agg")
|
||||
|
||||
|
||||
def test_plot_set_color_swatches_perceptual(tmp_path: Path) -> None:
|
||||
"""Génère le graphique perceptuel."""
|
||||
swatches_path = tmp_path / "set_color_swatches_perceptual.csv"
|
||||
destination = tmp_path / "figures" / "step28" / "set_color_swatches_perceptual.png"
|
||||
swatches_path.write_text(
|
||||
"set_num,set_id,name,year,rank,color_rgb,color_name,share_non_minifig,quantity_non_minifig\n"
|
||||
"123-1,123,Set A,2020,1,FF0000,Red,0.40000,10\n"
|
||||
"123-1,123,Set A,2020,2,00FF00,Green,0.30000,8\n"
|
||||
"123-1,123,Set A,2020,3,0000FF,Blue,0.20000,6\n"
|
||||
"123-1,123,Set A,2020,4,FFFF00,Yellow,0.10000,5\n"
|
||||
"123-1,123,Set A,2020,5,00FFFF,Cyan,0.05000,3\n"
|
||||
)
|
||||
|
||||
plot_set_color_swatches_perceptual(swatches_path, destination)
|
||||
|
||||
assert destination.exists()
|
||||
assert destination.stat().st_size > 0
|
||||
Reference in New Issue
Block a user