Fix the MRR recompute behind a board deck
Your task
An AI wrote the SQL that computes monthly recurring revenue (MRR) for a board deck. It returns believable numbers, which is exactly why nobody questioned it. To check it, your team recomputes MRR from the raw subscription rows, with every convention written down as agreed with finance.
An assistant wrote normalized_monthly_revenue_cents(subscription_lines). It is in the editor. It has a bug. Find it and fix it.
Input and output:
subscription_lines: one row per subscription, writtenstatus,interval,amount_cents.- Return MRR in cents, as an integer.
Rules the tests check:
- Split each row on
,. Skip a row that does not have exactly 3 fields. - Count only rows whose status is exactly
active. Trials, paused and canceled subscriptions are not revenue. - Skip a row whose amount is not one or more digits from 0 to 9.
- A
monthlyrow adds its amount. - An
annualrow adds its amount divided by 12, rounded to the nearest cent, with exactly half a cent rounding up. Round each annual row on its own, then add. - Skip any other interval. Status and interval are matched exactly, case included.
Examples
normalized_monthly_revenue_cents(subscription_lines: list[str]) -> intExample 1
Input
normalized_monthly_revenue_cents(["active,monthly,4900", "active,annual,120000", "trialing,monthly,4900"])Output
14900Example 2
Input
normalized_monthly_revenue_cents(["active,annual,100"])Output
8Example 3
Input
normalized_monthly_revenue_cents([])Output
0