File size: 1,163 Bytes
7282a65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Validate examples/sample_signal_log.json against datasets/schema/signal-log.schema.json

Usage:
  python scripts/validate.py
"""

import json
import sys
from pathlib import Path

from jsonschema import validate


def main() -> int:
    repo_root = Path(__file__).resolve().parents[1]

    schema_path = repo_root / "datasets" / "schema" / "signal-log.schema.json"
    sample_path = repo_root / "examples" / "sample_signal_log.json"

    if not schema_path.exists():
        print(f"[ERROR] Schema not found: {schema_path}", file=sys.stderr)
        return 2

    if not sample_path.exists():
        print(f"[ERROR] Sample log not found: {sample_path}", file=sys.stderr)
        return 2

    with schema_path.open("r", encoding="utf-8") as f:
        schema = json.load(f)

    with sample_path.open("r", encoding="utf-8") as f:
        data = json.load(f)

    validate(instance=data, schema=schema)
    print("OK: sample log matches schema")
    return 0


if __name__ == "__main__":
    try:
        raise SystemExit(main())
    except Exception as e:
        print(f"[ERROR] Validation failed: {e}", file=sys.stderr)
        raise