-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_larc_single.py
More file actions
296 lines (242 loc) · 10 KB
/
Copy pathbuild_larc_single.py
File metadata and controls
296 lines (242 loc) · 10 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Build a SINGLE self-contained offline referee HTML file from ITTF LARC Excel (.xlsx).
ONLY accepted input format (one and only):
BRAND PRODUCT APPROVAL-CODE
Examples:
STIGA S3 68-014
FRIENDSHIP 563 SP 27-017
Authoritative basis:
Brand + Product + Approval Code
Colors/Thickness/OX are ignored.
Usage:
pip3 install openpyxl
python3 build_larc_single.py --input LARC.xlsx --output LARC_Check.html --version "ITTF LARC 2026-01-23"
"""
from __future__ import annotations
import argparse
import json
import re
from pathlib import Path
from typing import Dict, List, Set, Tuple
from openpyxl import load_workbook
CODE_RE = re.compile(r"\b(\d{2,3}-\d{3})\b")
def norm(s: str) -> str:
s = (s or "").strip().upper()
s = s.replace("–", "-").replace("—", "-")
s = re.sub(r"\s+", " ", s)
s = re.sub(r"[^A-Z0-9 \-]", "", s)
s = re.sub(r"\s*-\s*", "-", s)
s = re.sub(r"\s+", " ", s).strip()
return s
def find_col(headers: List[str], wanted: str) -> int:
up = [norm(h) for h in headers]
w = norm(wanted)
if w in up:
return up.index(w)
for i, h in enumerate(up):
if w in h:
return i
return -1
HTML_TEMPLATE = """<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
<title>ITTF LARC Check</title>
<style>
:root { --pad: 16px; --r: 16px; }
body{ margin:0; padding:var(--pad); font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial; background:#f2f2f2; }
.card{ max-width:560px; margin:0 auto; background:#fff; border-radius:var(--r); box-shadow:0 8px 24px rgba(0,0,0,.12); padding:var(--pad); }
h1{ margin:6px 0 2px; text-align:center; font-size:18px; letter-spacing:.2px; }
.sub{ text-align:center; color:#666; font-size:12px; margin:0 0 10px; line-height:1.35; }
.rule{ margin-top:10px; padding:12px; background:#f7f7f7; border-radius:14px; font-size:13px; line-height:1.5; color:#222; }
.rule b{ font-weight:900; }
input{ width:100%; box-sizing:border-box; margin-top:12px; padding:16px; font-size:18px; border-radius:14px; border:1px solid #ddd; outline:none; }
input:focus{ border-color:#999; }
button{ width:100%; box-sizing:border-box; margin-top:12px; padding:18px; font-size:18px; font-weight:900; border:0; border-radius:14px; background:#111; color:#fff; }
.result{ margin-top:16px; text-align:center; font-weight:900; font-size:34px; letter-spacing:.5px; }
.yes{ color:#148a2a; }
.no{ color:#c62828; }
.info{ margin-top:10px; text-align:center; font-size:13px; line-height:1.45; color:#333; }
.evidence{ margin-top:8px; text-align:center; font-size:12px; color:#333; }
.meta{ margin-top:16px; color:#666; font-size:12px; line-height:1.4; }
.muted{ color:#777; }
.tiny{ margin-top:8px; font-size:12px; color:#666; line-height:1.4; }
.mono{ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono"; }
</style>
</head>
<body>
<div class="card">
<h1>ITTF Racket Covering Check</h1>
<div class="sub">Offline referee tool · Exact decision basis: Brand + Product + Approval Code</div>
<div class="rule">
<b>ONLY input format / 唯一输入格式:</b><br>
<span class="mono"><b>BRAND PRODUCT APPROVAL-CODE</b></span><br>
Examples / 示例:<br>
<span class="mono">STIGA S3 68-014</span><br>
<span class="mono">FRIENDSHIP 563 SP 27-017</span><br>
<span class="muted">These three items should appear on the rubber or its packaging.</span><br>
<span class="muted">这三项应能在胶皮或包装上对应找到。</span>
</div>
<input id="q" placeholder="Type here… 例如:STIGA S3 68-014" autocapitalize="characters" autocomplete="off" />
<button id="btn">CHECK</button>
<div id="res" class="result"></div>
<div id="info" class="info"></div>
<div id="ev" class="evidence"></div>
<div class="meta">
<div class="muted" id="ver"></div>
<div class="tiny">
<b>Disclaimer:</b> Assists referees only; does not replace ITTF regulations.<br>
<b>免责声明:</b>仅供裁判辅助,不替代 ITTF 官方规则与文件。<br>
<b>Final authority remains with ITTF.</b> / <b>最终解释权仍归 ITTF。</b>
</div>
</div>
</div>
<script>
const LARC_VERSION = "__LARC_VERSION__";
// entries: [{b:"STIGA", p:"S3", c:"68-014"}, ...]
const ENTRIES = __ENTRIES_JSON__;
// Index by composite key: "BRAND|PRODUCT|CODE"
const KEY_SET = new Set();
for (const e of ENTRIES){
KEY_SET.add(e.b + "|" + e.p + "|" + e.c);
}
const q = document.getElementById("q");
const btn = document.getElementById("btn");
const res = document.getElementById("res");
const info = document.getElementById("info");
const ev = document.getElementById("ev");
const ver = document.getElementById("ver");
ver.textContent = "Data version: " + LARC_VERSION + " · Entries: " + ENTRIES.length;
function norm(s){
return (s || "")
.toString()
.trim()
.toUpperCase()
.replace(/[–—]/g, "-")
.replace(/\\s+/g, " ")
.replace(/[^A-Z0-9 \\-]/g, "")
.replace(/\\s*-\\s*/g, "-")
.replace(/\\s+/g, " ")
.trim();
}
function parseStrict(s){
// Enforce: BRAND ... PRODUCT ... CODE(at end)
// CODE pattern: 2-3 digits '-' 3 digits
const m = s.match(/\\b(\\d{2,3}-\\d{3})\\b$/);
if (!m) return null;
const code = m[1];
// Remove trailing code
let left = s.slice(0, s.length - code.length).trim();
if (!left) return null;
const parts = left.split(" ").filter(Boolean);
if (parts.length < 2) return null;
const brand = parts[0];
const product = parts.slice(1).join(" ");
return {brand, product, code};
}
function setYes(brand, product, code){
res.className = "result yes";
res.textContent = "YES ✔";
info.innerHTML =
"<b>EN (authoritative):</b> Listed on the current ITTF LARC.<br>" +
"<b>中文(参考):</b> 已列入当期 ITTF LARC 清单。";
ev.textContent = "Evidence: " + brand + " / " + product + " / " + code;
}
function setNo(msg){
res.className = "result no";
res.textContent = "NO ✘";
info.innerHTML =
"<b>EN (authoritative):</b> Not found on the current ITTF LARC.<br>" +
"<b>中文(参考):</b> 未在当期 ITTF LARC 清单中找到。";
ev.textContent = msg || "";
}
function setFormatError(){
res.className = "result no";
res.textContent = "FORMAT ✘";
info.innerHTML =
"<b>Please use ONLY this format:</b><br>" +
"<span class='mono'><b>BRAND PRODUCT APPROVAL-CODE</b></span><br>" +
"Example: <span class='mono'>STIGA S3 68-014</span><br><br>" +
"<b>请按唯一格式输入:</b><span class='mono'><b>品牌 型号 批准编号</b></span>";
ev.textContent = "";
}
function check(){
const raw = norm(q.value);
if (!raw){
res.textContent = "";
info.textContent = "";
ev.textContent = "";
return;
}
const parsed = parseStrict(raw);
if (!parsed){
setFormatError();
return;
}
const b = norm(parsed.brand);
const p = norm(parsed.product);
const c = norm(parsed.code);
const k = b + "|" + p + "|" + c;
if (KEY_SET.has(k)){
setYes(b, p, c);
} else {
setNo("Evidence: " + b + " / " + p + " / " + c + " (not found)");
}
}
btn.addEventListener("click", check);
q.addEventListener("keydown", (e)=>{ if(e.key==="Enter") check(); });
setTimeout(()=>q.focus(), 200);
</script>
</body>
</html>
"""
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("--input", required=True, help="ITTF LARC .xlsx file path")
ap.add_argument("--output", default="LARC_Check.html", help="Output single HTML file")
ap.add_argument("--version", default="ITTF LARC (unknown)", help='Version label, e.g. "ITTF LARC 2026-01-23"')
ap.add_argument("--sheet", default=None, help="Sheet name (default: first)")
args = ap.parse_args()
in_path = Path(args.input)
out_path = Path(args.output)
wb = load_workbook(in_path, read_only=True, data_only=True)
sheet_name = args.sheet or wb.sheetnames[0]
ws = wb[sheet_name]
rows = ws.iter_rows(values_only=True)
headers_raw = next(rows)
headers = [str(h) if h is not None else "" for h in headers_raw]
b_idx = find_col(headers, "Brand")
p_idx = find_col(headers, "Product")
c_idx = find_col(headers, "Approval Code")
if b_idx < 0 or p_idx < 0 or c_idx < 0:
raise SystemExit(f"[ERROR] Missing required columns: Brand / Product / Approval Code. Headers: {headers}")
entries: List[Dict[str, str]] = []
seen: Set[Tuple[str, str, str]] = set()
for r in rows:
if r is None:
continue
brand = norm(str(r[b_idx])) if (b_idx < len(r) and r[b_idx] is not None) else ""
product = norm(str(r[p_idx])) if (p_idx < len(r) and r[p_idx] is not None) else ""
code_raw = norm(str(r[c_idx])) if (c_idx < len(r) and r[c_idx] is not None) else ""
if not brand or not product or not code_raw:
continue
m = CODE_RE.search(code_raw)
if not m:
continue
code = m.group(1)
t = (brand, product, code)
if t in seen:
continue
seen.add(t)
entries.append({"b": brand, "p": product, "c": code})
if len(entries) < 500:
print(f"[WARN] Only {len(entries)} entries extracted. Check if this is the correct LARC Excel.")
html = HTML_TEMPLATE.replace("__LARC_VERSION__", args.version)
html = html.replace("__ENTRIES_JSON__", json.dumps(entries, ensure_ascii=False))
out_path.write_text(html, encoding="utf-8")
print(f"[OK] Generated single-file HTML: {out_path} (entries embedded: {len(entries)})")
if __name__ == "__main__":
main()