broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (gs - a) % C
    return ['early', wait]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 80, 'green_start': 28, 'green_end': 61, 'max_ext': 15, 'max_early': 12, 'arrival': 236, 'last_granted': 0, 'cycle_index': 17, 'lockout': 3}, ['early', 12]), ({'cycle': 140, 'green_start': 18, 'green_end': 72, 'max_ext': 19, 'max_early': 15, 'arrival': 359, 'last_granted': 1, 'cycle_index': 10, 'lockout': 2}, ['extend', 8]), ({'cycle': 100, 'green_start': 40, 'green_end': 85, 'max_ext': 20, 'max_early': 14, 'arrival': 228, 'last_granted': 0, 'cycle_index': 12, 'lockout': 1}, ['early', 12]), ({'cycle': 110, 'green_start': 52, 'green_end': 85, 'max_ext': 13, 'max_early': 14, 'arrival': 329, 'last_granted': None, 'cycle_index': 10, 'lockout': 2}, ['early', 14]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 110, 'green_start': 40, 'green_end': 91, 'max_ext': 19, 'max_early': 8, 'arrival': 226, 'last_granted': 8, 'cycle_index': 16, 'lockout': 1}, ['early', 8])], [({'cycle': 120, 'green_start': 37, 'green_end': 94, 'max_ext': 13, 'max_early': 20, 'arrival': 14, 'last_granted': None, 'cycle_index': 2, 'lockout': 2}, ['early', 20]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 120, 'green_start': 21, 'green_end': 39, 'max_ext': 5, 'max_early': 15, 'arrival': 133, 'last_granted': 14, 'cycle_index': 21, 'lockout': 2}, ['early', 8]), ({'cycle': 130, 'green_start': 37, 'green_end': 74, 'max_ext': 16, 'max_early': 18, 'arrival': 6, 'last_granted': 9, 'cycle_index': 14, 'lockout': 1}, ['early', 18]), ({'cycle': 90, 'green_start': 27, 'green_end': 67, 'max_ext': 11, 'max_early': 10, 'arrival': 89, 'last_granted': 11, 'cycle_index': 6, 'lockout': 1}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 100, 'green_start': 45, 'green_end': 87, 'max_ext': 6, 'max_early': 20, 'arrival': 121, 'last_granted': None, 'cycle_index': 7, 'lockout': 3}, ['early', 20])], [({'cycle': 80, 'green_start': 33, 'green_end': 69, 'max_ext': 9, 'max_early': 10, 'arrival': 169, 'last_granted': None, 'cycle_index': 21, 'lockout': 1}, ['early', 10]), ({'cycle': 140, 'green_start': 27, 'green_end': 68, 'max_ext': 6, 'max_early': 9, 'arrival': 217, 'last_granted': None, 'cycle_index': 21, 'lockout': 2}, ['early', 9]), ({'cycle': 90, 'green_start': 2, 'green_end': 25, 'max_ext': 16, 'max_early': 17, 'arrival': 132, 'last_granted': None, 'cycle_index': 18, 'lockout': 1}, ['early', 17]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 110, 'green_start': 26, 'green_end': 51, 'max_ext': 5, 'max_early': 15, 'arrival': 129, 'last_granted': 8, 'cycle_index': 17, 'lockout': 3}, ['early', 7]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 140, 'green_start': 52, 'green_end': 106, 'max_ext': 6, 'max_early': 8, 'arrival': 98, 'last_granted': None, 'cycle_index': 1, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2])], [({'cycle': 100, 'green_start': 9, 'green_end': 55, 'max_ext': 8, 'max_early': 6, 'arrival': 190, 'last_granted': 9, 'cycle_index': 20, 'lockout': 3}, ['early', 6]), ({'cycle': 80, 'green_start': 35, 'green_end': 60, 'max_ext': 19, 'max_early': 12, 'arrival': 62, 'last_granted': None, 'cycle_index': 9, 'lockout': 3}, ['extend', 3]), ({'cycle': 120, 'green_start': 17, 'green_end': 67, 'max_ext': 15, 'max_early': 10, 'arrival': 10, 'last_granted': None, 'cycle_index': 5, 'lockout': 2}, ['early', 7]), ({'cycle': 120, 'green_start': 31, 'green_end': 81, 'max_ext': 14, 'max_early': 11, 'arrival': 340, 'last_granted': 0, 'cycle_index': 8, 'lockout': 3}, ['early', 11]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 80, 'green_start': 37, 'green_end': 55, 'max_ext': 5, 'max_early': 9, 'arrival': 11, 'last_granted': 7, 'cycle_index': 11, 'lockout': 2}, ['early', 9])], [({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 110, 'green_start': 19, 'green_end': 57, 'max_ext': 8, 'max_early': 12, 'arrival': 305, 'last_granted': 14, 'cycle_index': 11, 'lockout': 2}, ['locked', 0]), ({'cycle': 80, 'green_start': 3, 'green_end': 37, 'max_ext': 9, 'max_early': 10, 'arrival': 224, 'last_granted': 2, 'cycle_index': 14, 'lockout': 3}, ['early', 10]), ({'cycle': 120, 'green_start': 54, 'green_end': 83, 'max_ext': 7, 'max_early': 15, 'arrival': 7, 'last_granted': None, 'cycle_index': 1, 'lockout': 2}, ['early', 15]), ({'cycle': 140, 'green_start': 2, 'green_end': 49, 'max_ext': 8, 'max_early': 8, 'arrival': 204, 'last_granted': 0, 'cycle_index': 15, 'lockout': 3}, ['early', 8]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 130, 'green_start': 18, 'green_end': 47, 'max_ext': 19, 'max_early': 16, 'arrival': 138, 'last_granted': 4, 'cycle_index': 20, 'lockout': 1}, ['early', 10]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1])]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (gs - a) % C
    return ['early', x['max_early']]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 80, 'green_start': 28, 'green_end': 61, 'max_ext': 15, 'max_early': 12, 'arrival': 236, 'last_granted': 0, 'cycle_index': 17, 'lockout': 3}, ['early', 12]), ({'cycle': 140, 'green_start': 18, 'green_end': 72, 'max_ext': 19, 'max_early': 15, 'arrival': 359, 'last_granted': 1, 'cycle_index': 10, 'lockout': 2}, ['extend', 8]), ({'cycle': 100, 'green_start': 40, 'green_end': 85, 'max_ext': 20, 'max_early': 14, 'arrival': 228, 'last_granted': 0, 'cycle_index': 12, 'lockout': 1}, ['early', 12]), ({'cycle': 110, 'green_start': 52, 'green_end': 85, 'max_ext': 13, 'max_early': 14, 'arrival': 329, 'last_granted': None, 'cycle_index': 10, 'lockout': 2}, ['early', 14]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 110, 'green_start': 40, 'green_end': 91, 'max_ext': 19, 'max_early': 8, 'arrival': 226, 'last_granted': 8, 'cycle_index': 16, 'lockout': 1}, ['early', 8])], [({'cycle': 120, 'green_start': 37, 'green_end': 94, 'max_ext': 13, 'max_early': 20, 'arrival': 14, 'last_granted': None, 'cycle_index': 2, 'lockout': 2}, ['early', 20]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 120, 'green_start': 21, 'green_end': 39, 'max_ext': 5, 'max_early': 15, 'arrival': 133, 'last_granted': 14, 'cycle_index': 21, 'lockout': 2}, ['early', 8]), ({'cycle': 130, 'green_start': 37, 'green_end': 74, 'max_ext': 16, 'max_early': 18, 'arrival': 6, 'last_granted': 9, 'cycle_index': 14, 'lockout': 1}, ['early', 18]), ({'cycle': 90, 'green_start': 27, 'green_end': 67, 'max_ext': 11, 'max_early': 10, 'arrival': 89, 'last_granted': 11, 'cycle_index': 6, 'lockout': 1}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 100, 'green_start': 45, 'green_end': 87, 'max_ext': 6, 'max_early': 20, 'arrival': 121, 'last_granted': None, 'cycle_index': 7, 'lockout': 3}, ['early', 20])], [({'cycle': 80, 'green_start': 33, 'green_end': 69, 'max_ext': 9, 'max_early': 10, 'arrival': 169, 'last_granted': None, 'cycle_index': 21, 'lockout': 1}, ['early', 10]), ({'cycle': 140, 'green_start': 27, 'green_end': 68, 'max_ext': 6, 'max_early': 9, 'arrival': 217, 'last_granted': None, 'cycle_index': 21, 'lockout': 2}, ['early', 9]), ({'cycle': 90, 'green_start': 2, 'green_end': 25, 'max_ext': 16, 'max_early': 17, 'arrival': 132, 'last_granted': None, 'cycle_index': 18, 'lockout': 1}, ['early', 17]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 110, 'green_start': 26, 'green_end': 51, 'max_ext': 5, 'max_early': 15, 'arrival': 129, 'last_granted': 8, 'cycle_index': 17, 'lockout': 3}, ['early', 7]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 140, 'green_start': 52, 'green_end': 106, 'max_ext': 6, 'max_early': 8, 'arrival': 98, 'last_granted': None, 'cycle_index': 1, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2])], [({'cycle': 100, 'green_start': 9, 'green_end': 55, 'max_ext': 8, 'max_early': 6, 'arrival': 190, 'last_granted': 9, 'cycle_index': 20, 'lockout': 3}, ['early', 6]), ({'cycle': 80, 'green_start': 35, 'green_end': 60, 'max_ext': 19, 'max_early': 12, 'arrival': 62, 'last_granted': None, 'cycle_index': 9, 'lockout': 3}, ['extend', 3]), ({'cycle': 120, 'green_start': 17, 'green_end': 67, 'max_ext': 15, 'max_early': 10, 'arrival': 10, 'last_granted': None, 'cycle_index': 5, 'lockout': 2}, ['early', 7]), ({'cycle': 120, 'green_start': 31, 'green_end': 81, 'max_ext': 14, 'max_early': 11, 'arrival': 340, 'last_granted': 0, 'cycle_index': 8, 'lockout': 3}, ['early', 11]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 80, 'green_start': 37, 'green_end': 55, 'max_ext': 5, 'max_early': 9, 'arrival': 11, 'last_granted': 7, 'cycle_index': 11, 'lockout': 2}, ['early', 9])], [({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 110, 'green_start': 19, 'green_end': 57, 'max_ext': 8, 'max_early': 12, 'arrival': 305, 'last_granted': 14, 'cycle_index': 11, 'lockout': 2}, ['locked', 0]), ({'cycle': 80, 'green_start': 3, 'green_end': 37, 'max_ext': 9, 'max_early': 10, 'arrival': 224, 'last_granted': 2, 'cycle_index': 14, 'lockout': 3}, ['early', 10]), ({'cycle': 120, 'green_start': 54, 'green_end': 83, 'max_ext': 7, 'max_early': 15, 'arrival': 7, 'last_granted': None, 'cycle_index': 1, 'lockout': 2}, ['early', 15]), ({'cycle': 140, 'green_start': 2, 'green_end': 49, 'max_ext': 8, 'max_early': 8, 'arrival': 204, 'last_granted': 0, 'cycle_index': 15, 'lockout': 3}, ['early', 8]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 130, 'green_start': 18, 'green_end': 47, 'max_ext': 19, 'max_early': 16, 'arrival': 138, 'last_granted': 4, 'cycle_index': 20, 'lockout': 1}, ['early', 10]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1])]]
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)

