Admit source evidence snapshots and harden stream completeness
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a06e89-93a2-7aa2-82b3-ce5ccd2682e6
This commit is contained in:
parent
824fb1b966
commit
31e9963933
34 changed files with 1057 additions and 122 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
from collections.abc import Mapping, Sequence
|
||||
from dataclasses import dataclass
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
|
@ -32,15 +33,10 @@ def parse_interval(value: str | int) -> timedelta:
|
|||
return timedelta(hours=int(text[:-1]))
|
||||
if text.endswith("d") and text[:-1].isdigit():
|
||||
return timedelta(days=int(text[:-1]))
|
||||
if text.startswith("pt"):
|
||||
# Minimal ISO-8601 duration: PT24H, PT1H, PT30M.
|
||||
amount = text[2:]
|
||||
if amount.endswith("h") and amount[:-1].isdigit():
|
||||
return timedelta(hours=int(amount[:-1]))
|
||||
if amount.endswith("m") and amount[:-1].isdigit():
|
||||
return timedelta(minutes=int(amount[:-1]))
|
||||
if amount.endswith("s") and amount[:-1].isdigit():
|
||||
return timedelta(seconds=int(amount[:-1]))
|
||||
match = re.fullmatch(r"p(?:(\d+)d)?(?:t(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?)?", text)
|
||||
if match and any(match.groups()):
|
||||
days, hours, minutes, seconds = (int(value or 0) for value in match.groups())
|
||||
return timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)
|
||||
raise ValueError(f"unsupported interval: {value!r}")
|
||||
|
||||
|
||||
|
|
@ -71,10 +67,10 @@ class ReconciliationCadence:
|
|||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class EmissionCadence:
|
||||
"""Runtime view of the Taxonomy draft, loaded from the local worked example.
|
||||
"""Runtime projection of InfoTechCanon standard/emission-cadence 0.1.
|
||||
|
||||
This is a consumer of the draft in `specs/EmissionCadenceDeclaration.md`,
|
||||
not a competing schema. Ownership stays with Taxonomy.
|
||||
NetKingdom classifications and local provenance live in extensions.
|
||||
Canonical schema validation belongs to the owner's schema, not a local copy.
|
||||
"""
|
||||
|
||||
schema_version: str
|
||||
|
|
@ -106,12 +102,27 @@ def load_qonto_assistant_cadence() -> EmissionCadence:
|
|||
return emission_cadence_from_dict(payload)
|
||||
|
||||
|
||||
def load_qonto_assistant_source_cadence() -> EmissionCadence:
|
||||
"""Load qonto-assistant's shipped source-owned emission declaration."""
|
||||
payload = json.loads(
|
||||
files("kings_guard")
|
||||
.joinpath("fixtures")
|
||||
.joinpath("qonto_assistant_source_cadence.json")
|
||||
.read_text(encoding="utf-8")
|
||||
)
|
||||
return emission_cadence_from_dict(payload)
|
||||
|
||||
|
||||
def emission_cadence_from_dict(data: Mapping[str, Any]) -> EmissionCadence:
|
||||
rates: list[RateCadence] = []
|
||||
heartbeats: list[HeartbeatCadence] = []
|
||||
reconciliations: list[ReconciliationCadence] = []
|
||||
for item in data.get("sources", ()):
|
||||
evidence_class = EvidenceClass(str(item["evidence_class"]))
|
||||
if data.get("schema_version") != "0.1" or not data.get("declaration_id"):
|
||||
raise ValueError("expected canonical emission-cadence 0.1 declaration")
|
||||
provenance = data.get("extensions", {}).get("kings-guard", {})
|
||||
for item in data["sources"]:
|
||||
profile = item.get("extensions", {}).get("net-kingdom", {})
|
||||
evidence_class = EvidenceClass(str(profile["evidence_class"]))
|
||||
form = str(item["form"])
|
||||
if form == "expected-rate":
|
||||
rates.append(
|
||||
|
|
@ -150,11 +161,11 @@ def emission_cadence_from_dict(data: Mapping[str, Any]) -> EmissionCadence:
|
|||
)
|
||||
return EmissionCadence(
|
||||
schema_version=str(data.get("schema_version", "0.1")),
|
||||
status=str(data.get("status", "taxonomy-draft")),
|
||||
drafter=str(data.get("drafter", "kings-guard")),
|
||||
owner=str(data.get("owner", "Taxonomy")),
|
||||
status=str(provenance.get("status", "source-declared")),
|
||||
drafter=str(provenance.get("drafter", data["source"])),
|
||||
owner=str(provenance.get("owner", data["source"])),
|
||||
source_system=str(data.get("source", data.get("source_system", "unknown"))),
|
||||
reference_instance=str(data.get("reference_instance", "GH-WP-0002-T04")),
|
||||
reference_instance=str(provenance.get("reference_instance", data["declaration_id"])),
|
||||
rates=tuple(rates),
|
||||
heartbeats=tuple(heartbeats),
|
||||
reconciliations=tuple(reconciliations),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue