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

N = 1
observations = []
def solve(x):
    periods = sorted(x['periods'])
    out = []
    for eid, date, adjusting in x['entries']:
        found = None
        for p in periods:
            if p[0] <= date <= p[1]:
                found = p
                break
        if found is None:
            out.append([eid, None, 'no_period'])
            continue
        status = found[2]
        if status == 'soft':
            status = 'open'
        if status == 'open':
            out.append([eid, date, 'posted'])
        elif x['policy'] == 'roll':
            nxt = [p for p in periods if p[0] > found[1] and p[2] == 'open']
            if nxt:
                out.append([eid, nxt[0][0], 'rolled'])
            else:
                out.append([eid, None, 'closed'])
        else:
            out.append([eid, None, 'closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: soft close adjusting gate', {'periods': [[122, 151, 'soft'], [92, 121, 'soft'], [31, 60, 'closed'], [1, 30, 'soft'], [61, 91, 'open']], 'policy': 'reject', 'entries': [['E0', 151, False], ['E1', 125, False], ['E2', 121, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 1', {'periods': [[31, 60, 'closed'], [61, 90, 'closed'], [1, 30, 'closed'], [91, 121, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 121, False], ['E2', 94, True], ['E3', 1, False], ['E4', 34, False], ['E5', 61, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 2', {'periods': [[29, 58, 'open'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 58, True], ['E2', 58, False], ['E3', 29, True]]}, [['E0', 29, 'posted'], ['E1', 58, 'posted'], ['E2', 58, 'posted'], ['E3', 29, 'posted']]], ['control 3', {'periods': [[61, 91, 'open'], [31, 60, 'closed'], [92, 121, 'open'], [1, 30, 'open']], 'policy': 'reject', 'entries': [['E0', 4, False], ['E1', 64, False], ['E2', 92, True], ['E3', 63, False]]}, [['E0', 4, 'posted'], ['E1', 64, 'posted'], ['E2', 92, 'posted'], ['E3', 63, 'posted']]], ['control 4', {'periods': [[95, 122, 'closed'], [1, 31, 'open'], [67, 94, 'closed'], [32, 61, 'closed']], 'policy': 'roll', 'entries': [['E0', 62, False], ['E1', 95, False], ['E2', 123, False], ['E3', 61, False], ['E4', 122, False], ['E5', 32, False]]}, [['E0', None, 'no_period'], ['E1', None, 'closed'], ['E2', None, 'no_period'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 5', {'periods': [[59, 88, 'closed'], [31, 58, 'open'], [1, 30, 'open']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 89, False], ['E2', 30, True], ['E3', 61, False], ['E4', 31, False], ['E5', 59, False]]}, [['E0', 34, 'posted'], ['E1', None, 'no_period'], ['E2', 30, 'posted'], ['E3', None, 'closed'], ['E4', 31, 'posted'], ['E5', None, 'closed']]], ['control 6', {'periods': [[1, 28, 'open'], [34, 61, 'open']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, True], ['E2', 31, False], ['E3', 64, True], ['E4', 31, True], ['E5', 62, False]]}, [['E0', None, 'no_period'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', None, 'no_period'], ['E4', None, 'no_period'], ['E5', None, 'no_period']]]], [['regression: soft close adjusting gate', {'periods': [[93, 120, 'closed'], [121, 148, 'soft'], [63, 92, 'soft'], [1, 31, 'soft'], [32, 62, 'open']], 'policy': 'roll', 'entries': [['E0', 149, True], ['E1', 63, True], ['E2', 148, True], ['E3', 4, False]]}, [['E0', None, 'no_period'], ['E1', 63, 'posted'], ['E2', 148, 'posted'], ['E3', 32, 'rolled']]], ['control 1', {'periods': [[1, 31, 'closed'], [60, 90, 'soft'], [32, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 62, True], ['E2', 1, True], ['E3', 31, False], ['E4', 62, True]]}, [['E0', 60, 'posted'], ['E1', 62, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 62, 'posted']]], ['control 2', {'periods': [[29, 59, 'closed'], [1, 28, 'closed'], [65, 94, 'open']], 'policy': 'reject', 'entries': [['E0', 68, False], ['E1', 97, False], ['E2', 95, True], ['E3', 68, False], ['E4', 28, False], ['E5', 28, False]]}, [['E0', 68, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 68, 'posted'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[62, 89, 'open'], [1, 31, 'soft'], [32, 61, 'closed'], [90, 117, 'closed']], 'policy': 'reject', 'entries': [['E0', 62, False], ['E1', 117, False], ['E2', 93, False], ['E3', 65, False]]}, [['E0', 62, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 65, 'posted']]], ['control 4', {'periods': [[29, 59, 'open'], [1, 28, 'closed'], [60, 90, 'closed']], 'policy': 'roll', 'entries': [['E0', 31, False], ['E1', 62, True], ['E2', 29, False], ['E3', 93, False], ['E4', 59, False], ['E5', 60, True]]}, [['E0', 31, 'posted'], ['E1', None, 'closed'], ['E2', 29, 'posted'], ['E3', None, 'no_period'], ['E4', 59, 'posted'], ['E5', None, 'closed']]], ['control 5', {'periods': [[65, 92, 'open'], [34, 64, 'closed'], [1, 28, 'closed']], 'policy': 'reject', 'entries': [['E0', 67, False], ['E1', 1, False], ['E2', 64, True], ['E3', 68, False]]}, [['E0', 67, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 68, 'posted']]], ['control 6', {'periods': [[1, 28, 'closed'], [60, 89, 'closed'], [29, 59, 'closed'], [95, 125, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 90, True], ['E2', 92, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]]], [['regression: soft close adjusting gate', {'periods': [[1, 30, 'soft'], [31, 60, 'soft']], 'policy': 'roll', 'entries': [['E0', 30, False], ['E1', 31, False], ['E2', 31, True], ['E3', 30, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 31, 'posted'], ['E3', None, 'closed']]], ['control 1', {'periods': [[1, 28, 'closed'], [29, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, False], ['E2', 1, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 2', {'periods': [[65, 92, 'open'], [1, 28, 'closed'], [34, 64, 'soft']], 'policy': 'roll', 'entries': [['E0', 65, False], ['E1', 65, False], ['E2', 92, False]]}, [['E0', 65, 'posted'], ['E1', 65, 'posted'], ['E2', 92, 'posted']]], ['control 3', {'periods': [[63, 90, 'open'], [1, 31, 'closed'], [32, 62, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, True], ['E1', 65, True], ['E2', 63, True], ['E3', 1, False]]}, [['E0', 63, 'posted'], ['E1', 65, 'posted'], ['E2', 63, 'posted'], ['E3', 63, 'rolled']]], ['control 4', {'periods': [[1, 28, 'open'], [93, 122, 'closed'], [29, 59, 'soft'], [60, 87, 'open']], 'policy': 'roll', 'entries': [['E0', 93, True], ['E1', 122, True], ['E2', 87, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 87, 'posted']]], ['control 5', {'periods': [[65, 92, 'closed'], [37, 64, 'soft'], [121, 150, 'open'], [1, 31, 'open'], [93, 120, 'soft']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 150, False], ['E2', 64, True]]}, [['E0', None, 'no_period'], ['E1', 150, 'posted'], ['E2', 64, 'posted']]], ['control 6', {'periods': [[62, 92, 'soft'], [1, 28, 'closed'], [34, 61, 'closed'], [93, 123, 'closed']], 'policy': 'reject', 'entries': [['E0', 93, True], ['E1', 93, False], ['E2', 4, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]]], [['regression: soft close adjusting gate', {'periods': [[37, 66, 'soft'], [1, 31, 'closed']], 'policy': 'roll', 'entries': [['E0', 37, False], ['E1', 67, True], ['E2', 69, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]], ['control 1', {'periods': [[29, 58, 'closed'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 61, False], ['E1', 1, False], ['E2', 58, True]]}, [['E0', None, 'no_period'], ['E1', 1, 'posted'], ['E2', None, 'closed']]], ['control 2', {'periods': [[59, 86, 'open'], [29, 58, 'closed'], [1, 28, 'closed']], 'policy': 'roll', 'entries': [['E0', 59, False], ['E1', 87, False], ['E2', 87, False], ['E3', 61, False]]}, [['E0', 59, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 61, 'posted']]], ['control 3', {'periods': [[1, 31, 'soft'], [32, 59, 'open']], 'policy': 'reject', 'entries': [['E0', 60, True], ['E1', 32, False], ['E2', 62, False]]}, [['E0', None, 'no_period'], ['E1', 32, 'posted'], ['E2', None, 'no_period']]], ['control 4', {'periods': [[34, 61, 'soft'], [62, 92, 'open'], [1, 28, 'soft'], [93, 123, 'open']], 'policy': 'roll', 'entries': [['E0', 28, True], ['E1', 65, True], ['E2', 29, False], ['E3', 65, False], ['E4', 93, True]]}, [['E0', 28, 'posted'], ['E1', 65, 'posted'], ['E2', None, 'no_period'], ['E3', 65, 'posted'], ['E4', 93, 'posted']]], ['control 5', {'periods': [[63, 92, 'closed'], [1, 31, 'closed'], [98, 125, 'open'], [32, 62, 'soft']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 63, False], ['E2', 93, False]]}, [['E0', 32, 'posted'], ['E1', 98, 'rolled'], ['E2', None, 'no_period']]], ['control 6', {'periods': [[59, 86, 'closed'], [1, 30, 'closed'], [31, 58, 'closed']], 'policy': 'reject', 'entries': [['E0', 33, False], ['E1', 86, False], ['E2', 31, True], ['E3', 89, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'no_period']]]], [['regression: soft close adjusting gate', {'periods': [[1, 28, 'closed'], [29, 59, 'closed'], [60, 89, 'soft']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 32, True], ['E2', 63, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 63, 'posted']]], ['control 1', {'periods': [[34, 61, 'closed'], [1, 28, 'soft'], [67, 94, 'open'], [95, 122, 'open']], 'policy': 'roll', 'entries': [['E0', 95, True], ['E1', 37, False], ['E2', 94, False]]}, [['E0', 95, 'posted'], ['E1', 67, 'rolled'], ['E2', 94, 'posted']]], ['control 2', {'periods': [[93, 123, 'closed'], [1, 31, 'open'], [62, 92, 'closed'], [32, 61, 'closed']], 'policy': 'reject', 'entries': [['E0', 123, False], ['E1', 95, True], ['E2', 32, True], ['E3', 1, False], ['E4', 124, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 1, 'posted'], ['E4', None, 'no_period']]], ['control 3', {'periods': [[73, 100, 'open'], [1, 31, 'closed'], [37, 67, 'open'], [129, 159, 'open'], [101, 128, 'soft']], 'policy': 'reject', 'entries': [['E0', 129, False], ['E1', 40, True], ['E2', 132, True], ['E3', 73, False], ['E4', 132, False], ['E5', 34, False]]}, [['E0', 129, 'posted'], ['E1', 40, 'posted'], ['E2', 132, 'posted'], ['E3', 73, 'posted'], ['E4', 132, 'posted'], ['E5', None, 'no_period']]], ['control 4', {'periods': [[1, 28, 'open'], [29, 56, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 57, False], ['E2', 4, False], ['E3', 29, True]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', 4, 'posted'], ['E3', None, 'closed']]], ['control 5', {'periods': [[98, 125, 'closed'], [63, 92, 'open'], [32, 62, 'closed'], [126, 155, 'open'], [1, 31, 'open']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 126, False], ['E2', 32, False]]}, [['E0', None, 'closed'], ['E1', 126, 'posted'], ['E2', None, 'closed']]], ['control 6', {'periods': [[1, 30, 'closed'], [36, 63, 'open']], 'policy': 'roll', 'entries': [['E0', 31, True], ['E1', 30, True], ['E2', 33, False]]}, [['E0', None, 'no_period'], ['E1', 36, 'rolled'], ['E2', None, 'no_period']]]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    periods = sorted(x['periods'])
    out = []
    for eid, date, adjusting in x['entries']:
        found = None
        for p in periods:
            if p[0] <= date <= p[1]:
                found = p
                break
        if found is None:
            out.append([eid, None, 'no_period'])
            continue
        status = found[2]
        if status == 'soft' and not adjusting:
            status = 'open'
        if status == 'open':
            out.append([eid, date, 'posted'])
        elif x['policy'] == 'roll':
            nxt = [p for p in periods if p[0] > found[1] and p[2] == 'open']
            if nxt:
                out.append([eid, nxt[0][0], 'rolled'])
            else:
                out.append([eid, None, 'closed'])
        else:
            out.append([eid, None, 'closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: soft close adjusting gate', {'periods': [[122, 151, 'soft'], [92, 121, 'soft'], [31, 60, 'closed'], [1, 30, 'soft'], [61, 91, 'open']], 'policy': 'reject', 'entries': [['E0', 151, False], ['E1', 125, False], ['E2', 121, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 1', {'periods': [[31, 60, 'closed'], [61, 90, 'closed'], [1, 30, 'closed'], [91, 121, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 121, False], ['E2', 94, True], ['E3', 1, False], ['E4', 34, False], ['E5', 61, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 2', {'periods': [[29, 58, 'open'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 58, True], ['E2', 58, False], ['E3', 29, True]]}, [['E0', 29, 'posted'], ['E1', 58, 'posted'], ['E2', 58, 'posted'], ['E3', 29, 'posted']]], ['control 3', {'periods': [[61, 91, 'open'], [31, 60, 'closed'], [92, 121, 'open'], [1, 30, 'open']], 'policy': 'reject', 'entries': [['E0', 4, False], ['E1', 64, False], ['E2', 92, True], ['E3', 63, False]]}, [['E0', 4, 'posted'], ['E1', 64, 'posted'], ['E2', 92, 'posted'], ['E3', 63, 'posted']]], ['control 4', {'periods': [[95, 122, 'closed'], [1, 31, 'open'], [67, 94, 'closed'], [32, 61, 'closed']], 'policy': 'roll', 'entries': [['E0', 62, False], ['E1', 95, False], ['E2', 123, False], ['E3', 61, False], ['E4', 122, False], ['E5', 32, False]]}, [['E0', None, 'no_period'], ['E1', None, 'closed'], ['E2', None, 'no_period'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 5', {'periods': [[59, 88, 'closed'], [31, 58, 'open'], [1, 30, 'open']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 89, False], ['E2', 30, True], ['E3', 61, False], ['E4', 31, False], ['E5', 59, False]]}, [['E0', 34, 'posted'], ['E1', None, 'no_period'], ['E2', 30, 'posted'], ['E3', None, 'closed'], ['E4', 31, 'posted'], ['E5', None, 'closed']]], ['control 6', {'periods': [[1, 28, 'open'], [34, 61, 'open']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, True], ['E2', 31, False], ['E3', 64, True], ['E4', 31, True], ['E5', 62, False]]}, [['E0', None, 'no_period'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', None, 'no_period'], ['E4', None, 'no_period'], ['E5', None, 'no_period']]]], [['regression: soft close adjusting gate', {'periods': [[93, 120, 'closed'], [121, 148, 'soft'], [63, 92, 'soft'], [1, 31, 'soft'], [32, 62, 'open']], 'policy': 'roll', 'entries': [['E0', 149, True], ['E1', 63, True], ['E2', 148, True], ['E3', 4, False]]}, [['E0', None, 'no_period'], ['E1', 63, 'posted'], ['E2', 148, 'posted'], ['E3', 32, 'rolled']]], ['control 1', {'periods': [[1, 31, 'closed'], [60, 90, 'soft'], [32, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 62, True], ['E2', 1, True], ['E3', 31, False], ['E4', 62, True]]}, [['E0', 60, 'posted'], ['E1', 62, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 62, 'posted']]], ['control 2', {'periods': [[29, 59, 'closed'], [1, 28, 'closed'], [65, 94, 'open']], 'policy': 'reject', 'entries': [['E0', 68, False], ['E1', 97, False], ['E2', 95, True], ['E3', 68, False], ['E4', 28, False], ['E5', 28, False]]}, [['E0', 68, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 68, 'posted'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[62, 89, 'open'], [1, 31, 'soft'], [32, 61, 'closed'], [90, 117, 'closed']], 'policy': 'reject', 'entries': [['E0', 62, False], ['E1', 117, False], ['E2', 93, False], ['E3', 65, False]]}, [['E0', 62, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 65, 'posted']]], ['control 4', {'periods': [[29, 59, 'open'], [1, 28, 'closed'], [60, 90, 'closed']], 'policy': 'roll', 'entries': [['E0', 31, False], ['E1', 62, True], ['E2', 29, False], ['E3', 93, False], ['E4', 59, False], ['E5', 60, True]]}, [['E0', 31, 'posted'], ['E1', None, 'closed'], ['E2', 29, 'posted'], ['E3', None, 'no_period'], ['E4', 59, 'posted'], ['E5', None, 'closed']]], ['control 5', {'periods': [[65, 92, 'open'], [34, 64, 'closed'], [1, 28, 'closed']], 'policy': 'reject', 'entries': [['E0', 67, False], ['E1', 1, False], ['E2', 64, True], ['E3', 68, False]]}, [['E0', 67, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 68, 'posted']]], ['control 6', {'periods': [[1, 28, 'closed'], [60, 89, 'closed'], [29, 59, 'closed'], [95, 125, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 90, True], ['E2', 92, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]]], [['regression: soft close adjusting gate', {'periods': [[1, 30, 'soft'], [31, 60, 'soft']], 'policy': 'roll', 'entries': [['E0', 30, False], ['E1', 31, False], ['E2', 31, True], ['E3', 30, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 31, 'posted'], ['E3', None, 'closed']]], ['control 1', {'periods': [[1, 28, 'closed'], [29, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, False], ['E2', 1, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 2', {'periods': [[65, 92, 'open'], [1, 28, 'closed'], [34, 64, 'soft']], 'policy': 'roll', 'entries': [['E0', 65, False], ['E1', 65, False], ['E2', 92, False]]}, [['E0', 65, 'posted'], ['E1', 65, 'posted'], ['E2', 92, 'posted']]], ['control 3', {'periods': [[63, 90, 'open'], [1, 31, 'closed'], [32, 62, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, True], ['E1', 65, True], ['E2', 63, True], ['E3', 1, False]]}, [['E0', 63, 'posted'], ['E1', 65, 'posted'], ['E2', 63, 'posted'], ['E3', 63, 'rolled']]], ['control 4', {'periods': [[1, 28, 'open'], [93, 122, 'closed'], [29, 59, 'soft'], [60, 87, 'open']], 'policy': 'roll', 'entries': [['E0', 93, True], ['E1', 122, True], ['E2', 87, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 87, 'posted']]], ['control 5', {'periods': [[65, 92, 'closed'], [37, 64, 'soft'], [121, 150, 'open'], [1, 31, 'open'], [93, 120, 'soft']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 150, False], ['E2', 64, True]]}, [['E0', None, 'no_period'], ['E1', 150, 'posted'], ['E2', 64, 'posted']]], ['control 6', {'periods': [[62, 92, 'soft'], [1, 28, 'closed'], [34, 61, 'closed'], [93, 123, 'closed']], 'policy': 'reject', 'entries': [['E0', 93, True], ['E1', 93, False], ['E2', 4, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]]], [['regression: soft close adjusting gate', {'periods': [[37, 66, 'soft'], [1, 31, 'closed']], 'policy': 'roll', 'entries': [['E0', 37, False], ['E1', 67, True], ['E2', 69, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]], ['control 1', {'periods': [[29, 58, 'closed'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 61, False], ['E1', 1, False], ['E2', 58, True]]}, [['E0', None, 'no_period'], ['E1', 1, 'posted'], ['E2', None, 'closed']]], ['control 2', {'periods': [[59, 86, 'open'], [29, 58, 'closed'], [1, 28, 'closed']], 'policy': 'roll', 'entries': [['E0', 59, False], ['E1', 87, False], ['E2', 87, False], ['E3', 61, False]]}, [['E0', 59, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 61, 'posted']]], ['control 3', {'periods': [[1, 31, 'soft'], [32, 59, 'open']], 'policy': 'reject', 'entries': [['E0', 60, True], ['E1', 32, False], ['E2', 62, False]]}, [['E0', None, 'no_period'], ['E1', 32, 'posted'], ['E2', None, 'no_period']]], ['control 4', {'periods': [[34, 61, 'soft'], [62, 92, 'open'], [1, 28, 'soft'], [93, 123, 'open']], 'policy': 'roll', 'entries': [['E0', 28, True], ['E1', 65, True], ['E2', 29, False], ['E3', 65, False], ['E4', 93, True]]}, [['E0', 28, 'posted'], ['E1', 65, 'posted'], ['E2', None, 'no_period'], ['E3', 65, 'posted'], ['E4', 93, 'posted']]], ['control 5', {'periods': [[63, 92, 'closed'], [1, 31, 'closed'], [98, 125, 'open'], [32, 62, 'soft']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 63, False], ['E2', 93, False]]}, [['E0', 32, 'posted'], ['E1', 98, 'rolled'], ['E2', None, 'no_period']]], ['control 6', {'periods': [[59, 86, 'closed'], [1, 30, 'closed'], [31, 58, 'closed']], 'policy': 'reject', 'entries': [['E0', 33, False], ['E1', 86, False], ['E2', 31, True], ['E3', 89, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'no_period']]]], [['regression: soft close adjusting gate', {'periods': [[1, 28, 'closed'], [29, 59, 'closed'], [60, 89, 'soft']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 32, True], ['E2', 63, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 63, 'posted']]], ['control 1', {'periods': [[34, 61, 'closed'], [1, 28, 'soft'], [67, 94, 'open'], [95, 122, 'open']], 'policy': 'roll', 'entries': [['E0', 95, True], ['E1', 37, False], ['E2', 94, False]]}, [['E0', 95, 'posted'], ['E1', 67, 'rolled'], ['E2', 94, 'posted']]], ['control 2', {'periods': [[93, 123, 'closed'], [1, 31, 'open'], [62, 92, 'closed'], [32, 61, 'closed']], 'policy': 'reject', 'entries': [['E0', 123, False], ['E1', 95, True], ['E2', 32, True], ['E3', 1, False], ['E4', 124, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 1, 'posted'], ['E4', None, 'no_period']]], ['control 3', {'periods': [[73, 100, 'open'], [1, 31, 'closed'], [37, 67, 'open'], [129, 159, 'open'], [101, 128, 'soft']], 'policy': 'reject', 'entries': [['E0', 129, False], ['E1', 40, True], ['E2', 132, True], ['E3', 73, False], ['E4', 132, False], ['E5', 34, False]]}, [['E0', 129, 'posted'], ['E1', 40, 'posted'], ['E2', 132, 'posted'], ['E3', 73, 'posted'], ['E4', 132, 'posted'], ['E5', None, 'no_period']]], ['control 4', {'periods': [[1, 28, 'open'], [29, 56, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 57, False], ['E2', 4, False], ['E3', 29, True]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', 4, 'posted'], ['E3', None, 'closed']]], ['control 5', {'periods': [[98, 125, 'closed'], [63, 92, 'open'], [32, 62, 'closed'], [126, 155, 'open'], [1, 31, 'open']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 126, False], ['E2', 32, False]]}, [['E0', None, 'closed'], ['E1', 126, 'posted'], ['E2', None, 'closed']]], ['control 6', {'periods': [[1, 30, 'closed'], [36, 63, 'open']], 'policy': 'roll', 'entries': [['E0', 31, True], ['E1', 30, True], ['E2', 33, False]]}, [['E0', None, 'no_period'], ['E1', 36, 'rolled'], ['E2', None, 'no_period']]]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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:
Routine entries post into a soft-closed period.

x = {'periods': [[start_day, end_day, 'open'|'soft'|'closed']] (non-overlapping, any order), 'policy': 'reject'|'roll', 'entries': [[id, day, adjusting]]}. The period containing the day (start and end inclusive) is found; none gives [id, None, 'no_period']. Soft periods accept adjusting entries only. Open acceptance gives [id, day, 'posted']. Otherwise under 'roll' the entry posts on the start day of the earliest later open period ([id, start, 'rolled']) and with none, or under 'reject', gives [id, None, 'closed'].

split: open-access


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

N = 1
observations = []
def solve(x):
    periods = sorted(x['periods'])
    out = []
    for eid, date, adjusting in x['entries']:
        found = None
        for p in periods:
            if p[0] <= date <= p[1]:
                found = p
                break
        if found is None:
            out.append([eid, None, 'no_period'])
            continue
        status = found[2]
        if status == 'soft' and adjusting:
            status = 'open'
        if status == 'open':
            out.append([eid, date, 'posted'])
        elif x['policy'] == 'roll':
            nxt = [p for p in periods if p[0] > found[1] and p[2] != 'closed']
            if nxt:
                out.append([eid, nxt[0][0], 'rolled'])
            else:
                out.append([eid, None, 'closed'])
        else:
            out.append([eid, None, 'closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: roll target status', {'periods': [[59, 88, 'soft'], [117, 146, 'open'], [31, 58, 'closed'], [89, 116, 'closed'], [1, 30, 'closed']], 'policy': 'roll', 'entries': [['E0', 120, False], ['E1', 31, True], ['E2', 59, False], ['E3', 120, False], ['E4', 59, True]]}, [['E0', 120, 'posted'], ['E1', 117, 'rolled'], ['E2', 117, 'rolled'], ['E3', 120, 'posted'], ['E4', 59, 'posted']]], ['control 1', {'periods': [[122, 151, 'soft'], [92, 121, 'soft'], [31, 60, 'closed'], [1, 30, 'soft'], [61, 91, 'open']], 'policy': 'reject', 'entries': [['E0', 151, False], ['E1', 125, False], ['E2', 121, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 2', {'periods': [[31, 60, 'closed'], [61, 90, 'closed'], [1, 30, 'closed'], [91, 121, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 121, False], ['E2', 94, True], ['E3', 1, False], ['E4', 34, False], ['E5', 61, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[92, 121, 'closed'], [32, 61, 'soft'], [62, 91, 'closed'], [1, 31, 'soft']], 'policy': 'roll', 'entries': [['E0', 35, False], ['E1', 65, False], ['E2', 92, True], ['E3', 35, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 35, 'posted']]], ['control 4', {'periods': [[29, 58, 'open'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 58, True], ['E2', 58, False], ['E3', 29, True]]}, [['E0', 29, 'posted'], ['E1', 58, 'posted'], ['E2', 58, 'posted'], ['E3', 29, 'posted']]], ['control 5', {'periods': [[29, 58, 'closed'], [90, 119, 'closed'], [1, 28, 'open'], [59, 89, 'soft']], 'policy': 'reject', 'entries': [['E0', 93, True], ['E1', 89, True], ['E2', 59, False]]}, [['E0', None, 'closed'], ['E1', 89, 'posted'], ['E2', None, 'closed']]], ['control 6', {'periods': [[61, 91, 'open'], [31, 60, 'closed'], [92, 121, 'open'], [1, 30, 'open']], 'policy': 'reject', 'entries': [['E0', 4, False], ['E1', 64, False], ['E2', 92, True], ['E3', 63, False]]}, [['E0', 4, 'posted'], ['E1', 64, 'posted'], ['E2', 92, 'posted'], ['E3', 63, 'posted']]]], [['regression: roll target status', {'periods': [[1, 31, 'closed'], [60, 90, 'soft'], [32, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 62, True], ['E2', 1, True], ['E3', 31, False], ['E4', 62, True]]}, [['E0', 60, 'posted'], ['E1', 62, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 62, 'posted']]], ['regression: roll target status, partial-repair probe', {'periods': [[29, 56, 'closed'], [90, 119, 'closed'], [1, 28, 'closed'], [62, 89, 'open']], 'policy': 'roll', 'entries': [['E0', 56, True], ['E1', 90, True], ['E2', 90, False]]}, [['E0', 62, 'rolled'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 1', {'periods': [[93, 120, 'closed'], [121, 148, 'soft'], [63, 92, 'soft'], [1, 31, 'soft'], [32, 62, 'open']], 'policy': 'roll', 'entries': [['E0', 149, True], ['E1', 63, True], ['E2', 148, True], ['E3', 4, False]]}, [['E0', None, 'no_period'], ['E1', 63, 'posted'], ['E2', 148, 'posted'], ['E3', 32, 'rolled']]], ['control 2', {'periods': [[29, 59, 'closed'], [1, 28, 'closed'], [65, 94, 'open']], 'policy': 'reject', 'entries': [['E0', 68, False], ['E1', 97, False], ['E2', 95, True], ['E3', 68, False], ['E4', 28, False], ['E5', 28, False]]}, [['E0', 68, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 68, 'posted'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[62, 89, 'open'], [1, 31, 'soft'], [32, 61, 'closed'], [90, 117, 'closed']], 'policy': 'reject', 'entries': [['E0', 62, False], ['E1', 117, False], ['E2', 93, False], ['E3', 65, False]]}, [['E0', 62, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 65, 'posted']]], ['control 4', {'periods': [[29, 59, 'open'], [1, 28, 'closed'], [60, 90, 'closed']], 'policy': 'roll', 'entries': [['E0', 31, False], ['E1', 62, True], ['E2', 29, False], ['E3', 93, False], ['E4', 59, False], ['E5', 60, True]]}, [['E0', 31, 'posted'], ['E1', None, 'closed'], ['E2', 29, 'posted'], ['E3', None, 'no_period'], ['E4', 59, 'posted'], ['E5', None, 'closed']]], ['control 5', {'periods': [[65, 92, 'open'], [34, 64, 'closed'], [1, 28, 'closed']], 'policy': 'reject', 'entries': [['E0', 67, False], ['E1', 1, False], ['E2', 64, True], ['E3', 68, False]]}, [['E0', 67, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 68, 'posted']]]], [['regression: roll target status', {'periods': [[1, 30, 'soft'], [31, 60, 'soft']], 'policy': 'roll', 'entries': [['E0', 30, False], ['E1', 31, False], ['E2', 31, True], ['E3', 30, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 31, 'posted'], ['E3', None, 'closed']]], ['regression: roll target status, partial-repair probe', {'periods': [[63, 90, 'open'], [1, 31, 'closed'], [32, 62, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, True], ['E1', 65, True], ['E2', 63, True], ['E3', 1, False]]}, [['E0', 63, 'posted'], ['E1', 65, 'posted'], ['E2', 63, 'posted'], ['E3', 63, 'rolled']]], ['control 1', {'periods': [[1, 28, 'closed'], [29, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, False], ['E2', 1, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 2', {'periods': [[1, 28, 'open'], [29, 59, 'soft']], 'policy': 'roll', 'entries': [['E0', 1, False], ['E1', 29, False], ['E2', 31, False]]}, [['E0', 1, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 3', {'periods': [[65, 92, 'open'], [1, 28, 'closed'], [34, 64, 'soft']], 'policy': 'roll', 'entries': [['E0', 65, False], ['E1', 65, False], ['E2', 92, False]]}, [['E0', 65, 'posted'], ['E1', 65, 'posted'], ['E2', 92, 'posted']]], ['control 4', {'periods': [[29, 59, 'soft'], [123, 150, 'closed'], [1, 28, 'closed'], [60, 87, 'closed'], [93, 122, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, False], ['E1', 29, False], ['E2', 63, False], ['E3', 29, False], ['E4', 151, False], ['E5', 60, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'no_period'], ['E5', None, 'closed']]], ['control 5', {'periods': [[1, 28, 'open'], [93, 122, 'closed'], [29, 59, 'soft'], [60, 87, 'open']], 'policy': 'roll', 'entries': [['E0', 93, True], ['E1', 122, True], ['E2', 87, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 87, 'posted']]]], [['regression: roll target status', {'periods': [[29, 59, 'closed'], [60, 89, 'soft'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 4, False], ['E1', 4, False], ['E2', 32, False], ['E3', 31, True], ['E4', 62, False], ['E5', 28, False]]}, [['E0', 4, 'posted'], ['E1', 4, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', 28, 'posted']]], ['regression: roll target status, partial-repair probe', {'periods': [[63, 92, 'closed'], [1, 31, 'closed'], [98, 125, 'open'], [32, 62, 'soft']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 63, False], ['E2', 93, False]]}, [['E0', 32, 'posted'], ['E1', 98, 'rolled'], ['E2', None, 'no_period']]], ['control 1', {'periods': [[29, 58, 'closed'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 61, False], ['E1', 1, False], ['E2', 58, True]]}, [['E0', None, 'no_period'], ['E1', 1, 'posted'], ['E2', None, 'closed']]], ['control 2', {'periods': [[59, 86, 'open'], [29, 58, 'closed'], [1, 28, 'closed']], 'policy': 'roll', 'entries': [['E0', 59, False], ['E1', 87, False], ['E2', 87, False], ['E3', 61, False]]}, [['E0', 59, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 61, 'posted']]], ['control 3', {'periods': [[1, 31, 'soft'], [32, 59, 'open']], 'policy': 'reject', 'entries': [['E0', 60, True], ['E1', 32, False], ['E2', 62, False]]}, [['E0', None, 'no_period'], ['E1', 32, 'posted'], ['E2', None, 'no_period']]], ['control 4', {'periods': [[34, 61, 'soft'], [62, 92, 'open'], [1, 28, 'soft'], [93, 123, 'open']], 'policy': 'roll', 'entries': [['E0', 28, True], ['E1', 65, True], ['E2', 29, False], ['E3', 65, False], ['E4', 93, True]]}, [['E0', 28, 'posted'], ['E1', 65, 'posted'], ['E2', None, 'no_period'], ['E3', 65, 'posted'], ['E4', 93, 'posted']]], ['control 5', {'periods': [[37, 66, 'soft'], [1, 31, 'closed']], 'policy': 'roll', 'entries': [['E0', 37, False], ['E1', 67, True], ['E2', 69, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]]], [['regression: roll target status', {'periods': [[1, 28, 'closed'], [29, 59, 'closed'], [60, 89, 'soft']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 32, True], ['E2', 63, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 63, 'posted']]], ['regression: roll target status, partial-repair probe', {'periods': [[34, 61, 'closed'], [1, 28, 'soft'], [67, 94, 'open'], [95, 122, 'open']], 'policy': 'roll', 'entries': [['E0', 95, True], ['E1', 37, False], ['E2', 94, False]]}, [['E0', 95, 'posted'], ['E1', 67, 'rolled'], ['E2', 94, 'posted']]], ['control 1', {'periods': [[128, 155, 'open'], [31, 58, 'closed'], [1, 30, 'soft'], [59, 86, 'closed'], [92, 122, 'soft']], 'policy': 'reject', 'entries': [['E0', 125, False], ['E1', 31, False], ['E2', 156, True], ['E3', 1, False], ['E4', 95, False], ['E5', 95, False]]}, [['E0', None, 'no_period'], ['E1', None, 'closed'], ['E2', None, 'no_period'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 2', {'periods': [[31, 61, 'soft'], [62, 91, 'closed'], [92, 121, 'closed'], [1, 30, 'closed']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 92, False], ['E2', 30, False], ['E3', 1, False], ['E4', 31, True], ['E5', 124, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 31, 'posted'], ['E5', None, 'no_period']]], ['control 3', {'periods': [[93, 123, 'closed'], [1, 31, 'open'], [62, 92, 'closed'], [32, 61, 'closed']], 'policy': 'reject', 'entries': [['E0', 123, False], ['E1', 95, True], ['E2', 32, True], ['E3', 1, False], ['E4', 124, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 1, 'posted'], ['E4', None, 'no_period']]], ['control 4', {'periods': [[73, 100, 'open'], [1, 31, 'closed'], [37, 67, 'open'], [129, 159, 'open'], [101, 128, 'soft']], 'policy': 'reject', 'entries': [['E0', 129, False], ['E1', 40, True], ['E2', 132, True], ['E3', 73, False], ['E4', 132, False], ['E5', 34, False]]}, [['E0', 129, 'posted'], ['E1', 40, 'posted'], ['E2', 132, 'posted'], ['E3', 73, 'posted'], ['E4', 132, 'posted'], ['E5', None, 'no_period']]], ['control 5', {'periods': [[1, 28, 'open'], [29, 56, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 57, False], ['E2', 4, False], ['E3', 29, True]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', 4, 'posted'], ['E3', None, 'closed']]]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    periods = sorted(x['periods'])
    out = []
    for eid, date, adjusting in x['entries']:
        found = None
        for p in periods:
            if p[0] <= date <= p[1]:
                found = p
                break
        if found is None:
            out.append([eid, None, 'no_period'])
            continue
        status = found[2]
        if status == 'soft' and adjusting:
            status = 'open'
        if status == 'open':
            out.append([eid, date, 'posted'])
        elif x['policy'] == 'roll':
            nxt = [p for p in periods if p[0] == found[1] + 1 and p[2] == 'open']
            if nxt:
                out.append([eid, nxt[0][0], 'rolled'])
            else:
                out.append([eid, None, 'closed'])
        else:
            out.append([eid, None, 'closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: roll target status', {'periods': [[59, 88, 'soft'], [117, 146, 'open'], [31, 58, 'closed'], [89, 116, 'closed'], [1, 30, 'closed']], 'policy': 'roll', 'entries': [['E0', 120, False], ['E1', 31, True], ['E2', 59, False], ['E3', 120, False], ['E4', 59, True]]}, [['E0', 120, 'posted'], ['E1', 117, 'rolled'], ['E2', 117, 'rolled'], ['E3', 120, 'posted'], ['E4', 59, 'posted']]], ['control 1', {'periods': [[122, 151, 'soft'], [92, 121, 'soft'], [31, 60, 'closed'], [1, 30, 'soft'], [61, 91, 'open']], 'policy': 'reject', 'entries': [['E0', 151, False], ['E1', 125, False], ['E2', 121, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 2', {'periods': [[31, 60, 'closed'], [61, 90, 'closed'], [1, 30, 'closed'], [91, 121, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 121, False], ['E2', 94, True], ['E3', 1, False], ['E4', 34, False], ['E5', 61, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[92, 121, 'closed'], [32, 61, 'soft'], [62, 91, 'closed'], [1, 31, 'soft']], 'policy': 'roll', 'entries': [['E0', 35, False], ['E1', 65, False], ['E2', 92, True], ['E3', 35, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 35, 'posted']]], ['control 4', {'periods': [[29, 58, 'open'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 58, True], ['E2', 58, False], ['E3', 29, True]]}, [['E0', 29, 'posted'], ['E1', 58, 'posted'], ['E2', 58, 'posted'], ['E3', 29, 'posted']]], ['control 5', {'periods': [[29, 58, 'closed'], [90, 119, 'closed'], [1, 28, 'open'], [59, 89, 'soft']], 'policy': 'reject', 'entries': [['E0', 93, True], ['E1', 89, True], ['E2', 59, False]]}, [['E0', None, 'closed'], ['E1', 89, 'posted'], ['E2', None, 'closed']]], ['control 6', {'periods': [[61, 91, 'open'], [31, 60, 'closed'], [92, 121, 'open'], [1, 30, 'open']], 'policy': 'reject', 'entries': [['E0', 4, False], ['E1', 64, False], ['E2', 92, True], ['E3', 63, False]]}, [['E0', 4, 'posted'], ['E1', 64, 'posted'], ['E2', 92, 'posted'], ['E3', 63, 'posted']]]], [['regression: roll target status', {'periods': [[1, 31, 'closed'], [60, 90, 'soft'], [32, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 62, True], ['E2', 1, True], ['E3', 31, False], ['E4', 62, True]]}, [['E0', 60, 'posted'], ['E1', 62, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 62, 'posted']]], ['regression: roll target status, partial-repair probe', {'periods': [[29, 56, 'closed'], [90, 119, 'closed'], [1, 28, 'closed'], [62, 89, 'open']], 'policy': 'roll', 'entries': [['E0', 56, True], ['E1', 90, True], ['E2', 90, False]]}, [['E0', 62, 'rolled'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 1', {'periods': [[93, 120, 'closed'], [121, 148, 'soft'], [63, 92, 'soft'], [1, 31, 'soft'], [32, 62, 'open']], 'policy': 'roll', 'entries': [['E0', 149, True], ['E1', 63, True], ['E2', 148, True], ['E3', 4, False]]}, [['E0', None, 'no_period'], ['E1', 63, 'posted'], ['E2', 148, 'posted'], ['E3', 32, 'rolled']]], ['control 2', {'periods': [[29, 59, 'closed'], [1, 28, 'closed'], [65, 94, 'open']], 'policy': 'reject', 'entries': [['E0', 68, False], ['E1', 97, False], ['E2', 95, True], ['E3', 68, False], ['E4', 28, False], ['E5', 28, False]]}, [['E0', 68, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 68, 'posted'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[62, 89, 'open'], [1, 31, 'soft'], [32, 61, 'closed'], [90, 117, 'closed']], 'policy': 'reject', 'entries': [['E0', 62, False], ['E1', 117, False], ['E2', 93, False], ['E3', 65, False]]}, [['E0', 62, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 65, 'posted']]], ['control 4', {'periods': [[29, 59, 'open'], [1, 28, 'closed'], [60, 90, 'closed']], 'policy': 'roll', 'entries': [['E0', 31, False], ['E1', 62, True], ['E2', 29, False], ['E3', 93, False], ['E4', 59, False], ['E5', 60, True]]}, [['E0', 31, 'posted'], ['E1', None, 'closed'], ['E2', 29, 'posted'], ['E3', None, 'no_period'], ['E4', 59, 'posted'], ['E5', None, 'closed']]], ['control 5', {'periods': [[65, 92, 'open'], [34, 64, 'closed'], [1, 28, 'closed']], 'policy': 'reject', 'entries': [['E0', 67, False], ['E1', 1, False], ['E2', 64, True], ['E3', 68, False]]}, [['E0', 67, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 68, 'posted']]]], [['regression: roll target status', {'periods': [[1, 30, 'soft'], [31, 60, 'soft']], 'policy': 'roll', 'entries': [['E0', 30, False], ['E1', 31, False], ['E2', 31, True], ['E3', 30, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 31, 'posted'], ['E3', None, 'closed']]], ['regression: roll target status, partial-repair probe', {'periods': [[63, 90, 'open'], [1, 31, 'closed'], [32, 62, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, True], ['E1', 65, True], ['E2', 63, True], ['E3', 1, False]]}, [['E0', 63, 'posted'], ['E1', 65, 'posted'], ['E2', 63, 'posted'], ['E3', 63, 'rolled']]], ['control 1', {'periods': [[1, 28, 'closed'], [29, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, False], ['E2', 1, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 2', {'periods': [[1, 28, 'open'], [29, 59, 'soft']], 'policy': 'roll', 'entries': [['E0', 1, False], ['E1', 29, False], ['E2', 31, False]]}, [['E0', 1, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 3', {'periods': [[65, 92, 'open'], [1, 28, 'closed'], [34, 64, 'soft']], 'policy': 'roll', 'entries': [['E0', 65, False], ['E1', 65, False], ['E2', 92, False]]}, [['E0', 65, 'posted'], ['E1', 65, 'posted'], ['E2', 92, 'posted']]], ['control 4', {'periods': [[29, 59, 'soft'], [123, 150, 'closed'], [1, 28, 'closed'], [60, 87, 'closed'], [93, 122, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, False], ['E1', 29, False], ['E2', 63, False], ['E3', 29, False], ['E4', 151, False], ['E5', 60, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'no_period'], ['E5', None, 'closed']]], ['control 5', {'periods': [[1, 28, 'open'], [93, 122, 'closed'], [29, 59, 'soft'], [60, 87, 'open']], 'policy': 'roll', 'entries': [['E0', 93, True], ['E1', 122, True], ['E2', 87, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 87, 'posted']]]], [['regression: roll target status', {'periods': [[29, 59, 'closed'], [60, 89, 'soft'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 4, False], ['E1', 4, False], ['E2', 32, False], ['E3', 31, True], ['E4', 62, False], ['E5', 28, False]]}, [['E0', 4, 'posted'], ['E1', 4, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', 28, 'posted']]], ['regression: roll target status, partial-repair probe', {'periods': [[63, 92, 'closed'], [1, 31, 'closed'], [98, 125, 'open'], [32, 62, 'soft']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 63, False], ['E2', 93, False]]}, [['E0', 32, 'posted'], ['E1', 98, 'rolled'], ['E2', None, 'no_period']]], ['control 1', {'periods': [[29, 58, 'closed'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 61, False], ['E1', 1, False], ['E2', 58, True]]}, [['E0', None, 'no_period'], ['E1', 1, 'posted'], ['E2', None, 'closed']]], ['control 2', {'periods': [[59, 86, 'open'], [29, 58, 'closed'], [1, 28, 'closed']], 'policy': 'roll', 'entries': [['E0', 59, False], ['E1', 87, False], ['E2', 87, False], ['E3', 61, False]]}, [['E0', 59, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 61, 'posted']]], ['control 3', {'periods': [[1, 31, 'soft'], [32, 59, 'open']], 'policy': 'reject', 'entries': [['E0', 60, True], ['E1', 32, False], ['E2', 62, False]]}, [['E0', None, 'no_period'], ['E1', 32, 'posted'], ['E2', None, 'no_period']]], ['control 4', {'periods': [[34, 61, 'soft'], [62, 92, 'open'], [1, 28, 'soft'], [93, 123, 'open']], 'policy': 'roll', 'entries': [['E0', 28, True], ['E1', 65, True], ['E2', 29, False], ['E3', 65, False], ['E4', 93, True]]}, [['E0', 28, 'posted'], ['E1', 65, 'posted'], ['E2', None, 'no_period'], ['E3', 65, 'posted'], ['E4', 93, 'posted']]], ['control 5', {'periods': [[37, 66, 'soft'], [1, 31, 'closed']], 'policy': 'roll', 'entries': [['E0', 37, False], ['E1', 67, True], ['E2', 69, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]]], [['regression: roll target status', {'periods': [[1, 28, 'closed'], [29, 59, 'closed'], [60, 89, 'soft']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 32, True], ['E2', 63, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 63, 'posted']]], ['regression: roll target status, partial-repair probe', {'periods': [[34, 61, 'closed'], [1, 28, 'soft'], [67, 94, 'open'], [95, 122, 'open']], 'policy': 'roll', 'entries': [['E0', 95, True], ['E1', 37, False], ['E2', 94, False]]}, [['E0', 95, 'posted'], ['E1', 67, 'rolled'], ['E2', 94, 'posted']]], ['control 1', {'periods': [[128, 155, 'open'], [31, 58, 'closed'], [1, 30, 'soft'], [59, 86, 'closed'], [92, 122, 'soft']], 'policy': 'reject', 'entries': [['E0', 125, False], ['E1', 31, False], ['E2', 156, True], ['E3', 1, False], ['E4', 95, False], ['E5', 95, False]]}, [['E0', None, 'no_period'], ['E1', None, 'closed'], ['E2', None, 'no_period'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 2', {'periods': [[31, 61, 'soft'], [62, 91, 'closed'], [92, 121, 'closed'], [1, 30, 'closed']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 92, False], ['E2', 30, False], ['E3', 1, False], ['E4', 31, True], ['E5', 124, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 31, 'posted'], ['E5', None, 'no_period']]], ['control 3', {'periods': [[93, 123, 'closed'], [1, 31, 'open'], [62, 92, 'closed'], [32, 61, 'closed']], 'policy': 'reject', 'entries': [['E0', 123, False], ['E1', 95, True], ['E2', 32, True], ['E3', 1, False], ['E4', 124, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 1, 'posted'], ['E4', None, 'no_period']]], ['control 4', {'periods': [[73, 100, 'open'], [1, 31, 'closed'], [37, 67, 'open'], [129, 159, 'open'], [101, 128, 'soft']], 'policy': 'reject', 'entries': [['E0', 129, False], ['E1', 40, True], ['E2', 132, True], ['E3', 73, False], ['E4', 132, False], ['E5', 34, False]]}, [['E0', 129, 'posted'], ['E1', 40, 'posted'], ['E2', 132, 'posted'], ['E3', 73, 'posted'], ['E4', 132, 'posted'], ['E5', None, 'no_period']]], ['control 5', {'periods': [[1, 28, 'open'], [29, 56, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 57, False], ['E2', 4, False], ['E3', 29, True]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', 4, 'posted'], ['E3', None, 'closed']]]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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:
Rolled entries land in a soft-closed period.

x = {'periods': [[start_day, end_day, 'open'|'soft'|'closed']] (non-overlapping, any order), 'policy': 'reject'|'roll', 'entries': [[id, day, adjusting]]}. The period containing the day (start and end inclusive) is found; none gives [id, None, 'no_period']. Soft periods accept adjusting entries only. Open acceptance gives [id, day, 'posted']. Otherwise under 'roll' the entry posts on the start day of the earliest later open period ([id, start, 'rolled']) and with none, or under 'reject', gives [id, None, 'closed'].

split: open-access


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

N = 1
observations = []
def solve(x):
    periods = sorted(x['periods'])
    out = []
    for eid, date, adjusting in x['entries']:
        found = None
        for p in periods:
            if p[0] <= date <= p[1]:
                found = p
                break
        if found is None:
            out.append([eid, None, 'no_period'])
            continue
        status = found[2]
        if status == 'soft' and adjusting:
            status = 'open'
        if status == 'open':
            out.append([eid, date, 'posted'])
        elif x['policy'] == 'roll':
            nxt = [p for p in periods if p[0] > found[1] and p[2] == 'open']
            if nxt:
                out.append([eid, nxt[-1][0], 'rolled'])
            else:
                out.append([eid, None, 'closed'])
        else:
            out.append([eid, None, 'closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: roll target choice', {'periods': [[37, 67, 'open'], [1, 31, 'closed'], [68, 95, 'open']], 'policy': 'roll', 'entries': [['E0', 4, True], ['E1', 70, True], ['E2', 40, False]]}, [['E0', 37, 'rolled'], ['E1', 70, 'posted'], ['E2', 40, 'posted']]], ['control 1', {'periods': [[122, 151, 'soft'], [92, 121, 'soft'], [31, 60, 'closed'], [1, 30, 'soft'], [61, 91, 'open']], 'policy': 'reject', 'entries': [['E0', 151, False], ['E1', 125, False], ['E2', 121, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 2', {'periods': [[31, 60, 'closed'], [61, 90, 'closed'], [1, 30, 'closed'], [91, 121, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 121, False], ['E2', 94, True], ['E3', 1, False], ['E4', 34, False], ['E5', 61, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[92, 121, 'closed'], [32, 61, 'soft'], [62, 91, 'closed'], [1, 31, 'soft']], 'policy': 'roll', 'entries': [['E0', 35, False], ['E1', 65, False], ['E2', 92, True], ['E3', 35, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 35, 'posted']]], ['control 4', {'periods': [[59, 88, 'soft'], [117, 146, 'open'], [31, 58, 'closed'], [89, 116, 'closed'], [1, 30, 'closed']], 'policy': 'roll', 'entries': [['E0', 120, False], ['E1', 31, True], ['E2', 59, False], ['E3', 120, False], ['E4', 59, True]]}, [['E0', 120, 'posted'], ['E1', 117, 'rolled'], ['E2', 117, 'rolled'], ['E3', 120, 'posted'], ['E4', 59, 'posted']]], ['control 5', {'periods': [[29, 58, 'open'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 58, True], ['E2', 58, False], ['E3', 29, True]]}, [['E0', 29, 'posted'], ['E1', 58, 'posted'], ['E2', 58, 'posted'], ['E3', 29, 'posted']]], ['control 6', {'periods': [[29, 58, 'closed'], [90, 119, 'closed'], [1, 28, 'open'], [59, 89, 'soft']], 'policy': 'reject', 'entries': [['E0', 93, True], ['E1', 89, True], ['E2', 59, False]]}, [['E0', None, 'closed'], ['E1', 89, 'posted'], ['E2', None, 'closed']]]], [['regression: roll target choice', {'periods': [[1, 30, 'soft'], [31, 58, 'open'], [59, 86, 'open']], 'policy': 'roll', 'entries': [['E0', 30, False], ['E1', 62, False], ['E2', 59, False], ['E3', 4, False], ['E4', 1, False]]}, [['E0', 31, 'rolled'], ['E1', 62, 'posted'], ['E2', 59, 'posted'], ['E3', 31, 'rolled'], ['E4', 31, 'rolled']]], ['control 1', {'periods': [[1, 31, 'closed'], [60, 90, 'soft'], [32, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 62, True], ['E2', 1, True], ['E3', 31, False], ['E4', 62, True]]}, [['E0', 60, 'posted'], ['E1', 62, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 62, 'posted']]], ['control 2', {'periods': [[93, 120, 'closed'], [121, 148, 'soft'], [63, 92, 'soft'], [1, 31, 'soft'], [32, 62, 'open']], 'policy': 'roll', 'entries': [['E0', 149, True], ['E1', 63, True], ['E2', 148, True], ['E3', 4, False]]}, [['E0', None, 'no_period'], ['E1', 63, 'posted'], ['E2', 148, 'posted'], ['E3', 32, 'rolled']]], ['control 3', {'periods': [[29, 59, 'closed'], [1, 28, 'closed'], [65, 94, 'open']], 'policy': 'reject', 'entries': [['E0', 68, False], ['E1', 97, False], ['E2', 95, True], ['E3', 68, False], ['E4', 28, False], ['E5', 28, False]]}, [['E0', 68, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 68, 'posted'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 4', {'periods': [[62, 89, 'open'], [1, 31, 'soft'], [32, 61, 'closed'], [90, 117, 'closed']], 'policy': 'reject', 'entries': [['E0', 62, False], ['E1', 117, False], ['E2', 93, False], ['E3', 65, False]]}, [['E0', 62, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 65, 'posted']]], ['control 5', {'periods': [[29, 59, 'open'], [1, 28, 'closed'], [60, 90, 'closed']], 'policy': 'roll', 'entries': [['E0', 31, False], ['E1', 62, True], ['E2', 29, False], ['E3', 93, False], ['E4', 59, False], ['E5', 60, True]]}, [['E0', 31, 'posted'], ['E1', None, 'closed'], ['E2', 29, 'posted'], ['E3', None, 'no_period'], ['E4', 59, 'posted'], ['E5', None, 'closed']]], ['control 6', {'periods': [[65, 92, 'open'], [34, 64, 'closed'], [1, 28, 'closed']], 'policy': 'reject', 'entries': [['E0', 67, False], ['E1', 1, False], ['E2', 64, True], ['E3', 68, False]]}, [['E0', 67, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 68, 'posted']]]], [['regression: roll target choice', {'periods': [[61, 90, 'open'], [1, 30, 'open'], [31, 60, 'soft'], [91, 121, 'closed'], [122, 151, 'open']], 'policy': 'roll', 'entries': [['E0', 31, False], ['E1', 125, False], ['E2', 90, False], ['E3', 4, False], ['E4', 60, False], ['E5', 152, True]]}, [['E0', 61, 'rolled'], ['E1', 125, 'posted'], ['E2', 90, 'posted'], ['E3', 4, 'posted'], ['E4', 61, 'rolled'], ['E5', None, 'no_period']]], ['control 1', {'periods': [[1, 30, 'soft'], [31, 60, 'soft']], 'policy': 'roll', 'entries': [['E0', 30, False], ['E1', 31, False], ['E2', 31, True], ['E3', 30, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 31, 'posted'], ['E3', None, 'closed']]], ['control 2', {'periods': [[1, 28, 'closed'], [29, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, False], ['E2', 1, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 3', {'periods': [[1, 28, 'open'], [29, 59, 'soft']], 'policy': 'roll', 'entries': [['E0', 1, False], ['E1', 29, False], ['E2', 31, False]]}, [['E0', 1, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 4', {'periods': [[65, 92, 'open'], [1, 28, 'closed'], [34, 64, 'soft']], 'policy': 'roll', 'entries': [['E0', 65, False], ['E1', 65, False], ['E2', 92, False]]}, [['E0', 65, 'posted'], ['E1', 65, 'posted'], ['E2', 92, 'posted']]], ['control 5', {'periods': [[63, 90, 'open'], [1, 31, 'closed'], [32, 62, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, True], ['E1', 65, True], ['E2', 63, True], ['E3', 1, False]]}, [['E0', 63, 'posted'], ['E1', 65, 'posted'], ['E2', 63, 'posted'], ['E3', 63, 'rolled']]], ['control 6', {'periods': [[29, 59, 'soft'], [123, 150, 'closed'], [1, 28, 'closed'], [60, 87, 'closed'], [93, 122, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, False], ['E1', 29, False], ['E2', 63, False], ['E3', 29, False], ['E4', 151, False], ['E5', 60, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'no_period'], ['E5', None, 'closed']]]], [['regression: roll target choice', {'periods': [[32, 59, 'closed'], [65, 94, 'open'], [1, 31, 'soft'], [100, 130, 'open']], 'policy': 'roll', 'entries': [['E0', 130, True], ['E1', 68, False], ['E2', 4, False], ['E3', 131, False], ['E4', 133, True]]}, [['E0', 130, 'posted'], ['E1', 68, 'posted'], ['E2', 65, 'rolled'], ['E3', None, 'no_period'], ['E4', None, 'no_period']]], ['control 1', {'periods': [[29, 58, 'closed'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 61, False], ['E1', 1, False], ['E2', 58, True]]}, [['E0', None, 'no_period'], ['E1', 1, 'posted'], ['E2', None, 'closed']]], ['control 2', {'periods': [[59, 86, 'open'], [29, 58, 'closed'], [1, 28, 'closed']], 'policy': 'roll', 'entries': [['E0', 59, False], ['E1', 87, False], ['E2', 87, False], ['E3', 61, False]]}, [['E0', 59, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 61, 'posted']]], ['control 3', {'periods': [[1, 31, 'soft'], [32, 59, 'open']], 'policy': 'reject', 'entries': [['E0', 60, True], ['E1', 32, False], ['E2', 62, False]]}, [['E0', None, 'no_period'], ['E1', 32, 'posted'], ['E2', None, 'no_period']]], ['control 4', {'periods': [[34, 61, 'soft'], [62, 92, 'open'], [1, 28, 'soft'], [93, 123, 'open']], 'policy': 'roll', 'entries': [['E0', 28, True], ['E1', 65, True], ['E2', 29, False], ['E3', 65, False], ['E4', 93, True]]}, [['E0', 28, 'posted'], ['E1', 65, 'posted'], ['E2', None, 'no_period'], ['E3', 65, 'posted'], ['E4', 93, 'posted']]], ['control 5', {'periods': [[37, 66, 'soft'], [1, 31, 'closed']], 'policy': 'roll', 'entries': [['E0', 37, False], ['E1', 67, True], ['E2', 69, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]], ['control 6', {'periods': [[63, 92, 'closed'], [1, 31, 'closed'], [98, 125, 'open'], [32, 62, 'soft']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 63, False], ['E2', 93, False]]}, [['E0', 32, 'posted'], ['E1', 98, 'rolled'], ['E2', None, 'no_period']]]], [['regression: roll target choice', {'periods': [[34, 61, 'closed'], [1, 28, 'soft'], [67, 94, 'open'], [95, 122, 'open']], 'policy': 'roll', 'entries': [['E0', 95, True], ['E1', 37, False], ['E2', 94, False]]}, [['E0', 95, 'posted'], ['E1', 67, 'rolled'], ['E2', 94, 'posted']]], ['control 1', {'periods': [[1, 28, 'closed'], [29, 59, 'closed'], [60, 89, 'soft']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 32, True], ['E2', 63, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 63, 'posted']]], ['control 2', {'periods': [[128, 155, 'open'], [31, 58, 'closed'], [1, 30, 'soft'], [59, 86, 'closed'], [92, 122, 'soft']], 'policy': 'reject', 'entries': [['E0', 125, False], ['E1', 31, False], ['E2', 156, True], ['E3', 1, False], ['E4', 95, False], ['E5', 95, False]]}, [['E0', None, 'no_period'], ['E1', None, 'closed'], ['E2', None, 'no_period'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[31, 61, 'soft'], [62, 91, 'closed'], [92, 121, 'closed'], [1, 30, 'closed']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 92, False], ['E2', 30, False], ['E3', 1, False], ['E4', 31, True], ['E5', 124, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 31, 'posted'], ['E5', None, 'no_period']]], ['control 4', {'periods': [[93, 123, 'closed'], [1, 31, 'open'], [62, 92, 'closed'], [32, 61, 'closed']], 'policy': 'reject', 'entries': [['E0', 123, False], ['E1', 95, True], ['E2', 32, True], ['E3', 1, False], ['E4', 124, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 1, 'posted'], ['E4', None, 'no_period']]], ['control 5', {'periods': [[73, 100, 'open'], [1, 31, 'closed'], [37, 67, 'open'], [129, 159, 'open'], [101, 128, 'soft']], 'policy': 'reject', 'entries': [['E0', 129, False], ['E1', 40, True], ['E2', 132, True], ['E3', 73, False], ['E4', 132, False], ['E5', 34, False]]}, [['E0', 129, 'posted'], ['E1', 40, 'posted'], ['E2', 132, 'posted'], ['E3', 73, 'posted'], ['E4', 132, 'posted'], ['E5', None, 'no_period']]], ['control 6', {'periods': [[93, 123, 'closed'], [1, 28, 'open'], [29, 59, 'soft'], [65, 92, 'soft']], 'policy': 'roll', 'entries': [['E0', 93, False], ['E1', 123, False], ['E2', 32, False], ['E3', 123, False], ['E4', 123, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed']]]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    periods = sorted(x['periods'])
    out = []
    for eid, date, adjusting in x['entries']:
        found = None
        for p in periods:
            if p[0] <= date <= p[1]:
                found = p
                break
        if found is None:
            out.append([eid, None, 'no_period'])
            continue
        status = found[2]
        if status == 'soft' and adjusting:
            status = 'open'
        if status == 'open':
            out.append([eid, date, 'posted'])
        elif x['policy'] == 'roll':
            nxt = [p for p in periods if p[0] > found[1] and p[2] == 'open']
            if nxt:
                out.append([eid, nxt[0][1], 'rolled'])
            else:
                out.append([eid, None, 'closed'])
        else:
            out.append([eid, None, 'closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: roll target choice', {'periods': [[37, 67, 'open'], [1, 31, 'closed'], [68, 95, 'open']], 'policy': 'roll', 'entries': [['E0', 4, True], ['E1', 70, True], ['E2', 40, False]]}, [['E0', 37, 'rolled'], ['E1', 70, 'posted'], ['E2', 40, 'posted']]], ['control 1', {'periods': [[122, 151, 'soft'], [92, 121, 'soft'], [31, 60, 'closed'], [1, 30, 'soft'], [61, 91, 'open']], 'policy': 'reject', 'entries': [['E0', 151, False], ['E1', 125, False], ['E2', 121, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 2', {'periods': [[31, 60, 'closed'], [61, 90, 'closed'], [1, 30, 'closed'], [91, 121, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 121, False], ['E2', 94, True], ['E3', 1, False], ['E4', 34, False], ['E5', 61, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[92, 121, 'closed'], [32, 61, 'soft'], [62, 91, 'closed'], [1, 31, 'soft']], 'policy': 'roll', 'entries': [['E0', 35, False], ['E1', 65, False], ['E2', 92, True], ['E3', 35, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 35, 'posted']]], ['control 4', {'periods': [[59, 88, 'soft'], [117, 146, 'open'], [31, 58, 'closed'], [89, 116, 'closed'], [1, 30, 'closed']], 'policy': 'roll', 'entries': [['E0', 120, False], ['E1', 31, True], ['E2', 59, False], ['E3', 120, False], ['E4', 59, True]]}, [['E0', 120, 'posted'], ['E1', 117, 'rolled'], ['E2', 117, 'rolled'], ['E3', 120, 'posted'], ['E4', 59, 'posted']]], ['control 5', {'periods': [[29, 58, 'open'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 58, True], ['E2', 58, False], ['E3', 29, True]]}, [['E0', 29, 'posted'], ['E1', 58, 'posted'], ['E2', 58, 'posted'], ['E3', 29, 'posted']]], ['control 6', {'periods': [[29, 58, 'closed'], [90, 119, 'closed'], [1, 28, 'open'], [59, 89, 'soft']], 'policy': 'reject', 'entries': [['E0', 93, True], ['E1', 89, True], ['E2', 59, False]]}, [['E0', None, 'closed'], ['E1', 89, 'posted'], ['E2', None, 'closed']]]], [['regression: roll target choice', {'periods': [[1, 30, 'soft'], [31, 58, 'open'], [59, 86, 'open']], 'policy': 'roll', 'entries': [['E0', 30, False], ['E1', 62, False], ['E2', 59, False], ['E3', 4, False], ['E4', 1, False]]}, [['E0', 31, 'rolled'], ['E1', 62, 'posted'], ['E2', 59, 'posted'], ['E3', 31, 'rolled'], ['E4', 31, 'rolled']]], ['control 1', {'periods': [[1, 31, 'closed'], [60, 90, 'soft'], [32, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 60, True], ['E1', 62, True], ['E2', 1, True], ['E3', 31, False], ['E4', 62, True]]}, [['E0', 60, 'posted'], ['E1', 62, 'posted'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 62, 'posted']]], ['control 2', {'periods': [[93, 120, 'closed'], [121, 148, 'soft'], [63, 92, 'soft'], [1, 31, 'soft'], [32, 62, 'open']], 'policy': 'roll', 'entries': [['E0', 149, True], ['E1', 63, True], ['E2', 148, True], ['E3', 4, False]]}, [['E0', None, 'no_period'], ['E1', 63, 'posted'], ['E2', 148, 'posted'], ['E3', 32, 'rolled']]], ['control 3', {'periods': [[29, 59, 'closed'], [1, 28, 'closed'], [65, 94, 'open']], 'policy': 'reject', 'entries': [['E0', 68, False], ['E1', 97, False], ['E2', 95, True], ['E3', 68, False], ['E4', 28, False], ['E5', 28, False]]}, [['E0', 68, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 68, 'posted'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 4', {'periods': [[62, 89, 'open'], [1, 31, 'soft'], [32, 61, 'closed'], [90, 117, 'closed']], 'policy': 'reject', 'entries': [['E0', 62, False], ['E1', 117, False], ['E2', 93, False], ['E3', 65, False]]}, [['E0', 62, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 65, 'posted']]], ['control 5', {'periods': [[29, 59, 'open'], [1, 28, 'closed'], [60, 90, 'closed']], 'policy': 'roll', 'entries': [['E0', 31, False], ['E1', 62, True], ['E2', 29, False], ['E3', 93, False], ['E4', 59, False], ['E5', 60, True]]}, [['E0', 31, 'posted'], ['E1', None, 'closed'], ['E2', 29, 'posted'], ['E3', None, 'no_period'], ['E4', 59, 'posted'], ['E5', None, 'closed']]], ['control 6', {'periods': [[65, 92, 'open'], [34, 64, 'closed'], [1, 28, 'closed']], 'policy': 'reject', 'entries': [['E0', 67, False], ['E1', 1, False], ['E2', 64, True], ['E3', 68, False]]}, [['E0', 67, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 68, 'posted']]]], [['regression: roll target choice', {'periods': [[61, 90, 'open'], [1, 30, 'open'], [31, 60, 'soft'], [91, 121, 'closed'], [122, 151, 'open']], 'policy': 'roll', 'entries': [['E0', 31, False], ['E1', 125, False], ['E2', 90, False], ['E3', 4, False], ['E4', 60, False], ['E5', 152, True]]}, [['E0', 61, 'rolled'], ['E1', 125, 'posted'], ['E2', 90, 'posted'], ['E3', 4, 'posted'], ['E4', 61, 'rolled'], ['E5', None, 'no_period']]], ['control 1', {'periods': [[1, 30, 'soft'], [31, 60, 'soft']], 'policy': 'roll', 'entries': [['E0', 30, False], ['E1', 31, False], ['E2', 31, True], ['E3', 30, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 31, 'posted'], ['E3', None, 'closed']]], ['control 2', {'periods': [[1, 28, 'closed'], [29, 59, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, True], ['E1', 31, False], ['E2', 1, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 3', {'periods': [[1, 28, 'open'], [29, 59, 'soft']], 'policy': 'roll', 'entries': [['E0', 1, False], ['E1', 29, False], ['E2', 31, False]]}, [['E0', 1, 'posted'], ['E1', None, 'closed'], ['E2', None, 'closed']]], ['control 4', {'periods': [[65, 92, 'open'], [1, 28, 'closed'], [34, 64, 'soft']], 'policy': 'roll', 'entries': [['E0', 65, False], ['E1', 65, False], ['E2', 92, False]]}, [['E0', 65, 'posted'], ['E1', 65, 'posted'], ['E2', 92, 'posted']]], ['control 5', {'periods': [[63, 90, 'open'], [1, 31, 'closed'], [32, 62, 'closed']], 'policy': 'roll', 'entries': [['E0', 63, True], ['E1', 65, True], ['E2', 63, True], ['E3', 1, False]]}, [['E0', 63, 'posted'], ['E1', 65, 'posted'], ['E2', 63, 'posted'], ['E3', 63, 'rolled']]], ['control 6', {'periods': [[29, 59, 'soft'], [123, 150, 'closed'], [1, 28, 'closed'], [60, 87, 'closed'], [93, 122, 'closed']], 'policy': 'roll', 'entries': [['E0', 29, False], ['E1', 29, False], ['E2', 63, False], ['E3', 29, False], ['E4', 151, False], ['E5', 60, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'no_period'], ['E5', None, 'closed']]]], [['regression: roll target choice', {'periods': [[32, 59, 'closed'], [65, 94, 'open'], [1, 31, 'soft'], [100, 130, 'open']], 'policy': 'roll', 'entries': [['E0', 130, True], ['E1', 68, False], ['E2', 4, False], ['E3', 131, False], ['E4', 133, True]]}, [['E0', 130, 'posted'], ['E1', 68, 'posted'], ['E2', 65, 'rolled'], ['E3', None, 'no_period'], ['E4', None, 'no_period']]], ['control 1', {'periods': [[29, 58, 'closed'], [1, 28, 'open']], 'policy': 'roll', 'entries': [['E0', 61, False], ['E1', 1, False], ['E2', 58, True]]}, [['E0', None, 'no_period'], ['E1', 1, 'posted'], ['E2', None, 'closed']]], ['control 2', {'periods': [[59, 86, 'open'], [29, 58, 'closed'], [1, 28, 'closed']], 'policy': 'roll', 'entries': [['E0', 59, False], ['E1', 87, False], ['E2', 87, False], ['E3', 61, False]]}, [['E0', 59, 'posted'], ['E1', None, 'no_period'], ['E2', None, 'no_period'], ['E3', 61, 'posted']]], ['control 3', {'periods': [[1, 31, 'soft'], [32, 59, 'open']], 'policy': 'reject', 'entries': [['E0', 60, True], ['E1', 32, False], ['E2', 62, False]]}, [['E0', None, 'no_period'], ['E1', 32, 'posted'], ['E2', None, 'no_period']]], ['control 4', {'periods': [[34, 61, 'soft'], [62, 92, 'open'], [1, 28, 'soft'], [93, 123, 'open']], 'policy': 'roll', 'entries': [['E0', 28, True], ['E1', 65, True], ['E2', 29, False], ['E3', 65, False], ['E4', 93, True]]}, [['E0', 28, 'posted'], ['E1', 65, 'posted'], ['E2', None, 'no_period'], ['E3', 65, 'posted'], ['E4', 93, 'posted']]], ['control 5', {'periods': [[37, 66, 'soft'], [1, 31, 'closed']], 'policy': 'roll', 'entries': [['E0', 37, False], ['E1', 67, True], ['E2', 69, False]]}, [['E0', None, 'closed'], ['E1', None, 'no_period'], ['E2', None, 'no_period']]], ['control 6', {'periods': [[63, 92, 'closed'], [1, 31, 'closed'], [98, 125, 'open'], [32, 62, 'soft']], 'policy': 'roll', 'entries': [['E0', 32, True], ['E1', 63, False], ['E2', 93, False]]}, [['E0', 32, 'posted'], ['E1', 98, 'rolled'], ['E2', None, 'no_period']]]], [['regression: roll target choice', {'periods': [[34, 61, 'closed'], [1, 28, 'soft'], [67, 94, 'open'], [95, 122, 'open']], 'policy': 'roll', 'entries': [['E0', 95, True], ['E1', 37, False], ['E2', 94, False]]}, [['E0', 95, 'posted'], ['E1', 67, 'rolled'], ['E2', 94, 'posted']]], ['control 1', {'periods': [[1, 28, 'closed'], [29, 59, 'closed'], [60, 89, 'soft']], 'policy': 'roll', 'entries': [['E0', 63, False], ['E1', 32, True], ['E2', 63, True]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', 63, 'posted']]], ['control 2', {'periods': [[128, 155, 'open'], [31, 58, 'closed'], [1, 30, 'soft'], [59, 86, 'closed'], [92, 122, 'soft']], 'policy': 'reject', 'entries': [['E0', 125, False], ['E1', 31, False], ['E2', 156, True], ['E3', 1, False], ['E4', 95, False], ['E5', 95, False]]}, [['E0', None, 'no_period'], ['E1', None, 'closed'], ['E2', None, 'no_period'], ['E3', None, 'closed'], ['E4', None, 'closed'], ['E5', None, 'closed']]], ['control 3', {'periods': [[31, 61, 'soft'], [62, 91, 'closed'], [92, 121, 'closed'], [1, 30, 'closed']], 'policy': 'reject', 'entries': [['E0', 34, False], ['E1', 92, False], ['E2', 30, False], ['E3', 1, False], ['E4', 31, True], ['E5', 124, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', 31, 'posted'], ['E5', None, 'no_period']]], ['control 4', {'periods': [[93, 123, 'closed'], [1, 31, 'open'], [62, 92, 'closed'], [32, 61, 'closed']], 'policy': 'reject', 'entries': [['E0', 123, False], ['E1', 95, True], ['E2', 32, True], ['E3', 1, False], ['E4', 124, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', 1, 'posted'], ['E4', None, 'no_period']]], ['control 5', {'periods': [[73, 100, 'open'], [1, 31, 'closed'], [37, 67, 'open'], [129, 159, 'open'], [101, 128, 'soft']], 'policy': 'reject', 'entries': [['E0', 129, False], ['E1', 40, True], ['E2', 132, True], ['E3', 73, False], ['E4', 132, False], ['E5', 34, False]]}, [['E0', 129, 'posted'], ['E1', 40, 'posted'], ['E2', 132, 'posted'], ['E3', 73, 'posted'], ['E4', 132, 'posted'], ['E5', None, 'no_period']]], ['control 6', {'periods': [[93, 123, 'closed'], [1, 28, 'open'], [29, 59, 'soft'], [65, 92, 'soft']], 'policy': 'roll', 'entries': [['E0', 93, False], ['E1', 123, False], ['E2', 32, False], ['E3', 123, False], ['E4', 123, False]]}, [['E0', None, 'closed'], ['E1', None, 'closed'], ['E2', None, 'closed'], ['E3', None, 'closed'], ['E4', None, 'closed']]]]]
for label, args, expected in fixtures[N-1]:
    try:
        actual = solve(args)
    except Exception as exc:
        actual = 'raised ' + type(exc).__name__
    check(label, actual, 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:
Rolled entries skip ahead to the last open period of the year.

x = {'periods': [[start_day, end_day, 'open'|'soft'|'closed']] (non-overlapping, any order), 'policy': 'reject'|'roll', 'entries': [[id, day, adjusting]]}. The period containing the day (start and end inclusive) is found; none gives [id, None, 'no_period']. Soft periods accept adjusting entries only. Open acceptance gives [id, day, 'posted']. Otherwise under 'roll' the entry posts on the start day of the earliest later open period ([id, start, 'rolled']) and with none, or under 'reject', gives [id, None, 'closed'].

split: open-access