prompt:
Transit signal priority decision returns a wrong result when early green always uses the maximum advance.

Input {cycle, green_start, green_end (exclusive), max_ext, max_early, arrival (seconds, reduced modulo cycle), last_granted (cycle index or null), cycle_index, lockout}. A request within lockout cycles of the last grant (difference <= lockout) returns ['locked', 0]. Arrival in green needs nothing. If the arrival is less than max_ext seconds after green end (cyclically) green is extended through the arrival second: ['extend', d+1]. Otherwise green starts early by min(max_early, seconds until next green start).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (a - gs) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 130, 'green_start': 5, 'green_end': 23, 'max_ext': 5, 'max_early': 14, 'arrival': 261, 'last_granted': 0, 'cycle_index': 12, 'lockout': 1}, ['early', 4]), ({'cycle': 120, 'green_start': 28, 'green_end': 81, 'max_ext': 11, 'max_early': 16, 'arrival': 17, 'last_granted': None, 'cycle_index': 17, 'lockout': 2}, ['early', 11]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 90, 'green_start': 2, 'green_end': 24, 'max_ext': 19, 'max_early': 10, 'arrival': 151, 'last_granted': None, 'cycle_index': 3, 'lockout': 2}, ['early', 10]), ({'cycle': 140, 'green_start': 23, 'green_end': 39, 'max_ext': 18, 'max_early': 10, 'arrival': 206, 'last_granted': 1, 'cycle_index': 18, 'lockout': 3}, ['early', 10]), ({'cycle': 140, 'green_start': 36, 'green_end': 98, 'max_ext': 10, 'max_early': 15, 'arrival': 23, 'last_granted': 10, 'cycle_index': 13, 'lockout': 1}, ['early', 13])], [({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 110, 'green_start': 49, 'green_end': 88, 'max_ext': 8, 'max_early': 20, 'arrival': 36, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['early', 13]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 80, 'green_start': 13, 'green_end': 42, 'max_ext': 10, 'max_early': 5, 'arrival': 66, 'last_granted': None, 'cycle_index': 10, 'lockout': 3}, ['early', 5]), ({'cycle': 100, 'green_start': 24, 'green_end': 51, 'max_ext': 20, 'max_early': 20, 'arrival': 87, 'last_granted': 4, 'cycle_index': 17, 'lockout': 1}, ['early', 20]), ({'cycle': 80, 'green_start': 10, 'green_end': 38, 'max_ext': 10, 'max_early': 16, 'arrival': 157, 'last_granted': 17, 'cycle_index': 22, 'lockout': 2}, ['early', 13]), ({'cycle': 110, 'green_start': 9, 'green_end': 41, 'max_ext': 17, 'max_early': 18, 'arrival': 115, 'last_granted': None, 'cycle_index': 18, 'lockout': 3}, ['early', 4])], [({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 140, 'green_start': 4, 'green_end': 36, 'max_ext': 15, 'max_early': 11, 'arrival': 99, 'last_granted': None, 'cycle_index': 6, 'lockout': 1}, ['early', 11]), ({'cycle': 90, 'green_start': 25, 'green_end': 40, 'max_ext': 8, 'max_early': 9, 'arrival': 60, 'last_granted': None, 'cycle_index': 20, 'lockout': 1}, ['early', 9]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 2, 'green_end': 30, 'max_ext': 12, 'max_early': 13, 'arrival': 297, 'last_granted': None, 'cycle_index': 10, 'lockout': 3}, ['early', 5]), ({'cycle': 120, 'green_start': 50, 'green_end': 90, 'max_ext': 11, 'max_early': 8, 'arrival': 49, 'last_granted': 4, 'cycle_index': 13, 'lockout': 3}, ['early', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 42, 'green_end': 86, 'max_ext': 9, 'max_early': 11, 'arrival': 38, 'last_granted': None, 'cycle_index': 16, 'lockout': 3}, ['early', 4])], [({'cycle': 90, 'green_start': 42, 'green_end': 78, 'max_ext': 18, 'max_early': 14, 'arrival': 209, 'last_granted': None, 'cycle_index': 8, 'lockout': 2}, ['early', 13]), ({'cycle': 100, 'green_start': 1, 'green_end': 27, 'max_ext': 13, 'max_early': 8, 'arrival': 261, 'last_granted': None, 'cycle_index': 2, 'lockout': 3}, ['early', 8]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 26, 'green_end': 44, 'max_ext': 5, 'max_early': 15, 'arrival': 251, 'last_granted': None, 'cycle_index': 7, 'lockout': 3}, ['early', 15]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 120, 'green_start': 18, 'green_end': 55, 'max_ext': 12, 'max_early': 18, 'arrival': 126, 'last_granted': None, 'cycle_index': 20, 'lockout': 1}, ['early', 12]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 130, 'green_start': 4, 'green_end': 40, 'max_ext': 12, 'max_early': 20, 'arrival': 388, 'last_granted': None, 'cycle_index': 10, 'lockout': 1}, ['early', 6])], [({'cycle': 90, 'green_start': 29, 'green_end': 48, 'max_ext': 19, 'max_early': 20, 'arrival': 14, 'last_granted': 6, 'cycle_index': 10, 'lockout': 1}, ['early', 15]), ({'cycle': 130, 'green_start': 18, 'green_end': 48, 'max_ext': 17, 'max_early': 6, 'arrival': 257, 'last_granted': 19, 'cycle_index': 0, 'lockout': 1}, ['locked', 0]), ({'cycle': 120, 'green_start': 9, 'green_end': 40, 'max_ext': 10, 'max_early': 11, 'arrival': 349, 'last_granted': None, 'cycle_index': 1, 'lockout': 1}, ['early', 11]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 130, 'green_start': 33, 'green_end': 59, 'max_ext': 11, 'max_early': 17, 'arrival': 153, 'last_granted': None, 'cycle_index': 10, 'lockout': 1}, ['early', 10]), ({'cycle': 140, 'green_start': 23, 'green_end': 87, 'max_ext': 18, 'max_early': 8, 'arrival': 409, 'last_granted': 8, 'cycle_index': 17, 'lockout': 2}, ['early', 8]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2])]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = gs - a
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 130, 'green_start': 5, 'green_end': 23, 'max_ext': 5, 'max_early': 14, 'arrival': 261, 'last_granted': 0, 'cycle_index': 12, 'lockout': 1}, ['early', 4]), ({'cycle': 120, 'green_start': 28, 'green_end': 81, 'max_ext': 11, 'max_early': 16, 'arrival': 17, 'last_granted': None, 'cycle_index': 17, 'lockout': 2}, ['early', 11]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 90, 'green_start': 2, 'green_end': 24, 'max_ext': 19, 'max_early': 10, 'arrival': 151, 'last_granted': None, 'cycle_index': 3, 'lockout': 2}, ['early', 10]), ({'cycle': 140, 'green_start': 23, 'green_end': 39, 'max_ext': 18, 'max_early': 10, 'arrival': 206, 'last_granted': 1, 'cycle_index': 18, 'lockout': 3}, ['early', 10]), ({'cycle': 140, 'green_start': 36, 'green_end': 98, 'max_ext': 10, 'max_early': 15, 'arrival': 23, 'last_granted': 10, 'cycle_index': 13, 'lockout': 1}, ['early', 13])], [({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 110, 'green_start': 49, 'green_end': 88, 'max_ext': 8, 'max_early': 20, 'arrival': 36, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['early', 13]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 80, 'green_start': 13, 'green_end': 42, 'max_ext': 10, 'max_early': 5, 'arrival': 66, 'last_granted': None, 'cycle_index': 10, 'lockout': 3}, ['early', 5]), ({'cycle': 100, 'green_start': 24, 'green_end': 51, 'max_ext': 20, 'max_early': 20, 'arrival': 87, 'last_granted': 4, 'cycle_index': 17, 'lockout': 1}, ['early', 20]), ({'cycle': 80, 'green_start': 10, 'green_end': 38, 'max_ext': 10, 'max_early': 16, 'arrival': 157, 'last_granted': 17, 'cycle_index': 22, 'lockout': 2}, ['early', 13]), ({'cycle': 110, 'green_start': 9, 'green_end': 41, 'max_ext': 17, 'max_early': 18, 'arrival': 115, 'last_granted': None, 'cycle_index': 18, 'lockout': 3}, ['early', 4])], [({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 140, 'green_start': 4, 'green_end': 36, 'max_ext': 15, 'max_early': 11, 'arrival': 99, 'last_granted': None, 'cycle_index': 6, 'lockout': 1}, ['early', 11]), ({'cycle': 90, 'green_start': 25, 'green_end': 40, 'max_ext': 8, 'max_early': 9, 'arrival': 60, 'last_granted': None, 'cycle_index': 20, 'lockout': 1}, ['early', 9]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 2, 'green_end': 30, 'max_ext': 12, 'max_early': 13, 'arrival': 297, 'last_granted': None, 'cycle_index': 10, 'lockout': 3}, ['early', 5]), ({'cycle': 120, 'green_start': 50, 'green_end': 90, 'max_ext': 11, 'max_early': 8, 'arrival': 49, 'last_granted': 4, 'cycle_index': 13, 'lockout': 3}, ['early', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 42, 'green_end': 86, 'max_ext': 9, 'max_early': 11, 'arrival': 38, 'last_granted': None, 'cycle_index': 16, 'lockout': 3}, ['early', 4])], [({'cycle': 90, 'green_start': 42, 'green_end': 78, 'max_ext': 18, 'max_early': 14, 'arrival': 209, 'last_granted': None, 'cycle_index': 8, 'lockout': 2}, ['early', 13]), ({'cycle': 100, 'green_start': 1, 'green_end': 27, 'max_ext': 13, 'max_early': 8, 'arrival': 261, 'last_granted': None, 'cycle_index': 2, 'lockout': 3}, ['early', 8]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 26, 'green_end': 44, 'max_ext': 5, 'max_early': 15, 'arrival': 251, 'last_granted': None, 'cycle_index': 7, 'lockout': 3}, ['early', 15]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 120, 'green_start': 18, 'green_end': 55, 'max_ext': 12, 'max_early': 18, 'arrival': 126, 'last_granted': None, 'cycle_index': 20, 'lockout': 1}, ['early', 12]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 130, 'green_start': 4, 'green_end': 40, 'max_ext': 12, 'max_early': 20, 'arrival': 388, 'last_granted': None, 'cycle_index': 10, 'lockout': 1}, ['early', 6])], [({'cycle': 90, 'green_start': 29, 'green_end': 48, 'max_ext': 19, 'max_early': 20, 'arrival': 14, 'last_granted': 6, 'cycle_index': 10, 'lockout': 1}, ['early', 15]), ({'cycle': 130, 'green_start': 18, 'green_end': 48, 'max_ext': 17, 'max_early': 6, 'arrival': 257, 'last_granted': 19, 'cycle_index': 0, 'lockout': 1}, ['locked', 0]), ({'cycle': 120, 'green_start': 9, 'green_end': 40, 'max_ext': 10, 'max_early': 11, 'arrival': 349, 'last_granted': None, 'cycle_index': 1, 'lockout': 1}, ['early', 11]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 130, 'green_start': 33, 'green_end': 59, 'max_ext': 11, 'max_early': 17, 'arrival': 153, 'last_granted': None, 'cycle_index': 10, 'lockout': 1}, ['early', 10]), ({'cycle': 140, 'green_start': 23, 'green_end': 87, 'max_ext': 18, 'max_early': 8, 'arrival': 409, 'last_granted': 8, 'cycle_index': 17, 'lockout': 2}, ['early', 8]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2])]]
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)

