The backup is procured and proven, so the loop runs on real evidence. - data/actuals/2026-08.json: first real observation. database 0.6365 GB, stored 0.0066 GB over 8 objects, backup success 1/1, restore RTO 1.08 min. Five proxies null, each with a named owner in measurement_gaps. - data/thresholds/platform-audit-storage.json + tools/thresholds.py: budget variance, abnormal growth, stale backup, unused commitment. Fail-closed — an unmeasured value is reported as unmeasured, never as within. - financial_exchange.py gains a usage mode emitting technical_usage records to fin-hub, with measurement gaps carried through and no infrastructure amount: fin-hub owns the booked fact and a null is never sent as 0.00. - observation schema 0.2 allows null cost and usage proxies; variance.py fails closed rather than reporting a 100% favourable variance on a missing amount. - platform-audit-storage: ordered -> active, commissioned 2026-08-14, on operational fact rather than on the purchase. The optimization case is now approved by the founder. That needed a schema change: Host Europe never supplied written terms, so options gained excluded/exclusion_reason. Previously an unevaluable alternative blocked its case forever, leaving the record claiming no decision while the bucket was in production. An excluded option keeps its unknowns and must say what would bring it back. August produces no variance and should not: the decision forecast starts at 2026-09, so August is a commissioning baseline. Threshold run is 2 within, 1 not applicable, 6 unmeasured, 0 breaches. Also fixes a pre-existing test failure: reef-storage consumers_actual is now rapp-postgres, which the assertion still expected to be empty. 136 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Compare monthly resource actuals with the immutable decision forecast."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
METRICS = (
|
|
"database_gb", "stored_gb", "wal_gb", "restore_egress_gb",
|
|
"write_requests", "read_requests", "infrastructure_eur",
|
|
"internal_labor_hours", "internal_labor_eur", "total_eur",
|
|
)
|
|
|
|
|
|
def compare(forecast: dict, actual: dict) -> dict:
|
|
expected = {row["period"]: row for row in forecast["rows"]}
|
|
rows = []
|
|
for observed in actual["rows"]:
|
|
period = observed["period"]
|
|
if period not in expected:
|
|
rows.append({"period": period, "status": "no-forecast", "metrics": {}})
|
|
continue
|
|
metrics = {}
|
|
for metric in METRICS:
|
|
planned = expected[period][metric]
|
|
measured = observed[metric]
|
|
# An uninvoiced period has no cost to compare against. Treating a
|
|
# missing amount as zero would report a 100% favourable variance.
|
|
if planned is None or measured is None:
|
|
metrics[metric] = {
|
|
"forecast": planned,
|
|
"actual": measured,
|
|
"status": "unknown",
|
|
"category": "data_quality",
|
|
}
|
|
continue
|
|
error = measured - planned
|
|
metrics[metric] = {
|
|
"forecast": planned,
|
|
"actual": measured,
|
|
"error": round(error, 4),
|
|
"absolute_percentage_error": None if planned == 0 else round(abs(error) / planned * 100, 2),
|
|
}
|
|
rows.append({"period": period, "status": "compared", "metrics": metrics})
|
|
return {
|
|
"forecast_created_at": forecast["created_at"],
|
|
"provider_id": actual["provider_id"],
|
|
"rows": rows,
|
|
}
|
|
|
|
|
|
def main() -> int:
|
|
if len(sys.argv) != 3:
|
|
print(f"usage: {sys.argv[0]} FORECAST.json ACTUAL.json", file=sys.stderr)
|
|
return 2
|
|
forecast = json.loads(Path(sys.argv[1]).read_text())
|
|
actual = json.loads(Path(sys.argv[2]).read_text())
|
|
print(json.dumps(compare(forecast, actual), indent=2))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|