prompt:
Customers who opted out of an event are curtailed anyway.

profile is planned watts per slot. events are [start, end, pct, opt_out]; during [start, end) a non-opted-out event limits power to pct percent of plan (integer floor of p*pct/100), and overlapping events apply the lowest pct. Curtailed power never drops below min(plan, floor_w). Return [new profile, total curtailed watts over slots].

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
When two events overlap the milder one can win.

profile is planned watts per slot. events are [start, end, pct, opt_out]; during [start, end) a non-opted-out event limits power to pct percent of plan (integer floor of p*pct/100), and overlapping events apply the lowest pct. Curtailed power never drops below min(plan, floor_w). Return [new profile, total curtailed watts over slots].

split: open-access


prompt:
Curtailment lingers one slot after the event ends.

profile is planned watts per slot. events are [start, end, pct, opt_out]; during [start, end) a non-opted-out event limits power to pct percent of plan (integer floor of p*pct/100), and overlapping events apply the lowest pct. Curtailed power never drops below min(plan, floor_w). Return [new profile, total curtailed watts over slots].

split: open-access


prompt:
Curtailed setpoints are slightly lower than the stated percentage for odd plans.

profile is planned watts per slot. events are [start, end, pct, opt_out]; during [start, end) a non-opted-out event limits power to pct percent of plan (integer floor of p*pct/100), and overlapping events apply the lowest pct. Curtailed power never drops below min(plan, floor_w). Return [new profile, total curtailed watts over slots].

split: open-access


prompt:
Slots planned below the floor, even zero-power slots, are raised to the floor power.

profile is planned watts per slot. events are [start, end, pct, opt_out]; during [start, end) a non-opted-out event limits power to pct percent of plan (integer floor of p*pct/100), and overlapping events apply the lowest pct. Curtailed power never drops below min(plan, floor_w). Return [new profile, total curtailed watts over slots].

split: open-access


prompt:
Curtailment reports a negative reduction.

profile is planned watts per slot. events are [start, end, pct, opt_out]; during [start, end) a non-opted-out event limits power to pct percent of plan (integer floor of p*pct/100), and overlapping events apply the lowest pct. Curtailed power never drops below min(plan, floor_w). Return [new profile, total curtailed watts over slots].

split: open-access


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

