| |
| """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 |
| import re |
| import subprocess |
| import sys |
| from pathlib import Path |
|
|
| HERE = Path(__file__).parent |
|
|
| sys.path.insert(0, str(HERE)) |
| import container_stats |
| import dictionary |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| STRAIGHT_WALL_RULES = { |
| (600, 400): (550, 355, 15), |
| (400, 300): (350, 250, 10), |
| (300, 200): (260, 160, 10), |
| (800, 600): (750, 550, 20), |
| } |
|
|
| |
| |
| VDA_USABLE_RATIO = 48 / 67.2 |
|
|
| MM_PER_IN = 25.4 |
| L_PER_US_GAL = 3.785411784 |
|
|
|
|
| def inches(mm): |
| return round(mm / MM_PER_IN, 2) |
|
|
|
|
| def gallons(litres): |
| return round(litres / L_PER_US_GAL, 1) |
|
|
| |
| |
| |
| |
| |
| NAMES = { |
| "euro_stacking_container": ( |
| "Eurobox; Euro container; Eurocontainer; Euro stacking container; euro crate; " |
| "stacking crate; stacking tote; straight-wall tote; industrial tote; " |
| "KLT box (loose vendor usage); KLC; Eurobehälter (DE); Eurokiste (DE); " |
| "Stapelbehälter (DE); bac gerbable (FR); bac Euronorme (FR); " |
| "caja apilable (ES); stapelbak (NL)"), |
| "attached_lid_container": ( |
| "Attached lid container; ALC; attached top container; ATC; attached-lid tote; " |
| "hinged-lid crate; crocodile-lid box (UK); Hudson box (US, after Hudson " |
| "Exchange); distribution tote; industrial tote; Klappdeckelbehälter (DE); " |
| "Deckelbehälter (DE); bac à couvercle solidaire (FR)"), |
| "vda_klt_container": ( |
| "KLT; R-KLT; RL-KLT; Kleinladungsträger (DE); VDA container; VDA 4500 carrier; " |
| "small load carrier; SLC; automotive tote; returnable tote; ESD KLT (conductive)"), |
| } |
|
|
| 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)", |
| } |
|
|
| |
| |
| 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} |
|
|
| |
| |
| if (HERE / "build_listings.py").exists(): |
| subprocess.run([sys.executable, str(HERE / "build_listings.py")], check=True) |
|
|
|
|
| LISTINGS = container_stats.load_listings(HERE / "listings.csv") |
|
|
|
|
| def load_listing_index(): |
| """(type, L_mm, W_mm) -> list of observed heights in mm.""" |
| idx = {} |
| for r in LISTINGS: |
| key = container_stats.footprint(r) |
| if key: |
| idx.setdefault(key, []).append(float(r["external_height_cm"]) * 10) |
| return idx |
|
|
|
|
| LISTING_INDEX = load_listing_index() |
| INTERNAL_INDEX = container_stats.internal_index(LISTINGS) |
|
|
|
|
| def internal_dims_vendors(kind, L, W): |
| """How many vendors publish internal dimensions for this footprint. |
| |
| Vendors, not listings: Salesbridges lists the same 600x400 mould in five |
| colours, and five colours are not five opinions. |
| """ |
| return len(INTERNAL_INDEX.get((kind, L, W), {})) |
|
|
|
|
| def vendor_capacity_span(kind, L, W, H): |
| return container_stats.capacity_span(INTERNAL_INDEX, kind, L, W, H) |
|
|
|
|
| def published_internal(kind, L, W, H): |
| """Mean of the internal dimensions vendors publish for this exact size, in mm.""" |
| obs = [] |
| for r in LISTINGS: |
| try: |
| if (r["type"] != kind or not r["internal_length_cm"] |
| or round(float(r["external_length_cm"]) * 10) != L |
| or round(float(r["external_width_cm"]) * 10) != W |
| or abs(float(r["external_height_cm"]) * 10 - H) > HEIGHT_TOLERANCE_MM): |
| continue |
| obs.append(tuple(float(r[f"internal_{d}_cm"]) * 10 for d in ("length", "width", "height"))) |
| except ValueError: |
| continue |
| if not obs: |
| return None |
| return tuple(round(sum(o[i] for o in obs) / len(obs)) for i in range(3)) |
|
|
| |
| |
| |
| HEIGHT_TOLERANCE_MM = 6 |
|
|
|
|
| def listings_observed(kind, L, W, H): |
| heights = LISTING_INDEX.get((kind, L, W), []) |
| return sum(1 for h in heights if abs(h - H) <= HEIGHT_TOLERANCE_MM) |
|
|
|
|
| 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: |
| |
| |
| |
| |
| int_l = int_w = int_h = None |
| basis = "vendor_nominal" |
| dims_basis = "not_published_tapered_walls" |
| cap = capacity_l |
| elif vda: |
| |
| |
| |
| pub = published_internal(kind, L, W, H) |
| int_l, int_w, int_h = pub if pub else (None, None, None) |
| dims_basis = "vendor_published" if pub else "not_published" |
| 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" |
| dims_basis = "vendor_average_rule" |
|
|
| cap_low, cap_high = vendor_capacity_span(kind, L, W, H) |
|
|
| 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_length_in": inches(L), |
| "external_width_in": inches(W), |
| "external_height_in": inches(H), |
| "external_volume_l": round(ext_l, 1), |
| "external_volume_gal": gallons(ext_l), |
| "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 "", |
| "internal_length_in": inches(int_l) if int_l else "", |
| "internal_width_in": inches(int_w) if int_w else "", |
| "internal_height_in": inches(int_h) if int_h else "", |
| "internal_dims_basis": dims_basis, |
| "internal_dims_vendors": internal_dims_vendors(kind, L, W), |
| "typical_capacity_l": cap, |
| "typical_capacity_gal": gallons(cap), |
| |
| |
| "vendor_capacity_low_l": cap_low, |
| "vendor_capacity_high_l": cap_high, |
| "usable_ratio": round(cap / ext_l, 3), |
| "capacity_basis": basis, |
| "lidded": alc, |
| "lid_available_separately": not alc, |
| "nestable_when_empty": alc, |
| |
| |
| |
| "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)], |
| "listings_observed": listings_observed(kind, L, W, H), |
| "notes": note, |
| } |
|
|
|
|
| ROWS = [] |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| for H in (120, 150, 170, 175, 200, 220, 230, 240, 270, 280, |
| 300, 310, 320, 340, 365, 400, 420, 465): |
| ROWS.append(row("euro_stacking_container", 600, 400, H)) |
| for H in (120, 150, 170, 200, 220, 230, 240, 270, 320): |
| ROWS.append(row("euro_stacking_container", 400, 300, H)) |
| for H in (120, 150, 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", |
| )) |
|
|
| |
| 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 = [ |
| ("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") |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| DTYPES = dictionary.DTYPES |
|
|
|
|
| def write_dictionary(): |
| """Render the dictionary as a CSV and a document, and verify it matches.""" |
| dictionary.check("containers", FIELDS) |
| with (HERE / "listings.csv").open(encoding="utf-8") as f: |
| dictionary.check("listings", next(csv.reader(f))) |
|
|
| rows = [ |
| {"table": table, "file": fname, "column": name, "dtype": dtype, |
| "unit": unit, "description": desc} |
| for table, (fname, cols) in dictionary.TABLES.items() |
| for name, dtype, unit, desc in cols |
| ] |
| with (HERE / "data-dictionary.csv").open("w", newline="", encoding="utf-8") as f: |
| w = csv.DictWriter(f, fieldnames=list(rows[0])) |
| w.writeheader() |
| w.writerows(rows) |
|
|
| doc = [ |
| "# Data dictionary\n\n", |
| f"Version {dictionary.VERSION}. Generated by `build.py` from `dictionary.py` " |
| "— do not hand-edit.\n\n", |
| "Every column in both tables, with its type, unit and meaning. The machine-" |
| "readable form of this file is [`data-dictionary.csv`](../data-dictionary.csv); " |
| "the same definitions render the dataset card's field table and the Hub's " |
| "dtype declarations, so the three cannot disagree.\n", |
| ] |
| for table, (fname, cols) in dictionary.TABLES.items(): |
| doc.append(f"\n## `{table}` → `{fname}`\n") |
| doc.append(f"{len(cols)} columns.\n\n") |
| doc.append("| Column | Type | Unit | Description |\n|---|---|---|---|\n") |
| for name, dtype, unit, desc in cols: |
| doc.append(f"| `{name}` | {dtype} | {unit or '—'} | {desc} |\n") |
| (HERE / "docs").mkdir(exist_ok=True) |
| (HERE / "docs" / "data-dictionary.md").write_text("".join(doc), encoding="utf-8") |
|
|
| |
| |
| (HERE / "datasheet").mkdir(exist_ok=True) |
| (HERE / "datasheet" / "version.json").write_text( |
| json.dumps({"version": dictionary.VERSION}) + "\n", encoding="utf-8") |
| return rows |
|
|
|
|
| def fields_table(): |
| """The dataset card's Fields section, rendered from the dictionary.""" |
| out = ["| Field | Type | Notes |", "|---|---|---|"] |
| for name, dtype, unit, desc in dictionary.CONTAINERS: |
| u = f" ({unit})" if unit else "" |
| out.append(f"| `{name}` | {dtype}{u} | {desc} |") |
| return "\n".join(out) |
|
|
|
|
| def features(names, indent=" "): |
| return "\n".join( |
| f"{indent}- name: {n}\n{indent} dtype: {DTYPES.get(n, 'string')}" for n in names |
| ) |
|
|
|
|
| def config_block(name, csv_name, names, n_rows): |
| return (f" - config_name: {name}\n" |
| f" features:\n{features(names, ' ')}\n" |
| f" splits:\n - name: train\n num_examples: {n_rows}") |
|
|
|
|
| def frontmatter(): |
| |
| |
| listings = HERE / "listings.csv" |
| extra_cfg = "" |
| extra_info = "" |
| if listings.exists(): |
| with listings.open(encoding="utf-8") as f: |
| rdr = csv.reader(f) |
| lfields = next(rdr) |
| lrows = sum(1 for _ in rdr) |
| extra_cfg = "\n - config_name: listings\n data_files: listings.csv" |
| extra_info = "\n" + config_block("listings", "listings.csv", lfields, lrows) |
|
|
| feats = features(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{extra_cfg} |
| dataset_info: |
| {config_block("default", "containers.csv", FIELDS, len(ROWS))}{extra_info} |
| ---""" |
|
|
|
|
| DICT_ROWS = write_dictionary() |
|
|
| readme = HERE / "README.md" |
| if readme.exists(): |
| body = readme.read_text(encoding="utf-8") |
| if body.startswith("---"): |
| body = body.split("---", 2)[2].lstrip("\n") |
| |
| |
| body = re.sub( |
| r"(## Fields\n\n).*?(\n### )", |
| lambda m: m.group(1) + fields_table() + "\n" + m.group(2), |
| body, count=1, flags=re.S) |
| readme.write_text(frontmatter() + "\n\n" + body, encoding="utf-8") |
|
|
| print(f"{len(ROWS)} rows -> containers.csv, containers.jsonl, README.md frontmatter") |
| print(f"{len(DICT_ROWS)} columns -> data-dictionary.csv, docs/data-dictionary.md") |
| for kind in TYPE_LABELS: |
| n = sum(1 for r in ROWS if r["type"] == kind) |
| print(f" {kind}: {n}") |
|
|