"""Exact sensitivity worksheet, not measured MTTD or a fault-arrival process. One hypothetical persistent fault has an onset density proportional to a given piecewise-constant profile. The profile is fixed across inspection schedules. Integer-day durations and rational nonnegative weights are explicit input limits. No device experiment, renewal independence assumption or policy optimization. """ import argparse from datetime import datetime, timezone from fractions import Fraction import hashlib import json from pathlib import Path from model import encode, intervals_checked def weighted_wait(intervals, profile, threshold=14): """Integrate the next-check delay; merge ordered partitions in linear time.""" gaps = intervals_checked(intervals) if not isinstance(profile, (list, tuple)) or not profile: raise ValueError("provide nonempty (duration_days, relative_weight) pairs") for pair in profile: if not isinstance(pair, (list, tuple)) or len(pair) != 2: raise ValueError("profile entries must be duration/weight pairs") duration, weight = pair if type(duration) is not int or duration <= 0: raise ValueError("profile durations must be positive integer days") if type(weight) not in (int, Fraction) or weight < 0: raise ValueError("weights must be nonnegative integers or Fractions") if sum(duration for duration, _ in profile) != sum(gaps): raise ValueError("profile and inspection window must have equal duration") if type(threshold) not in (int, Fraction) or threshold < 0: raise ValueError("threshold must be a nonnegative integer or Fraction") mass = sum((duration * weight for duration, weight in profile), Fraction(0)) if mass <= 0: raise ValueError("onset profile must have positive total mass") i = j = 0 start = 0 check = gaps[0] profile_end = profile[0][0] area = tail_mass = Fraction(0) while i < len(gaps) and j < len(profile): end = min(check, profile_end) weight = profile[j][1] # Delay is affine between checks, so the trapezoid integral is exact. area += weight * (end - start) * (check - Fraction(start + end, 2)) tail_mass += weight * max(min(end, check - threshold) - start, 0) start = end if end == check: i += 1 if i < len(gaps): check += gaps[i] if end == profile_end: j += 1 if j < len(profile): profile_end += profile[j][0] return {"normalizing_mass_days": mass, "weighted_wait_area_days_squared": area, "mean_wait_days": area / mass, "tail_mass_days": tail_mass, "probability_wait_exceeds_threshold": tail_mass / mass} def result(): profiles = [("Uniform", [(56, 1)]), ("Early windows weighted fourfold", [(7, 4), (21, 1), (7, 4), (21, 1)])] schedules = [("Regular", [14, 14, 14, 14]), ("Alternating", [7, 21, 7, 21])] return { "schema_version": 1, "evidence_type": "exact-synthetic-onset-sensitivity", "unit_of_analysis": "one hypothetical fault in one fixed block over 56 days", "threshold_days": 14, "assumptions": [ "Each check detects the same persistent fault; the final check is at day 56.", "Onset density is proportional to relative weight, constant within each profile segment.", "The same onset profile is used for both schedules; there is no feedback or policy-induced damage.", "No intervening reads, overwrites, repairs, incomplete checks or censored edges.", ], "limitations": [ "Constructed sensitivity example, not a measured fault profile, hazard rate or fitted predictor.", "No inference about data loss, repair, optimal scrub frequency or whole-device I/O cost.", "No sampling confidence interval applies to these exact invented inputs.", ], "formula": "integral(weight(t) * (next_check(t) - t) dt) / integral(weight(t) dt)", "dependency_sha256": {name: hashlib.sha256(Path(__file__).with_name(name).read_bytes()).hexdigest() for name in ("model.py", "onset.py")}, "scenarios": [{"profile": label, "profile_duration_weight_pairs": [list(pair) for pair in profile], "schedule": name, "gaps_days": gaps, **{key: encode(value) for key, value in weighted_wait(gaps, profile).items()}} for label, profile in profiles for name, gaps in schedules], } def main(): parser = argparse.ArgumentParser(description=__doc__) actions = parser.add_mutually_exclusive_group() actions.add_argument("--write", action="store_true") actions.add_argument("--check", action="store_true") args = parser.parse_args() expected = result() path = Path(__file__).with_name("onset-results.json") if args.check: stored = json.loads(path.read_text()) stamp = stored.pop("generated_at") if datetime.fromisoformat(stamp).utcoffset() is None: raise SystemExit("generated_at must be timezone aware") if stored != expected: raise SystemExit("onset-results.json differs from the generator") print("Exact onset worksheet and source hashes verified") else: expected["generated_at"] = datetime.now(timezone.utc).isoformat() text = json.dumps(expected, indent=2) + "\n" if args.write: path.write_text(text) else: print(text, end="") if __name__ == "__main__": main()