prompt:
Transit signal priority decision returns a wrong result when time to next green is measured backwards.

Input {cycle, green_start, green_end (exclusive), max_ext, max_early, arrival (seconds, reduced modulo cycle), last_granted (cycle index or null), cycle_index, lockout}. A request within lockout cycles of the last grant (difference <= lockout) returns ['locked', 0]. Arrival in green needs nothing. If the arrival is less than max_ext seconds after green end (cyclically) green is extended through the arrival second: ['extend', d+1]. Otherwise green starts early by min(max_early, seconds until next green start).

split: open-access


broken_source:
"""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 = off // 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': 30, 'bins': 2, 'events': [[455, 463], [31, 33], [419, 422], [1, 4], [53, 58], [96, 391], [78, 79], [439, 441]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 2], 'occ_pct': [10, 23], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 4, 'events': [[8, 16], [44, 45], [72, 80], [101, 102]], 'max_presence': 240, 'no_activity': 240}, {'counts': [4, 0, 0, 0], 'occ_pct': [15, 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': 30, 'bins': 4, 'events': [[-14, -6], [31, 34], [55, 95], [124, 164], [188, 190], [194, 197], [222, 230]], 'max_presence': 100, 'no_activity': 600}, {'counts': [0, 2, 0, 0], 'occ_pct': [0, 26, 100, 16], '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': 120, 'bins': 3, 'events': [[0, 8], [32, 33], [54, 57], [84, 124], [155, 160], [187, 189]], 'max_presence': 180, 'no_activity': 120}, {'counts': [4, 2, 0], 'occ_pct': [40, 9, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [[4, 7]], 'max_presence': 100, 'no_activity': 240}, {'counts': [1, 0, 0, 0], 'occ_pct': [5, 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': 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': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 5, 'events': [[-15, -10], [27, 30]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0, 0], 'occ_pct': [5, 0, 0, 0, 0], 'status': 'ok'}), ({'interval': 120, 'bins': 2, 'events': [[-20, -12], [0, 1], [32, 37], [58, 98], [105, 108], [112, 152]], 'max_presence': 180, 'no_activity': 60}, {'counts': [5, 0], 'occ_pct': [47, 26], 'status': 'ok'}), ({'interval': 60, 'bins': 5, 'events': [[58, 59], [86, 89], [34, 36], [8, 13]], 'max_presence': 180, 'no_activity': 240}, {'counts': [3, 1, 0, 0, 0], 'occ_pct': [13, 5, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 3, 'events': [[-5, 0], [590, 593], [346, 555], [38, 235], [305, 306], [644, 652], [273, 274], [629, 631]], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 1, 0], 'occ_pct': [0, 73, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 2, 'events': [[-9, -8], [31, 36], [72, 74], [88, 91], [93, 94]], 'max_presence': 240, 'no_activity': 240}, {'counts': [0, 1], 'occ_pct': [0, 16], 'status': 'ok'})], [({'interval': 60, 'bins': 4, 'events': [], 'max_presence': 180, 'no_activity': 600}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 3, 'events': [[213, 214], [61, 62], [0, 40], [177, 179], [99, 139]], 'max_presence': 100, 'no_activity': 240}, {'counts': [1, 2, 1], 'occ_pct': [66, 36, 35], 'status': 'ok'}), ({'interval': 30, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 600}, {'counts': [0, 0], 'occ_pct': [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': 60, 'bins': 2, 'events': [[-4, -3], [28, 68], [96, 97], [116, 121], [153, 155]], 'max_presence': 100, 'no_activity': 60}, {'counts': [1, 2], 'occ_pct': [53, 21], 'status': 'ok'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 120, 'bins': 4, 'events': [[-20, -15], [8, 13], [48, 49], [82, 85], [101, 104], [132, 133], [165, 168], [201, 202]], 'max_presence': 240, 'no_activity': 600}, {'counts': [4, 3, 0, 0], 'occ_pct': [10, 4, 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': 4, 'events': [[2, 42], [52, 57], [92, 93], [106, 107], [127, 231], [259, 299]], 'max_presence': 100, 'no_activity': 240}, {'counts': [1, 1, 0, 2], 'occ_pct': [93, 56, 0, 6], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 4, 'events': [[-10, -7], [12, 14], [51, 59], [61, 101], [134, 137]], 'max_presence': 180, 'no_activity': 60}, {'counts': [3, 1, 0, 0], 'occ_pct': [41, 2, 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': 60, 'bins': 5, 'events': [], 'max_presence': 240, 'no_activity': 240}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 3, 'events': [[-3, 301], [324, 332], [344, 346]], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0, 0], 'occ_pct': [100, 100, 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': 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': [[1, 2], [17, 25], [60, 65], [67, 69], [86, 87]], 'max_presence': 100, 'no_activity': 60}, {'counts': [2, 3], 'occ_pct': [15, 13], 'status': 'ok'})], [({'interval': 60, 'bins': 4, 'events': [[-11, -6], [17, 20], [27, 67]], 'max_presence': 100, 'no_activity': 600}, {'counts': [2, 0, 0, 0], 'occ_pct': [60, 11, 0, 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': 5, 'events': [], 'max_presence': 100, 'no_activity': 120}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 4, 'events': [[-8, 0], [31, 71], [93, 94]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 1, 0, 0], 'occ_pct': [48, 20, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 3, 'events': [[10, 13], [49, 54], [90, 98]], 'max_presence': 180, 'no_activity': 600}, {'counts': [1, 1, 0], 'occ_pct': [10, 16, 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': 120, 'bins': 4, 'events': [[9, 17], [26, 31], [46, 51], [88, 93], [109, 114]], 'max_presence': 240, 'no_activity': 600}, {'counts': [5, 0, 0, 0], 'occ_pct': [23, 0, 0, 0], '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)

source:
"""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 + off) // 2 // 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': 30, 'bins': 2, 'events': [[455, 463], [31, 33], [419, 422], [1, 4], [53, 58], [96, 391], [78, 79], [439, 441]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 2], 'occ_pct': [10, 23], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 4, 'events': [[8, 16], [44, 45], [72, 80], [101, 102]], 'max_presence': 240, 'no_activity': 240}, {'counts': [4, 0, 0, 0], 'occ_pct': [15, 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': 30, 'bins': 4, 'events': [[-14, -6], [31, 34], [55, 95], [124, 164], [188, 190], [194, 197], [222, 230]], 'max_presence': 100, 'no_activity': 600}, {'counts': [0, 2, 0, 0], 'occ_pct': [0, 26, 100, 16], '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': 120, 'bins': 3, 'events': [[0, 8], [32, 33], [54, 57], [84, 124], [155, 160], [187, 189]], 'max_presence': 180, 'no_activity': 120}, {'counts': [4, 2, 0], 'occ_pct': [40, 9, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 4, 'events': [[4, 7]], 'max_presence': 100, 'no_activity': 240}, {'counts': [1, 0, 0, 0], 'occ_pct': [5, 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': 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': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 5, 'events': [[-15, -10], [27, 30]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 0, 0, 0, 0], 'occ_pct': [5, 0, 0, 0, 0], 'status': 'ok'}), ({'interval': 120, 'bins': 2, 'events': [[-20, -12], [0, 1], [32, 37], [58, 98], [105, 108], [112, 152]], 'max_presence': 180, 'no_activity': 60}, {'counts': [5, 0], 'occ_pct': [47, 26], 'status': 'ok'}), ({'interval': 60, 'bins': 5, 'events': [[58, 59], [86, 89], [34, 36], [8, 13]], 'max_presence': 180, 'no_activity': 240}, {'counts': [3, 1, 0, 0, 0], 'occ_pct': [13, 5, 0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 3, 'events': [[-5, 0], [590, 593], [346, 555], [38, 235], [305, 306], [644, 652], [273, 274], [629, 631]], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 1, 0], 'occ_pct': [0, 73, 100], 'status': 'stuck-on'}), ({'interval': 30, 'bins': 2, 'events': [[-9, -8], [31, 36], [72, 74], [88, 91], [93, 94]], 'max_presence': 240, 'no_activity': 240}, {'counts': [0, 1], 'occ_pct': [0, 16], 'status': 'ok'})], [({'interval': 60, 'bins': 4, 'events': [], 'max_presence': 180, 'no_activity': 600}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 3, 'events': [[213, 214], [61, 62], [0, 40], [177, 179], [99, 139]], 'max_presence': 100, 'no_activity': 240}, {'counts': [1, 2, 1], 'occ_pct': [66, 36, 35], 'status': 'ok'}), ({'interval': 30, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 600}, {'counts': [0, 0], 'occ_pct': [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': 60, 'bins': 2, 'events': [[-4, -3], [28, 68], [96, 97], [116, 121], [153, 155]], 'max_presence': 100, 'no_activity': 60}, {'counts': [1, 2], 'occ_pct': [53, 21], 'status': 'ok'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 120, 'bins': 4, 'events': [[-20, -15], [8, 13], [48, 49], [82, 85], [101, 104], [132, 133], [165, 168], [201, 202]], 'max_presence': 240, 'no_activity': 600}, {'counts': [4, 3, 0, 0], 'occ_pct': [10, 4, 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': 4, 'events': [[2, 42], [52, 57], [92, 93], [106, 107], [127, 231], [259, 299]], 'max_presence': 100, 'no_activity': 240}, {'counts': [1, 1, 0, 2], 'occ_pct': [93, 56, 0, 6], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 4, 'events': [[-10, -7], [12, 14], [51, 59], [61, 101], [134, 137]], 'max_presence': 180, 'no_activity': 60}, {'counts': [3, 1, 0, 0], 'occ_pct': [41, 2, 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': 60, 'bins': 5, 'events': [], 'max_presence': 240, 'no_activity': 240}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 3, 'events': [[-3, 301], [324, 332], [344, 346]], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0, 0], 'occ_pct': [100, 100, 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': 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': [[1, 2], [17, 25], [60, 65], [67, 69], [86, 87]], 'max_presence': 100, 'no_activity': 60}, {'counts': [2, 3], 'occ_pct': [15, 13], 'status': 'ok'})], [({'interval': 60, 'bins': 4, 'events': [[-11, -6], [17, 20], [27, 67]], 'max_presence': 100, 'no_activity': 600}, {'counts': [2, 0, 0, 0], 'occ_pct': [60, 11, 0, 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': 5, 'events': [], 'max_presence': 100, 'no_activity': 120}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 4, 'events': [[-8, 0], [31, 71], [93, 94]], 'max_presence': 180, 'no_activity': 60}, {'counts': [1, 1, 0, 0], 'occ_pct': [48, 20, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 3, 'events': [[10, 13], [49, 54], [90, 98]], 'max_presence': 180, 'no_activity': 600}, {'counts': [1, 1, 0], 'occ_pct': [10, 16, 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': 120, 'bins': 4, 'events': [[9, 17], [26, 31], [46, 51], [88, 93], [109, 114]], 'max_presence': 240, 'no_activity': 600}, {'counts': [5, 0, 0, 0], 'occ_pct': [23, 0, 0, 0], '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)

