#!/usr/bin/env python3 """Generate the storage-container-dimensions dataset. Single source of truth for containers.csv and containers.jsonl. Every derived number is computed here rather than typed, so the internal-dimension rule and the capacity that follows from it can never drift apart. Run: python3 build.py """ import csv import json from pathlib import Path HERE = Path(__file__).parent # --------------------------------------------------------------------------- # Internal-dimension rules. # # The standards (ISO 3394, EN 13199, VDA 4500) fix the *external* footprint and, # for VDA, the external height. None of them specifies internal dimensions — wall # thickness, draft angle and rib design are the manufacturer's choice. These rules # are therefore an average across vendor catalogues, accurate to about ±1 L on a # 60x40 box, and are meant for planning rather than for anything load-bearing. # # Format: (internal_L_mm, internal_W_mm, height_deduction_mm) STRAIGHT_WALL_RULES = { (600, 400): (550, 355, 15), (400, 300): (350, 250, 10), (300, 200): (260, 160, 10), (800, 600): (750, 550, 20), } # VDA KLTs are noticeably thicker-walled than consumer euroboxes. Anchored on the # one published pair: R-KLT 6429, 600x400x280 external = 67.2 L, 48 L internal. VDA_USABLE_RATIO = 48 / 67.2 NAMES = { "euro_stacking_container": "Eurobox; Euro container; Euro stacking container; euro crate; stacking tote", "attached_lid_container": "Attached lid container; ALC; attached-lid tote; hinged-lid crate", "vda_klt_container": "KLT; R-KLT; VDA container; small load carrier; SLC", } TYPE_LABELS = { "euro_stacking_container": "Euro stacking container (open top)", "attached_lid_container": "Attached-lid container (ALC)", "vda_klt_container": "VDA 4500 KLT (returnable small load carrier)", } # Footprints that are ISO 3394 packaging modules (they divide the 1200x800 Euro # pallet exactly) and are within the EN 13199 small-load-carrier cap of 600x400. ISO_MODULES = {(600, 400), (400, 300), (300, 200)} EUR1_PER_LAYER = {(600, 400): 4, (400, 300): 8, (300, 200): 16, (800, 600): 2} VDA_HEIGHTS_MM = {147.5, 213, 280} def standard_for(L, W, vda): """Return (conformant, standard string) for a footprint.""" if vda: return True, "VDA 4500 (R-KLT); ISO 3394 packaging module; EN 13199 small load carrier" if (L, W) in ISO_MODULES: return True, "ISO 3394 packaging module; within the EN 13199 600x400 small-load-carrier cap" if (L, W) == (800, 600): return True, "Euro pallet module (half of 1200x800); exceeds the EN 13199 600x400 small-load-carrier cap" return False, "" def row(kind, L, W, H, capacity_l=None, note="", vda_code=None): """Build one dataset record. Dimensions in mm; output in cm.""" ext_l = L * W * H / 1e6 vda = kind == "vda_klt_container" alc = kind == "attached_lid_container" if alc: # ALC walls taper, so a single internal L x W x H would be wrong wherever # you measured it. Capacity is the vendor's nominal figure and is the only # honest usable number; internal dimensions are left empty on purpose. int_l = int_w = int_h = None basis = "vendor_nominal" cap = capacity_l elif vda: int_l = int_w = int_h = None cap = capacity_l if capacity_l is not None else round(ext_l * VDA_USABLE_RATIO, 1) basis = "published" if capacity_l is not None else "derived_from_klt_ratio" else: il, iw, dh = STRAIGHT_WALL_RULES[(L, W)] int_l, int_w, int_h = il, iw, H - dh cap = round(il * iw * (H - dh) / 1e6, 1) basis = "derived_from_internal_dims" conformant, standard = standard_for(L, W, vda) ident = vda_code or f"{'alc' if alc else 'euro'}-{L}x{W}x{H}" return { "id": ident, "type": kind, "type_label": TYPE_LABELS[kind], "common_names": NAMES[kind], "external_length_cm": L / 10, "external_width_cm": W / 10, "external_height_cm": H / 10, "external_volume_l": round(ext_l, 1), "internal_length_cm": int_l / 10 if int_l else "", "internal_width_cm": int_w / 10 if int_w else "", "internal_height_cm": int_h / 10 if int_h else "", "typical_capacity_l": cap, "usable_ratio": round(cap / ext_l, 3), "capacity_basis": basis, "lidded": alc, "lid_available_separately": not alc, "nestable_when_empty": alc, # 0.0 rather than blank: a straight-walled box has a nesting ratio of zero, # which is a fact about it, not missing data. Blanks here also made the Hub's # type inference read the whole column as null. "typical_nesting_ratio": 0.75 if alc else 0.0, "standard_conformant": conformant, "standard": standard, "vda_4500_height": H in VDA_HEIGHTS_MM, "eur1_pallet_per_layer": EUR1_PER_LAYER[(L, W)], "notes": note, } ROWS = [] # --- Euro stacking containers, open top -------------------------------------- for H in (120, 170, 175, 220, 230, 270, 310, 320, 340, 420): ROWS.append(row("euro_stacking_container", 600, 400, H)) for H in (120, 170, 220, 270, 320): ROWS.append(row("euro_stacking_container", 400, 300, H)) for H in (120, 170, 220): ROWS.append(row("euro_stacking_container", 300, 200, H)) for H in (220, 320, 420): ROWS.append(row( "euro_stacking_container", 800, 600, H, note="800x600 internal rule is not cross-checked against a published internal " "dimension; thin-walled containers of this size are marketed above it", )) # --- Attached-lid containers ------------------------------------------------- ALC_600 = [ (250, 44, ""), (310, 56, "Nominal capacity for this external size varies by range: 56 L " "(Loadhog/Kaiman-compatible), 55 L and 53 L are all sold"), (367, 65, ""), (400, 80, "Outlier: 83 % usable ratio where the rest of the range sits at 73-75 %. " "Published figure, not independently measured — treat with caution"), ] for H, cap, note in ALC_600: ROWS.append(row("attached_lid_container", 600, 400, H, capacity_l=cap, note=note)) for H, cap in ((222, 22), (264, 25), (306, 30)): ROWS.append(row("attached_lid_container", 400, 300, H, capacity_l=cap)) # --- VDA 4500 R-KLT ---------------------------------------------------------- # The only heights the standard actually defines. 6429 is the published anchor. VDA = [ ("vda-rklt-6415", 600, 400, 147.5, None, ""), ("vda-rklt-6422", 600, 400, 213, None, ""), ("vda-rklt-6429", 600, 400, 280, 48.0, "Published: 65 L external / 48 L internal, tare 2.97 kg. Anchors the KLT ratio " "used for the other two heights"), ("vda-rklt-4315", 400, 300, 147.5, None, ""), ("vda-rklt-4322", 400, 300, 213, None, ""), ("vda-rklt-4329", 400, 300, 280, None, ""), ("vda-rklt-3215", 300, 200, 147.5, None, "The 300x200 module exists only in the 147.5 mm height"), ] for code, L, W, H, cap, note in VDA: ROWS.append(row("vda_klt_container", L, W, H, capacity_l=cap, note=note, vda_code=code)) FIELDS = list(ROWS[0].keys()) with (HERE / "containers.csv").open("w", newline="", encoding="utf-8") as f: w = csv.DictWriter(f, fieldnames=FIELDS) w.writeheader() w.writerows(ROWS) with (HERE / "containers.jsonl").open("w", encoding="utf-8") as f: for r in ROWS: clean = {k: (None if v == "" else v) for k, v in r.items()} f.write(json.dumps(clean, ensure_ascii=False) + "\n") # --------------------------------------------------------------------------- # Declare the schema in the dataset card. # # Without this the Hub infers column types from the CSV, and any column that is # mostly blank — `notes` especially — gets inferred as all-null, which breaks # `load_dataset` for anyone reading that field. Writing the frontmatter from the # same run that writes the data is the only way to keep the two in step. DTYPES = { "eur1_pallet_per_layer": "int64", **{k: "bool" for k in ( "lidded", "lid_available_separately", "nestable_when_empty", "standard_conformant", "vda_4500_height")}, **{k: "float64" for k in ( "external_length_cm", "external_width_cm", "external_height_cm", "external_volume_l", "internal_length_cm", "internal_width_cm", "internal_height_cm", "typical_capacity_l", "usable_ratio", "typical_nesting_ratio")}, } def frontmatter(): feats = "\n".join( f" - name: {name}\n dtype: {DTYPES.get(name, 'string')}" for name in FIELDS ) return f"""--- license: cc-by-4.0 language: - en pretty_name: Industrial Storage Container Dimensions size_categories: - n<1K tags: - logistics - supply-chain - warehousing - packaging - reference - tabular configs: - config_name: default data_files: containers.csv dataset_info: config_name: default features: {feats} splits: - name: train num_examples: {len(ROWS)} ---""" readme = HERE / "README.md" if readme.exists(): body = readme.read_text(encoding="utf-8") if body.startswith("---"): body = body.split("---", 2)[2].lstrip("\n") readme.write_text(frontmatter() + "\n\n" + body, encoding="utf-8") print(f"{len(ROWS)} rows -> containers.csv, containers.jsonl, README.md frontmatter") for kind in TYPE_LABELS: n = sum(1 for r in ROWS if r["type"] == kind) print(f" {kind}: {n}")