Score vendors on delivery, quality and price.
Done by an agent. Checked twice.
A ranked scorecard for the quarter with a grade per vendor and the reason behind each low score.
Real files in
- contract_prices.csv
The contract price for each vendor and item. 18 lines, 496 bytes. - receipts.csv
One quarter of goods receipts from eight vendors: 71 rows, with a duplicate, two open lines, a rejected count larger than the delivery and vendor names typed several ways. 72 lines, 6 KB. - scoring_rules.md
The scoring rules: weights, grade bands, the price penalty and the minimum lines for a grade. 22 lines, 518 bytes. - vendors.csv
The eight vendors and their names on file. 9 lines, 223 bytes.
Sample data written by Atris. Not a real company.
Three steps
- 1.Read and clean the receipts
- 2.Score each vendor
- 3.Write the scorecard and the review
Claude Sonnet 5.5, 56 seconds. No web. It never saw the check.
Checked twice
- Passed: 8 of 8 vendors appear once in scorecard.csv under the name on file
- Passed: 4 of 4 receipts left out carry the right reason and vendor while 8 of 8 line counts match
- Passed: 24 of 24 delivery, quality and price scores equal the scores rebuilt from the receipts
- Passed: 8 of 8 total scores equal the weighted sum of the three scores
- Passed: 8 of 8 grades and 8 of 8 ranks equal the recomputed ones
- Passed: review.md lists 7 of 7 ranked vendors by name with the right total score
- Passed: 58 of 58 numbers in review.md are right: vendor and receipt numbers match the files and the rest equal that vendor's scorecard row, a count behind it or a rule value
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 8 ways on purpose. The check caught 8.
1. Calder Fasteners (V-101) - total 99.9 - grade A 2. Greyfield Electrics (V-104) - total 95.4 - grade A 3. Ashdown Metals (V-105) - total 94.6 - grade A 4. Tessaly Packaging (V-103) - total 88.1 - grade B 5. Wrenfield Rubber (V-108) - total 84.7 - grade B 6. Lindqvist Bearings (V-106) - total 71.0 - grade C 7. Northmoor Plastics (V-102) - total 67.6 - grade D - Not ranked: Pemberley Coatings (V-107) - not_enough_data (2 lines scored) ## Vendors graded C or D - Lindqvist Bearings (grade C, total 71.0): lowest is delivery at 55.6 (5 of 9 scored lines on time). All three: delivery 55.6, quality 94.3, price 63.2. - Northmoor Plastics (grade D, total 67.6): lowest is delivery at 22.2 (2 of 9 scored lines on time). All three: delivery 22.2, quality 98.9, price 96.5.
How this was run
An AI agent on Claude Sonnet 5.5 was given a folder with the files below and a three-step flow, and nothing else. It had no web access and never saw the check. The check was written before the run and made stricter after it. It works the answer out again from the input files. Then Claude Opus 5.5 reviewed the result against the inputs. The input files are sample data written by Atris, with the problems a real week has planted in them.
Run 1 of 1 on 1 December 2026. The agent took 56 seconds.
What the second review verified
- Recomputed every vendor by hand from receipts.csv after counting duplicate RC-3025 once (70 unique receipts = 66 scored + 4 left out). All 8 rows in scorecard.csv match. For example, V-102 is delivery 2/9=22.2, quality 1-54/5020=98.9, price 100-10*(70/20102*100)=96.5, total 67.6 D.
- V-106 price: paid is 663.60 over a contract of 18027.00, so over_pct is 3.68% and the price score is 63.2. The total is 22.24+33.005+15.8=71.045, which rounds to 71.0, grade C, rank 6. Its lowest score is delivery at 55.6 (5 of 9 on time), which matches review.md.
- Left-out receipts and their reasons are correct: RC-3030 and RC-3058 have no received_date (not_received), RC-3040 has 90 rejected against 50 received (bad_quantity), and RC-3038 is 'Edge trim 5 m', which has no contract price for V-108 (no_contract_price).
- V-104 paid below contract overall (net -285.50), so its price score is capped at 100. V-107 has only 2 lines, fewer than min_lines 3, so it gets not_enough_data with a blank rank. The name variants are listed correctly: 'Calder Fastners' and 'CALDER FASTENERS LTD' for V-101, 'Lindquist Bearings' for V-106.
What this run does not show
- The check proves the weights and grade bands were applied as written and cannot say whether they are fair.
- Counts in the review are compared with a set of that vendor's true figures, so one swapped for another would pass.
- The sample quarter has 71 receipt rows from 8 vendors, with one clear case of each data problem.
Would the check catch a wrong answer?
A check that cannot fail proves nothing. After the run we took a copy of the output, broke it one small way at a time and ran the check again. It caught 8 of 8. The check was made stricter after the first try at this, and the same untouched output was graded again.
Open every file
flow.md · the three steps the agent followed
# Score vendors on delivery, quality and price function: operations for: the person who manages suppliers goal: Every vendor has a score and a grade for the quarter that can be traced back to the receipts. ## 1. Read and clean the receipts Read input/receipts.csv, input/vendors.csv, input/contract_prices.csv and input/scoring_rules.md. Take the weights, the grade bands, min_lines and price_penalty from the rules file. Group receipts by vendor_id. The vendor name typed on a receipt may be misspelled, so use the name in vendors.csv. If the same receipt_id appears twice with the same data, count it once. Leave a receipt out of every score when one of these applies. Check in this order and use the first: - `not_received` when received_date is blank. - `bad_quantity` when qty_received is blank or 0, or qty_rejected is more than qty_received. - `no_contract_price` when contract_prices.csv has no price for that vendor_id and item. ## 2. Score each vendor Use only the receipts that were not left out. - delivery_score is 100 times the lines received on or before promised_date, divided by all lines. - quality_score is 100 times (1 minus units rejected divided by units received). - For price, paid is the sum of qty_received times unit_price_paid. contract is the sum of qty_received times contract_price. over_pct is 100 times (paid minus contract) divided by contract. price_score is 100 minus price_penalty times over_pct, held between 0 and 100. Round each of the three scores to one decimal. total_score is the three rounded scores times their weights, divided by 100, rounded to one decimal. Give the grade from the grade bands. A vendor with fewer lines than min_lines gets the grade `not_enough_data` and a blank rank. Rank the other vendors by total_score, with 1 for the highest. ## 3. Write the scorecard and the review Write output/scorecard.csv with columns vendor_id,vendor_name,lines_scored,delivery_score,quality_score,price_score,total_score,grade,rank. One row per vendor in vendors.csv. Write output/left_out.csv with columns receipt_id,vendor_id,reason. One row per receipt left out, with the reason code from step 1. Write output/review.md for the supplier manager: one line per ranked vendor in rank order with rank, name, total score and grade. Then for each vendor graded C or D say which of its three scores is lowest and give the numbers behind it. Then list the receipts left out and any vendor name typed more than one way. Use only numbers that come from the files. ## Done looks like - Every vendor in vendors.csv appears once in scorecard.csv. - Every receipt is either scored or listed in left_out.csv with a reason. - Each total score can be rebuilt from the three scores and the weights.
input/contract_prices.csv · 18 lines, 496 bytes
vendor_id,item,contract_price V-101,M8 hex bolt box,14.20 V-101,M10 washer box,6.85 V-101,Rivet 4 mm box,9.40 V-102,Housing shell A,3.72 V-102,Housing shell B,4.15 V-103,Printed carton,0.84 V-103,Foam insert,0.39 V-103,Pallet wrap roll,7.60 V-104,Control board,41.50 V-104,Wiring loom,18.25 V-105,Steel bracket,2.95 V-105,Aluminium rail 1 m,11.80 V-106,Bearing 6204,5.60 V-106,Bearing 6305,8.90 V-107,Powder coat grey 20 kg,96.00 V-108,Door seal 2 m,3.10 V-108,Grommet bag,1.95
input/receipts.csv · 72 lines, 6 KB
receipt_id,vendor_id,vendor_name,po_number,item,promised_date,received_date,qty_received,qty_rejected,unit_price_paid RC-3001,V-101,Calder Fasteners,PO-7105,Rivet 4 mm box,2026-07-09,2026-07-09,500,0,9.40 RC-3002,V-104,Greyfield Electrics,PO-7139,Control board,2026-07-14,2026-07-10,60,0,43.37 RC-3003,V-106,Lindqvist Bearings,PO-7159,Bearing 6305,2026-07-14,2026-07-10,800,42,9.35 RC-3004,V-101,Calder Fasteners,PO-7111,M10 washer box,2026-07-13,2026-07-12,500,3,6.85 RC-3005,V-104,Greyfield Electrics,PO-7134,Wiring loom,2026-07-15,2026-07-12,1000,4,17.52 RC-3006,V-102,Northmoor Plastics,PO-7117,Housing shell A,2026-07-15,2026-07-13,250,4,3.72 RC-3007,V-108,Wrenfield Rubber,PO-7162,Door seal 2 m,2026-07-09,2026-07-14,120,1,3.10 RC-3008,V-108,Wrenfield Rubber,PO-7168,Grommet bag,2026-07-14,2026-07-14,100,1,1.95 RC-3009,V-104,Greyfield Electrics,PO-7136,Wiring loom,2026-07-19,2026-07-15,200,2,19.07 RC-3010,V-105,Ashdown Metals,PO-7142,Aluminium rail 1 m,2026-07-16,2026-07-15,100,1,11.80 RC-3011,V-108,Wrenfield Rubber,PO-7164,Grommet bag,2026-07-17,2026-07-15,1000,8,1.95 RC-3012,V-101,Calder Fastners,PO-7104,Rivet 4 mm box,2026-07-22,2026-07-18,120,0,9.40 RC-3013,V-101,Calder Fasteners,PO-7107,M10 washer box,2026-07-22,2026-07-18,120,0,6.85 RC-3014,V-102,Northmoor Plastics,PO-7113,Housing shell A,2026-07-14,2026-07-18,200,2,3.72 RC-3015,V-105,Ashdown Metals,PO-7150,Aluminium rail 1 m,2026-07-22,2026-07-19,400,6,11.80 RC-3016,V-107,Pemberley Coatings,PO-7161,Powder coat grey 20 kg,2026-07-23,2026-07-19,20,0,96.00 RC-3017,V-106,Lindqvist Bearings,PO-7156,Bearing 6204,2026-07-14,2026-07-21,120,8,5.88 RC-3018,V-108,Wrenfield Rubber,PO-7170,Door seal 2 m,2026-07-23,2026-07-21,400,4,3.10 RC-3019,V-101,Calder Fasteners,PO-7108,Rivet 4 mm box,2026-07-24,2026-07-23,500,1,9.40 RC-3020,V-103,Tessaly Packaging,PO-7124,Printed carton,2026-07-18,2026-07-23,250,18,0.84 RC-3021,V-105,Ashdown Metals,PO-7148,Aluminium rail 1 m,2026-07-21,2026-07-24,250,4,11.80 RC-3022,V-106,Lindqvist Bearings,PO-7155,Bearing 6305,2026-07-23,2026-07-25,250,14,9.35 RC-3023,V-103,Tessaly Packaging,PO-7122,Foam insert,2026-07-30,2026-07-27,800,72,0.39 RC-3024,V-106,Lindquist Bearings,PO-7151,Bearing 6305,2026-07-28,2026-07-27,250,20,9.35 RC-3025,V-103,Tessaly Packaging,PO-7126,Pallet wrap roll,2026-07-31,2026-07-28,500,39,7.60 RC-3026,V-102,Northmoor Plastics,PO-7121,Housing shell B,2026-07-28,2026-07-29,1000,8,4.15 RC-3027,V-102,Northmoor Plastics,PO-7112,Housing shell B,2026-08-02,2026-07-30,1000,7,4.15 RC-3028,V-105,Ashdown Metals,PO-7147,Aluminium rail 1 m,2026-08-04,2026-08-02,100,2,12.04 RC-3025,V-103,Tessaly Packaging,PO-7126,Pallet wrap roll,2026-07-31,2026-07-28,500,39,7.60 RC-3029,V-103,Tessaly Packaging,PO-7127,Pallet wrap roll,2026-08-08,2026-08-04,250,19,7.60 RC-3030,V-105,Ashdown Metals,PO-7146,Steel bracket,2026-08-08,,,,2.95 RC-3031,V-101,Calder Fasteners,PO-7106,Rivet 4 mm box,2026-08-06,2026-08-05,250,0,9.40 RC-3032,V-108,Wrenfield Rubber,PO-7166,Grommet bag,2026-08-06,2026-08-05,200,1,1.95 RC-3033,V-101,CALDER FASTENERS LTD,PO-7103,M8 hex bolt box,2026-08-08,2026-08-07,250,1,14.20 RC-3034,V-105,Ashdown Metals,PO-7141,Aluminium rail 1 m,2026-08-10,2026-08-09,400,10,11.80 RC-3035,V-101,Calder Fasteners,PO-7109,M10 washer box,2026-08-14,2026-08-10,120,1,6.85 RC-3036,V-103,Tessaly Packaging,PO-7128,Pallet wrap roll,2026-08-11,2026-08-10,50,4,7.60 RC-3037,V-108,Wrenfield Rubber,PO-7163,Grommet bag,2026-08-08,2026-08-13,250,2,1.95 RC-3038,V-108,Wrenfield Rubber,PO-7165,Edge trim 5 m,2026-08-14,2026-08-14,120,0,3.10 RC-3039,V-102,Northmoor Plastics,PO-7115,Housing shell B,2026-08-10,2026-08-17,120,1,4.15 RC-3040,V-103,Tessaly Packaging,PO-7130,Foam insert,2026-08-23,2026-08-19,50,90,0.39 RC-3041,V-104,Greyfield Electrics,PO-7133,Control board,2026-08-18,2026-08-19,10,0,41.50 RC-3042,V-102,Northmoor Plastics,PO-7120,Housing shell A,2026-08-19,2026-08-20,1000,12,3.79 RC-3043,V-103,Tessaly Packaging,PO-7125,Foam insert,2026-08-15,2026-08-21,250,21,0.39 RC-3044,V-103,Tessaly Packaging,PO-7131,Foam insert,2026-08-23,2026-08-22,250,28,0.39 RC-3045,V-104,Greyfield Electrics,PO-7138,Control board,2026-08-23,2026-08-22,20,0,43.37 RC-3046,V-105,Ashdown Metals,PO-7145,Steel bracket,2026-08-25,2026-08-22,800,21,2.95 RC-3047,V-108,Wrenfield Rubber,PO-7169,Door seal 2 m,2026-08-21,2026-08-26,50,2,3.10 RC-3048,V-108,Wrenfield Rubber,PO-7167,Grommet bag,2026-08-31,2026-08-27,800,10,1.95 RC-3049,V-101,Calder Fasteners,PO-7101,M10 washer box,2026-08-28,2026-08-28,250,0,6.85 RC-3050,V-101,Calder Fasteners,PO-7102,Rivet 4 mm box,2026-09-01,2026-08-29,1000,5,9.40 RC-3051,V-104,Greyfield Electrics,PO-7137,Wiring loom,2026-08-30,2026-08-30,500,1,18.25 RC-3052,V-106,Lindqvist Bearings,PO-7153,Bearing 6305,2026-08-26,2026-08-30,50,2,8.90 RC-3053,V-106,Lindqvist Bearings,PO-7157,Bearing 6305,2026-09-05,2026-09-03,200,8,8.90 RC-3054,V-107,Pemberley Coatings,PO-7160,Powder coat grey 20 kg,2026-09-07,2026-09-07,24,0,96.00 RC-3055,V-102,Northmoor Plastics,PO-7116,Housing shell A,2026-09-02,2026-09-08,250,0,3.72 RC-3056,V-102,Northmoor Plastics,PO-7119,Housing shell B,2026-09-06,2026-09-09,200,3,4.15 RC-3057,V-105,Ashdown Metals,PO-7144,Steel bracket,2026-09-11,2026-09-09,400,8,2.95 RC-3058,V-102,Northmoor Plastics,PO-7118,Housing shell A,2026-09-14,,,,3.72 RC-3059,V-104,Greyfield Electrics,PO-7132,Control board,2026-09-13,2026-09-10,10,1,43.37 RC-3060,V-104,Greyfield Electrics,PO-7140,Control board,2026-09-13,2026-09-10,60,0,43.37 RC-3061,V-103,Tessaly Packaging,PO-7123,Foam insert,2026-09-15,2026-09-13,50,4,0.39 RC-3062,V-106,Lindqvist Bearings,PO-7158,Bearing 6305,2026-09-16,2026-09-14,100,4,9.35 RC-3063,V-104,Greyfield Electrics,PO-7135,Control board,2026-09-22,2026-09-19,10,0,41.50 RC-3064,V-105,Ashdown Metals,PO-7149,Aluminium rail 1 m,2026-09-23,2026-09-19,800,20,11.80 RC-3065,V-101,Calder Fasteners,PO-7110,M8 hex bolt box,2026-09-20,2026-09-20,400,0,14.20 RC-3066,V-105,Ashdown Metals,PO-7143,Aluminium rail 1 m,2026-09-24,2026-09-20,100,2,11.80 RC-3067,V-103,Tessaly Packaging,PO-7129,Pallet wrap roll,2026-09-22,2026-09-22,120,8,7.60 RC-3068,V-106,Lindqvist Bearings,PO-7152,Bearing 6305,2026-09-23,2026-09-23,50,2,8.90 RC-3069,V-102,Northmoor Plastics,PO-7114,Housing shell B,2026-09-23,2026-10-01,1000,17,4.15 RC-3070,V-106,Lindqvist Bearings,PO-7154,Bearing 6305,2026-09-24,2026-10-03,250,18,8.90
input/scoring_rules.md · 22 lines, 518 bytes
# Vendor scoring rules Agreed by purchasing and quality. Used every quarter. ## Weights - delivery_weight: 40 - quality_weight: 35 - price_weight: 25 ## Grades - A: total score 90 or more - B: total score 80 or more - C: total score 70 or more - D: total score below 70 ## Small vendors - min_lines: 3 A vendor with fewer scored lines than min_lines gets the grade not_enough_data and no rank. ## Price penalty - price_penalty: 10 Each 1 percent paid over contract takes price_penalty points off the price score.
input/vendors.csv · 9 lines, 223 bytes
vendor_id,vendor_name V-101,Calder Fasteners V-102,Northmoor Plastics V-103,Tessaly Packaging V-104,Greyfield Electrics V-105,Ashdown Metals V-106,Lindqvist Bearings V-107,Pemberley Coatings V-108,Wrenfield Rubber
output/left_out.csv · written by the agent, 5 lines
receipt_id,vendor_id,reason RC-3030,V-105,not_received RC-3038,V-108,no_contract_price RC-3040,V-103,bad_quantity RC-3058,V-102,not_received
output/review.md · written by the agent, 35 lines
# Vendor scorecard review Weights: delivery 40, quality 35, price 25. Grades: A 90+, B 80+, C 70+, D below 70. min_lines 3, price_penalty 10. ## Ranking 1. Calder Fasteners (V-101) - total 99.9 - grade A 2. Greyfield Electrics (V-104) - total 95.4 - grade A 3. Ashdown Metals (V-105) - total 94.6 - grade A 4. Tessaly Packaging (V-103) - total 88.1 - grade B 5. Wrenfield Rubber (V-108) - total 84.7 - grade B 6. Lindqvist Bearings (V-106) - total 71.0 - grade C 7. Northmoor Plastics (V-102) - total 67.6 - grade D - Not ranked: Pemberley Coatings (V-107) - not_enough_data (2 lines scored) ## Vendors graded C or D - Lindqvist Bearings (grade C, total 71.0): lowest is delivery at 55.6 (5 of 9 scored lines on time). All three: delivery 55.6, quality 94.3, price 63.2. - Northmoor Plastics (grade D, total 67.6): lowest is delivery at 22.2 (2 of 9 scored lines on time). All three: delivery 22.2, quality 98.9, price 96.5. ## Receipts left out - RC-3030 (V-105, Ashdown Metals): not_received - received_date is blank - RC-3038 (V-108, Wrenfield Rubber): no_contract_price - no contract price for this vendor and item - RC-3040 (V-103, Tessaly Packaging): bad_quantity - qty_received blank or 0, or qty_rejected more than qty_received - RC-3058 (V-102, Northmoor Plastics): not_received - received_date is blank ## Duplicate receipts - RC-3025 appeared twice with identical data; counted once. ## Vendor names typed more than one way - V-101 (Calder Fasteners in vendors.csv): "CALDER FASTENERS LTD"; "Calder Fasteners"; "Calder Fastners" - V-106 (Lindqvist Bearings in vendors.csv): "Lindquist Bearings"; "Lindqvist Bearings"
output/scorecard.csv · written by the agent, 9 lines
vendor_id,vendor_name,lines_scored,delivery_score,quality_score,price_score,total_score,grade,rank V-101,Calder Fasteners,11,100.0,99.7,100.0,99.9,A,1 V-102,Northmoor Plastics,9,22.2,98.9,96.5,67.6,D,7 V-103,Tessaly Packaging,9,77.8,91.5,100.0,88.1,B,4 V-104,Greyfield Electrics,9,88.9,99.6,100.0,95.4,A,2 V-105,Ashdown Metals,9,88.9,97.8,99.2,94.6,A,3 V-106,Lindqvist Bearings,9,55.6,94.3,63.2,71.0,C,6 V-107,Pemberley Coatings,2,100.0,100.0,100.0,100.0,not_enough_data, V-108,Wrenfield Rubber,8,62.5,99.0,100.0,84.7,B,5
check.py · the check, written before the run
"""Rebuilds every vendor score from the receipts with exact fractions and compares it with the scorecard."""
import csv, re, sys
from fractions import Fraction as F
from pathlib import Path
root = Path(sys.argv[1]); ok = True
def say(passed, text):
global ok; ok = ok and passed; print(("PASS " if passed else "FAIL ") + text)
def load(name): return list(csv.DictReader((root/"input"/name).open()))
def r1(x): return F(int(x * 10 + F(1, 2)), 10)
def num(s):
try: return F((s or "").strip())
except Exception: return None
rules = (root/"input/scoring_rules.md").read_text()
def rule(k): return int(re.search(k + r":\s*(\d+)", rules).group(1))
wd, wq, wp, minl, pen = rule("delivery_weight"), rule("quality_weight"), rule("price_weight"), rule("min_lines"), rule("price_penalty")
bands = sorted(((int(n), g) for g, n in re.findall(r"- ([A-Z]): total score (\d+) or more", rules)), reverse=True)
low = re.search(r"- ([A-Z]): total score below", rules).group(1)
vendors = {r["vendor_id"]: r["vendor_name"] for r in load("vendors.csv")}
price = {(r["vendor_id"], r["item"]): F(r["contract_price"]) for r in load("contract_prices.csv")}
out, used, seen, sold = {}, {v: [] for v in vendors}, set(), {}
for r in load("receipts.csv"):
if r["receipt_id"] in seen: continue
seen.add(r["receipt_id"]); sold[r["receipt_id"]] = r["vendor_id"]; q, rej = num(r["qty_received"]), num(r["qty_rejected"]) or 0
if not r["received_date"].strip(): out[r["receipt_id"]] = "not_received"
elif not q or rej > q: out[r["receipt_id"]] = "bad_quantity"
elif (r["vendor_id"], r["item"]) not in price: out[r["receipt_id"]] = "no_contract_price"
else: used[r["vendor_id"]].append((r["received_date"] <= r["promised_date"], q, rej, F(r["unit_price_paid"]), price[(r["vendor_id"], r["item"])]))
want = {}
for v, ls in used.items():
w = {"lines": len(ls)}
if ls:
d = r1(F(100 * sum(1 for l in ls if l[0]), len(ls)))
q = r1(100 * (1 - F(sum(l[2] for l in ls), sum(l[1] for l in ls))))
paid, con = sum(l[1] * l[3] for l in ls), sum(l[1] * l[4] for l in ls)
p = r1(min(F(100), max(F(0), 100 - pen * 100 * (paid - con) / con)))
t = r1((d * wd + q * wq + p * wp) / 100)
w.update(d=d, q=q, p=p, t=t, grade=next((g for n, g in bands if t >= n), low))
if len(ls) < minl: w["grade"] = "not_enough_data"
want[v] = w
ranked = sorted((v for v, w in want.items() if w["grade"] != "not_enough_data"), key=lambda v: -want[v]["t"])
for i, v in enumerate(ranked, 1): want[v]["rank"] = i
path = root/"output/scorecard.csv"
if not path.exists():
say(False, "output/scorecard.csv was not written"); sys.exit(1)
rows = list(csv.DictReader(path.open()))
got = {r.get("vendor_id", ""): r for r in rows}
names = sum(1 for v, n in vendors.items() if sum(1 for r in rows if r.get("vendor_id") == v) == 1 and (got[v].get("vendor_name") or "").strip() == n)
say(names == len(vendors) and len(rows) == len(vendors), f"{names} of {len(vendors)} vendors appear once in scorecard.csv under the name on file")
lpath = root/"output/left_out.csv"
lgot = {r.get("receipt_id", ""): (r.get("reason") or "").strip() for r in csv.DictReader(lpath.open())} if lpath.exists() else {}
lines = sum(1 for v, w in want.items() if num(got.get(v, {}).get("lines_scored")) == w["lines"])
lrows = list(csv.DictReader(lpath.open())) if lpath.exists() else []
whose = sum(1 for r in lrows if sold.get(r.get("receipt_id", "")) == (r.get("vendor_id") or "").strip())
say(lgot == out and lines == len(want) and whose == len(lrows) == len(out), f"{sum(1 for r in lrows if out.get(r.get('receipt_id', '')) == (r.get('reason') or '').strip() and sold.get(r.get('receipt_id', '')) == (r.get('vendor_id') or '').strip())} of {len(out)} receipts left out carry the right reason and vendor while {lines} of {len(want)} line counts match")
def close(s, x, tol): n = num(s); return n is not None and abs(n - x) <= tol
scored = [v for v, w in want.items() if "t" in w]
parts = sum(close(got.get(v, {}).get(c), want[v][k], F(51, 1000)) for v in scored for c, k in (("delivery_score", "d"), ("quality_score", "q"), ("price_score", "p")))
say(parts == 3 * len(scored), f"{parts} of {3 * len(scored)} delivery, quality and price scores equal the scores rebuilt from the receipts")
def summed(v):
r = got.get(v, {}); three = [num(r.get(c)) for c in ("delivery_score", "quality_score", "price_score")]
return None not in three and close(r.get("total_score"), (three[0] * wd + three[1] * wq + three[2] * wp) / 100, F(1, 20))
tot = sum(1 for v in scored if close(got.get(v, {}).get("total_score"), want[v]["t"], F(11, 100)) and summed(v))
say(tot == len(scored), f"{tot} of {len(scored)} total scores equal the weighted sum of the three scores")
gr = sum(1 for v, w in want.items() if (got.get(v, {}).get("grade") or "").strip() == w["grade"])
rk = sum(1 for v, w in want.items() if (num(got.get(v, {}).get("rank")) or 0) == w.get("rank", 0))
say(gr == len(want) and rk == len(want), f"{gr} of {len(want)} grades and {rk} of {len(want)} ranks equal the recomputed ones")
text = (root/"output/review.md").read_text() if (root/"output/review.md").exists() else ""
def shown(v):
for ln in text.splitlines():
if vendors[v].lower() in ln.lower() and any(abs(F(n) - want[v]["t"]) <= F(11, 100) for n in re.findall(r"\d+\.\d+", ln)): return True
return False
rev = sum(1 for v in ranked if shown(v))
say(rev == len(ranked), f"review.md lists {rev} of {len(ranked)} ranked vendors by name with the right total score")
# Every number in the review must restate the scorecard row of the vendor on that line, a count behind it or a rule.
base = {F(x) for x in (wd, wq, wp, minl, pen, 0, 100, len(vendors), len(ranked), len(out), len(seen))} | {F(n) for n, _ in bands}
def own(v):
ls = used[v]; on_time = sum(1 for l in ls if l[0]); row = got.get(v, {})
f = {F(len(ls)), F(on_time), F(len(ls) - on_time), F(sum(1 for r in sold.values() if r == v)), F(want[v].get("rank", 0))}
return f | {num(row.get(c)) for c in ("delivery_score", "quality_score", "price_score", "total_score")}
count = wrong = 0; odd = []
for ln in text.splitlines():
here = [v for v, n in vendors.items() if v in ln or n.lower() in ln.lower()]
allowed = set(base) if not here else set().union(*(own(v) for v in here)) | ({F(0)} if "RC-" in ln else set())
for i in re.findall(r"\bV-\d+\b", ln): # a vendor number must be real and sit beside its own name
count += 1
if i not in vendors or (any(n.lower() in ln.lower() for n in vendors.values()) and vendors[i].lower() not in ln.lower()): wrong += 1; odd.append(i)
for i in re.findall(r"\bRC-\d+\b", ln): # a receipt number must be real, with its own vendor and reason when given
count += 1; codes = [c for c in set(out.values()) if c in ln]
if i not in sold or (here and sold[i] not in here) or (codes and codes != [out.get(i)]): wrong += 1; odd.append(i)
for n in re.findall(r"\d+(?:\.\d+)?", re.sub(r"\b[A-Z]{1,3}-\d+\b", " ", ln)):
count += 1
if F(n) not in allowed: wrong += 1; odd.append(n + (" for " + here[0] if here else ""))
say(count > 0 and wrong == 0, f"{count - wrong} of {count} numbers in review.md are right: vendor and receipt numbers match the files and the rest equal that vendor's scorecard row, a count behind it or a rule value" + (": not " + ", ".join(odd[:3]) if odd else ""))
sys.exit(0 if ok else 1)
contract_prices.csv: sample data written by Atris. Fingerprint 959ed0474f43.
receipts.csv: sample data written by Atris. Fingerprint 647deeba6fda.
scoring_rules.md: sample data written by Atris. Fingerprint 81b8209e43c8.
vendors.csv: sample data written by Atris. Fingerprint 18f29b6d35d9.
left_out.csv: written by the agent. Fingerprint 76782f0caeca.
review.md: written by the agent. Fingerprint ac3e5f5e4268.
scorecard.csv: written by the agent. Fingerprint 113acda01b08.