constructelligence commited on
Commit
5b8c6ad
·
verified ·
1 Parent(s): 98410e9

Data Centre Construction: rebrand + frontier-construction-AI positioning

Browse files
Files changed (4) hide show
  1. README.md +17 -8
  2. index.html +34 -14
  3. nameplate-model.js +309 -38
  4. nameplates-app.js +78 -13
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Data Centre Nameplates
3
  emoji: 🔌
4
  colorFrom: blue
5
  colorTo: indigo
@@ -9,14 +9,17 @@ license: apache-2.0
9
  short_description: Nameplate OCR checked against the equipment schedule
10
  ---
11
 
12
- # Data Centre Nameplates
 
 
 
13
 
14
  **Read an equipment nameplate and know if it is the unit the schedule asked for.**
15
 
16
- Photograph the nameplate of a UPS, PDU, switchgear, generator, transformer, busway, battery, CRAH or chiller. This
17
- runs OCR in your browser, pulls out the plate's fields — manufacturer, model, serial, voltage, phase, Hz, kVA, kW,
18
- amps, MCA, MOCP, refrigerant, manufacture date — and **checks each one against the equipment schedule**, flagging
19
- a mismatch instead of a silent pass. It builds an asset register and exports it to CSV.
20
 
21
  Nothing is uploaded: the photo and the schedule stay on your device.
22
 
@@ -26,12 +29,18 @@ Nothing is uploaded: the photo and the schedule stay on your device.
26
  2. Drop a nameplate photo (or click **Try a sample nameplate**).
27
  3. Click **Read nameplate** and check the verdict, field by field, against the plate.
28
 
 
 
29
  ## How it works
30
 
 
31
  - **OCR** — `tesseract.js@5` (English LSTM), loaded from a CDN, plus an error model for the way OCR misreads plate
32
  lettering (serifed `V`→`Vv`, `K`→`X` in `KVA`, `HZ`→`Hw`, codes split after their punctuation).
33
- - **Extraction** — labelled-field parsing of `MODEL`, `S/N`, `MVA`, `MCA`, `MOCP`, `FLA`, `VOLTS`, `REFRIGERANT`,
34
- `MFG DATE`, with voltages read as `480Y/277`, `13.8 kV` or `208/120`.
 
 
 
35
  - **Matching** — model and serial codes compared with `O/0`, `I/L/1`, `S/5`, `B/8`, `Z/2` folded, so a misread is
36
  not a false mismatch while a genuine voltage variant still fails.
37
 
 
1
  ---
2
+ title: Data Centre Construction
3
  emoji: 🔌
4
  colorFrom: blue
5
  colorTo: indigo
 
9
  short_description: Nameplate OCR checked against the equipment schedule
10
  ---
11
 
