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

N = 1
observations = []
def solve(x):
    ppv = sum(tc for q, tc in x['purchases']) - x['used'] * x['std_price']
    allowed = x['std_qty'] * x['good_units']
    usage = (x['used'] - allowed) * x['std_price']
    lab = lambda v: 'U' if v > 0 else ('F' if v < 0 else '-')
    return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'][-1:])
    allowed = x['std_qty'] * x['good_units']
    usage = (x['used'] - allowed) * x['std_price']
    lab = lambda v: 'U' if v > 0 else ('F' if v < 0 else '-')
    return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
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:
Purchase price variance changes with consumption even though it should be fixed when material is bought.

Input {std_price, std_qty (per good unit), good_units, scrap_units, purchases:[[qty,total_cost]], used}. The price variance is isolated at purchase: sum(total_cost - qty*std_price). Standard allowed quantity is std_qty*good_units (scrap earns no allowance). Usage variance = (used - allowed)*std_price. Labels: positive "U", negative "F", zero "-". Return {ppv, ppv_label, usage, usage_label, allowed}.

split: open-access


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

N = 1
observations = []
def solve(x):
    ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
    allowed = x['std_qty'] * (x['good_units'] + x['scrap_units'])
    usage = (x['used'] - allowed) * x['std_price']
    lab = lambda v: 'U' if v > 0 else ('F' if v < 0 else '-')
    return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
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

N = 1
observations = []
def solve(x):
    ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
    allowed = x['std_qty'] * x['good_units'] + x['scrap_units']
    usage = (x['used'] - allowed) * x['std_price']
    lab = lambda v: 'U' if v > 0 else ('F' if v < 0 else '-')
    return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
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:
Usage variance hides material wasted on scrapped units.

Input {std_price, std_qty (per good unit), good_units, scrap_units, purchases:[[qty,total_cost]], used}. The price variance is isolated at purchase: sum(total_cost - qty*std_price). Standard allowed quantity is std_qty*good_units (scrap earns no allowance). Usage variance = (used - allowed)*std_price. Labels: positive "U", negative "F", zero "-". Return {ppv, ppv_label, usage, usage_label, allowed}.

split: open-access


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

