Score an extraction agent's amounts within a tolerance
Your task
An agent reads invoices and pulls out every amount it finds. The eval compares its amounts with a person's gold list for the same invoice, and a rounding slip of a few cents should still count as a hit.
Write match_amounts(docs, tolerance) that returns [matched, extra, missed].
docs: a list of invoices, each[predicted, gold]: the agent's amounts and the person's amounts, as lists of whole cents in any order. Amounts can be negative (credits), and either list can repeat an amount or be empty.tolerance: whole cents, 0 or more.- Return the counts, summed over all invoices:
matchedis the number of matched pairs,extrathe predicted amounts left unmatched, andmissedthe gold amounts left unmatched.
Rules:
- A predicted amount and a gold amount from the same invoice may be matched when they differ by at most
tolerance. - Each amount, predicted or gold, is in at most one pair.
- In each invoice, match as many pairs as possible.
Examples
match_amounts(docs: list[list[list[int]]], tolerance: int) -> list[int]Example 1
Input
match_amounts([[[1000, 2550], [2549, 1000]]], 1)Output
[2, 0, 0]Example 2
Input
match_amounts([[[500, 700], [505]], [[], [100]]], 3)Output
[0, 2, 2]Example 3
Input
match_amounts([[[1299, 450, 450], [450, 1300]]], 2)Output
[2, 1, 0]