N = 1
observations = []
def solve(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t >= timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: authorisation timeout boundary',
   [[[60, 'ev_pause'], [90, 'ev_pause'], [95, 'plug'], [155, 'unplug'], [185, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['regression: authorisation timeout boundary (partial repair)',
   [[[61, 'ev_resume'], [91, 'plug'], [211, 'auth'], [241, 'auth'], [302, 'unplug'], [422, 'plug'],
     [483, 'unplug'], [483, 'auth'], [543, 'plug'], [543, 'stop']],
    60],
   ['Preparing', 0, 2, 0]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: authorisation timeout boundary',
   [[[0, 'ev_resume'], [5, 'plug'], [65, 'plug'], [95, 'unplug']], 90], ['Available', 0, 0, 0]],
  ['regression: authorisation timeout boundary (partial repair)',
   [[[61, 'ev_resume'], [91, 'plug'], [211, 'auth'], [241, 'auth'], [302, 'unplug'], [422, 'plug'],
     [483, 'unplug'], [483, 'auth'], [543, 'plug'], [543, 'stop']],
    60],
   ['Preparing', 0, 2, 0]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: authorisation timeout boundary',
   [[[300, 'unplug'], [305, 'plug'], [315, 'stop'], [315, 'unplug'], [615, 'plug'],
     [645, 'unplug']],
    30],
   ['Available', 0, 0, 0]],
  ['regression: authorisation timeout boundary (partial repair)',
   [[[5, 'plug'], [66, 'auth'], [66, 'unplug'], [127, 'ev_pause'], [157, 'ev_pause']], 60],
   ['Available', 0, 1, 0]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: authorisation timeout boundary',
   [[[30, 'plug'], [60, 'auth'], [120, 'ev_resume'], [180, 'ev_resume'], [185, 'plug'],
     [190, 'plug'], [250, 'ev_pause'], [370, 'unplug']],
    30],
   ['Available', 190, 0, 1]],
  ['regression: authorisation timeout boundary (partial repair)',
   [[[0, 'unplug'], [30, 'unplug'], [330, 'plug'], [360, 'plug'], [421, 'plug'], [426, 'auth']],
    90],
   ['Charging', 0, 1, 0]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: authorisation timeout boundary',
   [[[10, 'plug'], [15, 'unplug'], [75, 'plug'], [195, 'plug'], [255, 'unplug'], [260, 'plug'],
     [265, 'plug'], [295, 'ev_pause']],
    60],
   ['Preparing', 0, 1, 0]],
  ['regression: authorisation timeout boundary (partial repair)',
   [[[0, 'unplug'], [30, 'unplug'], [330, 'plug'], [360, 'plug'], [421, 'plug'], [426, 'auth']],
    90],
   ['Charging', 0, 1, 0]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout + 1:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: authorisation timeout boundary',
   [[[60, 'ev_pause'], [90, 'ev_pause'], [95, 'plug'], [155, 'unplug'], [185, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['regression: authorisation timeout boundary (partial repair)',
   [[[61, 'ev_resume'], [91, 'plug'], [211, 'auth'], [241, 'auth'], [302, 'unplug'], [422, 'plug'],
     [483, 'unplug'], [483, 'auth'], [543, 'plug'], [543, 'stop']],
    60],
   ['Preparing', 0, 2, 0]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: authorisation timeout boundary',
   [[[0, 'ev_resume'], [5, 'plug'], [65, 'plug'], [95, 'unplug']], 90], ['Available', 0, 0, 0]],
  ['regression: authorisation timeout boundary (partial repair)',
   [[[61, 'ev_resume'], [91, 'plug'], [211, 'auth'], [241, 'auth'], [302, 'unplug'], [422, 'plug'],
     [483, 'unplug'], [483, 'auth'], [543, 'plug'], [543, 'stop']],
    60],
   ['Preparing', 0, 2, 0]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: authorisation timeout boundary',
   [[[300, 'unplug'], [305, 'plug'], [315, 'stop'], [315, 'unplug'], [615, 'plug'],
     [645, 'unplug']],
    30],
   ['Available', 0, 0, 0]],
  ['regression: authorisation timeout boundary (partial repair)',
   [[[5, 'plug'], [66, 'auth'], [66, 'unplug'], [127, 'ev_pause'], [157, 'ev_pause']], 60],
   ['Available', 0, 1, 0]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: authorisation timeout boundary',
   [[[30, 'plug'], [60, 'auth'], [120, 'ev_resume'], [180, 'ev_resume'], [185, 'plug'],
     [190, 'plug'], [250, 'ev_pause'], [370, 'unplug']],
    30],
   ['Available', 190, 0, 1]],
  ['regression: authorisation timeout boundary (partial repair)',
   [[[0, 'unplug'], [30, 'unplug'], [330, 'plug'], [360, 'plug'], [421, 'plug'], [426, 'auth']],
    90],
   ['Charging', 0, 1, 0]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: authorisation timeout boundary',
   [[[10, 'plug'], [15, 'unplug'], [75, 'plug'], [195, 'plug'], [255, 'unplug'], [260, 'plug'],
     [265, 'plug'], [295, 'ev_pause']],
    60],
   ['Preparing', 0, 1, 0]],
  ['regression: authorisation timeout boundary (partial repair)',
   [[[0, 'unplug'], [30, 'unplug'], [330, 'plug'], [360, 'plug'], [421, 'plug'], [426, 'auth']],
    90],
   ['Charging', 0, 1, 0]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
A driver authorising exactly at the timeout is rejected.

Chronological [t, event] pairs drive states Available, Preparing, Charging, SuspendedEV, Finishing. plug: Available->Preparing. auth: Preparing->Charging. ev_pause/ev_resume toggle Charging/SuspendedEV. stop: Charging or SuspendedEV->Finishing. unplug: any non-Available state ->Available, counted abrupt from Charging or SuspendedEV. Before handling each event, a Preparing connector whose plug is more than timeout seconds old returns to Available (one timeout). Invalid events are ignored. Return [state, seconds spent in Charging, timeouts, abrupt].

split: open-access


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

N = 1
observations = []
def solve(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: two pauses in one session',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'ev_pause'],
     [245, 'stop']],
    60],
   ['Finishing', 120, 0, 0]],
  ['regression: pause accumulation',
   [[[10, 'plug'], [70, 'ev_resume'], [131, 'auth'], [191, 'unplug'], [196, 'auth'],
     [496, 'ev_resume'], [796, 'ev_resume'], [1096, 'plug'], [1156, 'auth'], [1217, 'ev_pause']],
    90],
   ['SuspendedEV', 61, 1, 0]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: two pauses in one session',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'ev_pause'],
     [245, 'stop']],
    60],
   ['Finishing', 120, 0, 0]],
  ['regression: pause accumulation',
   [[[10, 'plug'], [70, 'ev_resume'], [131, 'auth'], [191, 'unplug'], [196, 'auth'],
     [496, 'ev_resume'], [796, 'ev_resume'], [1096, 'plug'], [1156, 'auth'], [1217, 'ev_pause']],
    90],
   ['SuspendedEV', 61, 1, 0]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: two pauses in one session',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'ev_pause'],
     [245, 'stop']],
    60],
   ['Finishing', 120, 0, 0]],
  ['regression: pause accumulation',
   [[[0, 'ev_pause'], [60, 'unplug'], [90, 'unplug'], [150, 'unplug'], [270, 'plug'], [330, 'auth'],
     [630, 'ev_resume'], [750, 'auth'], [750, 'ev_pause']],
    90],
   ['SuspendedEV', 420, 0, 0]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: two pauses in one session',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'ev_pause'],
     [245, 'stop']],
    60],
   ['Finishing', 120, 0, 0]],
  ['regression: pause accumulation',
   [[[30, 'plug'], [60, 'auth'], [120, 'ev_resume'], [180, 'ev_resume'], [185, 'plug'],
     [190, 'plug'], [250, 'ev_pause'], [370, 'unplug']],
    30],
   ['Available', 190, 0, 1]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: two pauses in one session',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'ev_pause'],
     [245, 'stop']],
    60],
   ['Finishing', 120, 0, 0]],
  ['regression: pause accumulation',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged = t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: two pauses in one session',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'ev_pause'],
     [245, 'stop']],
    60],
   ['Finishing', 120, 0, 0]],
  ['regression: pause accumulation',
   [[[10, 'plug'], [70, 'ev_resume'], [131, 'auth'], [191, 'unplug'], [196, 'auth'],
     [496, 'ev_resume'], [796, 'ev_resume'], [1096, 'plug'], [1156, 'auth'], [1217, 'ev_pause']],
    90],
   ['SuspendedEV', 61, 1, 0]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: two pauses in one session',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'ev_pause'],
     [245, 'stop']],
    60],
   ['Finishing', 120, 0, 0]],
  ['regression: pause accumulation',
   [[[10, 'plug'], [70, 'ev_resume'], [131, 'auth'], [191, 'unplug'], [196, 'auth'],
     [496, 'ev_resume'], [796, 'ev_resume'], [1096, 'plug'], [1156, 'auth'], [1217, 'ev_pause']],
    90],
   ['SuspendedEV', 61, 1, 0]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: two pauses in one session',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'ev_pause'],
     [245, 'stop']],
    60],
   ['Finishing', 120, 0, 0]],
  ['regression: pause accumulation',
   [[[0, 'ev_pause'], [60, 'unplug'], [90, 'unplug'], [150, 'unplug'], [270, 'plug'], [330, 'auth'],
     [630, 'ev_resume'], [750, 'auth'], [750, 'ev_pause']],
    90],
   ['SuspendedEV', 420, 0, 0]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: two pauses in one session',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'ev_pause'],
     [245, 'stop']],
    60],
   ['Finishing', 120, 0, 0]],
  ['regression: pause accumulation',
   [[[30, 'plug'], [60, 'auth'], [120, 'ev_resume'], [180, 'ev_resume'], [185, 'plug'],
     [190, 'plug'], [250, 'ev_pause'], [370, 'unplug']],
    30],
   ['Available', 190, 0, 1]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: two pauses in one session',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'ev_pause'],
     [245, 'stop']],
    60],
   ['Finishing', 120, 0, 0]],
  ['regression: pause accumulation',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
Charging time before an EV-initiated pause disappears from the session total.

Chronological [t, event] pairs drive states Available, Preparing, Charging, SuspendedEV, Finishing. plug: Available->Preparing. auth: Preparing->Charging. ev_pause/ev_resume toggle Charging/SuspendedEV. stop: Charging or SuspendedEV->Finishing. unplug: any non-Available state ->Available, counted abrupt from Charging or SuspendedEV. Before handling each event, a Preparing connector whose plug is more than timeout seconds old returns to Available (one timeout). Invalid events are ignored. Return [state, seconds spent in Charging, timeouts, abrupt].

split: open-access


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

N = 1
observations = []
def solve(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: stop from suspended',
   [[[300, 'plug'], [310, 'auth'], [310, 'plug'], [371, 'ev_resume'], [381, 'auth'],
     [501, 'ev_pause'], [621, 'stop'], [921, 'ev_resume']],
    90],
   ['Finishing', 191, 0, 0]],
  ['regression: stop from suspended (partial repair)',
   [[[0, 'plug'], [10, 'auth'], [10, 'auth'], [20, 'ev_resume'], [140, 'auth'], [170, 'stop'],
     [175, 'auth'], [185, 'stop']],
    90],
   ['Finishing', 160, 0, 0]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: stop from suspended',
   [[[300, 'plug'], [310, 'auth'], [310, 'plug'], [371, 'ev_resume'], [381, 'auth'],
     [501, 'ev_pause'], [621, 'stop'], [921, 'ev_resume']],
    90],
   ['Finishing', 191, 0, 0]],
  ['regression: stop from suspended (partial repair)',
   [[[5, 'plug'], [10, 'auth'], [71, 'stop'], [76, 'unplug'], [137, 'ev_resume'], [142, 'plug'],
     [142, 'plug'], [202, 'plug'], [322, 'ev_resume'], [352, 'auth']],
    30],
   ['Available', 61, 2, 0]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: stop from suspended',
   [[[300, 'plug'], [310, 'auth'], [310, 'plug'], [371, 'ev_resume'], [381, 'auth'],
     [501, 'ev_pause'], [621, 'stop'], [921, 'ev_resume']],
    90],
   ['Finishing', 191, 0, 0]],
  ['regression: stop from suspended (partial repair)',
   [[[60, 'ev_pause'], [180, 'plug'], [190, 'ev_pause'], [195, 'auth'], [256, 'stop'],
     [266, 'ev_resume'], [327, 'stop'], [627, 'plug'], [687, 'stop']],
    90],
   ['Finishing', 61, 0, 0]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: stop from suspended',
   [[[300, 'plug'], [310, 'auth'], [310, 'plug'], [371, 'ev_resume'], [381, 'auth'],
     [501, 'ev_pause'], [621, 'stop'], [921, 'ev_resume']],
    90],
   ['Finishing', 191, 0, 0]],
  ['regression: stop from suspended (partial repair)',
   [[[61, 'plug'], [71, 'ev_resume'], [81, 'stop'], [86, 'auth'], [206, 'auth'], [267, 'auth'],
     [272, 'auth'], [392, 'plug'], [402, 'stop'], [412, 'auth']],
    90],
   ['Finishing', 316, 0, 0]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: stop from suspended',
   [[[300, 'plug'], [310, 'auth'], [310, 'plug'], [371, 'ev_resume'], [381, 'auth'],
     [501, 'ev_pause'], [621, 'stop'], [921, 'ev_resume']],
    90],
   ['Finishing', 191, 0, 0]],
  ['regression: stop from suspended (partial repair)',
   [[[30, 'plug'], [150, 'stop'], [211, 'plug'], [272, 'auth'], [392, 'stop'], [453, 'plug'],
     [753, 'unplug']],
    90],
   ['Available', 120, 1, 0]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'SuspendedEV':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: stop from suspended',
   [[[300, 'plug'], [310, 'auth'], [310, 'plug'], [371, 'ev_resume'], [381, 'auth'],
     [501, 'ev_pause'], [621, 'stop'], [921, 'ev_resume']],
    90],
   ['Finishing', 191, 0, 0]],
  ['regression: stop from suspended (partial repair)',
   [[[0, 'plug'], [10, 'auth'], [10, 'auth'], [20, 'ev_resume'], [140, 'auth'], [170, 'stop'],
     [175, 'auth'], [185, 'stop']],
    90],
   ['Finishing', 160, 0, 0]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: stop from suspended',
   [[[300, 'plug'], [310, 'auth'], [310, 'plug'], [371, 'ev_resume'], [381, 'auth'],
     [501, 'ev_pause'], [621, 'stop'], [921, 'ev_resume']],
    90],
   ['Finishing', 191, 0, 0]],
  ['regression: stop from suspended (partial repair)',
   [[[5, 'plug'], [10, 'auth'], [71, 'stop'], [76, 'unplug'], [137, 'ev_resume'], [142, 'plug'],
     [142, 'plug'], [202, 'plug'], [322, 'ev_resume'], [352, 'auth']],
    30],
   ['Available', 61, 2, 0]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: stop from suspended',
   [[[300, 'plug'], [310, 'auth'], [310, 'plug'], [371, 'ev_resume'], [381, 'auth'],
     [501, 'ev_pause'], [621, 'stop'], [921, 'ev_resume']],
    90],
   ['Finishing', 191, 0, 0]],
  ['regression: stop from suspended (partial repair)',
   [[[60, 'ev_pause'], [180, 'plug'], [190, 'ev_pause'], [195, 'auth'], [256, 'stop'],
     [266, 'ev_resume'], [327, 'stop'], [627, 'plug'], [687, 'stop']],
    90],
   ['Finishing', 61, 0, 0]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: stop from suspended',
   [[[300, 'plug'], [310, 'auth'], [310, 'plug'], [371, 'ev_resume'], [381, 'auth'],
     [501, 'ev_pause'], [621, 'stop'], [921, 'ev_resume']],
    90],
   ['Finishing', 191, 0, 0]],
  ['regression: stop from suspended (partial repair)',
   [[[61, 'plug'], [71, 'ev_resume'], [81, 'stop'], [86, 'auth'], [206, 'auth'], [267, 'auth'],
     [272, 'auth'], [392, 'plug'], [402, 'stop'], [412, 'auth']],
    90],
   ['Finishing', 316, 0, 0]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: stop from suspended',
   [[[300, 'plug'], [310, 'auth'], [310, 'plug'], [371, 'ev_resume'], [381, 'auth'],
     [501, 'ev_pause'], [621, 'stop'], [921, 'ev_resume']],
    90],
   ['Finishing', 191, 0, 0]],
  ['regression: stop from suspended (partial repair)',
   [[[30, 'plug'], [150, 'stop'], [211, 'plug'], [272, 'auth'], [392, 'stop'], [453, 'plug'],
     [753, 'unplug']],
    90],
   ['Available', 120, 1, 0]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
Time the EV spent suspended is counted as charging when the session is stopped.

Chronological [t, event] pairs drive states Available, Preparing, Charging, SuspendedEV, Finishing. plug: Available->Preparing. auth: Preparing->Charging. ev_pause/ev_resume toggle Charging/SuspendedEV. stop: Charging or SuspendedEV->Finishing. unplug: any non-Available state ->Available, counted abrupt from Charging or SuspendedEV. Before handling each event, a Preparing connector whose plug is more than timeout seconds old returns to Available (one timeout). Invalid events are ignored. Return [state, seconds spent in Charging, timeouts, abrupt].

split: open-access


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

N = 1
observations = []
def solve(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state == 'Charging':
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: abrupt unplug classification',
   [[[60, 'ev_pause'], [360, 'ev_pause'], [660, 'ev_pause'], [720, 'auth'], [781, 'plug'],
     [791, 'auth'], [1091, 'ev_pause'], [1391, 'auth'], [1691, 'unplug']],
    90],
   ['Available', 300, 0, 1]],
  ['regression: abrupt unplug classification (partial repair)',
   [[[5, 'plug'], [10, 'auth'], [71, 'stop'], [76, 'unplug'], [137, 'ev_resume'], [142, 'plug'],
     [142, 'plug'], [202, 'plug'], [322, 'ev_resume'], [352, 'auth']],
    30],
   ['Available', 61, 2, 0]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: abrupt unplug classification',
   [[[60, 'ev_pause'], [360, 'ev_pause'], [660, 'ev_pause'], [720, 'auth'], [781, 'plug'],
     [791, 'auth'], [1091, 'ev_pause'], [1391, 'auth'], [1691, 'unplug']],
    90],
   ['Available', 300, 0, 1]],
  ['regression: abrupt unplug classification (partial repair)',
   [[[5, 'plug'], [10, 'auth'], [71, 'stop'], [76, 'unplug'], [137, 'ev_resume'], [142, 'plug'],
     [142, 'plug'], [202, 'plug'], [322, 'ev_resume'], [352, 'auth']],
    30],
   ['Available', 61, 2, 0]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: abrupt unplug classification',
   [[[60, 'ev_pause'], [360, 'ev_pause'], [660, 'ev_pause'], [720, 'auth'], [781, 'plug'],
     [791, 'auth'], [1091, 'ev_pause'], [1391, 'auth'], [1691, 'unplug']],
    90],
   ['Available', 300, 0, 1]],
  ['regression: abrupt unplug classification (partial repair)',
   [[[60, 'plug'], [121, 'auth'], [241, 'auth'], [251, 'stop'], [371, 'unplug'], [376, 'ev_pause'],
     [406, 'unplug']],
    90],
   ['Available', 130, 0, 0]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: abrupt unplug classification',
   [[[30, 'plug'], [60, 'auth'], [120, 'ev_resume'], [180, 'ev_resume'], [185, 'plug'],
     [190, 'plug'], [250, 'ev_pause'], [370, 'unplug']],
    30],
   ['Available', 190, 0, 1]],
  ['regression: abrupt unplug classification (partial repair)',
   [[[61, 'plug'], [91, 'auth'], [101, 'stop'], [401, 'ev_resume'], [701, 'plug'], [701, 'plug'],
     [706, 'unplug'], [706, 'ev_pause'], [736, 'auth']],
    90],
   ['Available', 10, 0, 0]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: abrupt unplug classification',
   [[[10, 'plug'], [130, 'auth'], [250, 'plug'], [250, 'auth'], [250, 'ev_pause'], [550, 'unplug'],
     [555, 'auth'], [565, 'auth']],
    60],
   ['Available', 0, 1, 1]],
  ['regression: abrupt unplug classification (partial repair)',
   [[[30, 'plug'], [150, 'stop'], [211, 'plug'], [272, 'auth'], [392, 'stop'], [453, 'plug'],
     [753, 'unplug']],
    90],
   ['Available', 120, 1, 0]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state != 'Preparing':
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: abrupt unplug classification',
   [[[60, 'ev_pause'], [360, 'ev_pause'], [660, 'ev_pause'], [720, 'auth'], [781, 'plug'],
     [791, 'auth'], [1091, 'ev_pause'], [1391, 'auth'], [1691, 'unplug']],
    90],
   ['Available', 300, 0, 1]],
  ['regression: abrupt unplug classification (partial repair)',
   [[[5, 'plug'], [10, 'auth'], [71, 'stop'], [76, 'unplug'], [137, 'ev_resume'], [142, 'plug'],
     [142, 'plug'], [202, 'plug'], [322, 'ev_resume'], [352, 'auth']],
    30],
   ['Available', 61, 2, 0]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: abrupt unplug classification',
   [[[60, 'ev_pause'], [360, 'ev_pause'], [660, 'ev_pause'], [720, 'auth'], [781, 'plug'],
     [791, 'auth'], [1091, 'ev_pause'], [1391, 'auth'], [1691, 'unplug']],
    90],
   ['Available', 300, 0, 1]],
  ['regression: abrupt unplug classification (partial repair)',
   [[[5, 'plug'], [10, 'auth'], [71, 'stop'], [76, 'unplug'], [137, 'ev_resume'], [142, 'plug'],
     [142, 'plug'], [202, 'plug'], [322, 'ev_resume'], [352, 'auth']],
    30],
   ['Available', 61, 2, 0]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: abrupt unplug classification',
   [[[60, 'ev_pause'], [360, 'ev_pause'], [660, 'ev_pause'], [720, 'auth'], [781, 'plug'],
     [791, 'auth'], [1091, 'ev_pause'], [1391, 'auth'], [1691, 'unplug']],
    90],
   ['Available', 300, 0, 1]],
  ['regression: abrupt unplug classification (partial repair)',
   [[[60, 'plug'], [121, 'auth'], [241, 'auth'], [251, 'stop'], [371, 'unplug'], [376, 'ev_pause'],
     [406, 'unplug']],
    90],
   ['Available', 130, 0, 0]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: abrupt unplug classification',
   [[[30, 'plug'], [60, 'auth'], [120, 'ev_resume'], [180, 'ev_resume'], [185, 'plug'],
     [190, 'plug'], [250, 'ev_pause'], [370, 'unplug']],
    30],
   ['Available', 190, 0, 1]],
  ['regression: abrupt unplug classification (partial repair)',
   [[[61, 'plug'], [91, 'auth'], [101, 'stop'], [401, 'ev_resume'], [701, 'plug'], [701, 'plug'],
     [706, 'unplug'], [706, 'ev_pause'], [736, 'auth']],
    90],
   ['Available', 10, 0, 0]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: abrupt unplug classification',
   [[[10, 'plug'], [130, 'auth'], [250, 'plug'], [250, 'auth'], [250, 'ev_pause'], [550, 'unplug'],
     [555, 'auth'], [565, 'auth']],
    60],
   ['Available', 0, 1, 1]],
  ['regression: abrupt unplug classification (partial repair)',
   [[[30, 'plug'], [150, 'stop'], [211, 'plug'], [272, 'auth'], [392, 'stop'], [453, 'plug'],
     [753, 'unplug']],
    90],
   ['Available', 120, 1, 0]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
Unplugging a suspended vehicle is not flagged as an abrupt termination.

Chronological [t, event] pairs drive states Available, Preparing, Charging, SuspendedEV, Finishing. plug: Available->Preparing. auth: Preparing->Charging. ev_pause/ev_resume toggle Charging/SuspendedEV. stop: Charging or SuspendedEV->Finishing. unplug: any non-Available state ->Available, counted abrupt from Charging or SuspendedEV. Before handling each event, a Preparing connector whose plug is more than timeout seconds old returns to Available (one timeout). Invalid events are ignored. Return [state, seconds spent in Charging, timeouts, abrupt].

split: open-access


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

N = 1
observations = []
def solve(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                pass
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: unplug while charging banks time',
   [[[300, 'plug'], [305, 'auth'], [310, 'unplug'], [320, 'unplug']], 30], ['Available', 5, 0, 1]],
  ['regression: unplug while charging banks time (partial repair)',
   [[[30, 'ev_pause'], [91, 'unplug'], [151, 'plug'], [151, 'ev_resume'], [212, 'unplug'],
     [242, 'auth'], [252, 'plug'], [312, 'auth'], [312, 'unplug']],
    90],
   ['Available', 0, 0, 1]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: unplug while charging banks time',
   [[[30, 'auth'], [90, 'plug'], [90, 'ev_pause'], [150, 'auth'], [180, 'plug'], [190, 'unplug']],
    90],
   ['Available', 40, 0, 1]],
  ['regression: unplug while charging banks time (partial repair)',
   [[[30, 'ev_pause'], [91, 'unplug'], [151, 'plug'], [151, 'ev_resume'], [212, 'unplug'],
     [242, 'auth'], [252, 'plug'], [312, 'auth'], [312, 'unplug']],
    90],
   ['Available', 0, 0, 1]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: unplug while charging banks time',
   [[[30, 'auth'], [90, 'plug'], [90, 'ev_pause'], [150, 'auth'], [180, 'plug'], [190, 'unplug']],
    90],
   ['Available', 40, 0, 1]],
  ['regression: unplug while charging banks time (partial repair)',
   [[[120, 'stop'], [240, 'unplug'], [540, 'plug'], [570, 'auth'], [580, 'auth'], [610, 'plug'],
     [610, 'unplug']],
    90],
   ['Available', 40, 0, 1]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: unplug while charging banks time',
   [[[30, 'plug'], [35, 'plug'], [45, 'auth'], [45, 'plug'], [106, 'auth'], [166, 'unplug'],
     [166, 'auth']],
    30],
   ['Available', 121, 0, 1]],
  ['regression: unplug while charging banks time (partial repair)',
   [[[120, 'stop'], [181, 'plug'], [242, 'unplug'], [252, 'plug'], [257, 'auth'], [317, 'unplug'],
     [347, 'auth'], [647, 'plug'], [947, 'plug']],
    90],
   ['Preparing', 60, 1, 1]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: unplug while charging banks time',
   [[[60, 'plug'], [65, 'unplug'], [126, 'plug'], [131, 'ev_resume'], [141, 'auth'],
     [441, 'unplug']],
    60],
   ['Available', 300, 0, 1]],
  ['regression: unplug while charging banks time (partial repair)',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state == 'Preparing' and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - plug_t
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: unplug while charging banks time',
   [[[300, 'plug'], [305, 'auth'], [310, 'unplug'], [320, 'unplug']], 30], ['Available', 5, 0, 1]],
  ['regression: unplug while charging banks time (partial repair)',
   [[[30, 'ev_pause'], [91, 'unplug'], [151, 'plug'], [151, 'ev_resume'], [212, 'unplug'],
     [242, 'auth'], [252, 'plug'], [312, 'auth'], [312, 'unplug']],
    90],
   ['Available', 0, 0, 1]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: unplug while charging banks time',
   [[[30, 'auth'], [90, 'plug'], [90, 'ev_pause'], [150, 'auth'], [180, 'plug'], [190, 'unplug']],
    90],
   ['Available', 40, 0, 1]],
  ['regression: unplug while charging banks time (partial repair)',
   [[[30, 'ev_pause'], [91, 'unplug'], [151, 'plug'], [151, 'ev_resume'], [212, 'unplug'],
     [242, 'auth'], [252, 'plug'], [312, 'auth'], [312, 'unplug']],
    90],
   ['Available', 0, 0, 1]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: unplug while charging banks time',
   [[[30, 'auth'], [90, 'plug'], [90, 'ev_pause'], [150, 'auth'], [180, 'plug'], [190, 'unplug']],
    90],
   ['Available', 40, 0, 1]],
  ['regression: unplug while charging banks time (partial repair)',
   [[[120, 'stop'], [240, 'unplug'], [540, 'plug'], [570, 'auth'], [580, 'auth'], [610, 'plug'],
     [610, 'unplug']],
    90],
   ['Available', 40, 0, 1]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: unplug while charging banks time',
   [[[30, 'plug'], [35, 'plug'], [45, 'auth'], [45, 'plug'], [106, 'auth'], [166, 'unplug'],
     [166, 'auth']],
    30],
   ['Available', 121, 0, 1]],
  ['regression: unplug while charging banks time (partial repair)',
   [[[120, 'stop'], [181, 'plug'], [242, 'unplug'], [252, 'plug'], [257, 'auth'], [317, 'unplug'],
     [347, 'auth'], [647, 'plug'], [947, 'plug']],
    90],
   ['Preparing', 60, 1, 1]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: unplug while charging banks time',
   [[[60, 'plug'], [65, 'unplug'], [126, 'plug'], [131, 'ev_resume'], [141, 'auth'],
     [441, 'unplug']],
    60],
   ['Available', 300, 0, 1]],
  ['regression: unplug while charging banks time (partial repair)',
   [[[0, 'unplug'], [5, 'unplug'], [5, 'plug'], [35, 'auth'], [95, 'ev_pause'], [100, 'ev_resume'],
     [130, 'plug'], [160, 'unplug'], [160, 'plug'], [160, 'plug']],
    60],
   ['Preparing', 120, 0, 1]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
Sessions ended by pulling the cable report too little charging time.

Chronological [t, event] pairs drive states Available, Preparing, Charging, SuspendedEV, Finishing. plug: Available->Preparing. auth: Preparing->Charging. ev_pause/ev_resume toggle Charging/SuspendedEV. stop: Charging or SuspendedEV->Finishing. unplug: any non-Available state ->Available, counted abrupt from Charging or SuspendedEV. Before handling each event, a Preparing connector whose plug is more than timeout seconds old returns to Available (one timeout). Invalid events are ignored. Return [state, seconds spent in Charging, timeouts, abrupt].

split: open-access


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

N = 1
observations = []
def solve(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if plug_t is not None and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: timeout applies only to Preparing',
   [[[61, 'plug'], [66, 'stop'], [66, 'unplug'], [366, 'stop'], [371, 'stop'], [491, 'plug'],
     [491, 'unplug'], [611, 'auth'], [611, 'auth'], [731, 'plug']],
    90],
   ['Preparing', 0, 0, 0]],
  ['regression: timeout applies only to Preparing (partial repair)',
   [[[60, 'ev_pause'], [90, 'ev_pause'], [95, 'plug'], [155, 'unplug'], [185, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: timeout applies only to Preparing',
   [[[5, 'ev_resume'], [15, 'unplug'], [75, 'ev_pause'], [375, 'stop'], [675, 'plug'],
     [795, 'stop'], [856, 'auth']],
    30],
   ['Available', 0, 1, 0]],
  ['regression: timeout applies only to Preparing (partial repair)',
   [[[120, 'plug'], [130, 'stop'], [135, 'plug'], [140, 'plug'], [201, 'auth'], [321, 'plug'],
     [382, 'stop'], [502, 'ev_resume'], [532, 'auth'], [562, 'unplug']],
    60],
   ['Available', 0, 2, 0]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: timeout applies only to Preparing',
   [[[0, 'plug'], [300, 'plug'], [600, 'ev_pause'], [600, 'plug'], [720, 'plug'], [781, 'auth'],
     [841, 'auth'], [961, 'ev_pause'], [1261, 'auth']],
    30],
   ['Available', 0, 4, 0]],
  ['regression: timeout applies only to Preparing (partial repair)',
   [[[60, 'unplug'], [180, 'plug'], [190, 'unplug'], [250, 'stop'], [370, 'plug'], [370, 'unplug']],
    60],
   ['Available', 0, 0, 0]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: timeout applies only to Preparing',
   [[[10, 'auth'], [10, 'stop'], [15, 'ev_resume'], [135, 'unplug'], [435, 'ev_pause'],
     [735, 'plug'], [1035, 'auth'], [1335, 'unplug'], [1635, 'ev_pause'], [1695, 'auth']],
    90],
   ['Available', 0, 1, 0]],
  ['regression: timeout applies only to Preparing (partial repair)',
   [[[30, 'unplug'], [330, 'plug'], [391, 'unplug'], [401, 'unplug'], [411, 'auth'],
     [441, 'ev_pause'], [441, 'stop']],
    90],
   ['Available', 0, 0, 0]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: timeout applies only to Preparing',
   [[[5, 'ev_resume'], [65, 'unplug'], [75, 'unplug'], [75, 'auth'], [135, 'auth'], [140, 'plug'],
     [440, 'plug'], [440, 'unplug'], [501, 'stop'], [511, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['regression: timeout applies only to Preparing (partial repair)',
   [[[61, 'unplug'], [121, 'ev_pause'], [131, 'auth'], [131, 'auth'], [251, 'plug'],
     [256, 'ev_pause'], [376, 'auth'], [376, 'ev_resume'], [376, 'plug'], [376, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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(events, timeout):
    state = 'Available'
    plug_t = None
    since = None
    charged = 0
    timeouts = 0
    abrupt = 0
    for t, ev in events:
        if state in ('Preparing', 'Available') and plug_t is not None and t - plug_t > timeout:
            state = 'Available'
            timeouts += 1
        if ev == 'plug' and state == 'Available':
            state = 'Preparing'
            plug_t = t
        elif ev == 'auth' and state == 'Preparing':
            state = 'Charging'
            since = t
        elif ev == 'ev_pause' and state == 'Charging':
            charged += t - since
            state = 'SuspendedEV'
        elif ev == 'ev_resume' and state == 'SuspendedEV':
            state = 'Charging'
            since = t
        elif ev == 'stop' and state in ('Charging', 'SuspendedEV'):
            if state == 'Charging':
                charged += t - since
            state = 'Finishing'
        elif ev == 'unplug' and state != 'Available':
            if state == 'Charging':
                charged += t - since
            if state in ('Charging', 'SuspendedEV'):
                abrupt += 1
            state = 'Available'
    return [state, charged, timeouts, abrupt]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: timeout applies only to Preparing',
   [[[61, 'plug'], [66, 'stop'], [66, 'unplug'], [366, 'stop'], [371, 'stop'], [491, 'plug'],
     [491, 'unplug'], [611, 'auth'], [611, 'auth'], [731, 'plug']],
    90],
   ['Preparing', 0, 0, 0]],
  ['regression: timeout applies only to Preparing (partial repair)',
   [[[60, 'ev_pause'], [90, 'ev_pause'], [95, 'plug'], [155, 'unplug'], [185, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 1',
   [[[5, 'plug'], [5, 'plug'], [15, 'plug'], [315, 'auth'], [376, 'ev_resume'], [496, 'auth'],
     [796, 'auth'], [1096, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 2', [[[30, 'unplug'], [91, 'auth'], [96, 'unplug'], [106, 'ev_resume']], 90],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: timeout applies only to Preparing',
   [[[5, 'ev_resume'], [15, 'unplug'], [75, 'ev_pause'], [375, 'stop'], [675, 'plug'],
     [795, 'stop'], [856, 'auth']],
    30],
   ['Available', 0, 1, 0]],
  ['regression: timeout applies only to Preparing (partial repair)',
   [[[120, 'plug'], [130, 'stop'], [135, 'plug'], [140, 'plug'], [201, 'auth'], [321, 'plug'],
     [382, 'stop'], [502, 'ev_resume'], [532, 'auth'], [562, 'unplug']],
    60],
   ['Available', 0, 2, 0]],
  ['control 1', [[[120, 'auth'], [240, 'ev_resume'], [540, 'unplug']], 60], ['Available', 0, 0, 0]],
  ['control 2', [[[60, 'unplug'], [180, 'stop'], [240, 'stop'], [270, 'unplug']], 60],
   ['Available', 0, 0, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: timeout applies only to Preparing',
   [[[0, 'plug'], [300, 'plug'], [600, 'ev_pause'], [600, 'plug'], [720, 'plug'], [781, 'auth'],
     [841, 'auth'], [961, 'ev_pause'], [1261, 'auth']],
    30],
   ['Available', 0, 4, 0]],
  ['regression: timeout applies only to Preparing (partial repair)',
   [[[60, 'unplug'], [180, 'plug'], [190, 'unplug'], [250, 'stop'], [370, 'plug'], [370, 'unplug']],
    60],
   ['Available', 0, 0, 0]],
  ['control 1', [[[0, 'unplug'], [10, 'ev_pause'], [10, 'plug']], 60], ['Preparing', 0, 0, 0]],
  ['control 2', [[[300, 'plug'], [360, 'ev_pause'], [421, 'ev_pause']], 30],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: timeout applies only to Preparing',
   [[[10, 'auth'], [10, 'stop'], [15, 'ev_resume'], [135, 'unplug'], [435, 'ev_pause'],
     [735, 'plug'], [1035, 'auth'], [1335, 'unplug'], [1635, 'ev_pause'], [1695, 'auth']],
    90],
   ['Available', 0, 1, 0]],
  ['regression: timeout applies only to Preparing (partial repair)',
   [[[30, 'unplug'], [330, 'plug'], [391, 'unplug'], [401, 'unplug'], [411, 'auth'],
     [441, 'ev_pause'], [441, 'stop']],
    90],
   ['Available', 0, 0, 0]],
  ['control 1',
   [[[61, 'auth'], [91, 'unplug'], [211, 'unplug'], [221, 'ev_resume'], [281, 'plug'],
     [311, 'ev_pause'], [321, 'unplug'], [326, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['control 2',
   [[[300, 'plug'], [600, 'ev_resume'], [900, 'ev_resume'], [961, 'unplug'], [966, 'auth'],
     [971, 'unplug'], [1271, 'auth'], [1276, 'ev_pause']],
    60],
   ['Available', 0, 1, 0]]],
 [['boundary: authorised exactly at timeout', [[[0, 'plug'], [60, 'auth'], [100, 'stop']], 60],
   ['Finishing', 40, 0, 0]],
  ['normal: pause and resume',
   [[[0, 'plug'], [5, 'auth'], [65, 'ev_pause'], [125, 'ev_resume'], [185, 'stop'],
     [190, 'unplug']],
    60],
   ['Available', 120, 0, 0]],
  ['boundary: unplug while charging', [[[0, 'plug'], [10, 'auth'], [70, 'unplug']], 60],
   ['Available', 60, 0, 1]],
  ['regression: timeout applies only to Preparing',
   [[[5, 'ev_resume'], [65, 'unplug'], [75, 'unplug'], [75, 'auth'], [135, 'auth'], [140, 'plug'],
     [440, 'plug'], [440, 'unplug'], [501, 'stop'], [511, 'plug']],
    30],
   ['Preparing', 0, 1, 0]],
  ['regression: timeout applies only to Preparing (partial repair)',
   [[[61, 'unplug'], [121, 'ev_pause'], [131, 'auth'], [131, 'auth'], [251, 'plug'],
     [256, 'ev_pause'], [376, 'auth'], [376, 'ev_resume'], [376, 'plug'], [376, 'unplug']],
    60],
   ['Available', 0, 1, 0]],
  ['control 1', [[[61, 'unplug'], [361, 'auth'], [421, 'unplug'], [426, 'ev_pause']], 60],
   ['Available', 0, 0, 0]],
  ['control 2',
   [[[5, 'ev_resume'], [305, 'unplug'], [605, 'plug'], [665, 'ev_resume'], [670, 'ev_resume']], 60],
   ['Available', 0, 1, 0]]]]
for label, args, expected in fixtures[N-1]:
    check(label, 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:
Long charging sessions are kicked back to Available.

Chronological [t, event] pairs drive states Available, Preparing, Charging, SuspendedEV, Finishing. plug: Available->Preparing. auth: Preparing->Charging. ev_pause/ev_resume toggle Charging/SuspendedEV. stop: Charging or SuspendedEV->Finishing. unplug: any non-Available state ->Available, counted abrupt from Charging or SuspendedEV. Before handling each event, a Preparing connector whose plug is more than timeout seconds old returns to Available (one timeout). Invalid events are ignored. Return [state, seconds spent in Charging, timeouts, abrupt].

split: open-access