prompt:
Loop detector count and occupancy binning returns a wrong result when vehicles are counted in the bin where they leave.

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}.

split: open-access


broken_source:
"""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) - on)
    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': 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': [], 'max_presence': 240, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [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': 120, 'bins': 2, 'events': [[-10, -9], [10, 50], [80, 88], [122, 127], [153, 156], [157, 197], [218, 258], [262, 267]], 'max_presence': 100, 'no_activity': 600}, {'counts': [2, 4], 'occ_pct': [40, 58], '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': 2, 'events': [], 'max_presence': 100, 'no_activity': 240}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 3, 'events': [], 'max_presence': 100, 'no_activity': 120}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'ok'}), ({'interval': 120, 'bins': 4, 'events': [[151, 153], [50, 58], [109, 111], [93, 101], [175, 178], [191, 199], [-1, 39]], 'max_presence': 100, 'no_activity': 240}, {'counts': [3, 3, 0, 0], 'occ_pct': [47, 10, 0, 0], 'status': 'ok'})], [({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 240, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 3, 'events': [], 'max_presence': 180, 'no_activity': 240}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 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': 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': 3, 'events': [], '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': 5, 'events': [[-1, 0], [59, 424], [-18, -10], [23, 31]], 'max_presence': 240, 'no_activity': 60}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [57, 100, 100, 53, 0], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [[-8, 0], [13, 15], [45, 53], [58, 63], [68, 71], [92, 93]], 'max_presence': 240, 'no_activity': 240}, {'counts': [3, 2], 'occ_pct': [20, 11], 'status': 'ok'})], [({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 4, 'events': [[5, 45], [60, 61], [96, 99], [120, 384], [387, 392]], 'max_presence': 100, 'no_activity': 120}, {'counts': [1, 0, 1, 1], 'occ_pct': [83, 50, 3, 10], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 3, 'events': [], 'max_presence': 100, 'no_activity': 60}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'no-activity'}), ({'interval': 120, 'bins': 5, 'events': [[-9, -4], [2, 214], [235, 237]], 'max_presence': 100, 'no_activity': 240}, {'counts': [1, 1, 0, 0, 0], 'occ_pct': [98, 80, 0, 0, 0], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 2, 'events': [], 'max_presence': 100, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 100, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'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': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'})], [({'interval': 120, 'bins': 3, 'events': [[-5, -2], [5, 7]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 0, 0], 'occ_pct': [1, 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': 3, 'events': [], 'max_presence': 240, 'no_activity': 60}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'no-activity'}), ({'interval': 120, 'bins': 2, 'events': [], 'max_presence': 100, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 120, 'bins': 5, 'events': [[85, 86], [8, 48]], 'max_presence': 180, 'no_activity': 600}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [34, 0, 0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 5, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 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': 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': 60, 'bins': 2, 'events': [[10, 150], [170, 172], [177, 217]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 0], 'occ_pct': [83, 100], 'status': 'stuck-on'}), ({'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': 180, 'no_activity': 600}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 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': 30, 'bins': 2, 'events': [[8, 16], [26, 34], [55, 95], [97, 137], [160, 162], [165, 504], [524, 532], [547, 550]], 'max_presence': 240, 'no_activity': 120}, {'counts': [2, 1], 'occ_pct': [40, 30], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 3, 'events': [[-1, 0]], 'max_presence': 100, 'no_activity': 600}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [], 'max_presence': 240, 'no_activity': 240}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], '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)

source:
"""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 - on, I))
    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': 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': [], 'max_presence': 240, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [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': 120, 'bins': 2, 'events': [[-10, -9], [10, 50], [80, 88], [122, 127], [153, 156], [157, 197], [218, 258], [262, 267]], 'max_presence': 100, 'no_activity': 600}, {'counts': [2, 4], 'occ_pct': [40, 58], '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': 2, 'events': [], 'max_presence': 100, 'no_activity': 240}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 3, 'events': [], 'max_presence': 100, 'no_activity': 120}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'ok'}), ({'interval': 120, 'bins': 4, 'events': [[151, 153], [50, 58], [109, 111], [93, 101], [175, 178], [191, 199], [-1, 39]], 'max_presence': 100, 'no_activity': 240}, {'counts': [3, 3, 0, 0], 'occ_pct': [47, 10, 0, 0], 'status': 'ok'})], [({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 240, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 3, 'events': [], 'max_presence': 180, 'no_activity': 240}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 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': 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': 3, 'events': [], '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': 5, 'events': [[-1, 0], [59, 424], [-18, -10], [23, 31]], 'max_presence': 240, 'no_activity': 60}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [57, 100, 100, 53, 0], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [[-8, 0], [13, 15], [45, 53], [58, 63], [68, 71], [92, 93]], 'max_presence': 240, 'no_activity': 240}, {'counts': [3, 2], 'occ_pct': [20, 11], 'status': 'ok'})], [({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 4, 'events': [[5, 45], [60, 61], [96, 99], [120, 384], [387, 392]], 'max_presence': 100, 'no_activity': 120}, {'counts': [1, 0, 1, 1], 'occ_pct': [83, 50, 3, 10], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 3, 'events': [], 'max_presence': 100, 'no_activity': 60}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'no-activity'}), ({'interval': 120, 'bins': 5, 'events': [[-9, -4], [2, 214], [235, 237]], 'max_presence': 100, 'no_activity': 240}, {'counts': [1, 1, 0, 0, 0], 'occ_pct': [98, 80, 0, 0, 0], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 2, 'events': [], 'max_presence': 100, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 100, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'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': [[-5, 3], [58, 63], [70, 71]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 1], 'occ_pct': [8, 6], 'status': 'ok'})], [({'interval': 120, 'bins': 3, 'events': [[-5, -2], [5, 7]], 'max_presence': 180, 'no_activity': 120}, {'counts': [1, 0, 0], 'occ_pct': [1, 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': 3, 'events': [], 'max_presence': 240, 'no_activity': 60}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'no-activity'}), ({'interval': 120, 'bins': 2, 'events': [], 'max_presence': 100, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 120, 'bins': 5, 'events': [[85, 86], [8, 48]], 'max_presence': 180, 'no_activity': 600}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [34, 0, 0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 5, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0, 0, 0, 0], 'occ_pct': [0, 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': 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': 60, 'bins': 2, 'events': [[10, 150], [170, 172], [177, 217]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 0], 'occ_pct': [83, 100], 'status': 'stuck-on'}), ({'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': 180, 'no_activity': 600}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 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': 30, 'bins': 2, 'events': [[8, 16], [26, 34], [55, 95], [97, 137], [160, 162], [165, 504], [524, 532], [547, 550]], 'max_presence': 240, 'no_activity': 120}, {'counts': [2, 1], 'occ_pct': [40, 30], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 3, 'events': [[-1, 0]], 'max_presence': 100, 'no_activity': 600}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [], 'max_presence': 240, 'no_activity': 240}, {'counts': [0, 0, 0, 0], 'occ_pct': [0, 0, 0, 0], '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)

