Reconcile paid licenses against real use.
Done by an agent. Checked twice.
Seats paid, seats really in use, the seats to take back and the monthly saving for every software product.
Real files in
- license_assignments.csv
78 seat assignments across nine products, with leavers, idle seats, a repeated person and product names spelled three ways. 79 lines, 5 KB. - licenses_paid.csv
Nine software products the business pays for, one with a total that does not add up and one with no price. 10 lines, 637 bytes. - reconcile_rules.md
House rules for the count: the count date, the 60 day idle rule and which total to trust. 10 lines, 502 bytes. - staff.csv
Staff list of 34 people, five of them leavers and one with a leaving date still ahead. 35 lines, 3 KB.
Sample data written by Atris. Not a real company.
Three steps
- 1.Read what is paid and assigned
- 2.Judge every seat and product
- 3.Write the reconciliation
Claude Sonnet 5.5, 50 seconds. No web. It never saw the check.
Checked twice
- Passed: 10 of 10 products from the two files appear once in license_summary.csv
- Passed: 10 of 10 products have the paid, assigned and active seat counts recomputed from the input files
- Passed: 10 of 10 products have the right seats to cut, seats to buy and status
- Passed: 10 of 10 monthly savings equal seats to cut times price, left blank where the price is missing
- Passed: 13 of 13 seats that are not active are listed once in seats_to_reclaim.csv with the right reason and last used date and 0 active seats are listed by mistake
- Passed: summary.md states the total monthly saving, 527.00, and the yearly saving, 6,324.00
- Passed: 1 of 1 products whose listed monthly total does not add up are named in summary.md with both figures
- Passed: 6 of 6 products to cut back are on a line of summary.md with their seats to cut and saving and 3 of 3 other products that need a decision are named
- Passed: 47 of 47 other figures and dates in summary.md match the product they sit beside or the totals
Second review by Claude Opus 5.5: pass.
Then we broke a copy of the output 9 ways on purpose. The check caught 9.
**Total monthly saving: 527.00** | **Yearly saving: 6324.00** The total covers only products that have a price; Meetwell Video has none, so it is not in the total (see below). ## Products to cut back - Quillboard Office: cut 6 seats (paid 20, active 14), saves 75.00/month - Tallyhawk Books: cut 1 seats (paid 5, active 4), saves 45.00/month - Chatterfield: cut 2 seats (paid 12, active 10), saves 16.00/month - Driftline Design: cut 4 seats (paid 6, active 2), saves 220.00/month - Forgebench: cut 1 seats (paid 6, active 5), saves 21.00/month - Signpetal: cut 10 seats (paid 10, active 0), saves 150.00/month ## Products where more seats must be bought - Pinecrest CRM: buy 1 more (paid 10, active 11)
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 50 seconds.
What the second review verified
- Idle cut-off checked: 60 days before 2026-11-30 is 2026-10-01. Chatterfield wren.castillo (last used 2026-10-02, 59 days) and Vaultmoss adaeze.lindqvist (2026-10-01, exactly 60 days) are correctly active. Meetwell wren.castillo (2026-09-30, 61 days) is correctly idle.
- Matching and leaver rules checked: Quillboard Office has 17 people counted once (ignatius.thornbury appears twice and is counted once, using latest last_used 2026-11-26) and 14 active, so 6 seats to cut × 12.50 = 75.00. Pinecrest CRM has 13 assigned, with leavers anders.mbeki (end date 2026-11-14, even though status says active) and kieran.mahlangu. clementine.vasquez (end date 2026-12-12) is correctly kept, giving 11 active against 10 paid: buy 1.
- Every product total checked: Chatterfield's file total of 86.00 differs from 12 × 8.00 = 96.00 and is reported. All other totals with a price match. Signpetal (10 paid, nobody assigned) appears with saving 150.00. Deskhollow appears as no_purchase_record with 0.00. Meetwell Video's saving is left blank because it has no price.
- Totals checked: savings add up to 75 + 45 + 16 + 220 + 21 + 150 = 527.00 a month and 6324.00 a year, matching summary.md. seats_to_reclaim.csv has 13 rows, matching the 13 seats I found not active, each with the right reason.
What this run does not show
- Prices and seat counts are sample data, so plan tiers, yearly terms and discounts on a real bill are not handled.
- Every figure in the summary is tested against the product it sits beside, while the wording around the figures is read only by the second review.
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 9 of 9. 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
# Reconcile paid licenses against real use function: it for: the IT manager who approves software renewals goal: For every software product the business knows how many seats it pays for, how many are really in use, which seats to take back and what that saves each month. ## 1. Read what is paid and assigned Read input/licenses_paid.csv, input/license_assignments.csv, input/staff.csv and input/reconcile_rules.md. The rules give the count date and how long without use makes a seat idle. Product names are the same product when they match after ignoring capital letters and spaces. Emails match when they are equal after ignoring capital letters and spaces around them. When one person is assigned the same product more than once, count them once and use their most recent last_used. A person has left when end_date in the staff list is filled in and is on or before the count date, whatever the status column says. ## 2. Judge every seat and product Give each assigned seat (one person on one product) one state, using the first that applies: `not_on_staff` when the email matches nobody on the staff list, `leaver` when the person has left, `idle` under the rule in reconcile_rules.md, `active` otherwise. Then for each product work out: seats_paid, seats_assigned (people counted once), seats_active, seats_to_cut (seats_paid minus seats_active, never below 0), seats_to_buy (seats_active minus seats_paid, never below 0) and monthly_saving (seats_to_cut times price_per_seat_month). Give each product one status: `no_purchase_record` when it has assigned seats but no row in licenses_paid.csv (seats_paid, seats_to_cut and seats_to_buy are 0 and monthly_saving is 0.00), `buy_more` when seats_active is above seats_paid, `cut_back` when it is below, `right_size` when they are equal. When the price is blank, leave monthly_saving blank and do not work it out another way. Use seats_paid times price as the true monthly cost. Where monthly_total in the file differs from it, the product has a total that does not add up. ## 3. Write the reconciliation Write output/license_summary.csv with columns product,seats_paid,seats_assigned,seats_active,seats_to_cut,seats_to_buy,monthly_saving,status. One row per product, named as in licenses_paid.csv (or as first written in the assignments when there is no purchase row). Include paid products that nobody is assigned to. Money has two decimals. Write output/seats_to_reclaim.csv with columns product,user_email,reason,last_used. One row for every seat that is not active. reason is `not_on_staff`, `leaver` or `idle`. Write output/summary.md for the IT manager: the total monthly saving and the yearly saving, one line per product to cut back with seats and saving, the products where more seats must be bought, the products with no purchase record, the products with no price, and every product whose monthly_total does not add up, with both figures. ## Done looks like - Every product from either file appears once in license_summary.csv. - Every seat that is not active appears once in seats_to_reclaim.csv with its reason. - The total saving in summary.md equals the sum of monthly_saving in license_summary.csv.
input/license_assignments.csv · 79 lines, 5 KB
product,user_email,assigned_on,last_used Quillboard Office,marisol.kettering@larkmoor.example,2024-01-15,2026-11-28 Quillboard Office,thaddeus.nwosu@larkmoor.example,2024-01-15,2026-11-30 Quillboard Office,adaeze.lindqvist@larkmoor.example,2024-01-15,2026-11-25 Quillboard Office,Noor.Fairweather@Larkmoor.example,2024-01-15,2026-11-19 Quillboard Office,desmond.achterberg@larkmoor.example,2024-01-15,2026-11-27 QuillBoard Office,leopold.nakashima@larkmoor.example,2024-01-15,2026-11-12 Quillboard Office,beatrix.holloway@larkmoor.example,2024-01-15,2026-11-29 Quillboard Office,tabitha.rosenthal@larkmoor.example,2024-01-15,2026-10-30 Quillboard Office,IGNATIUS.THORNBURY@larkmoor.example,2023-02-01,2026-07-30 Quillboard Office,wren.castillo@larkmoor.example,2024-01-15,2026-11-21 Quillboard Office,ignatius.thornbury@larkmoor.example,2024-01-15,2026-11-26 Quillboard Office,lucinda.abara@larkmoor.example,2024-01-15,2026-11-06 Quillboard Office,odalys.fenwick@larkmoor.example,2024-01-15,2026-11-24 Quillboard Office,philippa.zielinski@larkmoor.example,2024-01-15,2026-10-14 Quillboard Office,gideon.farrow@larkmoor.example,2024-01-15,2026-11-30 Quillboard Office,kieran.mahlangu@larkmoor.example,2024-01-15,2026-11-20 Quillboard Office,tomasz.verhoeven@larkmoor.example,2024-01-15,2026-08-02 Quillboard Office,temp.frontdesk@larkmoor.example,2026-06-01,2026-08-28 Tallyhawk Books,adaeze.lindqvist@larkmoor.example,2023-04-01,2026-11-28 Tallyhawk Books,tomasz.verhoeven@larkmoor.example,2023-04-01,2026-11-28 Tallyhawk Books,priya.castellanos@larkmoor.example,2023-04-01,2026-11-27 Tallyhawk Books,philippa.zielinski@larkmoor.example,2023-04-01,2026-11-14 Tallyhawk Books,hollis.brandvold@larkmoor.example,2023-04-01,2026-10-15 Pinecrest CRM,beatrix.holloway@larkmoor.example,2024-12-20,2026-11-30 PineCrest CRM,mateo.grunewald@larkmoor.example,2024-12-20,2026-11-28 Pinecrest CRM,oluwaseun.whitlock@larkmoor.example,2024-12-20,2026-11-30 Pinecrest CRM,clementine.vasquez@larkmoor.example,2024-12-20,2026-11-27 PineCrest CRM,anders.mbeki@larkmoor.example,2024-12-20,2026-11-13 Pinecrest CRM,tabitha.rosenthal@larkmoor.example,2024-12-20,2026-11-29 Pinecrest CRM,emeka.lindgren@larkmoor.example,2024-12-20,2026-11-30 PineCrest CRM,saoirse.bellamy@larkmoor.example,2024-12-20,2026-10-09 Pinecrest CRM,rosalind.tavares@larkmoor.example,2024-12-20,2026-11-26 pinecrest crm,marisol.kettering@larkmoor.example,2024-12-20,2026-11-10 PineCrest CRM,thaddeus.nwosu@larkmoor.example,2024-12-20,2026-10-21 Pinecrest CRM,wren.castillo@larkmoor.example,2024-12-20,2026-11-04 Pinecrest CRM,kieran.mahlangu@larkmoor.example,2024-12-20,2026-11-20 Chatterfield,ingrid.solheim-park@larkmoor.example,2025-03-01,2026-11-30 Chatterfield,kwabena.rothwell@larkmoor.example,2025-03-01,2026-11-29 Chatterfield,yuki.marchetti@larkmoor.example,2025-03-01,2026-11-28 Chatterfield,farah.dunmore@larkmoor.example,2025-03-01,2026-11-21 Chatterfield,bartholomew.singh@larkmoor.example,2025-03-01,2026-11-30 Chatterfield,leopold.nakashima@larkmoor.example,2025-03-01,2026-11-30 Chatterfield,sunniva.abernathy@larkmoor.example,2025-03-01,2026-11-30 Chatterfield,rashad.pemberton@larkmoor.example,2025-03-01,2026-11-27 Chatterfield,tabitha.rosenthal@larkmoor.example,2025-03-01,2026-11-29 Chatterfield,emeka.lindgren@larkmoor.example,2025-03-01,2026-09-18 Chatterfield,mateo.grunewald@larkmoor.example,2025-03-01, Chatterfield,wren.castillo@larkmoor.example,2025-03-01,2026-10-02 Driftline Design,yuki.marchetti@larkmoor.example,2025-07-01,2026-11-18 Driftline Design,farah.dunmore@larkmoor.example,2025-07-01,2026-07-19 Driftline Design,bartholomew.singh@larkmoor.example,2025-07-01,2026-11-25 Vaultmoss,leopold.nakashima@larkmoor.example,2025-03-10,2026-11-30 Vaultmoss,sunniva.abernathy@larkmoor.example,2025-03-10,2026-11-30 Vaultmoss,rashad.pemberton@larkmoor.example,2025-03-10,2026-11-28 Vaultmoss,adaeze.lindqvist@larkmoor.example,2025-03-10,2026-10-01 Vaultmoss,noor.fairweather@larkmoor.example,2025-03-10,2026-11-17 Vaultmoss,ingrid.solheim-park@larkmoor.example,2025-03-10,2026-11-23 Vaultmoss,beatrix.holloway@larkmoor.example,2025-03-10,2026-11-09 Vaultmoss,marisol.kettering@larkmoor.example,2025-03-10,2026-11-02 Meetwell Video,marisol.kettering@larkmoor.example,2025-01-01,2026-11-24 Meetwell Video,thaddeus.nwosu@larkmoor.example,2025-01-01,2026-11-25 Meetwell Video,beatrix.holloway@larkmoor.example,2025-01-01,2026-11-26 Meetwell Video,mateo.grunewald@larkmoor.example,2025-01-01,2026-11-20 Meetwell Video,oluwaseun.whitlock@larkmoor.example,2025-01-01,2026-11-13 Meetwell Video,noor.fairweather@larkmoor.example,2025-01-01,2026-11-19 Meetwell Video,desmond.achterberg@larkmoor.example,2025-01-01,2026-11-24 Meetwell Video,wren.castillo@larkmoor.example,2025-01-01,2026-09-30 Meetwell Video,lucinda.abara@larkmoor.example,2025-01-01, Forgebench,ingrid.solheim-park@larkmoor.example,2025-05-05,2026-11-29 Forgebench,kwabena.rothwell@larkmoor.example,2025-05-05,2026-11-29 Forgebench,yuki.marchetti@larkmoor.example,2025-05-05,2026-11-28 Forgebench,farah.dunmore@larkmoor.example,2025-05-05,2026-11-21 Forgebench,bartholomew.singh@larkmoor.example,2025-05-05,2026-11-12 Forgebench,callum.oyelaran@larkmoor.example,2025-05-05,2026-09-29 Forgebench,j.merrow@brightquill.example,2025-05-05,2026-10-28 Deskhollow,leopold.nakashima@larkmoor.example,2026-02-01,2026-11-30 Deskhollow,sunniva.abernathy@larkmoor.example,2026-02-01,2026-11-28 Deskhollow,rashad.pemberton@larkmoor.example,2026-02-01,2026-11-30
input/licenses_paid.csv · 10 lines, 637 bytes
product,vendor,plan,seats_paid,price_per_seat_month,monthly_total,renewal_date Quillboard Office,Quillboard Ltd,Business,20,12.50,250.00,2027-01-15 Tallyhawk Books,Tallyhawk Software,Standard,5,45.00,225.00,2027-04-01 Pinecrest CRM,Pinecrest Systems,Team,10,65.00,650.00,2026-12-20 Chatterfield,Chatterfield Inc,Pro,12,8.00,86.00,2027-02-28 Driftline Design,Driftline Studio,Creator,6,55.00,330.00,2027-06-30 Vaultmoss,Vaultmoss Security,Teams,8,6.00,48.00,2027-03-10 Meetwell Video,Meetwell Co,Business,15,,,2026-12-31 Forgebench,Forgebench Labs,Team,6,21.00,126.00,2027-05-05 Signpetal,Signpetal Ltd,Starter,10,15.00,150.00,2027-01-31
input/reconcile_rules.md · 10 lines, 502 bytes
# Larkmoor Outfitters license check: house rules Count date: 2026-11-30 - A seat is idle when it has never been used, or when its last use was more than 60 days before the count date. - A seat held by someone who has left, or by an address that is not on the staff list, is taken back before anything else is looked at. - We pay per seat per month. Yearly figures are the monthly figure times 12. - The price list sometimes carries an old monthly total. Seats times price is the figure we trust.
input/staff.csv · 35 lines, 3 KB
employee_id,name,email,department,job_title,status,start_date,end_date E101,Adaeze Lindqvist,adaeze.lindqvist@larkmoor.example,Finance,Finance Director,active,2019-03-04, E102,Tomasz Verhoeven,tomasz.verhoeven@larkmoor.example,Finance,Accountant,active,2021-06-14, E103,Priya Castellanos,priya.castellanos@larkmoor.example,Finance,Accounts Payable Clerk,active,2022-01-10, E104,Hollis Brandvold,hollis.brandvold@larkmoor.example,Finance,Payroll Specialist,left,2020-09-01,2026-10-16 E105,Noor Fairweather,noor.fairweather@larkmoor.example,People,People Lead,active,2018-11-19, E106,Desmond Achterberg,desmond.achterberg@larkmoor.example,People,Recruiter,active,2023-02-06, E107,Ingrid Solheim-Park,ingrid.solheim-park@larkmoor.example,Engineering,Engineering Manager,active,2019-07-22, E108,Kwabena Rothwell,kwabena.rothwell@larkmoor.example,Engineering,Software Developer,active,2021-10-04, E109,Yuki Marchetti,yuki.marchetti@larkmoor.example,Engineering,Software Developer,active,2022-05-16, E110,Callum Oyelaran,callum.oyelaran@larkmoor.example,Engineering,Software Developer,left,2020-02-03,2026-09-30 E111,Farah Dunmore,farah.dunmore@larkmoor.example,Engineering,Quality Tester,active,2023-08-28, E112,Leopold Nakashima,leopold.nakashima@larkmoor.example,IT,IT Manager,active,2017-05-08, E113,Sunniva Abernathy,sunniva.abernathy@larkmoor.example,IT,Systems Administrator,active,2020-01-13, E114,Rashad Pemberton,rashad.pemberton@larkmoor.example,IT,Help Desk Technician,active,2024-04-02, E115,Beatrix Holloway,beatrix.holloway@larkmoor.example,Sales,Sales Director,active,2018-08-06, E116,Mateo Grunewald,mateo.grunewald@larkmoor.example,Sales,Account Executive,active,2021-03-29, E117,Oluwaseun Whitlock,oluwaseun.whitlock@larkmoor.example,Sales,Account Executive,active,2022-09-12, E118,Clementine Vasquez,clementine.vasquez@larkmoor.example,Sales,Account Executive,active,2023-01-23,2026-12-12 E119,Anders Mbeki,anders.mbeki@larkmoor.example,Sales,Sales Development Rep,active,2024-06-17,2026-11-14 E120,Tabitha Rosenthal,tabitha.rosenthal@larkmoor.example,Customer Support,Support Lead,active,2019-10-21, E121,Emeka Lindgren,emeka.lindgren@larkmoor.example,Customer Support,Support Agent,active,2022-07-05, E122,Saoirse Bellamy,saoirse.bellamy@larkmoor.example,Customer Support,Support Agent,active,2023-04-17, E123,Dmitri Hargreaves,dmitri.hargreaves@larkmoor.example,Customer Support,Support Agent,left,2021-11-08,2026-08-29 E124,Wren Castillo,wren.castillo@larkmoor.example,Operations,Operations Manager,active,2018-02-12, E125,Ignatius Thornbury,ignatius.thornbury@larkmoor.example,Operations,Warehouse Supervisor,active,2020-06-01, E126,Lucinda Abara,lucinda.abara@larkmoor.example,Operations,Purchasing Coordinator,active,2022-03-14, E127,Gideon Farrow,gideon.farrow@larkmoor.example,Operations,Warehouse Associate,active,2024-09-09, E128,Marisol Kettering,marisol.kettering@larkmoor.example,Leadership,Chief Executive,active,2016-01-04, E129,Thaddeus Nwosu,thaddeus.nwosu@larkmoor.example,Leadership,Chief Operating Officer,active,2017-09-18, E130,Philippa Zielinski,philippa.zielinski@larkmoor.example,Finance,Financial Analyst,active,2023-10-02, E131,Bartholomew Singh,bartholomew.singh@larkmoor.example,Engineering,Data Analyst,active,2025-02-24, E132,Odalys Fenwick,odalys.fenwick@larkmoor.example,People,Office Coordinator,active,2021-08-16, E133,Kieran Mahlangu,kieran.mahlangu@larkmoor.example,Sales,Account Executive,left,2022-11-07,2026-11-21 E134,Rosalind Tavares,rosalind.tavares@larkmoor.example,Customer Support,Support Agent,active,2025-05-12,
output/license_summary.csv · written by the agent, 11 lines
product,seats_paid,seats_assigned,seats_active,seats_to_cut,seats_to_buy,monthly_saving,status Quillboard Office,20,17,14,6,0,75.00,cut_back Tallyhawk Books,5,5,4,1,0,45.00,cut_back Pinecrest CRM,10,13,11,0,1,0.00,buy_more Chatterfield,12,12,10,2,0,16.00,cut_back Driftline Design,6,3,2,4,0,220.00,cut_back Vaultmoss,8,8,8,0,0,0.00,right_size Meetwell Video,15,9,7,8,0,,cut_back Forgebench,6,7,5,1,0,21.00,cut_back Signpetal,10,0,0,10,0,150.00,cut_back Deskhollow,0,3,3,0,0,0.00,no_purchase_record
output/seats_to_reclaim.csv · written by the agent, 14 lines
product,user_email,reason,last_used Quillboard Office,kieran.mahlangu@larkmoor.example,leaver,2026-11-20 Quillboard Office,temp.frontdesk@larkmoor.example,not_on_staff,2026-08-28 Quillboard Office,tomasz.verhoeven@larkmoor.example,idle,2026-08-02 Tallyhawk Books,hollis.brandvold@larkmoor.example,leaver,2026-10-15 Pinecrest CRM,anders.mbeki@larkmoor.example,leaver,2026-11-13 Pinecrest CRM,kieran.mahlangu@larkmoor.example,leaver,2026-11-20 Chatterfield,emeka.lindgren@larkmoor.example,idle,2026-09-18 Chatterfield,mateo.grunewald@larkmoor.example,idle, Driftline Design,farah.dunmore@larkmoor.example,idle,2026-07-19 Meetwell Video,lucinda.abara@larkmoor.example,idle, Meetwell Video,wren.castillo@larkmoor.example,idle,2026-09-30 Forgebench,callum.oyelaran@larkmoor.example,leaver,2026-09-29 Forgebench,j.merrow@brightquill.example,not_on_staff,2026-10-28
output/summary.md · written by the agent, 31 lines
# License reconciliation - Larkmoor Outfitters Count date: 2026-11-30. Idle = never used, or last used more than 60 days before (i.e. before 2026-10-01). **Total monthly saving: 527.00** | **Yearly saving: 6324.00** The total covers only products that have a price; Meetwell Video has none, so it is not in the total (see below). ## Products to cut back - Quillboard Office: cut 6 seats (paid 20, active 14), saves 75.00/month - Tallyhawk Books: cut 1 seats (paid 5, active 4), saves 45.00/month - Chatterfield: cut 2 seats (paid 12, active 10), saves 16.00/month - Driftline Design: cut 4 seats (paid 6, active 2), saves 220.00/month - Forgebench: cut 1 seats (paid 6, active 5), saves 21.00/month - Signpetal: cut 10 seats (paid 10, active 0), saves 150.00/month ## Products where more seats must be bought - Pinecrest CRM: buy 1 more (paid 10, active 11) ## Products with no purchase record - Deskhollow: 3 active seats in use, 3 assigned; no row in licenses_paid.csv, so seats paid, price and saving are unknown (shown as 0) ## Products with no price - Meetwell Video: 15 seats paid, 7 active, 8 could be cut, but the saving cannot be worked out without a price (monthly_saving left blank; monthly_total is also blank) ## Monthly totals that do not add up (seats x price vs monthly_total in the file) - Chatterfield: file says 86.00, seats x price is 96.00 ## Other - Right-size products: Vaultmoss - Every seat to take back is in seats_to_reclaim.csv.
check.py · the check, written before the run
"""Recomputes seat counts, seats to take back and savings from the input files, then compares."""
import csv, re, sys
from datetime import date, timedelta
from pathlib import Path
NUM = re.compile(r"(?<![\w.-])\d(?:[\d,]*\d)?(?:\.\d+)?(?![\w-])")
DAY = re.compile(r"\d{4}-\d{2}-\d{2}")
def rows(p):
with p.open(newline="") as fh:
return list(csv.DictReader(fh))
def pkey(s):
return re.sub(r"\s+", "", (s or "")).lower()
def ekey(s):
return (s or "").strip().lower()
def num(s):
try:
return float(str(s).replace(",", "").replace("$", "").strip())
except ValueError:
return None
def expected(root):
inp = root / "input"
rules = (inp / "reconcile_rules.md").read_text()
count_day = date.fromisoformat(re.search(r"Count date:\s*(\d{4}-\d{2}-\d{2})", rules).group(1))
idle_days = int(re.search(r"more than (\d+) days", rules).group(1))
staff = {ekey(r["email"]): r for r in rows(inp / "staff.csv")}
paid = {pkey(r["product"]): r for r in rows(inp / "licenses_paid.csv")}
names, seats = {}, {}
for k, r in paid.items():
names[k] = r["product"].strip(); seats[k] = {}
for r in rows(inp / "license_assignments.csv"):
k = pkey(r["product"]); names.setdefault(k, r["product"].strip())
last = r["last_used"].strip()
cur = seats.setdefault(k, {}).get(ekey(r["user_email"]), "")
seats[k][ekey(r["user_email"])] = max(cur, last)
products, reclaim, mismatch, last_used = {}, {}, [], {}
for k, people in seats.items():
active = 0
for email, last in people.items():
person = staff.get(email)
if not person: state = "not_on_staff"
elif person["end_date"].strip() and date.fromisoformat(person["end_date"].strip()) <= count_day: state = "leaver"
elif not last or (count_day - date.fromisoformat(last)).days > idle_days: state = "idle"
else: state = "active"
if state == "active": active += 1
else: reclaim[(k, email)] = state; last_used[(k, email)] = last
p = paid.get(k)
if not p:
products[k] = dict(name=names[k], paid=0, assigned=len(people), active=active, cut=0, buy=0, saving=0.0, status="no_purchase_record", money=set())
continue
sp = int(p["seats_paid"]); price = num(p["price_per_seat_month"])
cut, buy = max(0, sp - active), max(0, active - sp)
status = "buy_more" if active > sp else "cut_back" if active < sp else "right_size"
products[k] = dict(name=names[k], paid=sp, assigned=len(people), active=active, cut=cut, buy=buy,
saving=None if price is None else round(cut * price, 2), status=status)
listed = num(p["monthly_total"])
products[k]["money"] = {x for x in (price, listed, None if price is None else round(sp * price, 2), None if price is None else round(cut * price * 12, 2),
None if price is None else round(buy * price, 2)) if x is not None}
if price is not None and listed is not None and abs(listed - sp * price) > 0.005:
mismatch.append((names[k], listed, round(sp * price, 2)))
extras = {"reclaim": reclaim, "last_used": last_used, "idle_days": idle_days,
"days": {count_day.isoformat(), (count_day - timedelta(days=idle_days)).isoformat(), (count_day - timedelta(days=idle_days + 1)).isoformat()}}
return products, reclaim, mismatch, extras
def main():
root = Path(sys.argv[1]); ok = True
def say(passed, text):
nonlocal ok
ok = ok and passed; print(("PASS " if passed else "FAIL ") + text)
products, reclaim, mismatch, extras = expected(root)
path = root / "output/license_summary.csv"
if not path.exists():
say(False, "output/license_summary.csv was not written"); sys.exit(1)
got_rows = rows(path)
got = {pkey(r.get("product")): r for r in got_rows}
n = len(products)
say(len(got_rows) == len(got) and set(got) == set(products),
f"{len(set(got) & set(products))} of {n} products from the two files appear once in license_summary.csv")
def same(k, col, val):
v = num(got.get(k, {}).get(col, ""))
return v is not None and abs(v - val) < 0.005
counts = sum(1 for k, p in products.items() if same(k, "seats_paid", p["paid"]) and same(k, "seats_assigned", p["assigned"]) and same(k, "seats_active", p["active"]))
say(counts == n, f"{counts} of {n} products have the paid, assigned and active seat counts recomputed from the input files")
acts = sum(1 for k, p in products.items() if same(k, "seats_to_cut", p["cut"]) and same(k, "seats_to_buy", p["buy"])
and (got.get(k, {}).get("status") or "").strip().lower() == p["status"])
say(acts == n, f"{acts} of {n} products have the right seats to cut, seats to buy and status")
def saving_ok(k, p):
raw = (got.get(k, {}).get("monthly_saving") or "").strip()
return raw == "" if p["saving"] is None else same(k, "monthly_saving", p["saving"])
sav = sum(1 for k, p in products.items() if saving_ok(k, p))
say(sav == n, f"{sav} of {n} monthly savings equal seats to cut times price, left blank where the price is missing")
rpath = root / "output/seats_to_reclaim.csv"
got_r, got_last = {}, {}
if rpath.exists():
for r in rows(rpath):
got_r.setdefault((pkey(r.get("product")), ekey(r.get("user_email"))), []).append((r.get("reason") or "").strip().lower())
got_last[(pkey(r.get("product")), ekey(r.get("user_email")))] = (r.get("last_used") or "").strip()
right = sum(1 for key, state in reclaim.items() if got_r.get(key) == [state] and got_last.get(key) == extras["last_used"][key])
extra = len(set(got_r) - set(reclaim))
say(right == len(reclaim) and extra == 0,
f"{right} of {len(reclaim)} seats that are not active are listed once in seats_to_reclaim.csv with the right reason and last used date and {extra} active seats are listed by mistake")
summary = (root / "output/summary.md").read_text() if (root / "output/summary.md").exists() else ""
nums = {round(float(x.replace(",", "")), 2) for x in re.findall(r"\d[\d,]*\.\d{2}", summary)}
total = round(sum(p["saving"] or 0 for p in products.values()), 2)
say(total in nums and round(total * 12, 2) in nums,
f"summary.md states the total monthly saving, {total:,.2f}, and the yearly saving, {total * 12:,.2f}")
mm = sum(1 for name, listed, true in mismatch if name in summary and round(listed, 2) in nums and true in nums)
say(mm == len(mismatch), f"{mm} of {len(mismatch)} products whose listed monthly total does not add up are named in summary.md with both figures")
lines = summary.splitlines()
def on_line(ln):
return [k for k, p in products.items() if p["name"] in ln]
def nums_of(ln):
return [float(m.group(0).replace(",", "")) for m in NUM.finditer(DAY.sub(" ", ln))]
cuts = [k for k, p in products.items() if p["status"] == "cut_back" and p["saving"] is not None]
c_ok = sum(1 for k in cuts if any(k in on_line(ln) and float(products[k]["cut"]) in nums_of(ln) and products[k]["saving"] in nums_of(ln) for ln in lines))
others = [k for k, p in products.items() if p["status"] in ("buy_more", "no_purchase_record") or p["saving"] is None]
o_ok = sum(1 for k in others if products[k]["name"] in summary)
say(c_ok == len(cuts) and o_ok == len(others), f"{c_ok} of {len(cuts)} products to cut back are on a line of summary.md with their seats to cut and saving and {o_ok} of {len(others)} other products that need a decision are named")
seen = bad = 0
general = {total, round(total * 12, 2), float(extras["idle_days"]), float(n), float(len(reclaim)), float(len(cuts))}
labels = {"paid": "paid", "assigned": "assigned", "active": "active", "cut": "cut", "buy": "buy"}
for ln in lines:
ks = on_line(ln)
allowed = set(general)
for k in ks:
p = products[k]
allowed |= {float(p[f]) for f in ("paid", "assigned", "active", "cut", "buy")} | p["money"] | ({p["saving"], round(p["saving"] * 12, 2)} if p["saving"] is not None else set())
if not ks: allowed = set(general)
for m in NUM.finditer(DAY.sub(" ", ln)):
if len(m.group(0)) >= 2:
seen += 1; bad += not any(abs(float(m.group(0).replace(",", "")) - a) < 0.005 for a in allowed)
for d in DAY.findall(ln):
seen += 1; bad += d not in extras["days"]
if len(ks) == 1:
p = products[ks[0]]
for word, field in labels.items():
for m in list(re.finditer(r"\b" + word + r"\s+(\d+)(?![\w.])", ln)) + list(re.finditer(r"(?<![\w.-])(\d+)\s+(?:seats?\s+)?" + word + r"\b", ln)):
seen += 1; bad += int(m.group(1)) != p[field]
say(seen > 0 and bad == 0, f"{seen - bad} of {seen} other figures and dates in summary.md match the product they sit beside or the totals")
sys.exit(0 if ok else 1)
if __name__ == "__main__":
main()
license_assignments.csv: sample data written by Atris. Fingerprint 4b17dabe137c.
licenses_paid.csv: sample data written by Atris. Fingerprint a2a7ac06c4ea.
reconcile_rules.md: sample data written by Atris. Fingerprint 950ba2973cf7.
staff.csv: sample data written by Atris. Fingerprint d06060ba1b29.
license_summary.csv: written by the agent. Fingerprint fdeb99a68a22.
seats_to_reclaim.csv: written by the agent. Fingerprint 29661af1a3c8.
summary.md: written by the agent. Fingerprint 7a5529eacb3f.