N = 1
observations = []
def solve(x):
    ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
    allowed = x['std_qty'] * x['good_units']
    usage = (x['used'] - allowed) * (sum(tc for q, tc in x['purchases']) // max(1, sum(q for q, tc in x['purchases'])) or x['std_price'])
    lab = lambda v: 'U' if v > 0 else ('F' if v < 0 else '-')
    return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
    allowed = x['std_qty'] * x['good_units']
    usage = (x['used'] - allowed) * (x['purchases'][-1][1] // x['purchases'][-1][0] if x['purchases'] else x['std_price'])
    lab = lambda v: 'U' if v > 0 else ('F' if v < 0 else '-')
    return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
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:
The usage variance fluctuates with purchase prices even when consumption is unchanged.

Input {std_price, std_qty (per good unit), good_units, scrap_units, purchases:[[qty,total_cost]], used}. The price variance is isolated at purchase: sum(total_cost - qty*std_price). Standard allowed quantity is std_qty*good_units (scrap earns no allowance). Usage variance = (used - allowed)*std_price. Labels: positive "U", negative "F", zero "-". Return {ppv, ppv_label, usage, usage_label, allowed}.

split: open-access


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

N = 1
observations = []
def solve(x):
    ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
    allowed = x['std_qty'] * x['good_units']
    usage = (x['used'] - allowed) * x['std_price']
    lab = lambda v: 'F' if v > 0 else ('U' if v < 0 else '-')
    return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
    allowed = x['std_qty'] * x['good_units']
    usage = (x['used'] - allowed) * x['std_price']
    lab = lambda v: 'U' if abs(v) > 100 else ('F' if v != 0 else '-')
    return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
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:
Overspending is reported as favorable and savings as unfavorable.

Input {std_price, std_qty (per good unit), good_units, scrap_units, purchases:[[qty,total_cost]], used}. The price variance is isolated at purchase: sum(total_cost - qty*std_price). Standard allowed quantity is std_qty*good_units (scrap earns no allowance). Usage variance = (used - allowed)*std_price. Labels: positive "U", negative "F", zero "-". Return {ppv, ppv_label, usage, usage_label, allowed}.

split: open-access


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

N = 1
observations = []
def solve(x):
    ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
    allowed = x['std_qty'] * x['good_units']
    usage = (x['used'] - allowed) * x['std_price']
    lab = lambda v: 'U' if v >= 0 else 'F'
    return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    ppv = sum(tc - q * x['std_price'] for q, tc in x['purchases'])
    allowed = x['std_qty'] * x['good_units']
    usage = (x['used'] - allowed) * x['std_price']
    lab = lambda v: 'U' if v > 0 else 'F'
    return {'ppv': ppv, 'ppv_label': lab(ppv), 'usage': usage, 'usage_label': lab(usage), 'allowed': allowed}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8401]], 'used': 33}, {'ppv': 401, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 21, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 40}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 42}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1301]], 'used': 26}, {'ppv': 201, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 4, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 6}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2110], [5, 700]], 'used': 11}, {'ppv': -190, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8402]], 'used': 33}, {'ppv': 402, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 22, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 42}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 44}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1302]], 'used': 26}, {'ppv': 202, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 5, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 7}, {'ppv': 0, 'ppv_label': '-', 'usage': 90, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2120], [5, 700]], 'used': 11}, {'ppv': -180, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8403]], 'used': 33}, {'ppv': 403, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 23, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 44}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 46}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1303]], 'used': 26}, {'ppv': 203, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 6, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 180, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2130], [5, 700]], 'used': 11}, {'ppv': -170, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8404]], 'used': 33}, {'ppv': 404, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 24, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 46}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 48}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1304]], 'used': 26}, {'ppv': 204, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 7, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 9}, {'ppv': 0, 'ppv_label': '-', 'usage': 270, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2140], [5, 700]], 'used': 11}, {'ppv': -160, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]], [['unfavorable price', {'std_price': 200, 'std_qty': 3, 'good_units': 10, 'scrap_units': 1, 'purchases': [[40, 8405]], 'used': 33}, {'ppv': 405, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 30}], ['favorable usage', {'std_price': 150, 'std_qty': 2, 'good_units': 25, 'scrap_units': 0, 'purchases': [[50, 7000]], 'used': 48}, {'ppv': -500, 'ppv_label': 'F', 'usage': -300, 'usage_label': 'F', 'allowed': 50}], ['two purchases', {'std_price': 100, 'std_qty': 4, 'good_units': 5, 'scrap_units': 2, 'purchases': [[10, 900], [10, 1305]], 'used': 26}, {'ppv': 205, 'ppv_label': 'U', 'usage': 600, 'usage_label': 'U', 'allowed': 20}], ['exact standard', {'std_price': 75, 'std_qty': 1, 'good_units': 8, 'scrap_units': 0, 'purchases': [[8, 600]], 'used': 8}, {'ppv': 0, 'ppv_label': '-', 'usage': 0, 'usage_label': '-', 'allowed': 8}], ['scrap heavy', {'std_price': 50, 'std_qty': 5, 'good_units': 6, 'scrap_units': 8, 'purchases': [[60, 3300], [5, 200]], 'used': 45}, {'ppv': 250, 'ppv_label': 'U', 'usage': 750, 'usage_label': 'U', 'allowed': 30}], ['no purchases', {'std_price': 90, 'std_qty': 2, 'good_units': 3, 'scrap_units': 1, 'purchases': [], 'used': 10}, {'ppv': 0, 'ppv_label': '-', 'usage': 360, 'usage_label': 'U', 'allowed': 6}], ['mixed signs', {'std_price': 120, 'std_qty': 3, 'good_units': 4, 'scrap_units': 1, 'purchases': [[20, 2150], [5, 700]], 'used': 11}, {'ppv': -150, 'ppv_label': 'F', 'usage': -120, 'usage_label': 'F', 'allowed': 12}]]]
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 purchase exactly at standard is reported as unfavorable.

Input {std_price, std_qty (per good unit), good_units, scrap_units, purchases:[[qty,total_cost]], used}. The price variance is isolated at purchase: sum(total_cost - qty*std_price). Standard allowed quantity is std_qty*good_units (scrap earns no allowance). Usage variance = (used - allowed)*std_price. Labels: positive "U", negative "F", zero "-". Return {ppv, ppv_label, usage, usage_label, allowed}.

split: open-access