1

Ajouter la variante de têtes imprimées et simplifier les graphs globaux

This commit is contained in:
2025-12-03 16:21:22 +01:00
parent ff2fa1819a
commit 9ef0d6cb9f
5 changed files with 61 additions and 28 deletions

View File

@@ -10,15 +10,18 @@ from lib.rebrickable.parts_inventory import normalize_boolean, select_latest_inv
HEAD_CATEGORIES = {"59"}
def load_head_parts(parts_path: Path, head_categories: Set[str] | None = None) -> Set[str]:
def load_head_parts(parts_path: Path, head_categories: Set[str] | None = None, require_printed: bool = False) -> Dict[str, str]:
"""Construit l'ensemble des références de têtes via leur catégorie."""
categories = head_categories or HEAD_CATEGORIES
head_parts: Set[str] = set()
head_parts: Dict[str, str] = {}
with parts_path.open() as parts_file:
reader = csv.DictReader(parts_file)
for row in reader:
if row["part_cat_id"] in categories:
head_parts.add(row["part_num"])
if row["part_cat_id"] not in categories:
continue
if require_printed and "print" not in row["name"].lower():
continue
head_parts[row["part_num"]] = row["name"]
return head_parts
@@ -53,9 +56,10 @@ def aggregate_global_heads_by_year(
colors_path: Path,
sets_path: Path,
head_categories: Set[str] | None = None,
require_printed: bool = False,
) -> List[dict]:
"""Agrège les couleurs de têtes par année sur le catalogue complet."""
head_parts = load_head_parts(parts_path, head_categories)
head_parts = load_head_parts(parts_path, head_categories, require_printed=require_printed)
latest_inventories = select_latest_inventories(inventories_path)
latest_inventory_ids = {data["id"]: set_num for set_num, data in latest_inventories.items()}
colors_lookup = build_color_lookup(colors_path)