#!/usr/bin/env python3 """Synthetic interval-weighting arithmetic; not an AWS availability measurement.""" import argparse import json from decimal import Decimal, localcontext from fractions import Fraction from pathlib import Path REVIEWED = "2026-10-22" INTERVALS = 30 * 24 * 12 def summarize(intervals, expected_intervals): """Require explicit complete coverage; each pair is (requests, eligible errors).""" if type(expected_intervals) is not int or expected_intervals <= 0: raise ValueError("expected_intervals must be a positive integer") if len(intervals) != expected_intervals: raise ValueError("missing or extra intervals; do not infer idle periods") rates = [] requests = errors = idle = 0 for pair in intervals: if not isinstance(pair, (tuple, list)) or len(pair) != 2: raise ValueError("each interval needs request and eligible-error counts") n, e = pair if any(type(x) is not int or x < 0 for x in pair) or e > n: raise ValueError("counts must be nonnegative integers with errors <= requests") rates.append(Fraction(e, n) if n else Fraction(0)) requests += n errors += e idle += n == 0 return { "requests": requests, "eligible_errors": errors, "idle_intervals": idle, "interval_percentage": 100 * (1 - sum(rates, Fraction(0)) / expected_intervals), "request_percentage": 100 * (1 - Fraction(errors, requests)) if requests else None, } def percent(value): if value is None: return None with localcontext() as context: context.prec = 50 return format(Decimal(value.numerator) / Decimal(value.denominator), ".12f") def fixture_cases(): return [ ("separate-intervals", "One error alone; 999 successes in another interval", [(1, 1), (999, 0)] + [(0, 0)] * (INTERVALS - 2)), ("same-interval", "One error and 999 successes in the same interval", [(1000, 1)] + [(0, 0)] * (INTERVALS - 1)), ("all-idle", "All intervals explicitly have zero requests", [(0, 0)] * INTERVALS), ] def publication(): rows = [] for slug, label, intervals in fixture_cases(): result = summarize(intervals, INTERVALS) rows.append({ "id": slug, "label": label, "active_intervals": [ {"index": i, "requests": n, "eligible_errors": e} for i, (n, e) in enumerate(intervals) if n ], "remaining_intervals": "explicitly idle in this constructed fixture, not missing logs", **{k: v for k, v in result.items() if not k.endswith("_percentage")}, **{k: percent(v) for k, v in result.items() if k.endswith("_percentage")}, "interval_percentage_exact": str(result["interval_percentage"]), "request_percentage_exact": str(result["request_percentage"]) if result["request_percentage"] is not None else None, }) return { "schemaVersion": 1, "kind": "synthetic-arithmetic", "generated": REVIEWED, "period_days": 30, "interval_minutes": 5, "interval_count": INTERVALS, "unit": "percent", "scope": "One request type, storage class and account in one region; complete synthetic period.", "source": "https://aws.amazon.com/s3/sla/", "source_accessed": REVIEWED, "limits": [ "No customer logs, observed outage, incident rate or provider comparison.", "No service-credit determination or implementation of exclusions.", "Eligible errors are preclassified; all requests remain in the denominator.", "No cross-request-type aggregation is inferred.", "An idle-period convention is not evidence of successful service.", ], "rows": rows, } def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--output", type=Path) parser.add_argument("--check", action="store_true") args = parser.parse_args() if args.check and args.output is None: parser.error("--check requires --output") payload = json.dumps(publication(), indent=2) + "\n" if args.check: if not args.output.is_file() or args.output.read_text() != payload: parser.exit(1, "missing or stale generated result\n") elif args.output: args.output.parent.mkdir(parents=True, exist_ok=True) args.output.write_text(payload) else: print(payload, end="") if __name__ == "__main__": main()