broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    left = Fraction(x['bag_ml'])
    segs = x['segments']
    for i, (t0, rate) in enumerate(segs):
        t1 = segs[i + 1][0] if i + 1 < len(segs) else t0
        if rate == 0:
            continue
        per_min = Fraction(rate, 60)
        need = left / per_min
        if t1 is None or t0 + need <= t1:
            empty = t0 + need
            return {'empty_min': round(float(empty), 1), 'alarm_min': round(float(max(Fraction(0), empty - 30)), 1)}
        left -= per_min * (t1 - t0)
    return {'empty_min': None, 'alarm_min': None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('single rate', {'bag_ml': 500, 'segments': [[0, 125]]}, {'empty_min': 240.0, 'alarm_min': 210.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 260]]},
   {'empty_min': 355.4, 'alarm_min': 325.4}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [150, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 110, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 31]]},
   {'empty_min': 272.9, 'alarm_min': 242.9}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 80]]},
   {'empty_min': 15.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 30]]},
   {'empty_min': 230.0, 'alarm_min': 200.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 11]]},
   {'empty_min': 5241.8, 'alarm_min': 5211.8})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 150]]}, {'empty_min': 200.0, 'alarm_min': 170.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 270]]},
   {'empty_min': 351.1, 'alarm_min': 321.1}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [180, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 120, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 32]]},
   {'empty_min': 266.2, 'alarm_min': 236.2}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 100]]},
   {'empty_min': 12.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 60]]},
   {'empty_min': 160.0, 'alarm_min': 130.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 12]]},
   {'empty_min': 4810.0, 'alarm_min': 4780.0})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 175]]}, {'empty_min': 171.4, 'alarm_min': 141.4}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 280]]},
   {'empty_min': 347.1, 'alarm_min': 317.1}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [210, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 130, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 33]]},
   {'empty_min': 260.0, 'alarm_min': 230.0}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 120]]},
   {'empty_min': 10.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 90]]},
   {'empty_min': 136.7, 'alarm_min': 106.7}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 13]]},
   {'empty_min': 4444.6, 'alarm_min': 4414.6})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 200]]}, {'empty_min': 150.0, 'alarm_min': 120.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 290]]},
   {'empty_min': 343.4, 'alarm_min': 313.4}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [240, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 140, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 34]]},
   {'empty_min': 254.1, 'alarm_min': 224.1}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 140]]},
   {'empty_min': 8.6, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 120]]},
   {'empty_min': 125.0, 'alarm_min': 95.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 14]]},
   {'empty_min': 4131.4, 'alarm_min': 4101.4})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 225]]}, {'empty_min': 133.3, 'alarm_min': 103.3}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 300]]},
   {'empty_min': 340.0, 'alarm_min': 310.0}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [270, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 150, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 35]]},
   {'empty_min': 248.6, 'alarm_min': 218.6}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 160]]},
   {'empty_min': 7.5, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 150]]},
   {'empty_min': 118.0, 'alarm_min': 88.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 15]]},
   {'empty_min': 3860.0, 'alarm_min': 3830.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
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    left = Fraction(x['bag_ml'])
    segs = x['segments']
    for i, (t0, rate) in enumerate(segs):
        t1 = segs[i + 1][0] if i + 1 < len(segs) else 1440
        if rate == 0:
            continue
        per_min = Fraction(rate, 60)
        need = left / per_min
        if t1 is None or t0 + need <= t1:
            empty = t0 + need
            return {'empty_min': round(float(empty), 1), 'alarm_min': round(float(max(Fraction(0), empty - 30)), 1)}
        left -= per_min * (t1 - t0)
    return {'empty_min': None, 'alarm_min': None}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('single rate', {'bag_ml': 500, 'segments': [[0, 125]]}, {'empty_min': 240.0, 'alarm_min': 210.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 260]]},
   {'empty_min': 355.4, 'alarm_min': 325.4}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [150, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 110, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 31]]},
   {'empty_min': 272.9, 'alarm_min': 242.9}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 80]]},
   {'empty_min': 15.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 30]]},
   {'empty_min': 230.0, 'alarm_min': 200.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 11]]},
   {'empty_min': 5241.8, 'alarm_min': 5211.8})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 150]]}, {'empty_min': 200.0, 'alarm_min': 170.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 270]]},
   {'empty_min': 351.1, 'alarm_min': 321.1}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [180, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 120, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 32]]},
   {'empty_min': 266.2, 'alarm_min': 236.2}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 100]]},
   {'empty_min': 12.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 60]]},
   {'empty_min': 160.0, 'alarm_min': 130.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 12]]},
   {'empty_min': 4810.0, 'alarm_min': 4780.0})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 175]]}, {'empty_min': 171.4, 'alarm_min': 141.4}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 280]]},
   {'empty_min': 347.1, 'alarm_min': 317.1}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [210, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 130, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 33]]},
   {'empty_min': 260.0, 'alarm_min': 230.0}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 120]]},
   {'empty_min': 10.0, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 90]]},
   {'empty_min': 136.7, 'alarm_min': 106.7}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 13]]},
   {'empty_min': 4444.6, 'alarm_min': 4414.6})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 200]]}, {'empty_min': 150.0, 'alarm_min': 120.0}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 290]]},
   {'empty_min': 343.4, 'alarm_min': 313.4}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [240, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 140, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 34]]},
   {'empty_min': 254.1, 'alarm_min': 224.1}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 140]]},
   {'empty_min': 8.6, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 120]]},
   {'empty_min': 125.0, 'alarm_min': 95.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 14]]},
   {'empty_min': 4131.4, 'alarm_min': 4101.4})],
 [('single rate', {'bag_ml': 500, 'segments': [[0, 225]]}, {'empty_min': 133.3, 'alarm_min': 103.3}),
  ('rate change mid bag',
   {'bag_ml': 1000, 'segments': [[0, 125], [240, 300]]},
   {'empty_min': 340.0, 'alarm_min': 310.0}),
  ('empties exactly at pause',
   {'bag_ml': 250, 'segments': [[0, 125], [120, 0], [270, 60]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('empties exactly at end of final paused tail',
   {'bag_ml': 100, 'segments': [[0, 50], [120, 0]]},
   {'empty_min': 120.0, 'alarm_min': 90.0}),
  ('bag outlasts second segment before pause',
   {'bag_ml': 150, 'segments': [[0, 60], [60, 60], [100, 0]]},
   {'empty_min': None, 'alarm_min': None}),
  ('completed middle segment consumption',
   {'bag_ml': 200, 'segments': [[0, 60], [30, 120], [60, 35]]},
   {'empty_min': 248.6, 'alarm_min': 218.6}),
  ('small bag alarm clamps at zero',
   {'bag_ml': 20, 'segments': [[0, 160]]},
   {'empty_min': 7.5, 'alarm_min': 0.0}),
  ('pause then resume',
   {'bag_ml': 100, 'segments': [[0, 60], [30, 0], [90, 150]]},
   {'empty_min': 118.0, 'alarm_min': 88.0}),
  ('very slow multi-day tail',
   {'bag_ml': 1000, 'segments': [[0, 50], [60, 15]]},
   {'empty_min': 3860.0, 'alarm_min': 3830.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:
Bags that run out during the final rate are reported as never emptying.

Input {bag_ml, segments [[start_min, rate_ml_h], ...] ascending from 0}. Each segment runs until the next start; the last segment is open-ended. Paused segments (rate 0) consume nothing. Return {empty_min, alarm_min = max(0, empty-30)} rounded to 0.1 min, or both None when the bag never empties.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def mins(s):
        h, m = map(int, s.split(':'))
        return h * 60 + m
    dt = mins(x['draw']) - mins(x['dose'])
    dt = abs(dt)
    hrs = Fraction(dt, 60)
    if hrs < 6 or hrs > 14:
        return {'interval': 'OUT_OF_RANGE', 'hours': round(float(hrs), 2)}
    lv = Fraction(str(x['level']))
    rem = 14 - hrs
    if lv <= 2 + rem / 2:
        iv = 'q24h'
    elif lv <= 4 + rem * Fraction(3, 4):
        iv = 'q36h'
    elif lv <= 6 + rem:
        iv = 'q48h'
    else:
        iv = 'HOLD_RECHECK'
    return {'interval': iv, 'hours': round(float(hrs), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('draw after midnight',
   {'dose': '20:00', 'draw': '03:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 7.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 6}, {'interval': 'q24h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '2'}, {'interval': 'q24h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:10', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.17}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:15', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.25}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 4},
   {'interval': 'q24h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '04:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 8.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 7}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '3'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:20', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.33}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:20', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.33}),
  ('on the q24 line', {'dose': '08:00', 'draw': '15:00', 'level': '5.5'}, {'interval': 'q24h', 'hours': 7.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 5},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '05:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 9.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 8}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '4'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:30', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.5}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:25', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.42}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '19:00', 'level': '3.5'},
   {'interval': 'q24h', 'hours': 11.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 6},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '06:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 10.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 9}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '6'}, {'interval': 'q48h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:40', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.67}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:30', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.5}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '21:00', 'level': '2.5'},
   {'interval': 'q24h', 'hours': 13.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 7},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '07:00', 'level': '4'},
   {'interval': 'q36h', 'hours': 11.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 10}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours',
   {'dose': '06:30', 'draw': '20:30', 'level': '7'},
   {'interval': 'HOLD_RECHECK', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:50', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.83}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:35', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.58}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 8},
   {'interval': 'q48h', 'hours': 10.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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def mins(s):
        h, m = map(int, s.split(':'))
        return h * 60 + m
    dt = mins(x['draw']) - mins(x['dose'])
    if dt < 0:
        dt += 720
    hrs = Fraction(dt, 60)
    if hrs < 6 or hrs > 14:
        return {'interval': 'OUT_OF_RANGE', 'hours': round(float(hrs), 2)}
    lv = Fraction(str(x['level']))
    rem = 14 - hrs
    if lv <= 2 + rem / 2:
        iv = 'q24h'
    elif lv <= 4 + rem * Fraction(3, 4):
        iv = 'q36h'
    elif lv <= 6 + rem:
        iv = 'q48h'
    else:
        iv = 'HOLD_RECHECK'
    return {'interval': iv, 'hours': round(float(hrs), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('draw after midnight',
   {'dose': '20:00', 'draw': '03:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 7.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 6}, {'interval': 'q24h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '2'}, {'interval': 'q24h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:10', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.17}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:15', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.25}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 4},
   {'interval': 'q24h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '04:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 8.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 7}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '3'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:20', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.33}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:20', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.33}),
  ('on the q24 line', {'dose': '08:00', 'draw': '15:00', 'level': '5.5'}, {'interval': 'q24h', 'hours': 7.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 5},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '05:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 9.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 8}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '4'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:30', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.5}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:25', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.42}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '19:00', 'level': '3.5'},
   {'interval': 'q24h', 'hours': 11.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 6},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '06:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 10.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 9}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '6'}, {'interval': 'q48h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:40', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.67}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:30', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.5}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '21:00', 'level': '2.5'},
   {'interval': 'q24h', 'hours': 13.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 7},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '07:00', 'level': '4'},
   {'interval': 'q36h', 'hours': 11.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 10}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours',
   {'dose': '06:30', 'draw': '20:30', 'level': '7'},
   {'interval': 'HOLD_RECHECK', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:50', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.83}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:35', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.58}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 8},
   {'interval': 'q48h', 'hours': 10.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 02:00 level after a 20:00 dose is read as 18 hours and rejected.

Input {dose "HH:MM", draw "HH:MM" (a draw clock time earlier than the dose means the next day), level mg/L}. Hours after dose must be within 6-14 inclusive, else OUT_OF_RANGE. With rem = 14 - hours: level <= 2 + rem/2 gives q24h; <= 4 + 0.75*rem gives q36h; <= 6 + rem gives q48h; otherwise HOLD_RECHECK. Return {interval, hours (2 dp)}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def mins(s):
        h, m = map(int, s.split(':'))
        return h * 60 + m
    dt = mins(x['draw']) - mins(x['dose'])
    if dt < 0:
        dt += 1440
    hrs = Fraction(dt, 60)
    if hrs <= 6 or hrs >= 14:
        return {'interval': 'OUT_OF_RANGE', 'hours': round(float(hrs), 2)}
    lv = Fraction(str(x['level']))
    rem = 14 - hrs
    if lv <= 2 + rem / 2:
        iv = 'q24h'
    elif lv <= 4 + rem * Fraction(3, 4):
        iv = 'q36h'
    elif lv <= 6 + rem:
        iv = 'q48h'
    else:
        iv = 'HOLD_RECHECK'
    return {'interval': iv, 'hours': round(float(hrs), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('draw after midnight',
   {'dose': '20:00', 'draw': '03:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 7.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 6}, {'interval': 'q24h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '2'}, {'interval': 'q24h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:10', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.17}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:15', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.25}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 4},
   {'interval': 'q24h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '04:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 8.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 7}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '3'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:20', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.33}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:20', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.33}),
  ('on the q24 line', {'dose': '08:00', 'draw': '15:00', 'level': '5.5'}, {'interval': 'q24h', 'hours': 7.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 5},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '05:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 9.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 8}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '4'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:30', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.5}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:25', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.42}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '19:00', 'level': '3.5'},
   {'interval': 'q24h', 'hours': 11.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 6},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '06:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 10.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 9}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '6'}, {'interval': 'q48h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:40', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.67}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:30', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.5}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '21:00', 'level': '2.5'},
   {'interval': 'q24h', 'hours': 13.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 7},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '07:00', 'level': '4'},
   {'interval': 'q36h', 'hours': 11.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 10}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours',
   {'dose': '06:30', 'draw': '20:30', 'level': '7'},
   {'interval': 'HOLD_RECHECK', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:50', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.83}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:35', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.58}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 8},
   {'interval': 'q48h', 'hours': 10.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
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def mins(s):
        h, m = map(int, s.split(':'))
        return h * 60 + m
    dt = mins(x['draw']) - mins(x['dose'])
    if dt < 0:
        dt += 1440
    hrs = Fraction(dt, 60)
    if hrs < 6:
        return {'interval': 'OUT_OF_RANGE', 'hours': round(float(hrs), 2)}
    lv = Fraction(str(x['level']))
    rem = 14 - hrs
    if lv <= 2 + rem / 2:
        iv = 'q24h'
    elif lv <= 4 + rem * Fraction(3, 4):
        iv = 'q36h'
    elif lv <= 6 + rem:
        iv = 'q48h'
    else:
        iv = 'HOLD_RECHECK'
    return {'interval': iv, 'hours': round(float(hrs), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('draw after midnight',
   {'dose': '20:00', 'draw': '03:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 7.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 6}, {'interval': 'q24h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '2'}, {'interval': 'q24h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:10', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.17}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:15', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.25}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 4},
   {'interval': 'q24h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '04:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 8.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 7}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '3'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:20', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.33}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:20', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.33}),
  ('on the q24 line', {'dose': '08:00', 'draw': '15:00', 'level': '5.5'}, {'interval': 'q24h', 'hours': 7.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 5},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '05:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 9.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 8}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '4'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:30', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.5}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:25', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.42}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '19:00', 'level': '3.5'},
   {'interval': 'q24h', 'hours': 11.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 6},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '06:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 10.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 9}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '6'}, {'interval': 'q48h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:40', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.67}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:30', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.5}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '21:00', 'level': '2.5'},
   {'interval': 'q24h', 'hours': 13.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 7},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '07:00', 'level': '4'},
   {'interval': 'q36h', 'hours': 11.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 10}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours',
   {'dose': '06:30', 'draw': '20:30', 'level': '7'},
   {'interval': 'HOLD_RECHECK', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:50', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.83}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:35', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.58}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 8},
   {'interval': 'q48h', 'hours': 10.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:
Levels drawn exactly 6 or 14 hours after the dose are rejected.

Input {dose "HH:MM", draw "HH:MM" (a draw clock time earlier than the dose means the next day), level mg/L}. Hours after dose must be within 6-14 inclusive, else OUT_OF_RANGE. With rem = 14 - hours: level <= 2 + rem/2 gives q24h; <= 4 + 0.75*rem gives q36h; <= 6 + rem gives q48h; otherwise HOLD_RECHECK. Return {interval, hours (2 dp)}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def mins(s):
        h, m = map(int, s.split(':'))
        return h * 60 + m
    dt = mins(x['draw']) - mins(x['dose'])
    if dt < 0:
        dt += 1440
    hrs = Fraction(dt, 60)
    if hrs < 6 or hrs > 14:
        return {'interval': 'OUT_OF_RANGE', 'hours': round(float(hrs), 2)}
    lv = Fraction(str(x['level']))
    rem = hrs - 6
    if lv <= 2 + rem / 2:
        iv = 'q24h'
    elif lv <= 4 + rem * Fraction(3, 4):
        iv = 'q36h'
    elif lv <= 6 + rem:
        iv = 'q48h'
    else:
        iv = 'HOLD_RECHECK'
    return {'interval': iv, 'hours': round(float(hrs), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('draw after midnight',
   {'dose': '20:00', 'draw': '03:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 7.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 6}, {'interval': 'q24h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '2'}, {'interval': 'q24h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:10', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.17}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:15', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.25}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 4},
   {'interval': 'q24h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '04:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 8.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 7}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '3'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:20', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.33}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:20', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.33}),
  ('on the q24 line', {'dose': '08:00', 'draw': '15:00', 'level': '5.5'}, {'interval': 'q24h', 'hours': 7.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 5},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '05:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 9.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 8}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '4'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:30', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.5}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:25', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.42}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '19:00', 'level': '3.5'},
   {'interval': 'q24h', 'hours': 11.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 6},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '06:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 10.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 9}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '6'}, {'interval': 'q48h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:40', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.67}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:30', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.5}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '21:00', 'level': '2.5'},
   {'interval': 'q24h', 'hours': 13.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 7},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '07:00', 'level': '4'},
   {'interval': 'q36h', 'hours': 11.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 10}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours',
   {'dose': '06:30', 'draw': '20:30', 'level': '7'},
   {'interval': 'HOLD_RECHECK', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:50', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.83}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:35', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.58}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 8},
   {'interval': 'q48h', 'hours': 10.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
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def mins(s):
        h, m = map(int, s.split(':'))
        return h * 60 + m
    dt = mins(x['draw']) - mins(x['dose'])
    if dt < 0:
        dt += 1440
    hrs = Fraction(dt, 60)
    if hrs < 6 or hrs > 14:
        return {'interval': 'OUT_OF_RANGE', 'hours': round(float(hrs), 2)}
    lv = Fraction(str(x['level']))
    rem = 14 - math.floor(hrs)
    if lv <= 2 + rem / 2:
        iv = 'q24h'
    elif lv <= 4 + rem * Fraction(3, 4):
        iv = 'q36h'
    elif lv <= 6 + rem:
        iv = 'q48h'
    else:
        iv = 'HOLD_RECHECK'
    return {'interval': iv, 'hours': round(float(hrs), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('draw after midnight',
   {'dose': '20:00', 'draw': '03:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 7.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 6}, {'interval': 'q24h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '2'}, {'interval': 'q24h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:10', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.17}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:15', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.25}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 4},
   {'interval': 'q24h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '04:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 8.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 7}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '3'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:20', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.33}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:20', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.33}),
  ('on the q24 line', {'dose': '08:00', 'draw': '15:00', 'level': '5.5'}, {'interval': 'q24h', 'hours': 7.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 5},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '05:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 9.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 8}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '4'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:30', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.5}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:25', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.42}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '19:00', 'level': '3.5'},
   {'interval': 'q24h', 'hours': 11.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 6},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '06:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 10.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 9}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '6'}, {'interval': 'q48h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:40', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.67}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:30', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.5}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '21:00', 'level': '2.5'},
   {'interval': 'q24h', 'hours': 13.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 7},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '07:00', 'level': '4'},
   {'interval': 'q36h', 'hours': 11.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 10}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours',
   {'dose': '06:30', 'draw': '20:30', 'level': '7'},
   {'interval': 'HOLD_RECHECK', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:50', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.83}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:35', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.58}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 8},
   {'interval': 'q48h', 'hours': 10.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:
Early levels are compared against the lowest part of each line.

Input {dose "HH:MM", draw "HH:MM" (a draw clock time earlier than the dose means the next day), level mg/L}. Hours after dose must be within 6-14 inclusive, else OUT_OF_RANGE. With rem = 14 - hours: level <= 2 + rem/2 gives q24h; <= 4 + 0.75*rem gives q36h; <= 6 + rem gives q48h; otherwise HOLD_RECHECK. Return {interval, hours (2 dp)}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def mins(s):
        h, m = map(int, s.split(':'))
        return h * 60 + m
    dt = mins(x['draw']) - mins(x['dose'])
    if dt < 0:
        dt += 1440
    hrs = Fraction(dt, 60)
    if hrs < 6 or hrs > 14:
        return {'interval': 'OUT_OF_RANGE', 'hours': round(float(hrs), 2)}
    lv = Fraction(str(x['level']))
    rem = 14 - hrs
    if lv < 2 + rem / 2:
        iv = 'q24h'
    elif lv <= 4 + rem * Fraction(3, 4):
        iv = 'q36h'
    elif lv <= 6 + rem:
        iv = 'q48h'
    else:
        iv = 'HOLD_RECHECK'
    return {'interval': iv, 'hours': round(float(hrs), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('draw after midnight',
   {'dose': '20:00', 'draw': '03:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 7.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 6}, {'interval': 'q24h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '2'}, {'interval': 'q24h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:10', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.17}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:15', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.25}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 4},
   {'interval': 'q24h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '04:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 8.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 7}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '3'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:20', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.33}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:20', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.33}),
  ('on the q24 line', {'dose': '08:00', 'draw': '15:00', 'level': '5.5'}, {'interval': 'q24h', 'hours': 7.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 5},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '05:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 9.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 8}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '4'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:30', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.5}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:25', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.42}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '19:00', 'level': '3.5'},
   {'interval': 'q24h', 'hours': 11.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 6},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '06:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 10.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 9}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '6'}, {'interval': 'q48h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:40', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.67}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:30', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.5}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '21:00', 'level': '2.5'},
   {'interval': 'q24h', 'hours': 13.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 7},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '07:00', 'level': '4'},
   {'interval': 'q36h', 'hours': 11.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 10}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours',
   {'dose': '06:30', 'draw': '20:30', 'level': '7'},
   {'interval': 'HOLD_RECHECK', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:50', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.83}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:35', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.58}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 8},
   {'interval': 'q48h', 'hours': 10.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
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    def mins(s):
        h, m = map(int, s.split(':'))
        return h * 60 + m
    dt = mins(x['draw']) - mins(x['dose'])
    if dt < 0:
        dt += 1440
    hrs = Fraction(dt, 60)
    if hrs < 6 or hrs > 14:
        return {'interval': 'OUT_OF_RANGE', 'hours': round(float(hrs), 2)}
    lv = Fraction(str(x['level']))
    rem = 14 - hrs
    if lv <= 2 + rem // 2:
        iv = 'q24h'
    elif lv <= 4 + rem * Fraction(3, 4):
        iv = 'q36h'
    elif lv <= 6 + rem:
        iv = 'q48h'
    else:
        iv = 'HOLD_RECHECK'
    return {'interval': iv, 'hours': round(float(hrs), 2)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('draw after midnight',
   {'dose': '20:00', 'draw': '03:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 7.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 6}, {'interval': 'q24h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '2'}, {'interval': 'q24h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:10', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.17}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:15', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.25}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 4},
   {'interval': 'q24h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '04:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 8.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 7}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '3'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:20', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.33}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:20', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.33}),
  ('on the q24 line', {'dose': '08:00', 'draw': '15:00', 'level': '5.5'}, {'interval': 'q24h', 'hours': 7.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 5},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '05:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 9.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 8}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '4'}, {'interval': 'q36h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:30', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.5}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:25', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.42}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '19:00', 'level': '3.5'},
   {'interval': 'q24h', 'hours': 11.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 6},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '06:00', 'level': '4'},
   {'interval': 'q24h', 'hours': 10.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 9}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours', {'dose': '06:30', 'draw': '20:30', 'level': '6'}, {'interval': 'q48h', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:40', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.67}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:30', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.5}),
  ('on the q24 line',
   {'dose': '08:00', 'draw': '21:00', 'level': '2.5'},
   {'interval': 'q24h', 'hours': 13.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 7},
   {'interval': 'q36h', 'hours': 10.0})],
 [('draw after midnight',
   {'dose': '20:00', 'draw': '07:00', 'level': '4'},
   {'interval': 'q36h', 'hours': 11.0}),
  ('exactly 6 hours', {'dose': '08:00', 'draw': '14:00', 'level': 10}, {'interval': 'q36h', 'hours': 6.0}),
  ('exactly 14 hours',
   {'dose': '06:30', 'draw': '20:30', 'level': '7'},
   {'interval': 'HOLD_RECHECK', 'hours': 14.0}),
  ('beyond 14 hours',
   {'dose': '06:00', 'draw': '20:50', 'level': '1'},
   {'interval': 'OUT_OF_RANGE', 'hours': 14.83}),
  ('fractional hour reading',
   {'dose': '08:00', 'draw': '18:35', 'level': '3.95'},
   {'interval': 'q36h', 'hours': 10.58}),
  ('on the q24 line', {'dose': '08:00', 'draw': '17:00', 'level': '4.5'}, {'interval': 'q24h', 'hours': 9.0}),
  ('late draw mid-band',
   {'dose': '07:00', 'draw': '17:00', 'level': 8},
   {'interval': 'q48h', 'hours': 10.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 level exactly on the q24h line is assigned q36h.

Input {dose "HH:MM", draw "HH:MM" (a draw clock time earlier than the dose means the next day), level mg/L}. Hours after dose must be within 6-14 inclusive, else OUT_OF_RANGE. With rem = 14 - hours: level <= 2 + rem/2 gives q24h; <= 4 + 0.75*rem gives q36h; <= 6 + rem gives q48h; otherwise HOLD_RECHECK. Return {interval, hours (2 dp)}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    rr = x['rr']
    s_rr = 3 if rr <= 8 else 1 if rr <= 11 else 0 if rr <= 20 else 2 if rr <= 24 else 3
    sp = x['spo2']
    if x['scale2']:
        if sp <= 83:
            s_sp = 3
        elif sp <= 85:
            s_sp = 2
        elif sp <= 87:
            s_sp = 1
        elif sp <= 92 or not x['on_o2']:
            s_sp = 0
        elif sp <= 94:
            s_sp = 1
        elif sp <= 96:
            s_sp = 2
        else:
            s_sp = 3
    else:
        s_sp = 3 if sp <= 91 else 2 if sp <= 93 else 1 if sp <= 95 else 0
    s_o2 = 2 if x['on_o2'] else 0
    t = Fraction(str(x['temp'])) * 10
    s_t = 3 if t <= 350 else 1 if t <= 360 else 0 if t <= 380 else 1 if t <= 390 else 2
    bp = x['sbp']
    s_bp = 3 if bp <= 90 else 2 if bp <= 100 else 1 if bp <= 110 else 0 if bp <= 219 else 3
    hr = x['hr']
    s_hr = 3 if hr <= 40 else 1 if hr <= 50 else 0 if hr <= 90 else 1 if hr <= 110 else 2 if hr <= 130 else 3
    s_c = 3 if x['avpu'] in ('P', 'U') else 0
    parts = [s_rr, s_sp, s_o2, s_t, s_bp, s_hr, s_c]
    total = sum(parts)
    if total >= 7:
        risk = 'HIGH'
    elif total >= 5:
        risk = 'MEDIUM'
    elif 3 in parts:
        risk = 'LOW_MEDIUM'
    else:
        risk = 'LOW'
    return {'score': total, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 71, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.1', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 126, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 89, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 81, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 76, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.3', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 96, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 61, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 72, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 127, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 90, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 82, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 77, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.4', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 97, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 62, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 73, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.3', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 128, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 94, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 91, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 83, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 97, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 78, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.5', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 98, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 63, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 74, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.4', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 129, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 92, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 84, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 79, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.6', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 99, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 64, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.5', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 130, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 88, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 85, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 80, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.7', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22,
    'spo2': 97,
    'on_o2': False,
    'scale2': False,
    'temp': '37.0',
    'sbp': 140,
    'hr': 100,
    'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 65, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})]]
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
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    rr = x['rr']
    s_rr = 3 if rr <= 8 else 1 if rr <= 11 else 0 if rr <= 20 else 2 if rr <= 24 else 3
    sp = x['spo2']
    if x['scale2']:
        if sp <= 83:
            s_sp = 3
        elif sp <= 85:
            s_sp = 2
        elif sp <= 87:
            s_sp = 1
        elif sp <= 92 or not x['on_o2']:
            s_sp = 0
        elif sp <= 94:
            s_sp = 1
        elif sp <= 96:
            s_sp = 2
        else:
            s_sp = 3
    else:
        s_sp = 3 if sp <= 91 else 2 if sp <= 93 else 1 if sp <= 95 else 0
    s_o2 = 2 if x['on_o2'] else 0
    t = Fraction(str(x['temp'])) * 10
    s_t = 3 if t <= 350 else 1 if t <= 360 else 0 if t <= 380 else 1 if t <= 390 else 2
    bp = x['sbp']
    s_bp = 3 if bp <= 90 else 2 if bp <= 100 else 1 if bp <= 110 else 0 if bp <= 219 else 3
    hr = x['hr']
    s_hr = 3 if hr <= 40 else 1 if hr <= 50 else 0 if hr <= 90 else 1 if hr <= 110 else 2 if hr <= 130 else 3
    s_c = 3 if x['avpu'] in ('V', 'P', 'U') else 0
    parts = [s_rr, s_sp, s_o2, s_t, s_bp, s_hr, s_c]
    total = sum(parts)
    if total >= 7:
        risk = 'HIGH'
    elif total >= 5:
        risk = 'MEDIUM'
    elif 3 in parts:
        risk = 'LOW_MEDIUM'
    else:
        risk = 'LOW'
    return {'score': total, 'risk': risk}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 71, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.1', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 126, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 89, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 81, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 76, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.3', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 96, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 61, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 72, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 127, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 90, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 82, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 77, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.4', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 97, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 62, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 73, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.3', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 128, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 94, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 91, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 83, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 97, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 78, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.5', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 98, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 63, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 74, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.4', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 129, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 95, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 92, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 84, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 98, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 79, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.6', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 140, 'hr': 99, 'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 64, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})],
 [('healthy control',
   {'rr': 16, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('new confusion scores three',
   {'rr': 22, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '37.5', 'sbp': 120, 'hr': 80, 'avpu': 'C'},
   {'score': 5, 'risk': 'MEDIUM'}),
  ('responds to voice only',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': False, 'temp': '37.2', 'sbp': 130, 'hr': 85, 'avpu': 'V'},
   {'score': 3, 'risk': 'LOW_MEDIUM'}),
  ('scale 2 high saturation on air',
   {'rr': 18, 'spo2': 96, 'on_o2': False, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('scale 2 target range on oxygen',
   {'rr': 18, 'spo2': 88, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('scale 2 above target on oxygen',
   {'rr': 18, 'spo2': 95, 'on_o2': True, 'scale2': True, 'temp': '37.0', 'sbp': 130, 'hr': 85, 'avpu': 'A'},
   {'score': 4, 'risk': 'LOW'}),
  ('saturating well on oxygen',
   {'rr': 18, 'spo2': 99, 'on_o2': True, 'scale2': False, 'temp': '37.0', 'sbp': 130, 'hr': 80, 'avpu': 'A'},
   {'score': 2, 'risk': 'LOW'}),
  ('temperature exactly 36.0',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.0', 'sbp': 135, 'hr': 80, 'avpu': 'A'},
   {'score': 1, 'risk': 'LOW'}),
  ('temperature 36.x scores zero',
   {'rr': 18, 'spo2': 97, 'on_o2': False, 'scale2': False, 'temp': '36.7', 'sbp': 135, 'hr': 75, 'avpu': 'A'},
   {'score': 0, 'risk': 'LOW'}),
  ('aggregate three without red parameter',
   {'rr': 22,
    'spo2': 97,
    'on_o2': False,
    'scale2': False,
    'temp': '37.0',
    'sbp': 140,
    'hr': 100,
    'avpu': 'A'},
   {'score': 3, 'risk': 'LOW'}),
  ('pain-only response is red parameter',
   {'rr': 16, 'spo2': 98, 'on_o2': False, 'scale2': False, 'temp': '37.0', 'sbp': 120, 'hr': 65, 'avpu': 'P'},
   {'score': 3, 'risk': 'LOW_MEDIUM'})]]
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 newly confused patient responding to voice is scored as alert.

Input {rr, spo2, on_o2, scale2, temp (1 dp), sbp, hr, avpu}. Toy points: RR <=8:3, 9-11:1, 12-20:0, 21-24:2, >=25:3. SpO2 scale 1: <=91:3, 92-93:2, 94-95:1, >=96:0. Scale 2: <=83:3, 84-85:2, 86-87:1, 88-92:0, and >=93 scores 0 on air but on oxygen 93-94:1, 95-96:2, >=97:3. Oxygen +2. Temp <=35.0:3, 35.1-36.0:1, 36.1-38.0:0, 38.1-39.0:1, >=39.1:2. SBP <=90:3, 91-100:2, 101-110:1, 111-219:0, >=220:3. HR <=40:3, 41-50:1, 51-90:0, 91-110:1, 111-130:2, >=131:3. AVPU "A" 0, any other (C new confusion, V, P, U) 3. Risk: total >=7 HIGH, >=5 MEDIUM, else LOW_MEDIUM if any single parameter scores 3, else LOW. Return {score, risk}.

split: open-access