MI stratēģijas datukopa v0.1: shēma, XML (pppa-mis-2026-09-10), rīki
- schemas/mi-strategija-0.1.xsd: Stratēģija → Pīlārs → Mērķis → Rīcība - data/pppa-mis-2026-09-10.xml: 3 pīlāri, 5 mērķi, 27 rīcības (burtiski no v2.2) - tools/mi_strategija_no_html.py, tools/validate.py Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016679RwmHsuTFfxt26wP6rk
This commit is contained in:
60
tools/validate.py
Normal file
60
tools/validate.py
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Pārbauda MI stratēģijas datukopu: XSD, faila nosaukums = ID, numerācija.
|
||||
|
||||
Lietojums: python3 tools/validate.py [data/]
|
||||
Prasības: pip install lxml
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from lxml import etree
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
XSD = etree.XMLSchema(etree.parse(str(ROOT / "schemas" / "mi-strategija-0.1.xsd")))
|
||||
NS = {"s": "urn:pppa:cac:mi-strategija:0.1"}
|
||||
|
||||
|
||||
def check(path):
|
||||
errs = []
|
||||
doc = etree.parse(str(path))
|
||||
if not XSD.validate(doc):
|
||||
errs += [f"XSD {e.line}: {e.message}" for e in XSD.error_log]
|
||||
return errs
|
||||
r = doc.getroot()
|
||||
did = r.get("id")
|
||||
if path.stem != did:
|
||||
errs.append(f"faila nosaukums {path.name} ≠ ID {did}.xml")
|
||||
if r.find("s:Updated", NS).get("value") != did[-10:]:
|
||||
errs.append("ID datums nesakrīt ar Updated/@value")
|
||||
for p in r.iterfind("s:Pillar", NS):
|
||||
if not p.get("id").startswith(did + ".p"):
|
||||
errs.append(f"pīlāra ID {p.get('id')}")
|
||||
nums = []
|
||||
for a in r.iterfind(".//s:Action", NS):
|
||||
n = int(a.get("number"))
|
||||
nums.append(n)
|
||||
if a.get("id") != f"{did}.r{n:02d}":
|
||||
errs.append(f"rīcības {n} ID {a.get('id')} neatbilst numuram")
|
||||
if sorted(nums) != list(range(1, len(nums) + 1)):
|
||||
errs.append(f"rīcību numerācija nav 1..{len(nums)}: {sorted(nums)}")
|
||||
goals = [int(g.get("number").rstrip(".")) for g in r.iterfind(".//s:Goal", NS)]
|
||||
if goals != list(range(1, len(goals) + 1)):
|
||||
errs.append(f"mērķu numerācija {goals}")
|
||||
nores = [a.get("number") for a in r.iterfind(".//s:Action", NS) if a.find("s:Responsible", NS) is None]
|
||||
print(f" {path.name}: {len(list(r.iterfind('s:Pillar', NS)))} pīlāri, {len(goals)} mērķi, "
|
||||
f"{len(nums)} rīcības; bez atbildīgās institūcijas: {len(nores)}")
|
||||
return errs
|
||||
|
||||
|
||||
def main(folder):
|
||||
bad = 0
|
||||
for f in sorted(Path(folder).glob("pppa-mis-*.xml")):
|
||||
e = check(f)
|
||||
for x in e:
|
||||
print(" KĻŪDA", f.name, x)
|
||||
bad += bool(e)
|
||||
print("OK" if not bad else f"{bad} faili ar kļūdām")
|
||||
return 1 if bad else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else ROOT / "data"))
|
||||
Reference in New Issue
Block a user