broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    conc = Fraction(x['drug_mg']) * 1000 / Fraction(str(x['bag_ml']))
    rate = Fraction(str(x['dose'])) * Fraction(str(x['weight_kg'])) / conc
    tenths = math.floor(rate * 10 + Fraction(1, 2))
    if tenths > 9999:
        return {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': float(conc)}
    if tenths == 0:
        return {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': float(conc)}
    return {'status': 'OK', 'conc_mcg_ml': float(conc), 'rate_ml_h': tenths / 10}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('standard adult infusion',
   {'dose': '5', 'weight_kg': 71, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.3}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 5, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.3}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 101, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 101},
   {'status': 'OK', 'conc_mcg_ml': 594.059405940594, 'rate_ml_h': 151.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 67, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 8, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 72, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.5}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.5}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 102, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 102},
   {'status': 'OK', 'conc_mcg_ml': 588.2352941176471, 'rate_ml_h': 153.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 68, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 73, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.7}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 13, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.7}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 103, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 103},
   {'status': 'OK', 'conc_mcg_ml': 582.5242718446602, 'rate_ml_h': 154.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 69, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 10, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 74, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.9}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 17, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.9}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 104, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 104},
   {'status': 'OK', 'conc_mcg_ml': 576.9230769230769, 'rate_ml_h': 156.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 70, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 11, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 75, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 14.1}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 21, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 1.1}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 105, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 105},
   {'status': 'OK', 'conc_mcg_ml': 571.4285714285714, 'rate_ml_h': 157.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 71, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 12, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.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):
    conc = Fraction(x['drug_mg']) * 1000 / Fraction(str(x['bag_ml']))
    rate = Fraction(str(x['dose'])) * Fraction(str(x['weight_kg'])) / 60 / conc
    tenths = math.floor(rate * 10 + Fraction(1, 2))
    if tenths > 9999:
        return {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': float(conc)}
    if tenths == 0:
        return {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': float(conc)}
    return {'status': 'OK', 'conc_mcg_ml': float(conc), 'rate_ml_h': tenths / 10}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('standard adult infusion',
   {'dose': '5', 'weight_kg': 71, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.3}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 5, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.3}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 101, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 101},
   {'status': 'OK', 'conc_mcg_ml': 594.059405940594, 'rate_ml_h': 151.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 67, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 8, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 72, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.5}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.5}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 102, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 102},
   {'status': 'OK', 'conc_mcg_ml': 588.2352941176471, 'rate_ml_h': 153.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 68, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 73, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.7}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 13, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.7}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 103, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 103},
   {'status': 'OK', 'conc_mcg_ml': 582.5242718446602, 'rate_ml_h': 154.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 69, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 10, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 74, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.9}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 17, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.9}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 104, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 104},
   {'status': 'OK', 'conc_mcg_ml': 576.9230769230769, 'rate_ml_h': 156.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 70, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 11, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 75, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 14.1}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 21, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 1.1}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 105, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 105},
   {'status': 'OK', 'conc_mcg_ml': 571.4285714285714, 'rate_ml_h': 157.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 71, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 12, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.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:
Programmed rates are one sixtieth of the intended rate.

Input {dose (mcg/kg/min), weight_kg, drug_mg, bag_ml}. Concentration = drug_mg*1000/bag_ml mcg/mL. Rate mL/h = dose*weight*60/concentration, rounded half-up to 0.1 mL/h. Pump accepts 0.1-999.9 mL/h: a rounded rate above 999.9 returns status EXCEEDS_PUMP, a rounded rate of 0.0 returns BELOW_RESOLUTION; otherwise status OK with rate_ml_h. conc_mcg_ml is always reported.

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):
    conc = Fraction(x['drug_mg']) * 1000 / Fraction(str(x['bag_ml']))
    rate = Fraction(str(x['dose'])) * Fraction(str(x['weight_kg'])) * 60 / conc
    tenths = math.floor(rate * 10)
    if tenths > 9999:
        return {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': float(conc)}
    if tenths == 0:
        return {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': float(conc)}
    return {'status': 'OK', 'conc_mcg_ml': float(conc), 'rate_ml_h': tenths / 10}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('standard adult infusion',
   {'dose': '5', 'weight_kg': 71, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.3}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 5, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.3}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 101, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 101},
   {'status': 'OK', 'conc_mcg_ml': 594.059405940594, 'rate_ml_h': 151.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 67, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 8, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 72, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.5}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.5}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 102, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 102},
   {'status': 'OK', 'conc_mcg_ml': 588.2352941176471, 'rate_ml_h': 153.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 68, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 73, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.7}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 13, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.7}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 103, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 103},
   {'status': 'OK', 'conc_mcg_ml': 582.5242718446602, 'rate_ml_h': 154.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 69, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 10, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 74, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.9}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 17, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.9}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 104, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 104},
   {'status': 'OK', 'conc_mcg_ml': 576.9230769230769, 'rate_ml_h': 156.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 70, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 11, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 75, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 14.1}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 21, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 1.1}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 105, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 105},
   {'status': 'OK', 'conc_mcg_ml': 571.4285714285714, 'rate_ml_h': 157.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 71, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 12, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.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):
    conc = Fraction(x['drug_mg']) * 1000 / Fraction(str(x['bag_ml']))
    rate = Fraction(str(x['dose'])) * Fraction(str(x['weight_kg'])) * 60 / conc
    tenths = round(rate * 10)
    if tenths > 9999:
        return {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': float(conc)}
    if tenths == 0:
        return {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': float(conc)}
    return {'status': 'OK', 'conc_mcg_ml': float(conc), 'rate_ml_h': tenths / 10}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('standard adult infusion',
   {'dose': '5', 'weight_kg': 71, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.3}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 5, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.3}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 101, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 101},
   {'status': 'OK', 'conc_mcg_ml': 594.059405940594, 'rate_ml_h': 151.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 67, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 8, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 72, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.5}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.5}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 102, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 102},
   {'status': 'OK', 'conc_mcg_ml': 588.2352941176471, 'rate_ml_h': 153.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 68, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 73, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.7}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 13, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.7}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 103, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 103},
   {'status': 'OK', 'conc_mcg_ml': 582.5242718446602, 'rate_ml_h': 154.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 69, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 10, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 74, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.9}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 17, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.9}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 104, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 104},
   {'status': 'OK', 'conc_mcg_ml': 576.9230769230769, 'rate_ml_h': 156.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 70, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 11, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 75, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 14.1}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 21, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 1.1}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 105, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 105},
   {'status': 'OK', 'conc_mcg_ml': 571.4285714285714, 'rate_ml_h': 157.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 71, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 12, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.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:
Rates such as 2.25 mL/h are programmed as 2.2 mL/h.

Input {dose (mcg/kg/min), weight_kg, drug_mg, bag_ml}. Concentration = drug_mg*1000/bag_ml mcg/mL. Rate mL/h = dose*weight*60/concentration, rounded half-up to 0.1 mL/h. Pump accepts 0.1-999.9 mL/h: a rounded rate above 999.9 returns status EXCEEDS_PUMP, a rounded rate of 0.0 returns BELOW_RESOLUTION; otherwise status OK with rate_ml_h. conc_mcg_ml is always reported.

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):
    conc = Fraction(x['drug_mg']) * 1000 / Fraction(str(x['bag_ml']))
    rate = Fraction(str(x['dose'])) * Fraction(str(x['weight_kg'])) * 60 / conc
    tenths = math.floor(rate * 10 + Fraction(1, 2))
    if tenths >= 9999:
        return {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': float(conc)}
    if tenths == 0:
        return {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': float(conc)}
    return {'status': 'OK', 'conc_mcg_ml': float(conc), 'rate_ml_h': tenths / 10}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('standard adult infusion',
   {'dose': '5', 'weight_kg': 71, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.3}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 5, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.3}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 101, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 101},
   {'status': 'OK', 'conc_mcg_ml': 594.059405940594, 'rate_ml_h': 151.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 67, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 8, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 72, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.5}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.5}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 102, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 102},
   {'status': 'OK', 'conc_mcg_ml': 588.2352941176471, 'rate_ml_h': 153.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 68, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 73, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.7}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 13, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.7}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 103, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 103},
   {'status': 'OK', 'conc_mcg_ml': 582.5242718446602, 'rate_ml_h': 154.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 69, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 10, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 74, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.9}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 17, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.9}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 104, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 104},
   {'status': 'OK', 'conc_mcg_ml': 576.9230769230769, 'rate_ml_h': 156.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 70, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 11, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 75, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 14.1}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 21, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 1.1}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 105, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 105},
   {'status': 'OK', 'conc_mcg_ml': 571.4285714285714, 'rate_ml_h': 157.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 71, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 12, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.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):
    conc = Fraction(x['drug_mg']) * 1000 / Fraction(str(x['bag_ml']))
    rate = Fraction(str(x['dose'])) * Fraction(str(x['weight_kg'])) * 60 / conc
    tenths = math.floor(rate * 10 + Fraction(1, 2))
    if tenths > 999:
        return {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': float(conc)}
    if tenths == 0:
        return {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': float(conc)}
    return {'status': 'OK', 'conc_mcg_ml': float(conc), 'rate_ml_h': tenths / 10}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('standard adult infusion',
   {'dose': '5', 'weight_kg': 71, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.3}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 5, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.3}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 101, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 101},
   {'status': 'OK', 'conc_mcg_ml': 594.059405940594, 'rate_ml_h': 151.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 67, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 8, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 72, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.5}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.5}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 102, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 102},
   {'status': 'OK', 'conc_mcg_ml': 588.2352941176471, 'rate_ml_h': 153.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 68, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 73, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.7}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 13, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.7}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 103, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 103},
   {'status': 'OK', 'conc_mcg_ml': 582.5242718446602, 'rate_ml_h': 154.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 69, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 10, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 74, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.9}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 17, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.9}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 104, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 104},
   {'status': 'OK', 'conc_mcg_ml': 576.9230769230769, 'rate_ml_h': 156.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 70, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 11, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 75, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 14.1}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 21, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 1.1}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 105, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 105},
   {'status': 'OK', 'conc_mcg_ml': 571.4285714285714, 'rate_ml_h': 157.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 71, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 12, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.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 rate of exactly 999.9 mL/h is reported as exceeding the pump.

Input {dose (mcg/kg/min), weight_kg, drug_mg, bag_ml}. Concentration = drug_mg*1000/bag_ml mcg/mL. Rate mL/h = dose*weight*60/concentration, rounded half-up to 0.1 mL/h. Pump accepts 0.1-999.9 mL/h: a rounded rate above 999.9 returns status EXCEEDS_PUMP, a rounded rate of 0.0 returns BELOW_RESOLUTION; otherwise status OK with rate_ml_h. conc_mcg_ml is always reported.

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):
    conc = Fraction(x['drug_mg']) * 1000 / Fraction(str(x['bag_ml']))
    rate = Fraction(str(x['dose'])) * Fraction(str(x['weight_kg'])) * 60 / conc
    tenths = math.floor(rate * 10 + Fraction(1, 2))
    if tenths > 9999:
        return {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': float(conc)}
    if rate == 0:
        return {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': float(conc)}
    return {'status': 'OK', 'conc_mcg_ml': float(conc), 'rate_ml_h': tenths / 10}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('standard adult infusion',
   {'dose': '5', 'weight_kg': 71, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.3}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 5, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.3}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 101, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 101},
   {'status': 'OK', 'conc_mcg_ml': 594.059405940594, 'rate_ml_h': 151.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 67, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 8, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 72, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.5}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.5}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 102, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 102},
   {'status': 'OK', 'conc_mcg_ml': 588.2352941176471, 'rate_ml_h': 153.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 68, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 73, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.7}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 13, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.7}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 103, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 103},
   {'status': 'OK', 'conc_mcg_ml': 582.5242718446602, 'rate_ml_h': 154.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 69, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 10, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 74, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.9}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 17, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.9}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 104, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 104},
   {'status': 'OK', 'conc_mcg_ml': 576.9230769230769, 'rate_ml_h': 156.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 70, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 11, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 75, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 14.1}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 21, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 1.1}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 105, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 105},
   {'status': 'OK', 'conc_mcg_ml': 571.4285714285714, 'rate_ml_h': 157.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 71, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 12, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.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):
    conc = Fraction(x['drug_mg']) * 1000 / Fraction(str(x['bag_ml']))
    rate = Fraction(str(x['dose'])) * Fraction(str(x['weight_kg'])) * 60 / conc
    tenths = math.floor(rate * 10 + Fraction(1, 2))
    if tenths > 9999:
        return {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': float(conc)}
    if rate < Fraction(1, 10):
        return {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': float(conc)}
    return {'status': 'OK', 'conc_mcg_ml': float(conc), 'rate_ml_h': tenths / 10}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('standard adult infusion',
   {'dose': '5', 'weight_kg': 71, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.3}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 5, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.3}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 101, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 101},
   {'status': 'OK', 'conc_mcg_ml': 594.059405940594, 'rate_ml_h': 151.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 67, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 8, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 72, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.5}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.5}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 102, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 102},
   {'status': 'OK', 'conc_mcg_ml': 588.2352941176471, 'rate_ml_h': 153.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 68, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 9, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 73, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.7}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 13, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.7}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 103, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 103},
   {'status': 'OK', 'conc_mcg_ml': 582.5242718446602, 'rate_ml_h': 154.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 69, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 10, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 74, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 13.9}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 17, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.9}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 104, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 104},
   {'status': 'OK', 'conc_mcg_ml': 576.9230769230769, 'rate_ml_h': 156.0}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 70, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 11, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.0})],
 [('standard adult infusion',
   {'dose': '5', 'weight_kg': 75, 'drug_mg': 400, 'bag_ml': 250},
   {'status': 'OK', 'conc_mcg_ml': 1600.0, 'rate_ml_h': 14.1}),
  ('half-tenth rate rounds up',
   {'dose': '0.5', 'weight_kg': 21, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 1.1}),
  ('rate exactly at pump maximum',
   {'dose': '99.99', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 999.9}),
  ('rate above pump maximum',
   {'dose': '100', 'weight_kg': 105, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'EXCEEDS_PUMP', 'conc_mcg_ml': 600.0}),
  ('high but valid rate',
   {'dose': '15', 'weight_kg': 100, 'drug_mg': 60, 'bag_ml': 105},
   {'status': 'OK', 'conc_mcg_ml': 571.4285714285714, 'rate_ml_h': 157.5}),
  ('tiny rate that rounds to 0.1',
   {'dose': '0.01', 'weight_kg': 71, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'OK', 'conc_mcg_ml': 600.0, 'rate_ml_h': 0.1}),
  ('rate that rounds to zero',
   {'dose': '0.005', 'weight_kg': 12, 'drug_mg': 60, 'bag_ml': 100},
   {'status': 'BELOW_RESOLUTION', 'conc_mcg_ml': 600.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 rate of 0.04 mL/h is returned as OK with a 0.0 mL/h program.

Input {dose (mcg/kg/min), weight_kg, drug_mg, bag_ml}. Concentration = drug_mg*1000/bag_ml mcg/mL. Rate mL/h = dose*weight*60/concentration, rounded half-up to 0.1 mL/h. Pump accepts 0.1-999.9 mL/h: a rounded rate above 999.9 returns status EXCEEDS_PUMP, a rounded rate of 0.0 returns BELOW_RESOLUTION; otherwise status OK with rate_ml_h. conc_mcg_ml is always reported.

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):
    scr = Fraction(str(x['scr']))
    if x['age'] > 65:
        scr = max(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.floor(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2 // 5 * 5, tau * 2
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65 or scr < Fraction(4, 5):
        scr = max(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.floor(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2 // 5 * 5, tau * 2
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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 65-year-old with low creatinine gets an inflated clearance estimate.

Input {age, weight_kg, scr, sex, dose_mg, interval_h}. Toy rule: if age >= 65, serum creatinine is raised to at least 0.8 mg/dL. CrCl = (140-age)*weight/(72*scr), times 0.85 for sex "F", then truncated to an integer. Bands: CrCl >= 60 unchanged; 30-59 same dose, interval doubled; 15-29 dose halved and rounded down to a 5 mg multiple, interval doubled; < 15 action AVOID. Return {crcl, action, dose_mg, interval_h} (AVOID omits dose and interval).

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):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65:
        scr = min(scr, Fraction(4, 5))
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.floor(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2 // 5 * 5, tau * 2
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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):
    scr = Fraction(str(x['scr']))
    if x['age'] >= 65:
        scr = Fraction(4, 5)
    crcl = Fraction(140 - x['age']) * Fraction(str(x['weight_kg'])) / (72 * scr)
    if x['sex'] == 'F':
        crcl = crcl * Fraction(17, 20)
    c = math.floor(crcl)
    dose, tau = x['dose_mg'], x['interval_h']
    if c >= 60:
        pass
    elif c >= 30:
        tau = tau * 2
    elif c >= 15:
        dose, tau = dose // 2 // 5 * 5, tau * 2
    else:
        return {'crcl': c, 'action': 'AVOID'}
    return {'crcl': c, 'action': 'GIVE', 'dose_mg': dose, 'interval_h': tau}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('young adult normal function',
   {'age': 31, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 79, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 61, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 141, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 71, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 260, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 260, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 6},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 12}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 175, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 85, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 32, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 105, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 80, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 62, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 143, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 72, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 40, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 270, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 270, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 195, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 95, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 33, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 104, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 82, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 63, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 145, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 73, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 39, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 280, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 280, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 18},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 36}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 395, 'interval_h': 24},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 195, 'interval_h': 48}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 34, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 103, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 83, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 64, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 148, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 74, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 290, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 290, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 24},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 48}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 155, 'interval_h': 8},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 75, 'interval_h': 16}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})],
 [('young adult normal function',
   {'age': 35, 'weight_kg': 70, 'scr': '1.0', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 102, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('65-year-old low creatinine floored',
   {'age': 65, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 84, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('young adult low creatinine not floored',
   {'age': 40, 'weight_kg': 65, 'scr': '0.6', 'sex': 'M', 'dose_mg': 500, 'interval_h': 8},
   {'crcl': 150, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 8}),
  ('elderly high creatinine kept',
   {'age': 75, 'weight_kg': 70, 'scr': '1.4', 'sex': 'F', 'dose_mg': 500, 'interval_h': 12},
   {'crcl': 38, 'action': 'GIVE', 'dose_mg': 500, 'interval_h': 24}),
  ('clearance 59.7 truncates into moderate band',
   {'age': 80, 'weight_kg': '71.6', 'scr': '1.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 59, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 24}),
  ('clearance exactly 30',
   {'age': 80, 'weight_kg': 72, 'scr': '2.0', 'sex': 'M', 'dose_mg': 300, 'interval_h': 30},
   {'crcl': 30, 'action': 'GIVE', 'dose_mg': 300, 'interval_h': 60}),
  ('severe band halves dose',
   {'age': 80, 'weight_kg': 72, 'scr': '3.0', 'sex': 'M', 'dose_mg': 135, 'interval_h': 6},
   {'crcl': 20, 'action': 'GIVE', 'dose_mg': 65, 'interval_h': 12}),
  ('clearance under 15 avoided',
   {'age': 80, 'weight_kg': 72, 'scr': '6.0', 'sex': 'F', 'dose_mg': 300, 'interval_h': 12},
   {'crcl': 8, 'action': 'AVOID'})]]
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:
Elderly patients with impaired function are assigned a creatinine of 0.8 and look healthy.

Input {age, weight_kg, scr, sex, dose_mg, interval_h}. Toy rule: if age >= 65, serum creatinine is raised to at least 0.8 mg/dL. CrCl = (140-age)*weight/(72*scr), times 0.85 for sex "F", then truncated to an integer. Bands: CrCl >= 60 unchanged; 30-59 same dose, interval doubled; 15-29 dose halved and rounded down to a 5 mg multiple, interval doubled; < 15 action AVOID. Return {crcl, action, dose_mg, interval_h} (AVOID omits dose and interval).

split: open-access