File size: 9,306 Bytes
dd07087
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""The data dictionary — one definition per column, for both tables.

Authoritative. build.py renders it four ways and none of them is hand-written:

    data-dictionary.csv          machine-readable, one row per column
    docs/data-dictionary.md      the same as a document
    README.md "Fields" table     the dataset card
    README.md frontmatter        the Hub's dtype declarations

Adding a column to a builder without adding it here fails the build, which is the
point: the schema and its documentation cannot drift apart.

`unit` is the physical unit or "" for dimensionless and categorical columns.
`example` is illustrative, not drawn from the data.
"""

VERSION = "1.0"

# (name, dtype, unit, description)
CONTAINERS = [
    ("id", "string", "",
     "Stable slug, e.g. `euro-600x400x230`, `alc-600x400x310`, `vda-rklt-6429`"),
    ("type", "string", "",
     "`euro_stacking_container` · `attached_lid_container` · `vda_klt_container`"),
    ("type_label", "string", "", "Human-readable form of `type`"),
    ("common_names", "string", "",
     "Semicolon-separated search terms, ordered most standard to most colloquial, "
     "including regional ones (`Eurobehälter`, `bac gerbable`) and genericised vendor "
     "names (`Hudson box`). Search terms only — never discriminate families on them, "
     "see `guidance/naming.md`"),
    ("external_length_cm", "float64", "cm", "External length"),
    ("external_width_cm", "float64", "cm", "External width"),
    ("external_height_cm", "float64", "cm", "External height"),
    ("external_length_in", "float64", "in",
     "External length in inches. Always the derived side on this table — these "
     "nominal sizes are fixed in millimetres by the standards"),
    ("external_width_in", "float64", "in", "External width in inches, derived"),
    ("external_height_in", "float64", "in", "External height in inches, derived"),
    ("external_volume_l", "float64", "L", "L × W × H. **Not** what the box holds"),
    ("external_volume_gal", "float64", "US gal", "External volume in US liquid gallons"),
    ("internal_length_cm", "float64", "cm",
     "Typical internal length. Populated for every Euro row and for the two KLT sizes "
     "a vendor publishes; empty for ALCs, whose taper makes a single internal "
     "dimension meaningless"),
    ("internal_width_cm", "float64", "cm", "Typical internal width, same basis"),
    ("internal_height_cm", "float64", "cm", "Typical internal height, same basis"),
    ("internal_length_in", "float64", "in", "Typical internal length in inches, derived"),
    ("internal_width_in", "float64", "in", "Typical internal width in inches, derived"),
    ("internal_height_in", "float64", "in", "Typical internal height in inches, derived"),
    ("internal_dims_basis", "string", "",
     "Where those internal figures came from: `vendor_average_rule`, "
     "`vendor_published`, `not_published`, `not_published_tapered_walls`"),
    ("internal_dims_vendors", "int64", "",
     "How many **vendors** publish internal dimensions for this footprint. Vendors, "
     "not listings — one mould in five colours is one opinion"),
    ("typical_capacity_l", "float64", "L", "**The usable number.** Always populated"),
    ("typical_capacity_gal", "float64", "US gal",
     "Usable capacity in US liquid gallons"),
    ("vendor_capacity_low_l", "float64", "L",
     "Capacity implied by the least generous vendor's own published internal "
     "dimensions for this footprint. Empty where no vendor publishes any"),
    ("vendor_capacity_high_l", "float64", "L",
     "As above, most generous vendor. See `guidance/internal-dimensions.md`"),
    ("usable_ratio", "float64", "",
     "`typical_capacity_l / external_volume_l`"),
    ("capacity_basis", "string", "",
     "How the capacity was arrived at: `derived_from_internal_dims`, "
     "`vendor_nominal`, `published`, `derived_from_klt_ratio`"),
    ("lidded", "bool", "", "True where a lid is integral to the product (ALCs)"),
    ("lid_available_separately", "bool", "",
     "True where a lid exists but is a separate purchase"),
    ("nestable_when_empty", "bool", "",
     "True for ALCs; straight-walled boxes stack but do not nest"),
    ("typical_nesting_ratio", "float64", "",
     "Fraction of its own height a nested empty box saves. 0.75 for ALCs, **0 for "
     "everything else** — that is a fact about a straight-walled box, not missing data"),
    ("standard_conformant", "bool", "",
     "Whether the footprint conforms to a recognised module"),
    ("standard", "string", "", "Which one, stated precisely"),
    ("vda_4500_height", "bool", "",
     "Whether the external height is on the VDA KLT grid (147.5 / 213 / 280 mm)"),
    ("eur1_pallet_per_layer", "int64", "",
     "Boxes per layer on a 1200 × 800 Euro pallet, no overhang. The one column that "
     "reaches past the box itself — see Scope"),
    ("listings_observed", "int64", "",
     "How many rows in the `listings` table back this size — 0 means the row is a "
     "plausible interpolation, not something seen for sale"),
    ("notes", "string", "", "Per-row caveats. Read these"),
]

LISTINGS = [
    ("listing_id", "string", "", "Stable slug, `<vendor>-<sku or handle>`"),
    ("vendor", "string", "",
     "Salesbridges · Plastic Box Shop · Yosibox · Hudson Exchange"),
    ("vendor_country", "string", "", "ISO 3166-1 alpha-2 of the vendor's market"),
    ("product_name", "string", "", "The vendor's own product title, verbatim"),
    ("sku", "string", "", "Vendor SKU where published, else empty"),
    ("url", "string", "", "The listing, as captured on `captured_date`"),
    ("type", "string", "", "Family, assigned by this project — not the vendor's word"),
    ("native_unit", "string", "",
     "`metric` or `imperial`: which unit the vendor's own catalogue publishes in, and "
     "therefore which dimension columns are the figure and which are the conversion. "
     "See `guidance/units-and-us-vendors.md`"),
    ("external_length_cm", "float64", "cm", "External length as listed or converted"),
    ("external_width_cm", "float64", "cm", "External width as listed or converted"),
    ("external_height_cm", "float64", "cm", "External height as listed or converted"),
    ("external_length_in", "float64", "in", "External length; the vendor's own figure where `native_unit` is `imperial`"),
    ("external_width_in", "float64", "in", "External width, same basis"),
    ("external_height_in", "float64", "in", "External height, same basis"),
    ("internal_length_cm", "float64", "cm",
     "Internal length **as the vendor publishes it**, empty where they do not. 95 of "
     "121 rows carry these; vendors measure at different heights on a tapered box, "
     "which is why the typical table's figures are conservative"),
    ("internal_width_cm", "float64", "cm", "Internal width as published"),
    ("internal_height_cm", "float64", "cm", "Internal height as published"),
    ("internal_length_in", "float64", "in", "Internal length in inches"),
    ("internal_width_in", "float64", "in", "Internal width in inches"),
    ("internal_height_in", "float64", "in", "Internal height in inches"),
    ("stated_capacity_l", "float64", "L",
     "The vendor's own capacity claim. Not recomputed — the point of this table is "
     "what they say"),
    ("stated_capacity_gal", "float64", "US gal",
     "The same in US gallons; the vendor's own figure for Hudson Exchange"),
    ("external_volume_l", "float64", "L", "L × W × H, computed here"),
    ("external_volume_gal", "float64", "US gal", "The same in US gallons"),
    ("usable_ratio", "float64", "",
     "`stated_capacity_l / external_volume_l` — what **this** vendor claims, not what "
     "the typical table concluded"),
    ("price", "float64", "",
     "As captured, in `currency`. An observation with a date on it, not a price feed"),
    ("currency", "string", "", "ISO 4217"),
    ("price_includes_vat", "bool", "",
     "Whether the captured price is VAT-inclusive. Differs by market — UK and NL "
     "retail inclusive, US exclusive"),
    ("pack_quantity", "int64", "",
     "Units in the pack the price refers to. Multipacks and pallet deals are common"),
    ("unit_price", "float64", "", "`price / pack_quantity`"),
    ("captured_date", "string", "", "ISO 8601 date the listing was read"),
    ("notes", "string", "", "Per-row caveats, including non-conforming footprints"),
]

TABLES = {
    "containers": ("containers.csv", CONTAINERS),
    "listings": ("listings.csv", LISTINGS),
}

DTYPES = {name: dtype for _, cols in TABLES.values() for name, dtype, _, _ in cols}


def check(table: str, fields: list[str]) -> None:
    """Fail the build if a builder's columns and this dictionary disagree."""
    _, cols = TABLES[table]
    documented = [c[0] for c in cols]
    if documented != list(fields):
        missing = [f for f in fields if f not in documented]
        extra = [f for f in documented if f not in fields]
        raise SystemExit(
            f"{table}: dictionary and CSV columns disagree.\n"
            f"  undocumented in dictionary.py: {missing or 'none'}\n"
            f"  documented but not emitted:    {extra or 'none'}\n"
            f"  (order matters too — CSV order is {list(fields)})"
        )