FA-64311 / Medication dosing calculations / Open access
Infusion bag run-out time across rate changes: alarm floor at zero · case 01
A small bag shows an alarm time before the infusion started.
ROOT CAUSE
The pre-empty alarm is not clamped at time zero.
VERIFIED REPAIR
Clamp the alarm time with max(0, empty - 30).
Unsuccessful approach: Clamping before subtracting still produces negative alarm times.
Case contract
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.
Why this case matters
Run-out prediction walks piecewise-constant rates; segment edges, open-ended tails and unit conversion fail independently.
1 / The failure
Exit 1"""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 None
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(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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| single rate | {'alarm_min': 210.0, 'empty_min': 240.0} | {'alarm_min': 210.0, 'empty_min': 240.0} | Passed |
| rate change mid bag | {'alarm_min': 325.4, 'empty_min': 355.4} | {'alarm_min': 325.4, 'empty_min': 355.4} | Passed |
| empties exactly at pause | {'alarm_min': 90.0, 'empty_min': 120.0} | {'alarm_min': 90.0, 'empty_min': 120.0} | Passed |
| empties exactly at end of final paused tail | {'alarm_min': 90.0, 'empty_min': 120.0} | {'alarm_min': 90.0, 'empty_min': 120.0} | Passed |
| bag outlasts second segment before pause | {'alarm_min': None, 'empty_min': None} | {'alarm_min': None, 'empty_min': None} | Passed |
| completed middle segment consumption | {'alarm_min': 242.9, 'empty_min': 272.9} | {'alarm_min': 242.9, 'empty_min': 272.9} | Passed |
| small bag alarm clamps at zero | {'alarm_min': -15.0, 'empty_min': 15.0} | {'alarm_min': 0.0, 'empty_min': 15.0} | Failed |
| pause then resume | {'alarm_min': 200.0, 'empty_min': 230.0} | {'alarm_min': 200.0, 'empty_min': 230.0} | Passed |
| very slow multi-day tail | {'alarm_min': 5211.8, 'empty_min': 5241.8} | {'alarm_min': 5211.8, 'empty_min': 5241.8} | Passed |
SHA-256 / 667c221a1f69d211bf1bab65e86dccc0182e1749466f8717bd48e70960206463
2 / The unsuccessful fix
Exit 1"""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 None
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| single rate | {'alarm_min': 210.0, 'empty_min': 240.0} | {'alarm_min': 210.0, 'empty_min': 240.0} | Passed |
| rate change mid bag | {'alarm_min': 325.4, 'empty_min': 355.4} | {'alarm_min': 325.4, 'empty_min': 355.4} | Passed |
| empties exactly at pause | {'alarm_min': 90.0, 'empty_min': 120.0} | {'alarm_min': 90.0, 'empty_min': 120.0} | Passed |
| empties exactly at end of final paused tail | {'alarm_min': 90.0, 'empty_min': 120.0} | {'alarm_min': 90.0, 'empty_min': 120.0} | Passed |
| bag outlasts second segment before pause | {'alarm_min': None, 'empty_min': None} | {'alarm_min': None, 'empty_min': None} | Passed |
| completed middle segment consumption | {'alarm_min': 242.9, 'empty_min': 272.9} | {'alarm_min': 242.9, 'empty_min': 272.9} | Passed |
| small bag alarm clamps at zero | {'alarm_min': -15.0, 'empty_min': 15.0} | {'alarm_min': 0.0, 'empty_min': 15.0} | Failed |
| pause then resume | {'alarm_min': 200.0, 'empty_min': 230.0} | {'alarm_min': 200.0, 'empty_min': 230.0} | Passed |
| very slow multi-day tail | {'alarm_min': 5211.8, 'empty_min': 5241.8} | {'alarm_min': 5211.8, 'empty_min': 5241.8} | Passed |
SHA-256 / aab8f3dec309051c5617aa52fa3b49de930d99768d9a3637a127ec53a0a98517
3 / The verified repair
Exit 0"""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 None
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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| single rate | {'alarm_min': 210.0, 'empty_min': 240.0} | {'alarm_min': 210.0, 'empty_min': 240.0} | Passed |
| rate change mid bag | {'alarm_min': 325.4, 'empty_min': 355.4} | {'alarm_min': 325.4, 'empty_min': 355.4} | Passed |
| empties exactly at pause | {'alarm_min': 90.0, 'empty_min': 120.0} | {'alarm_min': 90.0, 'empty_min': 120.0} | Passed |
| empties exactly at end of final paused tail | {'alarm_min': 90.0, 'empty_min': 120.0} | {'alarm_min': 90.0, 'empty_min': 120.0} | Passed |
| bag outlasts second segment before pause | {'alarm_min': None, 'empty_min': None} | {'alarm_min': None, 'empty_min': None} | Passed |
| completed middle segment consumption | {'alarm_min': 242.9, 'empty_min': 272.9} | {'alarm_min': 242.9, 'empty_min': 272.9} | Passed |
| small bag alarm clamps at zero | {'alarm_min': 0.0, 'empty_min': 15.0} | {'alarm_min': 0.0, 'empty_min': 15.0} | Passed |
| pause then resume | {'alarm_min': 200.0, 'empty_min': 230.0} | {'alarm_min': 200.0, 'empty_min': 230.0} | Passed |
| very slow multi-day tail | {'alarm_min': 5211.8, 'empty_min': 5241.8} | {'alarm_min': 5211.8, 'empty_min': 5241.8} | Passed |
SHA-256 / cbb41fa490a85e762772542c51ce7ddfa4fdef8ba989c6a6780c3a2b383702d4
Verification & scope
A deterministic toy software model with explicitly stipulated thresholds and formulas; it is not clinical guidance, not a validated medical calculator, and makes no claim of conformance to any published protocol. Numbered variants vary patient and order inputs. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:47:23.262460+00:00.
Case digest / 52c507b89586806309b3f5bd3469b949238cc40a05c53f89a2da2ed64182ca30