12
+ # Data Centre Construction
13
+
14
+ > **Constructelligence is developing frontier construction-AI models.** This demo is the *lite*, open tier
15
+ > of the Data Centre Construction kit (see [constructelligence.co](https://constructelligence.co)).
16
 
17
  **Read an equipment nameplate and know if it is the unit the schedule asked for.**
18
 
19
+ Photograph the nameplate of a UPS, PDU, switchgear, generator, transformer, busway, battery, CRAH, chiller — or a
20
+ **server rack**. This runs OCR in your browser, pulls out **31 plate fields** across **55 data-centre equipment
21
+ types**, and **checks each one against the equipment schedule**, flagging a mismatch instead of a silent pass. It
22
+ builds an asset register and exports it to CSV.
23
 
24
  Nothing is uploaded: the photo and the schedule stay on your device.
25
 
 
29
  2. Drop a nameplate photo (or click **Try a sample nameplate**).
30
  3. Click **Read nameplate** and check the verdict, field by field, against the plate.
31
 
32
+ Sample plates include a matching UPS, a wrong-voltage UPS, a switchboard, a server and a rack PDU.
33
+
34
  ## How it works
35
 
36
+ - **Photo check** — a quick blur/glare/darkness/resolution read warns before you rely on a bad shot.
37
  - **OCR** — `tesseract.js@5` (English LSTM), loaded from a CDN, plus an error model for the way OCR misreads plate
38
  lettering (serifed `V`→`Vv`, `K`→`X` in `KVA`, `HZ`→`Hw`, codes split after their punctuation).
39
+ - **Extraction** — labelled-field parsing with numeric range guards, grouped into Identification, Electrical,
40
+ Cooling, Server racks/IT and Mechanical. Fields include voltage, phase, Hz, kVA, kW, amps, power factor, MCA,
41
+ MOCP, SCCR, enclosure, listings, battery type/Ah/cells, refrigerant, charge, cooling tons, BTU/h, CFM, GPM,
42
+ rack U, power W, PDU outlets, ports, speed and weight.
43
+ - **Typing** — 55 equipment families, device wording ranked above its family (server racks included).
44
  - **Matching** — model and serial codes compared with `O/0`, `I/L/1`, `S/5`, `B/8`, `Z/2` folded, so a misread is
45
  not a false mismatch while a genuine voltage variant still fails.
46
 
index.html CHANGED
@@ -3,8 +3,8 @@
3
  <head>
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>Data Centre Nameplates — read &amp; verify equipment nameplates</title>
7
- <meta name="description" content="Photograph an equipment nameplate and read it in your browser: model, serial, voltage and rating checked against your equipment schedule, with an asset register CSV. Nothing is uploaded." />
8
  <meta name="robots" content="index, follow" />
9
  <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22><rect width=%2224%22 height=%2224%22 rx=%225%22 fill=%22%230f2547%22/><rect x=%225%22 y=%227%22 width=%2214%22 height=%2210%22 rx=%221.5%22 fill=%22none%22 stroke=%22white%22 stroke-width=%221.8%22/><path d=%22M8 11h8M8 14h5%22 stroke=%22white%22 stroke-width=%221.6%22/></svg>" />
10
  <meta name="theme-color" content="#0f2547" />
@@ -13,33 +13,35 @@
13
 
14
  <meta property="og:type" content="website" />
15
  <meta property="og:site_name" content="BuildVision" />
16
- <meta property="og:title" content="Nameplates — read &amp; verify equipment nameplates in the browser" />
17
  <meta property="og:description" content="Photograph a data centre equipment nameplate and read it in your browser: model, serial, voltage and rating checked against your equipment schedule, with an asset register CSV. Nothing is uploaded." />
18
  <meta property="og:image" content="og-nameplates.png" />
19
  <meta property="og:image:width" content="1200" />
20
  <meta property="og:image:height" content="630" />
21
- <meta property="og:image:alt" content="BuildVision Nameplates — read and verify data centre equipment nameplates against the equipment schedule" />
22
  <meta name="twitter:card" content="summary_large_image" />
23
- <meta name="twitter:title" content="Nameplates — read &amp; verify equipment nameplates in the browser" />
24
  <meta name="twitter:description" content="Photograph a UPS, PDU, switchgear or chiller nameplate and check model, serial, voltage and rating against the equipment schedule. Runs in your browser; nothing is uploaded." />
25
  <meta name="twitter:image" content="og-nameplates.png" />
26
- <meta name="twitter:image:alt" content="BuildVision Nameplates — equipment-nameplate OCR checked against the equipment schedule" />
27
 
28
  <script type="application/ld+json">
29
  {
30
  "@context": "https://schema.org",
31
  "@type": "WebApplication",
32
- "name": "BuildVision Nameplates",
33
- "description": "Browser tool that reads an equipment nameplate (UPS, PDU, switchgear, generator, transformer, battery, CRAH, chiller) with in-browser OCR and checks model, serial, voltage, phase, Hz, kVA, kW, amps, MCA, MOCP and refrigerant against the equipment schedule, then exports an asset register CSV. Photos never leave the device.",
34
  "applicationCategory": "BusinessApplication",
35
  "operatingSystem": "Any (runs in a modern web browser)",
36
  "offers": { "@type": "Offer", "price": "0", "priceCurrency": "USD" },
37
  "featureList": [
38
  "On-device nameplate OCR (nothing uploaded)",
39
- "13 equipment types: UPS, generator, ATS, switchgear, transformer, PDU, panelboard, busway, battery, CDU, chiller, CRAH/CRAC, pump",
40
- "Field-by-field check against the equipment schedule",
41
- "Flags wrong voltage, rating or model instead of a silent pass",
42
- "Asset register with duplicate-serial and missing-tag detection, exported as CSV"
 
 
43
  ]
44
  }
45
  </script>
@@ -74,6 +76,13 @@
74
  .np-fields label { color: var(--text-dim); font-weight: 600; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
75
  .np-fields input, .np-fields select, .np-tag select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 16px; background: var(--bg); color: var(--text); min-width: 0; }
76
  .np-fields input.low { border-color: var(--warning, #c98a00); background: color-mix(in srgb, var(--warning, #c98a00) 8%, var(--bg)); }
 
 
 
 
 
 
 
77
  .np-key { display: inline-block; width: 9px; height: 9px; border-radius: 2px; flex: none; }
78
  .np-tag { display: flex; flex-direction: column; gap: 6px; font-size: 0.84rem; font-weight: 600; }
79
  .np-checks { list-style: none; margin: 0; padding: 0; font-size: 0.84rem; display: flex; flex-direction: column; gap: 4px; }
@@ -125,7 +134,7 @@
125
  <nav class="mode-switch" aria-label="Page">
126
  <a class="mode-link" href="https://huggingface.co/constructelligence/data-centre-nameplates" target="_blank" rel="noopener">Model card</a>
127
  <a class="mode-link" href="https://constructelligence.co" target="_blank" rel="noopener">constructelligence.co</a>
128
- <span class="mode-link active" aria-current="page">Nameplates</span>
129
  </nav>
130
  <div class="header-status"><span id="npModel" class="status-pill model-status">OCR idle</span></div>
131
  </header>
@@ -143,7 +152,7 @@
143
  <button id="npSchedClear" class="np-btn link" type="button" hidden>Remove</button>
144
  </div>
145
  <p id="npSchedStatus" class="np-status" style="margin-top:8px" aria-live="polite"></p>
146
- <p style="margin-top:6px">Optional. Needs a Tag or Model column; Manufacturer, Voltage, Phase, kVA, kW, Amps, Refrigerant, Serial and Location are checked when present.</p>
147
  </section>
148
  <section>
149
  <h2>2. Nameplate photo</h2>
@@ -156,6 +165,7 @@
156
  <button id="npRotate" class="np-btn" type="button" disabled title="Rotate the photo 90°">Rotate</button>
157
  </div>
158
  <p style="margin-top:8px">Fill the frame with the plate, without glare across the text. Tilted shots are straightened automatically. Pick several photos at once to read a whole walk into the register, then click a row to review it.</p>
 
159
  </section>
160
  <section>
161
  <button id="npRun" class="np-btn primary" type="button" disabled>Read nameplate</button>
@@ -192,6 +202,16 @@
192
  <div class="np-register">
193
  <h2>Asset register</h2>
194
  <div id="npSummary" class="np-summary"></div>
 
 
 
 
 
 
 
 
 
 
195
  <div class="np-row" style="margin-bottom:10px">
196
  <button id="npCsv" class="np-btn" type="button" disabled>Download register CSV</button>
197
  <button id="npClearReg" class="np-btn link" type="button" disabled>Clear register</button>
 
3
  <head>
4
  <meta charset="UTF-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Data Centre Construction — read &amp; verify equipment nameplates</title>
7
+ <meta name="description" content="Photograph an equipment nameplate and read it in your browser: model, serial, voltage and ratings checked against your equipment schedule, with an asset register CSV. Covers UPS, PDU, switchgear, generators, transformers, battery, cooling towers, chillers, CRAH, CDUs, pumps and more. Nothing is uploaded." />
8
  <meta name="robots" content="index, follow" />
9
  <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22><rect width=%2224%22 height=%2224%22 rx=%225%22 fill=%22%230f2547%22/><rect x=%225%22 y=%227%22 width=%2214%22 height=%2210%22 rx=%221.5%22 fill=%22none%22 stroke=%22white%22 stroke-width=%221.8%22/><path d=%22M8 11h8M8 14h5%22 stroke=%22white%22 stroke-width=%221.6%22/></svg>" />
10
  <meta name="theme-color" content="#0f2547" />
 
13
 
14
  <meta property="og:type" content="website" />
15
  <meta property="og:site_name" content="BuildVision" />
16
+ <meta property="og:title" content="Data Centre Construction — read &amp; verify equipment nameplates in the browser" />
17
  <meta property="og:description" content="Photograph a data centre equipment nameplate and read it in your browser: model, serial, voltage and rating checked against your equipment schedule, with an asset register CSV. Nothing is uploaded." />
18
  <meta property="og:image" content="og-nameplates.png" />
19
  <meta property="og:image:width" content="1200" />
20
  <meta property="og:image:height" content="630" />
21
+ <meta property="og:image:alt" content="BuildVision Data Centre Construction — read and verify data centre equipment nameplates against the equipment schedule" />
22
  <meta name="twitter:card" content="summary_large_image" />
23
+ <meta name="twitter:title" content="Data Centre Construction — read &amp; verify equipment nameplates in the browser" />
24
  <meta name="twitter:description" content="Photograph a UPS, PDU, switchgear or chiller nameplate and check model, serial, voltage and rating against the equipment schedule. Runs in your browser; nothing is uploaded." />
25
  <meta name="twitter:image" content="og-nameplates.png" />
26
+ <meta name="twitter:image:alt" content="BuildVision Data Centre Construction — equipment-nameplate OCR checked against the equipment schedule" />
27
 
28
  <script type="application/ld+json">
29
  {
30
  "@context": "https://schema.org",
31
  "@type": "WebApplication",
32
+ "name": "BuildVision Data Centre Construction",
33
+ "description": "Browser tool that reads an equipment nameplate (UPS, PDU, switchgear, generator, transformer, battery, cooling tower, chiller, CDU, CRAH, pump and more) with in-browser OCR and checks model, serial, voltage, phase, Hz, kVA, kW, amps, power factor, MCA, MOCP, SCCR, enclosure, listings, battery type/amp-hours/cells, refrigerant, charge, cooling, airflow, flow, speed and weight against the equipment schedule, then exports an asset register CSV. Photos never leave the device.",
34
  "applicationCategory": "BusinessApplication",
35
  "operatingSystem": "Any (runs in a modern web browser)",
36
  "offers": { "@type": "Offer", "price": "0", "priceCurrency": "USD" },
37
  "featureList": [
38
  "On-device nameplate OCR (nothing uploaded)",
39
+ "55 data centre equipment types: UPS, flywheel, ATS/STS, rectifier, inverter, BESS, generator, paralleling gear, fuel, nitrogen, switchgear, MCC, metering, protective relays, transformer and DGA monitors, SPD, capacitor, VFD, busway, panelboard, PDU, battery, load bank, cooling tower, chiller, dry cooler, CDU, CRAH/CRAC, AHU, heat pump, heat exchanger, pump, expansion tank, air separator, boiler, humidifier, water treatment, compressor, fan coil, RTU, makeup air, thermal storage, fire suppression, fire alarm, leak detection, BMS, KVM, rack, server, network and more",
40
+ "Field-by-field check against the equipment schedule, grouped into identification, electrical, cooling, server racks/IT and mechanical",
41
+ "Server-rack subsection: rack U and form factor, power and static/dynamic load, PDU outlet mix, network ports and link speed for servers, rack PDUs, switches and in-row cooling",
42
+ "Flags wrong voltage, rating, power factor, SCCR, battery type, listings or model instead of a silent pass",
43
+ "Advisory photo check: warns on blur, glare, dark or low-resolution shots before you rely on the read",
44
+ "Asset register with search, status filter, duplicate-serial and missing-tag detection, exported as CSV"
45
  ]
46
  }
47
  </script>
 
76
  .np-fields label { color: var(--text-dim); font-weight: 600; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
77
  .np-fields input, .np-fields select, .np-tag select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 16px; background: var(--bg); color: var(--text); min-width: 0; }
78
  .np-fields input.low { border-color: var(--warning, #c98a00); background: color-mix(in srgb, var(--warning, #c98a00) 8%, var(--bg)); }
79
+ .np-fields .np-group { grid-column: 1 / -1; margin: 8px 0 0; padding-top: 6px; border-top: 1px solid var(--border); font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
80
+ .np-fields .np-group:first-of-type { margin-top: 0; padding-top: 0; border-top: none; }
81
+ .np-quality { font-size: 0.8rem; color: var(--text-dim); min-height: 1.1em; margin: 8px 0 0; }
82
+ .np-quality.warn { color: var(--warning, #c98a00); }
83
+ .np-filter { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
84
+ .np-filter input, .np-filter select { padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.84rem; background: var(--bg); color: var(--text); }
85
+ .np-filter input { flex: 1; min-width: 140px; }
86
  .np-key { display: inline-block; width: 9px; height: 9px; border-radius: 2px; flex: none; }
87
  .np-tag { display: flex; flex-direction: column; gap: 6px; font-size: 0.84rem; font-weight: 600; }
88
  .np-checks { list-style: none; margin: 0; padding: 0; font-size: 0.84rem; display: flex; flex-direction: column; gap: 4px; }
 
134
  <nav class="mode-switch" aria-label="Page">
135
  <a class="mode-link" href="https://huggingface.co/constructelligence/data-centre-nameplates" target="_blank" rel="noopener">Model card</a>
136
  <a class="mode-link" href="https://constructelligence.co" target="_blank" rel="noopener">constructelligence.co</a>
137
+ <span class="mode-link active" aria-current="page">Data Centre Construction</span>
138
  </nav>
139
  <div class="header-status"><span id="npModel" class="status-pill model-status">OCR idle</span></div>
140
  </header>
 
152
  <button id="npSchedClear" class="np-btn link" type="button" hidden>Remove</button>
153
  </div>
154
  <p id="npSchedStatus" class="np-status" style="margin-top:8px" aria-live="polite"></p>
155
+ <p style="margin-top:6px">Optional. Needs a Tag or Model column; Manufacturer, Voltage, Phase, kVA, kW, Amps, Power factor, MCA, MOCP, SCCR, Enclosure, Listings, Battery type, Battery Ah, Cells, Rack U, Form factor, Power, Rack load, Outlet mix, Outlets, Port speed, Ports, Refrigerant, Charge, Cooling, Airflow, Flow, Speed, Weight, Serial and Location are checked when present.</p>
156
  </section>
157
  <section>
158
  <h2>2. Nameplate photo</h2>
 
165
  <button id="npRotate" class="np-btn" type="button" disabled title="Rotate the photo 90°">Rotate</button>
166
  </div>
167
  <p style="margin-top:8px">Fill the frame with the plate, without glare across the text. Tilted shots are straightened automatically. Pick several photos at once to read a whole walk into the register, then click a row to review it.</p>
168
+ <p id="npQuality" class="np-quality" role="status" aria-live="polite"></p>
169
  </section>
170
  <section>
171
  <button id="npRun" class="np-btn primary" type="button" disabled>Read nameplate</button>
 
202
  <div class="np-register">
203
  <h2>Asset register</h2>
204
  <div id="npSummary" class="np-summary"></div>
205
+ <div class="np-filter">
206
+ <input id="npSearch" type="search" placeholder="Search tag, model, serial or maker…" aria-label="Search the register" autocomplete="off" />
207
+ <select id="npFilter" aria-label="Filter the register by status">
208
+ <option value="all">All statuses</option>
209
+ <option value="verified">Verified</option>
210
+ <option value="partial">Matched, fields unread</option>
211
+ <option value="mismatch">Does not match</option>
212
+ <option value="unmatched">Not on schedule</option>
213
+ </select>
214
+ </div>
215
  <div class="np-row" style="margin-bottom:10px">
216
  <button id="npCsv" class="np-btn" type="button" disabled>Download register CSV</button>
217
  <button id="npClearReg" class="np-btn link" type="button" disabled>Clear register</button>
nameplate-model.js CHANGED
@@ -11,41 +11,133 @@
11
  import { parseCsv } from './schedule-import.js';
12
 
13
  export const FIELDS = [
14
- ['manufacturer', 'Manufacturer'], ['model', 'Model'], ['serial', 'Serial'], ['voltage', 'Voltage'],
15
- ['phase', 'Phase'], ['hz', 'Hz'], ['kva', 'kVA'], ['kw', 'kW'], ['amps', 'Amps'], ['mca', 'MCA'], ['mocp', 'MOCP'],
16
- ['refrigerant', 'Refrigerant'], ['mfgDate', 'Mfg date'],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ];
18
 
 
 
 
 
 
 
 
 
19
  export const EQUIPMENT_TYPES = [
 
 
20
  ['ups', 'UPS', /\bUPS\b|UNINTERRUPTIBLE/],
21
- ['generator', 'Generator', /GENERATOR|GENSET|\bEKW\b|STANDBY POWER|PRIME POWER/],
22
- ['ats', 'Transfer switch', /TRANSFER SWITCH|\bATS\b|\bSTS\b/],
23
- ['switchgear', 'Switchgear / switchboard', /SWITCHGEAR|SWITCHBOARD/],
24
- ['transformer', 'Transformer', /TRANSFORMER|\bXFMR\b|PRIMARY.*SECONDARY/],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ['pdu', 'PDU / RPP', /POWER DISTRIBUTION UNIT|\bPDU\b|\bRPP\b|REMOTE POWER PANEL/],
26
- ['panelboard', 'Panelboard', /PANELBOARD/],
27
- ['busway', 'Busway', /BUSWAY|BUS PLUG|BUS DUCT/],
28
- ['battery', 'Battery cabinet', /BATTERY|\bVRLA\b|LITHIUM/],
29
- ['cdu', 'Coolant distribution unit', /COOLANT DISTRIBUTION|\bCDU\b/],
30
- ['chiller', 'Chiller', /CHILLER/],
31
- ['crah', 'CRAH / CRAC', /\bCRAH\b|\bCRAC\b|COMPUTER ROOM AIR|AIR HANDL/],
32
  ['pump', 'Pump', /\bPUMP\b/],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  ];
34
 
35
- // Makers common on data centre electrical and cooling packages. Matched as
36
- // whole words; anything else falls back to a line that reads like a company.
 
37
  const MAKERS = [
38
  'Schneider Electric', 'Square D', 'APC', 'Eaton', 'ABB', 'Siemens', 'Vertiv', 'Liebert', 'Caterpillar', 'Cummins',
39
- 'Kohler', 'Rolls-Royce', 'MTU', 'Generac', 'Trane', 'Carrier', 'Daikin', 'York', 'Johnson Controls', 'Stulz',
40
- 'Munters', 'nVent', 'Legrand', 'Mitsubishi Electric', 'Toshiba', 'General Electric', 'Hubbell', 'Socomec', 'Piller',
41
- 'Starline', 'Raritan', 'Server Technology', 'Emerson', 'Russelectric', 'ASCO', 'Hitachi', 'Riello',
42
- 'Rittal', 'Motivair', 'CoolIT', 'Hitec', 'EnerSys', 'Leclanché', 'Samsung SDI',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  ];
44
- const COMPANY_LINE = /\b(INC|CORP|CORPORATION|LTD|LLC|GMBH|CO\.|COMPANY|SYSTEMS|ELECTRIC|POWER|TECHNOLOGIES|INDUSTRIES)\b/;
45
 
46
  const NUM = '(\\d{1,5}(?:[.,]\\d+)?)';
47
  // "1,002" is a thousands separator on a US plate; "2,5" is a European decimal.
48
  const num = s => (s == null ? null : parseFloat(/^\d{1,3},\d{3}$/.test(String(s)) ? String(s).replace(',', '') : String(s).replace(',', '.')));
 
 
 
49
 
50
  /**
51
  * Nameplate fields from OCR output: a string, or lines as [{ text, confidence }]
@@ -71,11 +163,11 @@ export function parseNameplate(input) {
71
  const CODE = '([A-Z0-9][A-Z0-9\\-\\/\\.]{2,})';
72
  scan('model', new RegExp(`(?:\\bMODEL\\b|\\bMOD\\.|\\bM\\/N\\b|\\bCAT(?:ALOG)?\\.?\\s*(?:NO\\b\\.?|#|NUMBER)|\\bP\\/N\\b|\\bPART\\s*(?:NO\\b\\.?|#|NUMBER))\\s*(?:NO\\b\\.?|NUMBER\\b|#)?\\s*[:#.]?\\s*${CODE}`), m => cleanCode(m[1]));
73
  scan('serial', new RegExp(`(?:\\bSERIAL\\b|\\bSER\\.|\\bS\\/N\\b|\\b5\\/N\\b|\\bSN\\b)\\s*(?:NO\\b\\.?|NUMBER\\b|#)?\\s*[:#.]?\\s*([A-Z0-9][A-Z0-9\\-]{3,})`), m => cleanCode(m[1]));
74
- scan('refrigerant', /\bR[-\s]?(410A|134A|1234ZE|1234YF|513A|514A|1233ZD|454B|407C|32|22)\b/, m => `R-${m[1]}`);
75
  scan('hz', /\b(50|60)\s*HZ\b|\bHZ\s*[:]?\s*(50|60)\b|\bFREQ(?:UENCY)?\.?\s*[:]?\s*(50|60)\b/, m => +(m[1] || m[2] || m[3]));
76
  scan('phase', /\b([13])\s*-?\s*(?:PH|PHASE|Ø|Φ)\b|\bPH(?:ASE)?\s*[:]?\s*([13])\b/, m => +(m[1] || m[2]));
77
- scan('kva', new RegExp(`${NUM}\\s*KVA\\b|\\bKVA\\s*[:]?\\s*${NUM}`), m => num(m[1] || m[2]));
78
- scan('kw', new RegExp(`${NUM}\\s*E?KW\\b|\\bE?KW\\s*[:]?\\s*${NUM}`), m => num(m[1] || m[2]));
79
  scan('mfgDate', /\b(?:MFG\.?|MANUFACTURED|MFD\.?|BUILD|PROD(?:UCTION)?\.?)\s*(?:DATE)?\s*[:]?\s*(\d{1,2}[/-]\d{2,4}|\d{4}[/-]\d{1,2}(?:[/-]\d{1,2})?|\d{1,2}[/-]\d{1,2}[/-]\d{2,4})/, m => m[1]);
80
 
81
  // Voltage: every voltage on the plate (a transformer or UPS carries more than one).
@@ -91,24 +183,74 @@ export function parseNameplate(input) {
91
  if (volts.length) fields.voltage = { value: voltLine.text, conf: voltLine.conf, line: voltLine.line, values: volts };
92
 
93
  // Amps: a labelled rated current first, then any bare "1002 A". Refrigerants (R-410A) are not amps.
94
- scan('amps', new RegExp(`(?:\\bFLA\\b|\\bRLA\\b|\\bCURRENT\\b|\\bAMPS?\\b|\\bAMPERES\\b)\\s*[:]?\\s*${NUM}`), m => num(m[1]));
95
- if (!fields.amps) scan('amps', new RegExp(`(?<![-\\d.R])${NUM}\\s*(?:A|AMPS?)\\b`), m => num(m[1]));
96
- scan('mca', new RegExp(`\\bMCA\\b\\s*[:]?\\s*${NUM}`), m => num(m[1]));
97
- scan('mocp', new RegExp(`(?:\\bMOCP\\b|\\bMAX\\.?\\s*(?:FUSE|BREAKER|OCP))\\s*(?:SIZE)?\\s*[:]?\\s*${NUM}`), m => num(m[1]));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  // Manufacturer: a known maker anywhere, else a line that reads like a company name.
 
100
  for (const [i, l] of lines.entries()) {
101
  // "New York" on a supplier's address is not York the maker.
102
  const t = up(l.text).replace(/NEW YORK/g, '');
103
  const maker = MAKERS.find(mk => new RegExp(`\\b${escapeRe(up(mk))}\\b`).test(t));
104
- if (maker) { set('manufacturer', maker, l.conf, i); break; }
105
  }
106
  if (!fields.manufacturer) {
107
  const i = lines.findIndex(x => COMPANY_LINE.test(up(x.text)) && !/\d{3}/.test(x.text) && x.text.length <= 48);
108
- if (i >= 0) set('manufacturer', titleCase(lines[i].text.replace(/[^A-Za-z0-9&.,\- ]/g, '').trim()), lines[i].conf, i);
109
  }
110
 
111
- const all = up(lines.map(l => l.text).join('\n'));
 
 
112
  const type = (EQUIPMENT_TYPES.find(([, , re]) => re.test(all)) || [null])[0];
113
  const conf = lines.length ? Math.round(lines.reduce((s, l) => s + l.conf, 0) / lines.length) : 0;
114
  return { fields, type, conf, text: lines.map(l => l.text).join('\n'), lines: lines.map(l => ({ text: l.text, conf: l.conf, bbox: l.bbox })) };
@@ -174,9 +316,31 @@ const HEADERS = {
174
  kva: /^(kva|rating \(kva\)|kva rating|capacity \(kva\))$/i,
175
  kw: /^(kw|ekw|rating \(kw\)|kw rating|capacity \(kw\))$/i,
176
  amps: /^(amps|a|amperage|fla|rated current|current)$/i,
 
177
  mca: /^(mca|min\.? circuit amp(s|acity)?|minimum circuit ampacity)$/i,
178
  mocp: /^(mocp|max\.? (fuse|breaker|ocp)( size)?|maximum overcurrent protection)$/i,
 
 
 
 
179
  refrigerant: /^(refrigerant|ref\.?)$/i,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  location: /^(location|room|area|level|space|served from|zone)$/i,
181
  };
182
 
@@ -197,7 +361,15 @@ export function parseEquipmentSchedule(text) {
197
  else items.push({
198
  tag, type: get('type'), manufacturer: get('manufacturer'), model: get('model'), serial: get('serial'),
199
  voltage: get('voltage'), phase: num(get('phase').match(/[13]/)?.[0]), kva: num(get('kva')) || null, kw: num(get('kw')) || null,
200
- amps: num(get('amps')) || null, mca: num(get('mca')) || null, mocp: num(get('mocp')) || null, refrigerant: get('refrigerant'), location: get('location'),
 
 
 
 
 
 
 
 
201
  });
202
  });
203
  if (!items.length) problems.push('The header was found but no equipment rows under it.');
@@ -251,12 +423,23 @@ export function candidatesFor(reading, items, register = []) {
251
  const mk = item.manufacturer && f.manufacturer?.value ? (sameMaker(item.manufacturer, f.manufacturer.value) ? 1 : 0) : 0.5;
252
  const ty = reading.type && item.type ? (typeOf(item.type) === reading.type ? 1 : 0) : 0.5;
253
  score = 0.7 * m + 0.15 * mk + 0.15 * ty;
 
 
 
254
  }
255
  if (score >= 0.5) out.push({ item, score: Math.round(score * 100) / 100, registered: taken.has(item.tag) });
256
  }
257
  return out.sort((a, b) => (b.score - a.score) || (a.registered - b.registered));
258
  }
259
 
 
 
 
 
 
 
 
 
260
  /** Equipment type key for free text such as a schedule's description column. */
261
  export function typeOf(text) {
262
  const s = up(text);
@@ -284,13 +467,33 @@ export function checkAgainst(reading, item) {
284
  push('voltage', item.voltage, f.voltage?.value, want.length > 0 && want.every(v => have.includes(v)));
285
  }
286
  if (item.phase) push('phase', item.phase, f.phase?.value, +item.phase === +f.phase?.value);
287
- for (const k of ['kva', 'kw', 'amps', 'mca', 'mocp']) {
 
288
  if (item[k]) push(k, item[k], f[k]?.value, Math.abs(+f[k]?.value - item[k]) <= Math.max(0.5, item[k] * 0.01));
289
  }
 
 
 
 
 
290
  if (item.refrigerant) push('refrigerant', item.refrigerant, f.refrigerant?.value, up(item.refrigerant).replace(/[^A-Z0-9]/g, '') === up(f.refrigerant?.value).replace(/[^A-Z0-9]/g, ''));
291
  return out;
292
  }
293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  /** Overall status of a register entry: matched and clean, matched with a problem, or not on the schedule. */
295
  export function statusOf(checks, tag) {
296
  if (!tag) return 'unmatched';
@@ -329,7 +532,11 @@ export function registerSummary(register, items = []) {
329
 
330
  /** Asset register CSV: one row per scanned plate, then every scheduled tag not scanned yet. */
331
  export function registerCsv(register, items = []) {
332
- const head = ['Tag', 'Status', 'Type', 'Location', 'Manufacturer', 'Model', 'Serial', 'Voltage', 'Phase', 'Hz', 'kVA', 'kW', 'Amps', 'MCA', 'MOCP', 'Refrigerant', 'Mfg date', 'Issues', 'Scanned'];
 
 
 
 
333
  const byTag = new Map(items.map(i => [i.tag, i]));
334
  const typeLabel = k => (EQUIPMENT_TYPES.find(t => t[0] === k) || [])[1] || '';
335
  const dups = new Set(duplicateSerials(register).flat());
@@ -339,14 +546,20 @@ export function registerCsv(register, items = []) {
339
  const issues = (r.checks || []).filter(c => c.status === 'mismatch').map(c => `${c.label}: schedule ${c.expected}, plate ${c.found}`);
340
  if (dups.has(r.id)) issues.push('Serial also on another scanned plate');
341
  return [r.tag || '', STATUS_LABELS[r.status] || r.status, typeLabel(r.type), byTag.get(r.tag)?.location || '',
342
- v('manufacturer'), v('model'), v('serial'), v('voltage'), v('phase'), v('hz'), v('kva'), v('kw'), v('amps'),
343
- v('mca'), v('mocp'), v('refrigerant'), v('mfgDate'), issues.join('; '), r.scannedAt ? new Date(r.scannedAt).toISOString().slice(0, 16).replace('T', ' ') : ''];
 
 
344
  });
345
  const tags = new Set(register.map(r => r.tag));
346
  for (const i of items) {
347
  if (tags.has(i.tag)) continue;
348
- rows.push([i.tag, STATUS_LABELS.missing, i.type, i.location, i.manufacturer, i.model, i.serial, i.voltage, i.phase ?? '', '',
349
- i.kva ?? '', i.kw ?? '', i.amps ?? '', i.mca ?? '', i.mocp ?? '', i.refrigerant, '', '', '']);
 
 
 
 
350
  }
351
  return [head, ...rows].map(r => r.map(csvCell).join(',')).join('\n') + '\n';
352
  }
@@ -368,12 +581,29 @@ CRAH-1-01,Computer room air handler,Coldline Systems,CW-150-480,480,3,,,45,60,,D
368
  CH-01,Air-cooled chiller,Coldline Systems,AC-1200,460,3,,,612,800,R-513A,Roof
369
  `;
370
 
371
- /** Text of the two sample plates: one that matches UPS-1A, one delivered at the wrong voltage. */
372
  export const SAMPLE_PLATES = [
373
  ['NORTHLINE POWER SYSTEMS', 'UNINTERRUPTIBLE POWER SUPPLY', 'MODEL NO: NPX-750-480', 'SERIAL NO: NL26A01937',
374
  'INPUT: 480Y/277 VAC 3 PH 60 HZ', 'RATING: 750 KVA / 675 KW', 'INPUT CURRENT: 1002 A', 'MFG DATE: 03/2026'],
375
  ['NORTHLINE POWER SYSTEMS', 'UNINTERRUPTIBLE POWER SUPPLY', 'MODEL NO: NPX-750-415', 'SERIAL NO: NL26A02210',
376
  'INPUT: 415Y/240 VAC 3 PH 50 HZ', 'RATING: 750 KVA / 675 KW', 'INPUT CURRENT: 1160 A', 'MFG DATE: 04/2026'],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  ];
378
 
379
  // ------------------------------------------------------------------ helpers
@@ -382,6 +612,47 @@ function up(s) { return String(s ?? '').toUpperCase(); }
382
  function escapeRe(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }
383
  function cleanCode(s) { return s.replace(/[.\-/]+$/, ''); }
384
  function titleCase(s) { return s.toLowerCase().replace(/\b[a-z]/g, c => c.toUpperCase()); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  function csvCell(v) { const s = String(v ?? ''); return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s; }
386
 
387
  export function levenshtein(a, b) {
 
11
  import { parseCsv } from './schedule-import.js';
12
 
13
  export const FIELDS = [
14
+ // Identification.
15
+ ['manufacturer', 'Manufacturer', 'id'], ['model', 'Model', 'id'], ['serial', 'Serial', 'id'], ['mfgDate', 'Mfg date', 'id'],
16
+ // Electrical.
17
+ ['voltage', 'Voltage', 'electrical'], ['phase', 'Phase', 'electrical'], ['hz', 'Hz', 'electrical'],
18
+ ['kva', 'kVA', 'electrical'], ['kw', 'kW', 'electrical'], ['amps', 'Amps', 'electrical'], ['pf', 'Power factor', 'electrical'],
19
+ ['mca', 'MCA', 'electrical'], ['mocp', 'MOCP', 'electrical'], ['sccr', 'SCCR (kA)', 'electrical'],
20
+ ['enclosure', 'Enclosure', 'electrical'], ['standards', 'Listings', 'electrical'], ['batteryType', 'Battery type', 'electrical'],
21
+ ['batteryAh', 'Battery Ah', 'electrical'], ['cells', 'Battery cells', 'electrical'],
22
+ // Cooling.
23
+ ['refrigerant', 'Refrigerant', 'cooling'], ['charge', 'Refrigerant charge', 'cooling'], ['tons', 'Cooling (tons)', 'cooling'],
24
+ ['btu', 'Cooling (BTU/h)', 'cooling'], ['cfm', 'Airflow (CFM)', 'cooling'], ['gpm', 'Flow (GPM)', 'cooling'],
25
+ // Server racks and IT.
26
+ ['uHeight', 'Rack U', 'rack'], ['formFactor', 'Form factor', 'rack'],
27
+ ['powerW', 'Power (W)', 'rack'], ['rackLoad', 'Rack load (kg)', 'rack'],
28
+ ['outletTypes', 'Outlet mix', 'rack'], ['outlets', 'PDU outlets', 'rack'],
29
+ ['portSpeed', 'Port speed (GbE)', 'rack'], ['ports', 'Ports', 'rack'],
30
+ // Mechanical.
31
+ ['rpm', 'Speed (RPM)', 'mechanical'], ['weight', 'Weight (kg)', 'mechanical'],
32
  ];
33
 
34
+ // Field groups for the reading panel; keys match the third element of FIELDS.
35
+ export const FIELD_GROUPS = [['id', 'Identification'], ['electrical', 'Electrical'], ['cooling', 'Cooling'], ['rack', 'Server racks / IT'], ['mechanical', 'Mechanical']];
36
+
37
+ // Data centre equipment types. Order is the whole game: the first pattern that
38
+ // matches a plate wins, so device-specific wording comes before the families it
39
+ // belongs to (flywheel before UPS, paralleling gear before generator, heat pump
40
+ // and pumps before the cooling families, metering before transformer, controls
41
+ // before racks).
42
  export const EQUIPMENT_TYPES = [
43
+ // Power conversion and transfer.
44
+ ['flywheel', 'Flywheel UPS', /FLYWHEEL/],
45
  ['ups', 'UPS', /\bUPS\b|UNINTERRUPTIBLE/],
46
+ ['sts', 'Static transfer switch', /STATIC TRANSFER|STATIC BYPASS|\bSTS\b|RACK[-\s]?ATS/],
47
+ ['ats', 'Automatic transfer switch', /TRANSFER SWITCH|\bATS\b|\bATSE\b/],
48
+ ['rectifier', 'Rectifier / DC power', /RECTIFIER|BATTERY CHARGER|DC POWER SYSTEM/],
49
+ ['inverter', 'Inverter', /\bINVERTER\b|POWER CONVERSION SYSTEM/],
50
+ ['bess', 'Battery energy storage', /BATTERY ENERGY STORAGE|\bBESS\b|ENERGY STORAGE/],
51
+ // Prime power and distribution.
52
+ ['nitrogen', 'Nitrogen generator', /NITROGEN GENERATOR|\bN2\s?GENERATOR\b/],
53
+ ['paralleling', 'Paralleling gear', /PARALLELING|GENERATOR CONTROL|SYNCHRONIS|BUS TIE/],
54
+ ['generator', 'Generator', /GENERATOR|GENSET|\bEKW\b|STANDBY POWER|PRIME POWER|DIESEL ENGINE/],
55
+ ['fueltank', 'Fuel system', /FUEL TANK|DAY TANK|DIESEL TANK|FUEL OIL|FUEL POLISH|BULK FUEL/],
56
+ ['switchgear', 'Switchgear / switchboard', /SWITCHGEAR|SWITCHBOARD|DISTRIBUTION BOARD|\bMDP\b|MAIN DISTRIBUTION/],
57
+ ['mcc', 'Motor control centre', /MOTOR CONTROL|\bMCC\b/],
58
+ ['metering', 'Metering / CT cabinet', /METERING|POWER METER|KWH METER|ELECTRIC METER|CT CABINET/],
59
+ ['relay', 'Protective relay', /PROTECTIVE RELAY|PROTECTION RELAY|FEEDER RELAY|POWER SYSTEM RELAY|\bANSI\s?(?:50|51|27|59|81|87)\b/],
60
+ ['tmonitor', 'Transformer / DGA monitor', /TRANSFORMER MONITOR|DISSOLVED GAS|\bDGA\b|TRANSFORMER MONITORING/],
61
+ ['transformer', 'Transformer', /TRANSFORMER|\bXFMR\b|PRIMARY.*SECONDARY|DRY TYPE|ISOLATION TRANSFORMER|K[-\s]?RATED/],
62
+ ['spd', 'Surge protection', /SURGE PROTECT|\bSPD\b|\bTVSS\b|TRANSIENT VOLTAGE/],
63
+ ['capacitor', 'Power factor / filter', /CAPACITOR|POWER FACTOR|HARMONIC FILTER|\bPFC\b/],
64
+ ['ngr', 'Neutral grounding resistor', /NEUTRAL GROUNDING|GROUNDING RESISTOR|\bNGR\b/],
65
+ ['vfd', 'Variable frequency drive', /VARIABLE FREQUENCY|VARIABLE SPEED|\bVFD\b|\bVSD\b|\bAFD\b/],
66
+ ['busway', 'Busway', /BUSWAY|BUS PLUG|BUS DUCT|ISOLATED PHASE BUS|PHASE BUS/],
67
+ ['panelboard', 'Panelboard', /PANELBOARD|PANEL BOARD|LOAD CENTER/],
68
  ['pdu', 'PDU / RPP', /POWER DISTRIBUTION UNIT|\bPDU\b|\bRPP\b|REMOTE POWER PANEL/],
69
+ ['battery', 'Battery / battery cabinet', /\bBATTERY\b|VRLA|LITHIUM|LEAD ACID/],
70
+ ['loadbank', 'Load bank', /LOAD BANK|LOADBANK|RESISTIVE LOAD/],
71
+ // Pumps come before the cooling families: a "condenser water pump" or a
72
+ // "chilled water pump" is a pump, not the machine it serves; "heat pump" is
73
+ // matched first so the compressor word inside it does not win.
74
+ ['heatpump', 'Heat pump', /HEAT PUMP/],
75
  ['pump', 'Pump', /\bPUMP\b/],
76
+ // Cooling and mechanical.
77
+ ['coolingtower', 'Cooling tower', /COOLING TOWER|COOLING TWR|EVAPORATIVE CONDENSER/],
78
+ ['thermalstorage', 'Thermal storage', /THERMAL STORAGE|CHILLED WATER STORAGE|ICE STORAGE/],
79
+ ['chiller', 'Chiller', /\bCHILLER\b/],
80
+ ['condenser', 'Dry cooler / condenser', /DRY COOLER|FLUID COOLER|EVAPORATIVE COOLER|REMOTE CONDENSER|AIR[-\s]?COOLED CONDENSER|ADIABATIC|CONDENSER/],
81
+ ['cdu', 'CDU / liquid cooling', /COOLANT DISTRIBUTION|\bCDU\b|LIQUID COOLING|IMMERSION|DIRECT TO CHIP|COOLANT MANIFOLD|REAR DOOR/],
82
+ ['crah', 'CRAH / CRAC', /\bCRAH\b|\bCRAC\b|COMPUTER ROOM AIR/],
83
+ ['ahu', 'Air handling unit', /\bAHU\b|AIR HANDLING|AIR HANDLER/],
84
+ ['heatexchanger', 'Heat exchanger', /HEAT EXCHANGER|PLATE HEAT|PLATE AND FRAME/],
85
+ ['expansiontank', 'Expansion tank', /EXPANSION TANK|HYDROPNEUMATIC/],
86
+ ['airseparator', 'Air separator', /AIR SEPARATOR|AIR SEPARATION|\bAIR SCOOP\b/],
87
+ ['boiler', 'Boiler', /\bBOILER\b/],
88
+ ['humidifier', 'Humidifier / dehumidifier', /HUMIDIFIER|HUMIDIFICATION|DEHUMIDIFIER/],
89
+ ['watertreatment', 'Water treatment', /WATER TREATMENT|WATER SOFTENER|REVERSE OSMOSIS|\bRO SYSTEM\b|CHEMICAL DOSING|SIDE STREAM FILTER|SAND FILTER|CARBON FILTER|WATER FILTER/],
90
+ ['dryer', 'Air dryer', /AIR DRYER|DESICCANT|REFRIGERATED DRYER/],
91
+ ['compressor', 'Compressor', /\bCOMPRESSOR\b/],
92
+ ['fcu', 'Fan coil / fan wall', /\bFCU\b|FAN COIL|FAN WALL|EXHAUST FAN|SUPPLY FAN|RETURN FAN/],
93
+ ['rtu', 'Rooftop unit', /ROOFTOP UNIT|\bRTU\b|PACKAGED UNIT|PACKAGE UNIT/],
94
+ ['mua', 'Makeup air unit', /MAKEUP AIR|MAKE-UP AIR|\bMUA\b/],
95
+ ['economizer', 'Economizer', /ECONOMIZER/],
96
+ // Fire, safety and controls.
97
+ ['firesuppression', 'Fire suppression', /FIRE SUPPRESSION|CLEAN AGENT|\bFM[-\s]?200\b|NOVEC|INERT GAS|SPRINKLER|PRE[-\s]?ACTION|\bCO2\b|AEROSOL/],
98
+ ['firealarm', 'Fire alarm', /FIRE ALARM|\bVESDA\b|SMOKE DETECT|ASPIRATING|HEAT DETECT/],
99
+ ['leakdetection', 'Leak / gas detection', /LEAK DETECT|WATER DETECT|REFRIGERANT MONITOR|GAS DETECT/],
100
+ ['bms', 'BMS / controls', /\bBMS\b|\bEPMS\b|\bDCIM\b|BUILDING MANAGEMENT|\bBAS\b|CONTROL PANEL|CONTROL CABINET|\bPLC\b|CONTROLLER/],
101
+ // IT and white space. Rack before server so "server rack / enclosure" is a
102
+ // rack; KVM before server so "console server" is a console.
103
+ ['kvm', 'KVM / console', /\bKVM\b|CONSOLE SERVER/],
104
+ ['rack', 'Rack / enclosure', /EQUIPMENT RACK|\bRACK\b|ENCLOSURE|\bCABINET\b/],
105
+ ['server', 'Server / storage', /\bSERVER\b|BLADE|STORAGE ARRAY|\bSAN\b|\bNAS\b|HCI NODE/],
106
+ ['network', 'Network gear', /NETWORK SWITCH|ETHERNET SWITCH|\bROUTER\b|PATCH PANEL|FIREWALL|LOAD BALANCER/],
107
  ];
108
 
109
+ // Makers common on data centre electrical, cooling, IT and fire packages.
110
+ // Matched as whole words; anything else falls back to a line that reads like a
111
+ // company. Longer names precede the shorter names they contain.
112
  const MAKERS = [
113
  'Schneider Electric', 'Square D', 'APC', 'Eaton', 'ABB', 'Siemens', 'Vertiv', 'Liebert', 'Caterpillar', 'Cummins',
114
+ 'Kohler', 'Rolls-Royce Power Systems', 'Rolls-Royce', 'MTU', 'Generac', 'Trane', 'Carrier', 'Daikin', 'York',
115
+ 'Johnson Controls', 'Stulz', 'Munters', 'nVent', 'Legrand', 'Mitsubishi Electric', 'Toshiba', 'General Electric',
116
+ 'Hubbell', 'Socomec', 'Piller', 'Starline', 'Raritan', 'Server Technology', 'Emerson', 'Russelectric', 'ASCO',
117
+ 'Hitachi', 'Riello', 'Rittal', 'Motivair', 'CoolIT', 'Hitec', 'EnerSys', 'Leclanché', 'Samsung SDI',
118
+ // Cooling and mechanical.
119
+ 'Airedale', 'Uniflair', 'Climaveneta', 'Aermec', 'FläktGroup', 'FlaktGroup', 'Systemair', 'ebm-papst', 'Danfoss',
120
+ 'Grundfos', 'Wilo', 'Xylem', 'Bell & Gossett', 'Armstrong', 'Taco', 'Flowserve', 'SPX', 'Baltimore Aircoil',
121
+ 'Evapco', 'Marley', 'LU-VE', 'Alfa Laval', 'SWEP', 'Tranter', 'Boyd', 'Asetek',
122
+ // Power distribution, switchgear and batteries.
123
+ 'PDI', 'Power Distribution Inc', 'Anord Mardix', 'Mardix', 'Universal Electric', 'Hammond', 'Hoffman',
124
+ 'Exide', 'C&D Technologies', 'GS Yuasa', 'FIAMM', 'NorthStar', 'Saft', 'Hoppecke', 'LG Energy', 'CATL', 'Fluence',
125
+ 'Aggreko', 'Himoinsa', 'Perkins', 'Volvo Penta', 'Deutz', 'Wartsila',
126
+ // IT and network.
127
+ 'Dell', 'HPE', 'Hewlett Packard', 'Cisco', 'Juniper', 'Arista', 'Lenovo', 'Supermicro', 'IBM', 'Fujitsu', 'NetApp',
128
+ 'Pure Storage', 'Aten', 'Avocent',
129
+ // Fire, detection and controls.
130
+ 'Fike', 'Kidde', 'Tyco', 'Viking', 'Victaulic', 'Hochiki', 'Xtralis', 'VESDA', 'Notifier', 'Honeywell',
131
+ 'Delta Controls', 'Distech', 'Automated Logic', 'Tridium',
132
  ];
133
+ const COMPANY_LINE = /\b(INC|CORP|CORPORATION|LTD|LLC|GMBH|CO\.|COMPANY|SYSTEMS|ELECTRIC|POWER|TECHNOLOGIES|INDUSTRIES|ENGINEERING|INTERNATIONAL|GROUP|AG|SA|BV|NV|PTY|WORKS|THERMAL|CONTROLS|SOLUTIONS|MANUFACTURING)\b/;
134
 
135
  const NUM = '(\\d{1,5}(?:[.,]\\d+)?)';
136
  // "1,002" is a thousands separator on a US plate; "2,5" is a European decimal.
137
  const num = s => (s == null ? null : parseFloat(/^\d{1,3},\d{3}$/.test(String(s)) ? String(s).replace(',', '') : String(s).replace(',', '.')));
138
+ // Range guards: a rating of 0, or an absurd value, is an OCR artefact, not a field.
139
+ const positive = v => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : null);
140
+ const inRange = (v, lo, hi) => (typeof v === 'number' && Number.isFinite(v) && v >= lo && v <= hi ? v : null);
141
 
142
  /**
143
  * Nameplate fields from OCR output: a string, or lines as [{ text, confidence }]
 
163
  const CODE = '([A-Z0-9][A-Z0-9\\-\\/\\.]{2,})';
164
  scan('model', new RegExp(`(?:\\bMODEL\\b|\\bMOD\\.|\\bM\\/N\\b|\\bCAT(?:ALOG)?\\.?\\s*(?:NO\\b\\.?|#|NUMBER)|\\bP\\/N\\b|\\bPART\\s*(?:NO\\b\\.?|#|NUMBER))\\s*(?:NO\\b\\.?|NUMBER\\b|#)?\\s*[:#.]?\\s*${CODE}`), m => cleanCode(m[1]));
165
  scan('serial', new RegExp(`(?:\\bSERIAL\\b|\\bSER\\.|\\bS\\/N\\b|\\b5\\/N\\b|\\bSN\\b)\\s*(?:NO\\b\\.?|NUMBER\\b|#)?\\s*[:#.]?\\s*([A-Z0-9][A-Z0-9\\-]{3,})`), m => cleanCode(m[1]));
166
+ scan('refrigerant', /\bR[-\s]?(410A|134A|1234ZE|1234YF|1233ZD|513A|514A|515B|454B|468A|449A|407C|452A|455A|245FA|123|32|22|717|744|290|128|503|508B)\b/, m => `R-${m[1]}`);
167
  scan('hz', /\b(50|60)\s*HZ\b|\bHZ\s*[:]?\s*(50|60)\b|\bFREQ(?:UENCY)?\.?\s*[:]?\s*(50|60)\b/, m => +(m[1] || m[2] || m[3]));
168
  scan('phase', /\b([13])\s*-?\s*(?:PH|PHASE|Ø|Φ)\b|\bPH(?:ASE)?\s*[:]?\s*([13])\b/, m => +(m[1] || m[2]));
169
+ scan('kva', new RegExp(`${NUM}\\s*KVA\\b|\\bKVA\\s*[:]?\\s*${NUM}`), m => positive(num(m[1] || m[2])));
170
+ scan('kw', new RegExp(`${NUM}\\s*E?KW\\b|\\bE?KW\\s*[:]?\\s*${NUM}`), m => positive(num(m[1] || m[2])));
171
  scan('mfgDate', /\b(?:MFG\.?|MANUFACTURED|MFD\.?|BUILD|PROD(?:UCTION)?\.?)\s*(?:DATE)?\s*[:]?\s*(\d{1,2}[/-]\d{2,4}|\d{4}[/-]\d{1,2}(?:[/-]\d{1,2})?|\d{1,2}[/-]\d{1,2}[/-]\d{2,4})/, m => m[1]);
172
 
173
  // Voltage: every voltage on the plate (a transformer or UPS carries more than one).
 
183
  if (volts.length) fields.voltage = { value: voltLine.text, conf: voltLine.conf, line: voltLine.line, values: volts };
184
 
185
  // Amps: a labelled rated current first, then any bare "1002 A". Refrigerants (R-410A) are not amps.
186
+ scan('amps', new RegExp(`(?:\\bFLA\\b|\\bRLA\\b|\\bCURRENT\\b|\\bAMPS?\\b|\\bAMPERES\\b)\\s*[:]?\\s*${NUM}`), m => positive(num(m[1])));
187
+ if (!fields.amps) scan('amps', new RegExp(`(?<![-\\d.R])${NUM}\\s*(?:A|AMPS?)\\b`), m => positive(num(m[1])));
188
+ scan('mca', new RegExp(`\\bMCA\\b\\s*[:]?\\s*${NUM}`), m => positive(num(m[1])));
189
+ scan('mocp', new RegExp(`(?:\\bMOCP\\b|\\bMAX\\.?\\s*(?:FUSE|BREAKER|OCP))\\s*(?:SIZE)?\\s*[:]?\\s*${NUM}`), m => positive(num(m[1])));
190
+
191
+ // Data centre electrical: power factor and short-circuit/interrupting rating.
192
+ scan('pf', /(?:POWER\s*FACTOR|\bP\.?F\b)\s*[:=]?\s*(0?[.,]\d{1,3}|1(?:[.,]0+)?)\b|(0?[.,]\d{1,3})\s*P\.?F\b/, m => inRange(num(m[1] || m[2]), 0.01, 1));
193
+ scan('sccr', new RegExp(`${NUM}\\s*KAIC\\b|(?:\\bSCCR\\b|SHORT[\\s-]?CIRCUIT|WITHSTAND|INTERRUPTING RATING|\\bKAIC\\b)[^0-9]{0,12}${NUM}\\s*(?:KA|K)?\\b`), m => inRange(num(m[1] || m[2]), 0.1, 1000));
194
+
195
+ // Enclosure rating: NEMA type or IEC IP code.
196
+ scan('enclosure', /\bNEMA\s*(?:TYPE\s*)?(\d{1,2}[A-Z]?)\b|\bIP\s*(\d{2}[A-Z]{0,2})\b/, m => (m[1] ? `NEMA ${m[1]}` : `IP ${m[2]}`));
197
+
198
+ // Mechanical / cooling nameplates: refrigerant charge, capacity, airflow and flow.
199
+ scan('charge', new RegExp(`CHARGE\\s*(?:WEIGHT)?\\s*[:]?\\s*${NUM}\\s*(?:LBS?|KG|KGS?|OZ)?\\b`), m => positive(num(m[1])));
200
+ scan('tons', new RegExp(`${NUM}\\s*TONS?\\b|\\bTONS?\\s*[:]?\\s*${NUM}`), m => positive(num(m[1] || m[2])));
201
+ scan('btu', new RegExp(`${NUM}\\s*(?:BTU\\/?H?R?|BTUH)\\b|\\bBTU\\/?H?R?\\s*[:]?\\s*${NUM}`), m => positive(num(m[1] || m[2])));
202
+ scan('cfm', new RegExp(`${NUM}\\s*CFM\\b|\\bCFM\\s*[:]?\\s*${NUM}`), m => positive(num(m[1] || m[2])));
203
+ scan('gpm', new RegExp(`${NUM}\\s*(?:GPM|LPM|L\\/S|M3\\/H)\\b|\\bGPM\\s*[:]?\\s*${NUM}`), m => positive(num(m[1] || m[2])));
204
+ scan('batteryAh', new RegExp(`${NUM}\\s*(?:AH|AMP[\\s-]?HOURS?)\\b`), m => positive(num(m[1])));
205
+
206
+ // Battery chemistry, cell count, rotating speed, rigging weight and listing marks.
207
+ scan('batteryType', /\b(VRLA|AGM|GEL|FLOODED|LITHIUM[-\s]?ION|LI[-\s]?ION|LIFEPO4|NICD|NI[-\s]?CD|LEAD[-\s]?ACID|NICKEL[-\s]?CADMIUM|VALVE[-\s]?REGULATED)\b/, m => batteryTypeName(m[1]));
208
+ scan('cells', new RegExp(`(?:CELLS?|CELL\\s*COUNT)\\s*[:]?\\s*${NUM}\\b|${NUM}\\s*CELLS?\\b`), m => inRange(num(m[1] || m[2]), 1, 1000));
209
+ scan('rpm', new RegExp(`${NUM}\\s*RPM\\b|\\bRPM\\s*[:]?\\s*${NUM}`), m => inRange(num(m[1] || m[2]), 1, 200000));
210
+ scan('weight', new RegExp(`(?:WEIGHT|NET\\s?WEIGHT|NET\\s?WT|MASS)\\s*[:]?\\s*${NUM}\\s*(LBS?|LB|KGS?|KG|TONS?)?\\b`), m => positive(weightKg(num(m[1]), m[2])));
211
+ scan('standards', /\b(UL\s?\d{3,5}[A-Z]?|IEC\s?\d{4,5}|ANSI\s?[A-Z]{1,3}[-\s]?\d{1,4}|IEEE\s?\d{1,4}|NFPA\s?\d{1,3}|CSA\s?[A-Z]?\d{1,4}|EN\s?\d{4,5})\b/, m => m[1].replace(/\s+/g, ' ').trim());
212
+
213
+ // Server racks and IT: enclosure U height, the equipment's own form factor,
214
+ // power draw and static/dynamic load, the PDU outlet mix, and the network port
215
+ // count and speed. Rack U also catches the "42RU" spelling; the form factor is
216
+ // blade/tower or an explicitly labelled "FORM FACTOR 2U", so a server's model
217
+ // suffix ("R650-2U") is its Rack U, not a second field.
218
+ scan('uHeight', /\b(\d{1,2})\s*R?U\b/, m => { const v = +m[1]; return v >= 1 && v <= 60 ? v : null; });
219
+ scan('formFactor', /\b(?:FORM\s*FACTOR|CHASSIS|FORM)\s*[:]?\s*(\d{1,2})\s*U\b|\b(\d{1,2})\s*U\s*(?:SERVER|NODE|STORAGE|CHASSIS)\b/, m => `${m[1] || m[2]}U`);
220
+ if (!fields.formFactor) scan('formFactor', /\b(BLADE|TOWER)\b/, m => m[1].toLowerCase());
221
+ scan('powerW', new RegExp(`(?:POWER|INPUT POWER|RATED POWER)\\s*[:]?\\s*${NUM}\\s*W\\b|(?<![KE])${NUM}\\s*W\\b`), m => positive(num(m[1] || m[2])));
222
+ scan('rackLoad', new RegExp(`(?:(?:STATIC|DYNAMIC|SEISMIC)\\s*(?:LOAD|RATING|CAPACITY)|(?:RACK|FLOOR|CABINET|EQUIPMENT)\\s*LOAD|LOAD\\s*(?:RATING|CAPACITY))[^0-9]{0,16}${NUM}\\s*(LBS?|LB|KGS?|KG|TONS?)?\\b`), m => inRange(weightKg(num(m[1]), m[2]), 1, 200000));
223
+ scan('outlets', new RegExp(`${NUM}\\s*(?:OUTLETS?|RECEPTACLES?)\\b|\\bOUTLETS?\\s*[:]?\\s*${NUM}`), m => inRange(num(m[1] || m[2]), 1, 10000));
224
+ scan('ports', new RegExp(`\\b(\\d{1,3})\\s*-?\\s*PORTS?\\b|\\bPORTS?\\s*[:]?\\s*${NUM}`), m => inRange(num(m[1] || m[2]), 1, 10000));
225
+
226
+ // The outlet mix and the port speed need the whole line: a count can sit on
227
+ // either side of an outlet family ("24x C13" or "C13 x24"), and a switch's
228
+ // speed is the fastest link, not the first number seen.
229
+ for (const [i, l] of lines.entries()) {
230
+ const mix = outletMix(up(l.text));
231
+ if (mix) { set('outletTypes', mix, l.conf, i); break; }
232
+ }
233
+ for (const [i, l] of lines.entries()) {
234
+ const spd = portSpeed(up(l.text));
235
+ if (spd) { set('portSpeed', spd, l.conf, i); break; }
236
+ }
237
 
238
  // Manufacturer: a known maker anywhere, else a line that reads like a company name.
239
+ let makerLine = -1;
240
  for (const [i, l] of lines.entries()) {
241
  // "New York" on a supplier's address is not York the maker.
242
  const t = up(l.text).replace(/NEW YORK/g, '');
243
  const maker = MAKERS.find(mk => new RegExp(`\\b${escapeRe(up(mk))}\\b`).test(t));
244
+ if (maker) { set('manufacturer', maker, l.conf, i); makerLine = i; break; }
245
  }
246
  if (!fields.manufacturer) {
247
  const i = lines.findIndex(x => COMPANY_LINE.test(up(x.text)) && !/\d{3}/.test(x.text) && x.text.length <= 48);
248
+ if (i >= 0) { set('manufacturer', titleCase(lines[i].text.replace(/[^A-Za-z0-9&.,\- ]/g, '').trim()), lines[i].conf, i); makerLine = i; }
249
  }
250
 
251
+ // Equipment type from plate text, excluding the maker line: a vendor called
252
+ // "…Transformer Corp" or "…Switchgear Ltd" must not type a chiller plate.
253
+ const all = up(lines.filter((_, i) => i !== makerLine).map(l => l.text).join('\n'));
254
  const type = (EQUIPMENT_TYPES.find(([, , re]) => re.test(all)) || [null])[0];
255
  const conf = lines.length ? Math.round(lines.reduce((s, l) => s + l.conf, 0) / lines.length) : 0;
256
  return { fields, type, conf, text: lines.map(l => l.text).join('\n'), lines: lines.map(l => ({ text: l.text, conf: l.conf, bbox: l.bbox })) };
 
316
  kva: /^(kva|rating \(kva\)|kva rating|capacity \(kva\))$/i,
317
  kw: /^(kw|ekw|rating \(kw\)|kw rating|capacity \(kw\))$/i,
318
  amps: /^(amps|a|amperage|fla|rated current|current)$/i,
319
+ pf: /^(pf|power factor)$/i,
320
  mca: /^(mca|min\.? circuit amp(s|acity)?|minimum circuit ampacity)$/i,
321
  mocp: /^(mocp|max\.? (fuse|breaker|ocp)( size)?|maximum overcurrent protection)$/i,
322
+ sccr: /^(sccr|short.?circuit|withstand|interrupting rating|kaic)$/i,
323
+ enclosure: /^(enclosure|nema|nema type|ip rating|enclosure type)$/i,
324
+ standards: /^(standards?|listings?|approvals?|compliance|ul|iec|ansi)$/i,
325
+ batteryType: /^(battery type|battery technology|battery chemistry|cell type)$/i,
326
  refrigerant: /^(refrigerant|ref\.?)$/i,
327
+ charge: /^(charge|refrigerant charge|charge (lbs|kg))$/i,
328
+ tons: /^(tons|tonnage|cooling \(tons\)|cooling tons|refrigeration tons|tr)$/i,
329
+ btu: /^(btu|btuh|btu\/h|cooling \(btu\/?h\)|cooling btu)$/i,
330
+ cfm: /^(cfm|airflow|air flow|air volume)$/i,
331
+ gpm: /^(gpm|flow|water flow|flow rate)$/i,
332
+ batteryAh: /^(ah|amp.?hours?|battery ah|battery capacity)$/i,
333
+ cells: /^(cells?|cell count|battery cells)$/i,
334
+ rpm: /^(rpm|speed|rated speed|r\/min)$/i,
335
+ weight: /^(weight|net weight|mass|wt|weight \(kg\))$/i,
336
+ uHeight: /^(u|u height|rack u|ru|height \(u\)|u size)$/i,
337
+ formFactor: /^(form factor|ff|form|chassis|mounting|mount type)$/i,
338
+ powerW: /^(power|power \(w\)|watts?|w|rated power|input power)$/i,
339
+ rackLoad: /^(rack load|load|load (rating|capacity)|static load|dynamic load|floor load|seismic load|max load)$/i,
340
+ outletTypes: /^(outlet (types?|mix|configuration)|receptacle types?|outlet arrangement)$/i,
341
+ outlets: /^(outlets?|receptacles?|pdu outlets?|outlet count)$/i,
342
+ portSpeed: /^(port speed|uplink speed|link speed|network speed|speed \(gbe\))$/i,
343
+ ports: /^(ports?|port count|network ports?)$/i,
344
  location: /^(location|room|area|level|space|served from|zone)$/i,
345
  };
346
 
 
361
  else items.push({
362
  tag, type: get('type'), manufacturer: get('manufacturer'), model: get('model'), serial: get('serial'),
363
  voltage: get('voltage'), phase: num(get('phase').match(/[13]/)?.[0]), kva: num(get('kva')) || null, kw: num(get('kw')) || null,
364
+ amps: num(get('amps')) || null, pf: num(get('pf')) || null, mca: num(get('mca')) || null, mocp: num(get('mocp')) || null,
365
+ sccr: num(get('sccr')) || null, enclosure: get('enclosure'), standards: get('standards'), batteryType: get('batteryType'),
366
+ refrigerant: get('refrigerant'), charge: num(get('charge')) || null, tons: num(get('tons')) || null, btu: num(get('btu')) || null,
367
+ cfm: num(get('cfm')) || null, gpm: num(get('gpm')) || null, batteryAh: num(get('batteryAh')) || null,
368
+ cells: num(get('cells')) || null, rpm: num(get('rpm')) || null, weight: num(get('weight')) || null,
369
+ uHeight: num(get('uHeight')) || null, formFactor: get('formFactor'), powerW: num(get('powerW')) || null,
370
+ rackLoad: num(get('rackLoad')) || null, outletTypes: get('outletTypes'),
371
+ outlets: num(get('outlets')) || null, portSpeed: num(get('portSpeed')) || null,
372
+ ports: num(get('ports')) || null, location: get('location'),
373
  });
374
  });
375
  if (!items.length) problems.push('The header was found but no equipment rows under it.');
 
423
  const mk = item.manufacturer && f.manufacturer?.value ? (sameMaker(item.manufacturer, f.manufacturer.value) ? 1 : 0) : 0.5;
424
  const ty = reading.type && item.type ? (typeOf(item.type) === reading.type ? 1 : 0) : 0.5;
425
  score = 0.7 * m + 0.15 * mk + 0.15 * ty;
426
+ // A compatible voltage is a positive signal; mismatched voltages are only a
427
+ // tie-breaker, so a UPS plate still prefers a UPS row over a same-voltage PDU.
428
+ if (voltageCompatible(item, reading)) score += 0.1;
429
  }
430
  if (score >= 0.5) out.push({ item, score: Math.round(score * 100) / 100, registered: taken.has(item.tag) });
431
  }
432
  return out.sort((a, b) => (b.score - a.score) || (a.registered - b.registered));
433
  }
434
 
435
+ /** True when the schedule row and the plate share at least one voltage. */
436
+ function voltageCompatible(item, reading) {
437
+ if (!item.voltage) return false;
438
+ const want = scheduleVoltages(item.voltage);
439
+ const have = reading.fields?.voltage?.values || [];
440
+ return want.length > 0 && have.length > 0 && want.some(v => have.includes(v));
441
+ }
442
+
443
  /** Equipment type key for free text such as a schedule's description column. */
444
  export function typeOf(text) {
445
  const s = up(text);
 
467
  push('voltage', item.voltage, f.voltage?.value, want.length > 0 && want.every(v => have.includes(v)));
468
  }
469
  if (item.phase) push('phase', item.phase, f.phase?.value, +item.phase === +f.phase?.value);
470
+ if (item.pf) push('pf', item.pf, f.pf?.value, Math.abs(+f.pf?.value - item.pf) <= 0.02);
471
+ for (const k of ['kva', 'kw', 'amps', 'mca', 'mocp', 'sccr', 'charge', 'tons', 'btu', 'cfm', 'gpm', 'batteryAh', 'cells', 'rpm', 'weight', 'uHeight', 'powerW', 'rackLoad', 'outlets', 'portSpeed', 'ports']) {
472
  if (item[k]) push(k, item[k], f[k]?.value, Math.abs(+f[k]?.value - item[k]) <= Math.max(0.5, item[k] * 0.01));
473
  }
474
+ if (item.enclosure) push('enclosure', item.enclosure, f.enclosure?.value, enclosureMatch(item.enclosure, f.enclosure?.value));
475
+ if (item.batteryType) push('batteryType', item.batteryType, f.batteryType?.value, looseEq(item.batteryType, f.batteryType?.value));
476
+ if (item.standards) push('standards', item.standards, f.standards?.value, looseEq(item.standards, f.standards?.value));
477
+ if (item.formFactor) push('formFactor', item.formFactor, f.formFactor?.value, looseEq(item.formFactor, f.formFactor?.value));
478
+ if (item.outletTypes) push('outletTypes', item.outletTypes, f.outletTypes?.value, outletMix(up(item.outletTypes)) === outletMix(up(f.outletTypes?.value)));
479
  if (item.refrigerant) push('refrigerant', item.refrigerant, f.refrigerant?.value, up(item.refrigerant).replace(/[^A-Z0-9]/g, '') === up(f.refrigerant?.value).replace(/[^A-Z0-9]/g, ''));
480
  return out;
481
  }
482
 
483
+ /** Two short strings equal ignoring case, punctuation and spacing ("IP55" vs "IP 55"). */
484
+ function looseEq(a, b) {
485
+ const norm = s => up(s).replace(/[^A-Z0-9]/g, '');
486
+ const x = norm(a), y = norm(b);
487
+ return !!x && !!y && (x === y || x.includes(y) || y.includes(x));
488
+ }
489
+
490
+ /** "NEMA 3R" vs "3R", "IP55" vs "IP 55": compare the rating code, ignoring the label. */
491
+ function enclosureMatch(a, b) {
492
+ const norm = s => up(s).replace(/\bNEMA\b|\bTYPE\b|\bIP\b/g, '').replace(/[^A-Z0-9]/g, '');
493
+ const x = norm(a), y = norm(b);
494
+ return !!x && !!y && (x === y || x.includes(y) || y.includes(x));
495
+ }
496
+
497
  /** Overall status of a register entry: matched and clean, matched with a problem, or not on the schedule. */
498
  export function statusOf(checks, tag) {
499
  if (!tag) return 'unmatched';
 
532
 
533
  /** Asset register CSV: one row per scanned plate, then every scheduled tag not scanned yet. */
534
  export function registerCsv(register, items = []) {
535
+ const head = ['Tag', 'Status', 'Type', 'Location', 'Manufacturer', 'Model', 'Serial', 'Voltage', 'Phase', 'Hz', 'kVA', 'kW',
536
+ 'Amps', 'PF', 'MCA', 'MOCP', 'SCCR', 'Enclosure', 'Listings', 'Battery type', 'Battery Ah', 'Battery cells',
537
+ 'Refrigerant', 'Charge', 'Cooling (tons)', 'Cooling (BTU/h)', 'Airflow (CFM)', 'Flow (GPM)', 'Speed (RPM)',
538
+ 'Weight (kg)', 'Rack U', 'Form factor', 'Power (W)', 'Rack load (kg)', 'Outlet mix', 'Outlets', 'Port speed (GbE)',
539
+ 'Ports', 'Mfg date', 'Issues', 'Scanned'];
540
  const byTag = new Map(items.map(i => [i.tag, i]));
541
  const typeLabel = k => (EQUIPMENT_TYPES.find(t => t[0] === k) || [])[1] || '';
542
  const dups = new Set(duplicateSerials(register).flat());
 
546
  const issues = (r.checks || []).filter(c => c.status === 'mismatch').map(c => `${c.label}: schedule ${c.expected}, plate ${c.found}`);
547
  if (dups.has(r.id)) issues.push('Serial also on another scanned plate');
548
  return [r.tag || '', STATUS_LABELS[r.status] || r.status, typeLabel(r.type), byTag.get(r.tag)?.location || '',
549
+ v('manufacturer'), v('model'), v('serial'), v('voltage'), v('phase'), v('hz'), v('kva'), v('kw'), v('amps'), v('pf'),
550
+ v('mca'), v('mocp'), v('sccr'), v('enclosure'), v('standards'), v('batteryType'), v('batteryAh'), v('cells'),
551
+ v('refrigerant'), v('charge'), v('tons'), v('btu'), v('cfm'), v('gpm'), v('rpm'), v('weight'), v('uHeight'), v('formFactor'), v('powerW'), v('rackLoad'), v('outletTypes'), v('outlets'), v('portSpeed'), v('ports'), v('mfgDate'),
552
+ issues.join('; '), r.scannedAt ? new Date(r.scannedAt).toISOString().slice(0, 16).replace('T', ' ') : ''];
553
  });
554
  const tags = new Set(register.map(r => r.tag));
555
  for (const i of items) {
556
  if (tags.has(i.tag)) continue;
557
+ rows.push([i.tag, STATUS_LABELS.missing, i.type, i.location, i.manufacturer, i.model, i.serial, i.voltage, i.phase ?? '',
558
+ '', i.kva ?? '', i.kw ?? '', i.amps ?? '', i.pf ?? '', i.mca ?? '', i.mocp ?? '', i.sccr ?? '', i.enclosure ?? '',
559
+ i.standards ?? '', i.batteryType ?? '', i.batteryAh ?? '', i.cells ?? '', i.refrigerant, i.charge ?? '', i.tons ?? '',
560
+ i.btu ?? '', i.cfm ?? '', i.gpm ?? '', i.rpm ?? '', i.weight ?? '', i.uHeight ?? '', i.formFactor ?? '', i.powerW ?? '',
561
+ i.rackLoad ?? '', i.outletTypes ?? '', i.outlets ?? '', i.portSpeed ?? '',
562
+ i.ports ?? '', '', '', '']);
563
  }
564
  return [head, ...rows].map(r => r.map(csvCell).join(',')).join('\n') + '\n';
565
  }
 
581
  CH-01,Air-cooled chiller,Coldline Systems,AC-1200,460,3,,,612,800,R-513A,Roof
582
  `;
583
 
584
+ /** The two sample plates: one that matches UPS-1A, one delivered at the wrong voltage. */
585
  export const SAMPLE_PLATES = [
586
  ['NORTHLINE POWER SYSTEMS', 'UNINTERRUPTIBLE POWER SUPPLY', 'MODEL NO: NPX-750-480', 'SERIAL NO: NL26A01937',
587
  'INPUT: 480Y/277 VAC 3 PH 60 HZ', 'RATING: 750 KVA / 675 KW', 'INPUT CURRENT: 1002 A', 'MFG DATE: 03/2026'],
588
  ['NORTHLINE POWER SYSTEMS', 'UNINTERRUPTIBLE POWER SUPPLY', 'MODEL NO: NPX-750-415', 'SERIAL NO: NL26A02210',
589
  'INPUT: 415Y/240 VAC 3 PH 50 HZ', 'RATING: 750 KVA / 675 KW', 'INPUT CURRENT: 1160 A', 'MFG DATE: 04/2026'],
590
+ // A few more data centre plates so the sample shows the wider equipment set.
591
+ ['IRONSIDE SWITCHGEAR CORP', 'SWITCHBOARD', 'MODEL NO: IS-4000-MDP', 'SERIAL NO: IS26C01188',
592
+ '480Y/277 V 3 PH 60 HZ', '1000 KVA MAIN BUS', 'SCCR 65 KAIC', 'NEMA 3R MFG DATE: 05/2026'],
593
+ ['COLDLINE SYSTEMS', 'COMPUTER ROOM AIR HANDLER', 'MODEL NO: CW-150-480', 'SERIAL NO: CL6600172',
594
+ '480 V 3 PH 60 HZ', 'FLA 38.5 MCA 45 MOCP 60', 'AIRFLOW 12000 CFM', 'MFG DATE: 01/2026'],
595
+ ['HARBOR ENGINE WORKS INC', 'DIESEL GENERATOR SET', 'MODEL: HG-3000', 'S/N: HEW0098812',
596
+ '13.8 KV 3 PHASE 60 HZ', '3750 KVA 3000 EKW', '0.8 PF', 'BUILD DATE 2026-01'],
597
+ ['POLARIS THERMAL', 'COOLING TOWER', 'MODEL NO: PT-CT-900', 'SERIAL NO: PT26D00417',
598
+ '460 V 3 PH 60 HZ', 'MCA 86 MOCP 110', 'FLOW 2400 GPM', 'MFG DATE: 07/2026'],
599
+ ['DELL EMC', 'POWEREDGE R650 SERVER', 'MODEL NO: R650-2U', 'SERIAL NO: DL26R00442',
600
+ '480 V 3 PH 60 HZ', '800 W 12.5 A', 'AIRFLOW 120 CFM', 'MFG DATE: 06/2026'],
601
+ ['VERTIV', 'RACK PDU', 'MODEL NO: MPX-30-C13', 'SERIAL NO: VR26P00117',
602
+ '400 V 3 PH 60 HZ', '30 A 5.5 KW', '24 OUTLETS (12x C13, 4x C19)', 'MFG DATE: 08/2026'],
603
+ ['CISCO', 'CATALYST NETWORK SWITCH', 'MODEL NO: C9300-48P', 'SERIAL NO: FOC26X0011',
604
+ '230 V 3 PH 50 HZ', '48-PORT POE 1100 W', 'UPLINK 25G', 'MFG DATE: 09/2026'],
605
+ ['NEXUS COMPUTE', 'BLADE SERVER CHASSIS', 'MODEL NO: BX-7000', 'SERIAL NO: NC26B00123',
606
+ 'FORM FACTOR 8U', '480 V 3 PH 60 HZ', 'STATIC LOAD 1360 KG', 'MFG DATE: 05/2026'],
607
  ];
608
 
609
  // ------------------------------------------------------------------ helpers
 
612
  function escapeRe(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }
613
  function cleanCode(s) { return s.replace(/[.\-/]+$/, ''); }
614
  function titleCase(s) { return s.toLowerCase().replace(/\b[a-z]/g, c => c.toUpperCase()); }
615
+ /** Canonical battery chemistry from the many ways plates spell it. */
616
+ function batteryTypeName(s) {
617
+ const t = up(s).replace(/\s+/g, ' ');
618
+ if (/LIFEPO4/.test(t)) return 'LiFePO4';
619
+ if (/LITHIUM|LI[-\s]?ION/.test(t)) return 'Lithium-ion';
620
+ if (/NICD|NICKEL/.test(t)) return 'NiCd';
621
+ if (/LEAD/.test(t)) return 'Lead-acid';
622
+ if (/VRLA|VALVE/.test(t)) return 'VRLA';
623
+ if (/AGM/.test(t)) return 'AGM';
624
+ if (/GEL/.test(t)) return 'Gel';
625
+ if (/FLOODED/.test(t)) return 'Flooded';
626
+ return titleCase(s);
627
+ }
628
+ /** Weight normalised to kilograms so a lb plate and a kg schedule compare. */
629
+ function weightKg(v, unit) {
630
+ if (v == null) return null;
631
+ const u = up(unit || 'KG');
632
+ if (/^LB/.test(u)) return Math.round(v * 0.45359237 * 10) / 10;
633
+ if (/^TON/.test(u)) return Math.round(v * 907.18474 * 10) / 10;
634
+ return v;
635
+ }
636
+ /** Canonical PDU outlet mix from the ways plates write it: "24x C13, 6x C19" -> "C13x24 C19x6". */
637
+ function outletMix(t) {
638
+ const counts = new Map();
639
+ let m;
640
+ const pairA = /\b(\d{1,3})\s*[X\u00d7]\s*(C\d{1,2})\b/g; // 24x C13
641
+ while ((m = pairA.exec(t))) { const n = +m[1]; if (n >= 1 && n <= 1000) counts.set(m[2], (counts.get(m[2]) || 0) + n); }
642
+ const pairB = /\b(C\d{1,2})\s*[X\u00d7]\s*(\d{1,3})\b/g; // C13 x24
643
+ while ((m = pairB.exec(t))) { const n = +m[2]; if (n >= 1 && n <= 1000) counts.set(m[1], (counts.get(m[1]) || 0) + n); }
644
+ if (!counts.size && !/OUTLET|RECEPTACLE/.test(t)) return null; // a "C13" in a model code is not an outlet mix
645
+ const bare = /\b(C\d{1,2})\b/g;
646
+ while ((m = bare.exec(t))) if (!counts.has(m[1])) counts.set(m[1], 0);
647
+ return [...counts.entries()].sort((a, b) => a[0].localeCompare(b[0])).map(([f, n]) => (n > 0 ? `${f}x${n}` : f)).join(' ');
648
+ }
649
+ /** Fastest link speed on a line, in GbE: "48-port 10G", "25/100GbE" -> 100. */
650
+ function portSpeed(t) {
651
+ let max = 0, m;
652
+ const re = /\b(1|10|25|40|50|100|200|400)\s*G(?:BE|BPS|BASE-T|IGABIT|IGE)?\b/g;
653
+ while ((m = re.exec(t))) max = Math.max(max, +m[1]);
654
+ return max || null;
655
+ }
656
  function csvCell(v) { const s = String(v ?? ''); return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s; }
657
 
658
  export function levenshtein(a, b) {
nameplates-app.js CHANGED
@@ -2,7 +2,7 @@
2
  // OCR it (Tesseract.js, in the browser), parse and check the fields against the
3
  // schedule, and keep an asset register that exports to CSV.
4
  import {
5
- FIELDS, EQUIPMENT_TYPES, STATUS_LABELS, SAMPLE_SCHEDULE, SAMPLE_PLATES,
6
  parseNameplate, parseEquipmentSchedule, candidatesFor, checkAgainst, statusOf,
7
  registerSummary, registerCsv, duplicateSerials, voltagesIn,
8
  } from './nameplate-model.js';
@@ -10,18 +10,22 @@ import {
10
  const TESSERACT = 'https://cdn.jsdelivr.net/npm/tesseract.js@5.1.1/dist/tesseract.min.js';
11
  const STORE = 'buildvision.nameplates.v1';
12
  const LOW_CONF = 70;
13
- const NUMERIC = new Set(['phase', 'hz', 'kva', 'kw', 'amps', 'mca', 'mocp']);
14
  // Dark enough for white label text on the photo overlay.
15
  const COLORS = {
16
  manufacturer: '#0f2547', model: '#1b5fa8', serial: '#7340a8', voltage: '#c0262d', phase: '#b04f00', hz: '#7a4a35',
17
- kva: '#1f7a32', kw: '#0b7285', amps: '#a8327a', mca: '#5c6b00', mocp: '#8a5a00', refrigerant: '#4d6b1f', mfgDate: '#555b63',
 
 
 
 
18
  };
19
 
20
  const $ = id => document.getElementById(id);
21
  const els = Object.fromEntries([
22
  'npSchedDrop', 'npSchedFile', 'npSchedSample', 'npSchedClear', 'npSchedStatus', 'npDrop', 'npFile', 'npSample', 'npRotate',
23
- 'npRun', 'npProg', 'npStatus', 'npModel', 'npCanvas', 'npEmpty', 'npReading', 'npVerdict', 'npFields', 'npTag', 'npTagNote',
24
- 'npChecks', 'npAdd', 'npText', 'npSummary', 'npCsv', 'npClearReg', 'npRows', 'npEmptyReg', 'npMissing',
25
  ].map(id => [id.slice(2, 3).toLowerCase() + id.slice(3), $(id)]));
26
 
27
  const state = {
@@ -33,6 +37,8 @@ const state = {
33
  tag: '',
34
  sample: 0,
35
  editing: null, // register id being reviewed (Add then updates it)
 
 
36
  photos: new Map(), // register id -> { image, reading } for this session (photos are not stored)
37
  };
38
  window.BuildVisionNameplates = state;
@@ -151,9 +157,49 @@ function setImage(src, w, h) {
151
  els.reading.hidden = true;
152
  els.run.disabled = false;
153
  els.rotate.disabled = false;
 
154
  draw();
155
  }
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  function rotate() {
158
  const s = state.image;
159
  const c = document.createElement('canvas');
@@ -415,14 +461,18 @@ function renderReading() {
415
  els.reading.hidden = !r;
416
  if (!r) return;
417
  els.text.textContent = r.text || '(no text)';
418
- // Fields: editable, low-confidence ones highlighted.
419
  const typeOpts = ['<option value="">Unknown</option>', ...EQUIPMENT_TYPES.map(([k, label]) => `<option value="${k}"${r.type === k ? ' selected' : ''}>${esc(label)}</option>`)].join('');
 
 
 
 
 
 
420
  els.fields.innerHTML = `<label for="npf-type">Type</label><select id="npf-type">${typeOpts}</select>` +
421
- FIELDS.map(([k, label]) => {
422
- const f = r.fields[k];
423
- const low = f && !f.edited && f.conf < LOW_CONF;
424
- return `<label for="npf-${k}"><span class="np-key" style="background:${f ? COLORS[k] : 'transparent'}"></span>${esc(label)}</label>` +
425
- `<input id="npf-${k}" data-key="${k}" value="${esc(f?.value ?? '')}" ${low ? `class="low" title="OCR confidence ${f.conf}%: check against the plate"` : ''} autocomplete="off" spellcheck="false" />`;
426
  }).join('');
427
 
428
  // Tag picker: likely tags first, then the rest of the schedule.
@@ -588,7 +638,15 @@ function renderRegister() {
588
  sum.unmatched ? `<span><b>${sum.unmatched}</b> not on schedule</span>` : '',
589
  sum.duplicates ? `<span style="color:var(--danger)"><b>${sum.duplicates}</b> duplicate serial${sum.duplicates === 1 ? '' : 's'}</span>` : '',
590
  ].join('') : '';
591
- els.rows.innerHTML = state.register.map(r => {
 
 
 
 
 
 
 
 
592
  const issues = r.checks.filter(c => c.status === 'mismatch').map(c => `${c.label}: schedule ${c.expected}, plate ${c.found}`);
593
  if (dups.has(r.id)) issues.push('Serial also on another scanned plate');
594
  if (r.lowConf?.length) issues.push(`Check ${r.lowConf.map(x => { const [k, c] = x.split(':'); return `${inSentence((FIELDS.find(f => f[0] === k) || [k, k])[1])} (OCR ${c}%)`; }).join(', ')}`);
@@ -600,10 +658,15 @@ function renderRegister() {
600
  `<td><button class="np-btn link" type="button" data-remove="${r.id}" aria-label="Remove ${esc(r.tag || 'entry')}">✕</button></td></tr>`;
601
  }).join('');
602
  els.emptyReg.hidden = state.register.length > 0;
 
 
 
 
603
  els.csv.disabled = !state.register.length && !items.length;
604
  els.clearReg.disabled = !state.register.length;
605
  els.missing.textContent = items.length && sum.missing.length && state.register.length
606
- ? `Not scanned yet (${sum.missing.length}): ${sum.missing.slice(0, 24).join(', ')}${sum.missing.length > 24 ? '…' : ''}` : '';
 
607
  }
608
 
609
  function download(name, text, type) {
@@ -665,6 +728,8 @@ els.clearReg.addEventListener('click', () => {
665
  save();
666
  renderRegister();
667
  });
 
 
668
  els.csv.addEventListener('click', () => download('asset-register.csv', registerCsv(state.register, state.schedule?.items || []), 'text/csv'));
669
 
670
  load();
 
2
  // OCR it (Tesseract.js, in the browser), parse and check the fields against the
3
  // schedule, and keep an asset register that exports to CSV.
4
  import {
5
+ FIELDS, FIELD_GROUPS, EQUIPMENT_TYPES, STATUS_LABELS, SAMPLE_SCHEDULE, SAMPLE_PLATES,
6
  parseNameplate, parseEquipmentSchedule, candidatesFor, checkAgainst, statusOf,
7
  registerSummary, registerCsv, duplicateSerials, voltagesIn,
8
  } from './nameplate-model.js';
 
10
  const TESSERACT = 'https://cdn.jsdelivr.net/npm/tesseract.js@5.1.1/dist/tesseract.min.js';
11
  const STORE = 'buildvision.nameplates.v1';
12
  const LOW_CONF = 70;
13
+ const NUMERIC = new Set(['phase', 'hz', 'kva', 'kw', 'amps', 'pf', 'mca', 'mocp', 'sccr', 'charge', 'tons', 'btu', 'cfm', 'gpm', 'batteryAh', 'cells', 'rpm', 'weight', 'uHeight', 'powerW', 'rackLoad', 'outlets', 'portSpeed', 'ports']);
14
  // Dark enough for white label text on the photo overlay.
15
  const COLORS = {
16
  manufacturer: '#0f2547', model: '#1b5fa8', serial: '#7340a8', voltage: '#c0262d', phase: '#b04f00', hz: '#7a4a35',
17
+ kva: '#1f7a32', kw: '#0b7285', amps: '#a8327a', pf: '#8a1c5a', mca: '#5c6b00', mocp: '#8a5a00', sccr: '#6b2d8a',
18
+ enclosure: '#3a4a5a', standards: '#4a3f6b', batteryType: '#5a2d6b', batteryAh: '#7a3f00', cells: '#6b4a00',
19
+ refrigerant: '#4d6b1f', charge: '#2f6b3a', tons: '#0b6b6b', btu: '#0b5c8a', cfm: '#5a5c00', gpm: '#00636b',
20
+ uHeight: '#3a3f8a', formFactor: '#4a3f8a', powerW: '#8a5a1f', rackLoad: '#6b5a1f', outletTypes: '#6b3a6b', outlets: '#6b3a6b', portSpeed: '#3a6b5a', ports: '#3a6b5a',
21
+ rpm: '#7a2c2c', weight: '#444a52', mfgDate: '#555b63',
22
  };
23
 
24
  const $ = id => document.getElementById(id);
25
  const els = Object.fromEntries([
26
  'npSchedDrop', 'npSchedFile', 'npSchedSample', 'npSchedClear', 'npSchedStatus', 'npDrop', 'npFile', 'npSample', 'npRotate',
27
+ 'npRun', 'npProg', 'npStatus', 'npModel', 'npCanvas', 'npEmpty', 'npQuality', 'npReading', 'npVerdict', 'npFields', 'npTag', 'npTagNote',
28
+ 'npChecks', 'npAdd', 'npText', 'npSummary', 'npCsv', 'npClearReg', 'npSearch', 'npFilter', 'npRows', 'npEmptyReg', 'npMissing',
29
  ].map(id => [id.slice(2, 3).toLowerCase() + id.slice(3), $(id)]));
30
 
31
  const state = {
 
37
  tag: '',
38
  sample: 0,
39
  editing: null, // register id being reviewed (Add then updates it)
40
+ photoFilter: 'all', // register status filter
41
+ photoQuery: '', // register search text
42
  photos: new Map(), // register id -> { image, reading } for this session (photos are not stored)
43
  };
44
  window.BuildVisionNameplates = state;
 
157
  els.reading.hidden = true;
158
  els.run.disabled = false;
159
  els.rotate.disabled = false;
160
+ showQuality(photoWarning(state.image, w, h));
161
  draw();
162
  }
163
 
164
+ /** Show (or clear) the advisory "retake this photo" line. */
165
+ function showQuality(text) {
166
+ if (!els.quality) return;
167
+ els.quality.textContent = text || '';
168
+ els.quality.classList.toggle('warn', !!text);
169
+ }
170
+
171
+ /**
172
+ * Advisory read of the photo before OCR: too blurry, dark, glared or small to
173
+ * read. Returns a sentence to show, or '' when the shot looks usable. Never
174
+ * blocks a read; it just tells the person to retake if the result looks poor.
175
+ */
176
+ function photoWarning(src, origW, origH) {
177
+ try {
178
+ const w = Math.min(240, src.width), h = Math.max(1, Math.round((src.height * w) / src.width));
179
+ const c = document.createElement('canvas');
180
+ c.width = w; c.height = h;
181
+ const g = c.getContext('2d', { willReadFrequently: true });
182
+ g.drawImage(src, 0, 0, w, h);
183
+ const d = g.getImageData(0, 0, w, h).data;
184
+ const n = w * h, gray = new Float32Array(n);
185
+ let sum = 0, bright = 0;
186
+ for (let i = 0, j = 0; j < n; i += 4, j++) { gray[j] = d[i] * 0.299 + d[i + 1] * 0.587 + d[i + 2] * 0.114; sum += gray[j]; if (gray[j] > 250) bright++; }
187
+ let lapSum = 0, lapSq = 0, count = 0;
188
+ for (let y = 1; y < h - 1; y++) for (let x = 1; x < w - 1; x++) {
189
+ const i = y * w + x;
190
+ const lap = 4 * gray[i] - gray[i - 1] - gray[i + 1] - gray[i - w] - gray[i + w];
191
+ lapSum += lap; lapSq += lap * lap; count++;
192
+ }
193
+ const lapVar = count ? lapSq / count - (lapSum / count) ** 2 : 0;
194
+ const notes = [];
195
+ if (Math.min(origW || src.width, origH || src.height) < 500) notes.push('is low resolution');
196
+ else if (lapVar < 20) notes.push('looks blurry');
197
+ if (sum / n < 45) notes.push('is dark');
198
+ if (bright / n > 0.12) notes.push('has glare over the plate');
199
+ return notes.length ? `Photo ${notes.join(' and ')}. Retake closer and straight on, without glare, for a better read.` : '';
200
+ } catch { return ''; }
201
+ }
202
+
203
  function rotate() {
204
  const s = state.image;
205
  const c = document.createElement('canvas');
 
461
  els.reading.hidden = !r;
462
  if (!r) return;
463
  els.text.textContent = r.text || '(no text)';
464
+ // Fields: grouped, editable, low-confidence ones highlighted.
465
  const typeOpts = ['<option value="">Unknown</option>', ...EQUIPMENT_TYPES.map(([k, label]) => `<option value="${k}"${r.type === k ? ' selected' : ''}>${esc(label)}</option>`)].join('');
466
+ const fieldInput = ([k, label]) => {
467
+ const f = r.fields[k];
468
+ const low = f && !f.edited && f.conf < LOW_CONF;
469
+ return `<label for="npf-${k}"><span class="np-key" style="background:${f ? COLORS[k] : 'transparent'}"></span>${esc(label)}</label>` +
470
+ `<input id="npf-${k}" data-key="${k}" value="${esc(f?.value ?? '')}" ${low ? `class="low" title="OCR confidence ${f.conf}%: check against the plate"` : ''} autocomplete="off" spellcheck="false" />`;
471
+ };
472
  els.fields.innerHTML = `<label for="npf-type">Type</label><select id="npf-type">${typeOpts}</select>` +
473
+ FIELD_GROUPS.map(([g, label]) => {
474
+ const group = FIELDS.filter(f => (f[2] || 'id') === g);
475
+ return group.length ? `<div class="np-group">${esc(label)}</div>${group.map(fieldInput).join('')}` : '';
 
 
476
  }).join('');
477
 
478
  // Tag picker: likely tags first, then the rest of the schedule.
 
638
  sum.unmatched ? `<span><b>${sum.unmatched}</b> not on schedule</span>` : '',
639
  sum.duplicates ? `<span style="color:var(--danger)"><b>${sum.duplicates}</b> duplicate serial${sum.duplicates === 1 ? '' : 's'}</span>` : '',
640
  ].join('') : '';
641
+ // Filter and search the register: a walk can be hundreds of tags.
642
+ const q = state.photoQuery.trim().toUpperCase();
643
+ const shown = state.register.filter(r => {
644
+ if (state.photoFilter !== 'all' && r.status !== state.photoFilter) return false;
645
+ if (!q) return true;
646
+ return [r.tag, typeLabel(r.type), r.fields?.model?.value, r.fields?.serial?.value, r.fields?.manufacturer?.value, r.source]
647
+ .join(' ').toUpperCase().includes(q);
648
+ });
649
+ els.rows.innerHTML = shown.map(r => {
650
  const issues = r.checks.filter(c => c.status === 'mismatch').map(c => `${c.label}: schedule ${c.expected}, plate ${c.found}`);
651
  if (dups.has(r.id)) issues.push('Serial also on another scanned plate');
652
  if (r.lowConf?.length) issues.push(`Check ${r.lowConf.map(x => { const [k, c] = x.split(':'); return `${inSentence((FIELDS.find(f => f[0] === k) || [k, k])[1])} (OCR ${c}%)`; }).join(', ')}`);
 
658
  `<td><button class="np-btn link" type="button" data-remove="${r.id}" aria-label="Remove ${esc(r.tag || 'entry')}">✕</button></td></tr>`;
659
  }).join('');
660
  els.emptyReg.hidden = state.register.length > 0;
661
+ if (els.emptyReg) els.emptyReg.textContent = state.register.length && !shown.length
662
+ ? 'No register entries match the filter.'
663
+ : 'Nothing scanned yet. Each plate you add appears here with its check result.';
664
+ if (els.filter) els.filter.value = state.photoFilter;
665
  els.csv.disabled = !state.register.length && !items.length;
666
  els.clearReg.disabled = !state.register.length;
667
  els.missing.textContent = items.length && sum.missing.length && state.register.length
668
+ ? `Not scanned yet (${sum.missing.length}): ${sum.missing.slice(0, 24).join(', ')}${sum.missing.length > 24 ? '…' : ''}` +
669
+ (shown.length !== state.register.length ? ` Showing ${shown.length} of ${state.register.length} scanned.` : '') : '';
670
  }
671
 
672
  function download(name, text, type) {
 
728
  save();
729
  renderRegister();
730
  });
731
+ els.search?.addEventListener('input', () => { state.photoQuery = els.search.value; renderRegister(); });
732
+ els.filter?.addEventListener('change', () => { state.photoFilter = els.filter.value; renderRegister(); });
733
  els.csv.addEventListener('click', () => download('asset-register.csv', registerCsv(state.register, state.schedule?.items || []), 'text/csv'));
734
 
735
  load();