1

Reviens à l’état fbf20e2 sans palettes par set

This commit is contained in:
2025-12-02 16:23:56 +01:00
parent 909a1eae71
commit c0700a8829
11 changed files with 0 additions and 816 deletions

View File

@@ -1,155 +0,0 @@
"""Tests de la préparation des palettes par set."""
from pathlib import Path
from lib.rebrickable.set_color_swatches import build_top_colors_by_set
def write_csv(path: Path, content: str) -> None:
"""Écrit un CSV brut."""
path.write_text(content)
def test_build_top_colors_by_set_selects_top5_non_minifig(tmp_path: Path) -> None:
"""Sélectionne les 5 couleurs dominantes en excluant les minifigs."""
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,111111,false,Black,10,10,0,10\n"
"123-1,123,2020,222222,false,Red,5,5,0,5\n"
"123-1,123,2020,333333,false,Blue,3,3,0,3\n"
"123-1,123,2020,444444,false,Green,2,2,0,2\n"
"123-1,123,2020,555555,false,Yellow,1,1,0,1\n"
"123-1,123,2020,666666,false,Pink,1,1,0,1\n"
"123-1,123,2020,0033B2,false,Ignored Blue,50,50,0,50\n"
"124-1,124,2021,aaaaaa,false,Gray,4,4,4,0\n",
)
sets_path = tmp_path / "sets_enriched.csv"
write_csv(
sets_path,
"set_num,name,year,theme_id,num_parts,img_url,set_id,rebrickable_url,in_collection\n"
"123-1,Set A,2020,1,100,,123,,false\n"
"124-1,Set B,2021,1,50,,124,,false\n",
)
rows = build_top_colors_by_set(
[
row
for row in [
{
"set_num": "123-1",
"set_id": "123",
"year": "2020",
"color_rgb": "111111",
"color_name": "Black",
"quantity_non_minifig": "10",
},
{
"set_num": "123-1",
"set_id": "123",
"year": "2020",
"color_rgb": "222222",
"color_name": "Red",
"quantity_non_minifig": "5",
},
{
"set_num": "123-1",
"set_id": "123",
"year": "2020",
"color_rgb": "333333",
"color_name": "Blue",
"quantity_non_minifig": "3",
},
{
"set_num": "123-1",
"set_id": "123",
"year": "2020",
"color_rgb": "444444",
"color_name": "Green",
"quantity_non_minifig": "2",
},
{
"set_num": "123-1",
"set_id": "123",
"year": "2020",
"color_rgb": "555555",
"color_name": "Yellow",
"quantity_non_minifig": "1",
},
{
"set_num": "123-1",
"set_id": "123",
"year": "2020",
"color_rgb": "666666",
"color_name": "Pink",
"quantity_non_minifig": "1",
},
{
"set_num": "124-1",
"set_id": "124",
"year": "2021",
"color_rgb": "aaaaaa",
"color_name": "Gray",
"quantity_non_minifig": "0",
},
]
],
{
"123-1": {"name": "Set A", "year": 2020, "set_id": "123"},
"124-1": {"name": "Set B", "year": 2021, "set_id": "124"},
},
top_n=5,
)
assert rows == [
{
"set_num": "123-1",
"set_id": "123",
"name": "Set A",
"year": "2020",
"rank": "1",
"color_rgb": "111111",
"color_name": "Black",
"quantity_non_minifig": "10",
},
{
"set_num": "123-1",
"set_id": "123",
"name": "Set A",
"year": "2020",
"rank": "2",
"color_rgb": "222222",
"color_name": "Red",
"quantity_non_minifig": "5",
},
{
"set_num": "123-1",
"set_id": "123",
"name": "Set A",
"year": "2020",
"rank": "3",
"color_rgb": "333333",
"color_name": "Blue",
"quantity_non_minifig": "3",
},
{
"set_num": "123-1",
"set_id": "123",
"name": "Set A",
"year": "2020",
"rank": "4",
"color_rgb": "444444",
"color_name": "Green",
"quantity_non_minifig": "2",
},
{
"set_num": "123-1",
"set_id": "123",
"name": "Set A",
"year": "2020",
"rank": "5",
"color_rgb": "666666",
"color_name": "Pink",
"quantity_non_minifig": "1",
},
]

View File

@@ -1,84 +0,0 @@
"""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

View File

@@ -1,28 +0,0 @@
"""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

View File

@@ -1,29 +0,0 @@
"""Tests du graphique de palettes dominantes par set."""
import matplotlib
from pathlib import Path
from lib.plots.set_color_swatches import plot_set_color_swatches
matplotlib.use("Agg")
def test_plot_set_color_swatches(tmp_path: Path) -> None:
"""Génère le nuancier top 5 par set."""
swatches_path = tmp_path / "set_color_swatches.csv"
destination = tmp_path / "figures" / "step27" / "set_color_swatches.png"
swatches_path.write_text(
"set_num,set_id,name,year,rank,color_rgb,color_name,quantity_non_minifig\n"
"123-1,123,Set A,2020,1,111111,Black,10\n"
"123-1,123,Set A,2020,2,222222,Red,5\n"
"123-1,123,Set A,2020,3,333333,Blue,3\n"
"123-1,123,Set A,2020,4,444444,Green,2\n"
"123-1,123,Set A,2020,5,555555,Yellow,1\n"
"124-1,124,Set B,2021,1,aaaaaa,Gray,4\n"
)
plot_set_color_swatches(swatches_path, destination)
assert destination.exists()
assert destination.stat().st_size > 0