43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate a compact runtime index for the 403-object contract matrix."""
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
source_path = ROOT / "docs/p6/object-contract-matrix.json"
|
|
out = ROOT / "web/public/api/object-runtime-index.json"
|
|
source = json.loads(source_path.read_text(encoding="utf-8"))
|
|
rows = source["records"]
|
|
fields = {
|
|
"modules": sorted({row["module"] for row in rows}),
|
|
"families": sorted({row["adapterFamily"] for row in rows}),
|
|
"statuses": sorted({row["status"] for row in rows}),
|
|
"capabilities": sorted({capability for row in rows for capability in row["capabilities"]}),
|
|
}
|
|
lookup = {key: {value: index for index, value in enumerate(values)} for key, values in fields.items()}
|
|
records = []
|
|
for row in rows:
|
|
mask = 0
|
|
for capability in row["capabilities"]:
|
|
mask |= 1 << lookup["capabilities"][capability]
|
|
records.append([
|
|
row["id"],
|
|
lookup["modules"][row["module"]],
|
|
row["name"],
|
|
lookup["families"][row["adapterFamily"]],
|
|
lookup["statuses"][row["status"]],
|
|
mask,
|
|
])
|
|
index = {
|
|
"schema": "freecad-web-object-runtime-index/v1",
|
|
"source": {"matrix": "docs/p6/object-contract-matrix.json", "matrixSha256": hashlib.sha256(source_path.read_bytes()).hexdigest()},
|
|
"fields": fields,
|
|
"records": records,
|
|
}
|
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
out.write_text(json.dumps(index, ensure_ascii=False, separators=(",", ":")) + "\n", encoding="utf-8")
|
|
print(json.dumps({"output": str(out.relative_to(ROOT)), "records": len(records), "bytes": out.stat().st_size, "sha256": hashlib.sha256(out.read_bytes()).hexdigest()}, ensure_ascii=False))
|