prompt:
Loop detector count and occupancy binning returns a wrong result when occupied time is measured from vehicle arrival rather than bin start.

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}.

split: open-access


broken_source:
"""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': 30, 'bins': 3, 'events': [[189, 197], [8, 9], [30, 38], [68, 71], [80, 120], [160, 161], [221, 395]], 'max_presence': 180, 'no_activity': 240}, {'counts': [1, 1, 2], 'occ_pct': [3, 26, 43], 'status': 'ok'}), ({'interval': 120, 'bins': 5, 'events': [[1, 233], [234, 236], [250, 258], [267, 272], [284, 287], [313, 315]], 'max_presence': 100, 'no_activity': 240}, {'counts': [1, 1, 4, 0, 0], 'occ_pct': [99, 95, 15, 0, 0], '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': 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': 3, 'events': [[-6, -3], [15, 20], [36, 37]], 'max_presence': 100, 'no_activity': 240}, {'counts': [2, 0, 0], 'occ_pct': [10, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[-19, -11], [15, 16], [31, 36]], 'max_presence': 180, 'no_activity': 600}, {'counts': [1, 1, 0, 0], 'occ_pct': [3, 16, 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': 60, 'bins': 3, 'events': [[5, 234], [236, 244]], 'max_presence': 100, 'no_activity': 120}, {'counts': [1, 0, 0], 'occ_pct': [91, 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': 30, 'bins': 3, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'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': [[-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': [[-11, 29], [68, 71], [73, 385], [423, 463]], 'max_presence': 240, 'no_activity': 600}, {'counts': [0, 2], 'occ_pct': [48, 83], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 3, 'events': [[-18, 22], [25, 65], [67, 188], [221, 222]], 'max_presence': 180, 'no_activity': 600}, {'counts': [1, 1, 0], 'occ_pct': [95, 96, 100], 'status': 'ok'}), ({'interval': 120, 'bins': 4, 'events': [[-8, -5], [16, 19], [23, 28], [55, 58], [89, 92], [107, 112], [149, 151], [189, 192]], 'max_presence': 100, 'no_activity': 240}, {'counts': [5, 2, 0, 0], 'occ_pct': [15, 4, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 2, 'events': [[-15, -13], [-10, -5], [-4, -3], [35, 36], [69, 74], [110, 113]], 'max_presence': 240, 'no_activity': 600}, {'counts': [0, 1], 'occ_pct': [0, 3], 'status': 'ok'})], [({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 120, 'bins': 3, 'events': [[7, 344], [378, 688], [724, 764], [781, 821], [836, 1109], [1115, 1117], [1135, 1137], [1138, 1140]], 'max_presence': 100, 'no_activity': 120}, {'counts': [1, 0, 0], 'occ_pct': [94, 100, 86], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 4, 'events': [[1, 204], [238, 240], [251, 603], [638, 678], [704, 712], [739, 779]], 'max_presence': 100, 'no_activity': 120}, {'counts': [1, 0, 0, 0], 'occ_pct': [96, 100, 100, 100], 'status': 'stuck-on'}), ({'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': 5, 'events': [[4, 5]], 'max_presence': 240, 'no_activity': 240}, {'counts': [1, 0, 0, 0, 0], 'occ_pct': [1, 0, 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': 30, 'bins': 5, 'events': [[-1, 0], [39, 79], [94, 97], [134, 136]], 'max_presence': 240, 'no_activity': 600}, {'counts': [0, 1, 0, 1, 1], 'occ_pct': [0, 70, 63, 10, 6], 'status': 'ok'})], [({'interval': 60, 'bins': 3, 'events': [[-9, -4], [13, 14], [15, 18], [40, 45], [63, 426], [451, 491], [522, 527], [549, 552]], 'max_presence': 180, 'no_activity': 240}, {'counts': [3, 1, 0], 'occ_pct': [15, 95, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 5, 'events': [[-13, -10], [21, 61], [79, 87], [96, 97]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 2, 0, 0, 0], 'occ_pct': [65, 16, 0, 0, 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': 5, 'events': [[3, 8], [14, 17]], 'max_presence': 100, 'no_activity': 240}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [13, 0, 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': [[-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': [[-13, 27], [55, 400]], 'max_presence': 100, 'no_activity': 60}, {'counts': [1, 0], 'occ_pct': [76, 100], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 5, 'events': [[2, 7], [24, 27]], 'max_presence': 100, 'no_activity': 60}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [6, 0, 0, 0, 0], 'status': 'ok'})], [({'interval': 30, 'bins': 3, 'events': [[-13, -8], [21, 26], [37, 39], [45, 209], [217, 220], [247, 255], [257, 262], [277, 582]], 'max_presence': 240, 'no_activity': 60}, {'counts': [1, 2, 0], 'occ_pct': [16, 56, 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': 4, 'events': [[-3, 5], [16, 56]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 0, 0, 0], 'occ_pct': [75, 0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 2, 'events': [[48, 53], [4, 12], [134, 136], [92, 97]], 'max_presence': 100, 'no_activity': 600}, {'counts': [2, 1], 'occ_pct': [21, 8], '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': 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': 4, 'events': [[2, 3], [22, 62], [76, 78], [116, 124], [142, 147], [173, 175], [215, 220], [255, 258]], 'max_presence': 100, 'no_activity': 120}, {'counts': [2, 2, 2, 1], 'occ_pct': [65, 13, 18, 8], 'status': 'ok'}), ({'interval': 60, 'bins': 3, 'events': [], 'max_presence': 100, 'no_activity': 60}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'no-activity'})]]
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)

source:
"""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'] and off < B * I:
            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': 30, 'bins': 3, 'events': [[189, 197], [8, 9], [30, 38], [68, 71], [80, 120], [160, 161], [221, 395]], 'max_presence': 180, 'no_activity': 240}, {'counts': [1, 1, 2], 'occ_pct': [3, 26, 43], 'status': 'ok'}), ({'interval': 120, 'bins': 5, 'events': [[1, 233], [234, 236], [250, 258], [267, 272], [284, 287], [313, 315]], 'max_presence': 100, 'no_activity': 240}, {'counts': [1, 1, 4, 0, 0], 'occ_pct': [99, 95, 15, 0, 0], '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': 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': 3, 'events': [[-6, -3], [15, 20], [36, 37]], 'max_presence': 100, 'no_activity': 240}, {'counts': [2, 0, 0], 'occ_pct': [10, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 4, 'events': [[-19, -11], [15, 16], [31, 36]], 'max_presence': 180, 'no_activity': 600}, {'counts': [1, 1, 0, 0], 'occ_pct': [3, 16, 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': 60, 'bins': 3, 'events': [[5, 234], [236, 244]], 'max_presence': 100, 'no_activity': 120}, {'counts': [1, 0, 0], 'occ_pct': [91, 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': 30, 'bins': 3, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'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': [[-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': [[-11, 29], [68, 71], [73, 385], [423, 463]], 'max_presence': 240, 'no_activity': 600}, {'counts': [0, 2], 'occ_pct': [48, 83], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 3, 'events': [[-18, 22], [25, 65], [67, 188], [221, 222]], 'max_presence': 180, 'no_activity': 600}, {'counts': [1, 1, 0], 'occ_pct': [95, 96, 100], 'status': 'ok'}), ({'interval': 120, 'bins': 4, 'events': [[-8, -5], [16, 19], [23, 28], [55, 58], [89, 92], [107, 112], [149, 151], [189, 192]], 'max_presence': 100, 'no_activity': 240}, {'counts': [5, 2, 0, 0], 'occ_pct': [15, 4, 0, 0], 'status': 'ok'}), ({'interval': 30, 'bins': 2, 'events': [[-15, -13], [-10, -5], [-4, -3], [35, 36], [69, 74], [110, 113]], 'max_presence': 240, 'no_activity': 600}, {'counts': [0, 1], 'occ_pct': [0, 3], 'status': 'ok'})], [({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 120}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 120, 'bins': 3, 'events': [[7, 344], [378, 688], [724, 764], [781, 821], [836, 1109], [1115, 1117], [1135, 1137], [1138, 1140]], 'max_presence': 100, 'no_activity': 120}, {'counts': [1, 0, 0], 'occ_pct': [94, 100, 86], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 2, 'events': [], 'max_presence': 180, 'no_activity': 60}, {'counts': [0, 0], 'occ_pct': [0, 0], 'status': 'no-activity'}), ({'interval': 30, 'bins': 4, 'events': [[1, 204], [238, 240], [251, 603], [638, 678], [704, 712], [739, 779]], 'max_presence': 100, 'no_activity': 120}, {'counts': [1, 0, 0, 0], 'occ_pct': [96, 100, 100, 100], 'status': 'stuck-on'}), ({'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': 5, 'events': [[4, 5]], 'max_presence': 240, 'no_activity': 240}, {'counts': [1, 0, 0, 0, 0], 'occ_pct': [1, 0, 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': 30, 'bins': 5, 'events': [[-1, 0], [39, 79], [94, 97], [134, 136]], 'max_presence': 240, 'no_activity': 600}, {'counts': [0, 1, 0, 1, 1], 'occ_pct': [0, 70, 63, 10, 6], 'status': 'ok'})], [({'interval': 60, 'bins': 3, 'events': [[-9, -4], [13, 14], [15, 18], [40, 45], [63, 426], [451, 491], [522, 527], [549, 552]], 'max_presence': 180, 'no_activity': 240}, {'counts': [3, 1, 0], 'occ_pct': [15, 95, 100], 'status': 'stuck-on'}), ({'interval': 60, 'bins': 5, 'events': [[-13, -10], [21, 61], [79, 87], [96, 97]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 2, 0, 0, 0], 'occ_pct': [65, 16, 0, 0, 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': 5, 'events': [[3, 8], [14, 17]], 'max_presence': 100, 'no_activity': 240}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [13, 0, 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': [[-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': [[-13, 27], [55, 400]], 'max_presence': 100, 'no_activity': 60}, {'counts': [1, 0], 'occ_pct': [76, 100], 'status': 'stuck-on'}), ({'interval': 120, 'bins': 5, 'events': [[2, 7], [24, 27]], 'max_presence': 100, 'no_activity': 60}, {'counts': [2, 0, 0, 0, 0], 'occ_pct': [6, 0, 0, 0, 0], 'status': 'ok'})], [({'interval': 30, 'bins': 3, 'events': [[-13, -8], [21, 26], [37, 39], [45, 209], [217, 220], [247, 255], [257, 262], [277, 582]], 'max_presence': 240, 'no_activity': 60}, {'counts': [1, 2, 0], 'occ_pct': [16, 56, 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': 4, 'events': [[-3, 5], [16, 56]], 'max_presence': 100, 'no_activity': 600}, {'counts': [1, 0, 0, 0], 'occ_pct': [75, 0, 0, 0], 'status': 'ok'}), ({'interval': 60, 'bins': 2, 'events': [[48, 53], [4, 12], [134, 136], [92, 97]], 'max_presence': 100, 'no_activity': 600}, {'counts': [2, 1], 'occ_pct': [21, 8], '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': 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': 4, 'events': [[2, 3], [22, 62], [76, 78], [116, 124], [142, 147], [173, 175], [215, 220], [255, 258]], 'max_presence': 100, 'no_activity': 120}, {'counts': [2, 2, 2, 1], 'occ_pct': [65, 13, 18, 8], 'status': 'ok'}), ({'interval': 60, 'bins': 3, 'events': [], 'max_presence': 100, 'no_activity': 60}, {'counts': [0, 0, 0], 'occ_pct': [0, 0, 0], 'status': 'no-activity'})]]
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)

prompt:
Loop detector count and occupancy binning returns a wrong result when a presence exactly at the threshold is not stuck.

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}.

split: open-access