FA-68246 / Traffic signal timing plans / Open access
Loop detector count and occupancy binning: occupancy percent is scaled after integer division · case 01
Loop detector count and occupancy binning returns a wrong result when occupancy percent is scaled after integer division.
ROOT CAUSE
Dividing before scaling makes every partially occupied bin 0 percent.
VERIFIED REPAIR
Restore the occupancy percent rule so that the step reads `o * 100 // I`.
Unsuccessful approach: Rounding to nearest disagrees with the stipulated floor for fractional percentages.
Case contract
Input {interval s, bins, events: [[on, off]] seconds relative to period start (on may be negative), max_presence, no_activity}. A vehicle is counted in the bin of its on time if inside the period; occupied time is split across bins by overlap; occupancy percent is floor(occupied*100/interval). Status is 'stuck-on' if any presence lasts >= max_presence, 'no-activity' if there are no events and the period (bins*interval) is >= no_activity, else 'ok'. Return {counts, occ_pct, status}.
Why this case matters
Signal timing arithmetic is exact and integer or rational; a wrong rule silently produces unsafe or inefficient timing plans.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
I = x['interval']
B = x['bins']
counts = [0] * B
occ = [0] * B
status = 'ok'
for on, off in sorted(x['events']):
b = on // I
if 0 <= b < B:
counts[b] += 1
if off - on >= x['max_presence']:
status = 'stuck-on'
for k in range(B):
lo, hi = k * I, (k + 1) * I
occ[k] += max(0, min(off, hi) - max(on, lo))
if not x['events'] and B * I >= x['no_activity']:
status = 'no-activity'
return {'counts': counts, 'occ_pct': [o // I * 100 for o in occ], 'status': status}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 5, 'events': [[336, 344], [10, 326], [5, 7], [370, 373]], 'max_presence': 100, 'no_activity': 240}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [73, 100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 5, 'events': [[-19, -16]], 'max_presence': 240, 'no_activity': 240}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 5, 'events': [[89, 90], [67, 72], [123, 126], [-14, -9], [26, 34]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 0, 2, 0, 1], 'occ_pct': [13, 13, 20, 0, 10], 'status': 'ok'}), ({'interval': 30, 'bins': 5, 'events': [[-5, 0], [39, 47], [68, 71], [75, 83], [88, 96], [111, 119], [121, 124], [126, 166]], 'max_presence': 180, 'no_activity': 240}, {'counts': [0, 1, 3, 1, 2], 'occ_pct': [0, 26, 43, 46, 90], 'status': 'ok'}), ({'interval': 60, 'bins': 5, 'events': [], 'max_presence': 240, 'no_activity': 60}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'})], [({'interval': 30, 'bins': 5, 'events': [[-16, -14], [26, 66], [101, 102], [103, 104], [112, 115]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 0, 0, 3, 0], 'occ_pct': [13, 100, 20, 16, 0], 'status': 'ok'}), ({'interval': 120, 'bins': 4, 'events': [], 'max_presence': 100, 'no_activity': 240}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 3, 'events': [[-4, -3]], 'max_presence': 100, 'no_activity': 600}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'}), ({'interval': 120, 'bins': 2, 'events': [[6, 14], [70, 110], [123, 126], [24, 64], [152, 153], [177, 179]], 'max_presence': 100, 'no_activity': 120}, {'counts': [3, 3], 'occ_pct': [73, 5], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [[4, 6], [34, 74]], 'max_presence': 180, 'no_activity': 60}, {'counts': [2, 0, 0, 0], 'occ_pct': [46, 23, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'})], [({'interval': 30, 'bins': 2, 'events': [[-20, 20]], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [66, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [[3, 6], [29, 37], [42, 43], [47, 344], [357, 359], [392, 395], [426, 427], [436, 438]], 'max_presence': 100, 'no_activity': 240}, {'counts': [4, 0, 0, 0], 'occ_pct': [41, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 5, 'events': [[-13, 230], [264, 265], [303, 306], [342, 350]], 'max_presence': 100, 'no_activity': 600}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [100, 100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 3, 'events': [], 'max_presence': 180, 'no_activity': 240}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [[-9, -4], [26, 27], [47, 55]], 'max_presence': 240, 'no_activity': 600}, {'counts': [2, 0], 'occ_pct': [15, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'})], [({'interval': 60, 'bins': 4, 'events': [[-18, -15]], 'max_presence': 240, 'no_activity': 120}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [], 'max_presence': 240, 'no_activity': 600}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[-10, -2], [26, 28], [54, 56], [73, 367], [392, 400], [406, 407], [439, 444]], 'max_presence': 240, 'no_activity': 120}, {'counts': [1, 1, 1, 0], 'occ_pct': [6, 6, 56, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 5, 'events': [[10, 12], [52, 57], [59, 62], [69, 77]], 'max_presence': 180, 'no_activity': 600}, {'counts': [4, 0, 0, 0, 0], 'occ_pct': [15, 0, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 3, 'events': [[-15, -10], [24, 380], [410, 415], [455, 495], [511, 516]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0], 'occ_pct': [20, 100, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'})], [({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'}), ({'interval': 60, 'bins': 3, 'events': [], 'max_presence': 240, 'no_activity': 60}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 3, 'events': [[-3, 0], [13, 18]], 'max_presence': 180, 'no_activity': 600}, {'counts': [1, 0, 0], 'occ_pct': [8, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [[-19, 129], [148, 253], [263, 268], [288, 607], [646, 647]], 'max_presence': 180, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [100, 100], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 3, 'events': [[9, 14], [39, 41], [57, 97], [104, 144], [177, 182]], 'max_presence': 100, 'no_activity': 240}, {'counts': [4, 1, 0], 'occ_pct': [52, 24, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 5, 'events': [[86, 88], [118, 121], [148, 150], [167, 169], [9, 49]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 0, 1, 1, 1], 'occ_pct': [70, 63, 6, 6, 10], 'status': 'ok'})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| timing oracle 0 | {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'} | {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'} | Passed |
| timing oracle 1 | {'counts': [1, 1], 'occ_pct': [0, 0], 'status': 'ok'} | {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'} | Failed |
| timing oracle 2 | {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'} | {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'} | Passed |
| timing oracle 3 | {'counts': [2, 0, 0, 0, 0], 'occ_pct': [0, 100, 100, 100, 100], 'status': 'stuck-on'} | {'counts': [2, 0, 0, 0, 0], 'occ_pct': [73, 100, 100, 100, 100], 'status': 'stuck-on'} | Failed |
| timing oracle 4 | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'} | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'} | Passed |
| timing oracle 5 | {'counts': [1, 0, 2, 0, 1], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'} | {'counts': [1, 0, 2, 0, 1], 'occ_pct': [13, 13, 20, 0, 10], 'status': 'ok'} | Failed |
| timing oracle 6 | {'counts': [0, 1, 3, 1, 2], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'} | {'counts': [0, 1, 3, 1, 2], 'occ_pct': [0, 26, 43, 46, 90], 'status': 'ok'} | Failed |
| timing oracle 7 | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'} | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'} | Passed |
SHA-256 / 494b89c1297ba09a72b0a624913dc397d7c90d386790ec82b9e926ebb06c3b1d
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
I = x['interval']
B = x['bins']
counts = [0] * B
occ = [0] * B
status = 'ok'
for on, off in sorted(x['events']):
b = on // I
if 0 <= b < B:
counts[b] += 1
if off - on >= x['max_presence']:
status = 'stuck-on'
for k in range(B):
lo, hi = k * I, (k + 1) * I
occ[k] += max(0, min(off, hi) - max(on, lo))
if not x['events'] and B * I >= x['no_activity']:
status = 'no-activity'
return {'counts': counts, 'occ_pct': [round(o * 100 / I) for o in occ], 'status': status}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 5, 'events': [[336, 344], [10, 326], [5, 7], [370, 373]], 'max_presence': 100, 'no_activity': 240}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [73, 100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 5, 'events': [[-19, -16]], 'max_presence': 240, 'no_activity': 240}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 5, 'events': [[89, 90], [67, 72], [123, 126], [-14, -9], [26, 34]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 0, 2, 0, 1], 'occ_pct': [13, 13, 20, 0, 10], 'status': 'ok'}), ({'interval': 30, 'bins': 5, 'events': [[-5, 0], [39, 47], [68, 71], [75, 83], [88, 96], [111, 119], [121, 124], [126, 166]], 'max_presence': 180, 'no_activity': 240}, {'counts': [0, 1, 3, 1, 2], 'occ_pct': [0, 26, 43, 46, 90], 'status': 'ok'}), ({'interval': 60, 'bins': 5, 'events': [], 'max_presence': 240, 'no_activity': 60}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'})], [({'interval': 30, 'bins': 5, 'events': [[-16, -14], [26, 66], [101, 102], [103, 104], [112, 115]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 0, 0, 3, 0], 'occ_pct': [13, 100, 20, 16, 0], 'status': 'ok'}), ({'interval': 120, 'bins': 4, 'events': [], 'max_presence': 100, 'no_activity': 240}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 3, 'events': [[-4, -3]], 'max_presence': 100, 'no_activity': 600}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'}), ({'interval': 120, 'bins': 2, 'events': [[6, 14], [70, 110], [123, 126], [24, 64], [152, 153], [177, 179]], 'max_presence': 100, 'no_activity': 120}, {'counts': [3, 3], 'occ_pct': [73, 5], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [[4, 6], [34, 74]], 'max_presence': 180, 'no_activity': 60}, {'counts': [2, 0, 0, 0], 'occ_pct': [46, 23, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'})], [({'interval': 30, 'bins': 2, 'events': [[-20, 20]], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [66, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [[3, 6], [29, 37], [42, 43], [47, 344], [357, 359], [392, 395], [426, 427], [436, 438]], 'max_presence': 100, 'no_activity': 240}, {'counts': [4, 0, 0, 0], 'occ_pct': [41, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 5, 'events': [[-13, 230], [264, 265], [303, 306], [342, 350]], 'max_presence': 100, 'no_activity': 600}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [100, 100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 3, 'events': [], 'max_presence': 180, 'no_activity': 240}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [[-9, -4], [26, 27], [47, 55]], 'max_presence': 240, 'no_activity': 600}, {'counts': [2, 0], 'occ_pct': [15, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'})], [({'interval': 60, 'bins': 4, 'events': [[-18, -15]], 'max_presence': 240, 'no_activity': 120}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [], 'max_presence': 240, 'no_activity': 600}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[-10, -2], [26, 28], [54, 56], [73, 367], [392, 400], [406, 407], [439, 444]], 'max_presence': 240, 'no_activity': 120}, {'counts': [1, 1, 1, 0], 'occ_pct': [6, 6, 56, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 5, 'events': [[10, 12], [52, 57], [59, 62], [69, 77]], 'max_presence': 180, 'no_activity': 600}, {'counts': [4, 0, 0, 0, 0], 'occ_pct': [15, 0, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 3, 'events': [[-15, -10], [24, 380], [410, 415], [455, 495], [511, 516]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0], 'occ_pct': [20, 100, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'})], [({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'}), ({'interval': 60, 'bins': 3, 'events': [], 'max_presence': 240, 'no_activity': 60}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 3, 'events': [[-3, 0], [13, 18]], 'max_presence': 180, 'no_activity': 600}, {'counts': [1, 0, 0], 'occ_pct': [8, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [[-19, 129], [148, 253], [263, 268], [288, 607], [646, 647]], 'max_presence': 180, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [100, 100], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 3, 'events': [[9, 14], [39, 41], [57, 97], [104, 144], [177, 182]], 'max_presence': 100, 'no_activity': 240}, {'counts': [4, 1, 0], 'occ_pct': [52, 24, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 5, 'events': [[86, 88], [118, 121], [148, 150], [167, 169], [9, 49]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 0, 1, 1, 1], 'occ_pct': [70, 63, 6, 6, 10], 'status': 'ok'})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| timing oracle 0 | {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'} | {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'} | Passed |
| timing oracle 1 | {'counts': [1, 1], 'occ_pct': [8, 7], 'status': 'ok'} | {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'} | Failed |
| timing oracle 2 | {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'} | {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'} | Passed |
| timing oracle 3 | {'counts': [2, 0, 0, 0, 0], 'occ_pct': [73, 100, 100, 100, 100], 'status': 'stuck-on'} | {'counts': [2, 0, 0, 0, 0], 'occ_pct': [73, 100, 100, 100, 100], 'status': 'stuck-on'} | Passed |
| timing oracle 4 | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'} | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'} | Passed |
| timing oracle 5 | {'counts': [1, 0, 2, 0, 1], 'occ_pct': [13, 13, 20, 0, 10], 'status': 'ok'} | {'counts': [1, 0, 2, 0, 1], 'occ_pct': [13, 13, 20, 0, 10], 'status': 'ok'} | Passed |
| timing oracle 6 | {'counts': [0, 1, 3, 1, 2], 'occ_pct': [0, 27, 43, 47, 90], 'status': 'ok'} | {'counts': [0, 1, 3, 1, 2], 'occ_pct': [0, 26, 43, 46, 90], 'status': 'ok'} | Failed |
| timing oracle 7 | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'} | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'} | Passed |
SHA-256 / 6fd30fedb2b0205d4a9b0918740565b003d3026d63a75c2045ff9918d639f26e
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
I = x['interval']
B = x['bins']
counts = [0] * B
occ = [0] * B
status = 'ok'
for on, off in sorted(x['events']):
b = on // I
if 0 <= b < B:
counts[b] += 1
if off - on >= x['max_presence']:
status = 'stuck-on'
for k in range(B):
lo, hi = k * I, (k + 1) * I
occ[k] += max(0, min(off, hi) - max(on, lo))
if not x['events'] and B * I >= x['no_activity']:
status = 'no-activity'
return {'counts': counts, 'occ_pct': [o * 100 // I for o in occ], 'status': status}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 5, 'events': [[336, 344], [10, 326], [5, 7], [370, 373]], 'max_presence': 100, 'no_activity': 240}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [73, 100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 5, 'events': [[-19, -16]], 'max_presence': 240, 'no_activity': 240}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 5, 'events': [[89, 90], [67, 72], [123, 126], [-14, -9], [26, 34]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 0, 2, 0, 1], 'occ_pct': [13, 13, 20, 0, 10], 'status': 'ok'}), ({'interval': 30, 'bins': 5, 'events': [[-5, 0], [39, 47], [68, 71], [75, 83], [88, 96], [111, 119], [121, 124], [126, 166]], 'max_presence': 180, 'no_activity': 240}, {'counts': [0, 1, 3, 1, 2], 'occ_pct': [0, 26, 43, 46, 90], 'status': 'ok'}), ({'interval': 60, 'bins': 5, 'events': [], 'max_presence': 240, 'no_activity': 60}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'})], [({'interval': 30, 'bins': 5, 'events': [[-16, -14], [26, 66], [101, 102], [103, 104], [112, 115]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 0, 0, 3, 0], 'occ_pct': [13, 100, 20, 16, 0], 'status': 'ok'}), ({'interval': 120, 'bins': 4, 'events': [], 'max_presence': 100, 'no_activity': 240}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 3, 'events': [[-4, -3]], 'max_presence': 100, 'no_activity': 600}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'}), ({'interval': 120, 'bins': 2, 'events': [[6, 14], [70, 110], [123, 126], [24, 64], [152, 153], [177, 179]], 'max_presence': 100, 'no_activity': 120}, {'counts': [3, 3], 'occ_pct': [73, 5], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [[4, 6], [34, 74]], 'max_presence': 180, 'no_activity': 60}, {'counts': [2, 0, 0, 0], 'occ_pct': [46, 23, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'})], [({'interval': 30, 'bins': 2, 'events': [[-20, 20]], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [66, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [[3, 6], [29, 37], [42, 43], [47, 344], [357, 359], [392, 395], [426, 427], [436, 438]], 'max_presence': 100, 'no_activity': 240}, {'counts': [4, 0, 0, 0], 'occ_pct': [41, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 5, 'events': [[-13, 230], [264, 265], [303, 306], [342, 350]], 'max_presence': 100, 'no_activity': 600}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [100, 100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 3, 'events': [], 'max_presence': 180, 'no_activity': 240}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [[-9, -4], [26, 27], [47, 55]], 'max_presence': 240, 'no_activity': 600}, {'counts': [2, 0], 'occ_pct': [15, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'})], [({'interval': 60, 'bins': 4, 'events': [[-18, -15]], 'max_presence': 240, 'no_activity': 120}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [], 'max_presence': 240, 'no_activity': 600}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[-10, -2], [26, 28], [54, 56], [73, 367], [392, 400], [406, 407], [439, 444]], 'max_presence': 240, 'no_activity': 120}, {'counts': [1, 1, 1, 0], 'occ_pct': [6, 6, 56, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 5, 'events': [[10, 12], [52, 57], [59, 62], [69, 77]], 'max_presence': 180, 'no_activity': 600}, {'counts': [4, 0, 0, 0, 0], 'occ_pct': [15, 0, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 3, 'events': [[-15, -10], [24, 380], [410, 415], [455, 495], [511, 516]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0], 'occ_pct': [20, 100, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'})], [({'interval': 60, 'bins': 2, 'events': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'}), ({'interval': 60, 'bins': 3, 'events': [], 'max_presence': 240, 'no_activity': 60}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 3, 'events': [[-3, 0], [13, 18]], 'max_presence': 180, 'no_activity': 600}, {'counts': [1, 0, 0], 'occ_pct': [8, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[0, 180]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [[-19, 129], [148, 253], [263, 268], [288, 607], [646, 647]], 'max_presence': 180, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [100, 100], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 3, 'events': [[9, 14], [39, 41], [57, 97], [104, 144], [177, 182]], 'max_presence': 100, 'no_activity': 240}, {'counts': [4, 1, 0], 'occ_pct': [52, 24, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 5, 'events': [[86, 88], [118, 121], [148, 150], [167, 169], [9, 49]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 0, 1, 1, 1], 'occ_pct': [70, 63, 6, 6, 10], 'status': 'ok'})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
check('timing oracle' + ' %d' % i, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| timing oracle 0 | {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'} | {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'} | Passed |
| timing oracle 1 | {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'} | {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'} | Passed |
| timing oracle 2 | {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'} | {'counts': [1, 0, 0, 0], 'occ_pct': [100, 100, 100, 100], 'status': 'stuck-on'} | Passed |
| timing oracle 3 | {'counts': [2, 0, 0, 0, 0], 'occ_pct': [73, 100, 100, 100, 100], 'status': 'stuck-on'} | {'counts': [2, 0, 0, 0, 0], 'occ_pct': [73, 100, 100, 100, 100], 'status': 'stuck-on'} | Passed |
| timing oracle 4 | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'} | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'ok'} | Passed |
| timing oracle 5 | {'counts': [1, 0, 2, 0, 1], 'occ_pct': [13, 13, 20, 0, 10], 'status': 'ok'} | {'counts': [1, 0, 2, 0, 1], 'occ_pct': [13, 13, 20, 0, 10], 'status': 'ok'} | Passed |
| timing oracle 6 | {'counts': [0, 1, 3, 1, 2], 'occ_pct': [0, 26, 43, 46, 90], 'status': 'ok'} | {'counts': [0, 1, 3, 1, 2], 'occ_pct': [0, 26, 43, 46, 90], 'status': 'ok'} | Passed |
| timing oracle 7 | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'} | {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'} | Passed |
SHA-256 / 1cf3e5a535a66013e857881ffa423a1b7f812acbeb5eb95399ced9141642375f
Verification & scope
A deterministic, bounded toy model with a stipulated contract; it makes no claim of conformance to any agency manual or standard. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:48:00.409147+00:00.
Case digest / 63495eaa974fe94b2ae6e78ad97f00f34a13880a1c212acd255a3da934e51f01