File size: 18,768 Bytes
9672429
 
 
 
 
 
 
 
 
 
 
 
dd07087
a138f28
 
9672429
 
 
 
f0ed0b4
 
dd07087
f0ed0b4
9672429
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9258bfa
 
 
 
 
 
 
 
 
 
 
5af6ad9
 
 
 
 
9672429
5af6ad9
 
 
 
 
 
 
 
 
 
 
 
 
 
9672429
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a138f28
 
 
 
 
 
f0ed0b4
5af6ad9
 
 
 
 
 
f0ed0b4
 
5af6ad9
a138f28
 
 
 
f0ed0b4
5af6ad9
 
 
 
 
 
 
 
 
 
 
 
f0ed0b4
5af6ad9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a138f28
 
 
 
 
 
 
 
 
 
9672429
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5af6ad9
 
 
 
9672429
 
5af6ad9
9672429
 
5af6ad9
 
 
 
 
 
9672429
 
 
 
 
 
 
5af6ad9
 
 
9672429
 
 
 
 
 
 
 
 
9258bfa
 
 
 
 
9672429
 
 
9258bfa
 
 
9672429
9258bfa
9672429
 
 
9258bfa
 
 
5af6ad9
 
9672429
9258bfa
5af6ad9
 
 
 
9672429
 
 
 
 
ddf9b76
 
 
 
9672429
 
 
 
a138f28
9672429
 
 
 
 
 
 
a138f28
 
 
 
 
 
 
 
 
9672429
a138f28
9672429
a138f28
9672429
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddf9b76
 
 
 
 
 
 
 
 
dd07087
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddf9b76
 
a138f28
 
 
ddf9b76
a138f28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddf9b76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a138f28
ddf9b76
a138f28
ddf9b76
 
 
dd07087
 
ddf9b76
 
 
 
 
dd07087
 
 
 
 
 
ddf9b76
 
 
dd07087
9672429
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#!/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
import re
import subprocess
import sys
from pathlib import Path

HERE = Path(__file__).parent

sys.path.insert(0, str(HERE))
import container_stats  # noqa: E402  (needs HERE on the path)
import dictionary  # noqa: E402

# ---------------------------------------------------------------------------
# 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

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)

# Search terms, not a taxonomy. Ordered from the most standard to the most
# colloquial, and deliberately including the loose and the regional: someone
# searching "Hudson box" or "industrial tote" should land on the right family.
# Which terms are evidenced by the captured listings and which are ordinary trade
# usage is set out in guidance/naming.md.
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)",
}

# 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}

# Build the listings table first, so each typical row can record how many real
# listings sit behind it. Single entry point: `python3 build.py` does everything.
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))

# Vendors round heights differently for what is the same mould — 31 vs 31.5 cm,
# 36.5 vs 36.7. A 6 mm window matches a typical row to its real listings without
# swallowing the next size up, the closest of which is 20 mm away.
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:
        # ALC walls taper hard enough that a single internal L x W x H would be
        # wrong wherever you measured it, and no vendor in listings.csv publishes
        # one for a 600x400 or 400x300 ALC. Capacity is the vendor's nominal
        # figure and is the only honest usable number here.
        int_l = int_w = int_h = None
        basis = "vendor_nominal"
        dims_basis = "not_published_tapered_walls"
        cap = capacity_l
    elif vda:
        # KLTs are thicker-walled than consumer euroboxes, so the straight-wall
        # rule does not transfer. Where a vendor publishes internal dimensions for
        # the exact size, use theirs; elsewhere leave them empty.
        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],
        # Both unit systems on every row. These nominal sizes are metric by
        # definition — the standards fix them in millimetres — so the inch columns
        # are always the derived side here, unlike listings.csv where a US vendor's
        # own figure is the inch one. They are carried anyway because the reader
        # comparing a US tote against a Eurobox should not have to convert first.
        "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),
        # The same external size quoted by different vendors. Empty where no
        # vendor in listings.csv publishes internal dimensions for the footprint.
        "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,
        # 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)],
        "listings_observed": listings_observed(kind, L, W, H),
        "notes": note,
    }


ROWS = []

# --- Euro stacking containers, open top --------------------------------------
#
# The height series below is the union of what was actually observed on sale in
# the captures under raw/ and the 2026-07-23 Israeli research pass, with
# near-duplicates merged to the round figure (315 -> 310, 365/370 -> 365,
# 415/420 -> 420). No standard defines these heights — unlike the VDA grid, the
# consumer euro series is whatever manufacturers converged on — so "common" here
# means "seen for sale", not "specified anywhere".
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",
    ))

# --- 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 = 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")

    # The datasheet is a Typst document that reads the CSVs at compile time; the
    # one thing it cannot get from them is the dictionary's version.
    (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.csv is produced by build_listings.py, run just above. Reading its
    # header here rather than duplicating the field list keeps the two in step.
    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")
    # The Fields table is rendered from dictionary.py, so replace whatever is
    # between the heading and the next one rather than trusting it to be current.
    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}")