Fix the MRR recompute behind a board deck

Review the AI's codeEasy10 minStripe style

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, written status,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 monthly row adds its amount.
  • An annual row 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]) -> int
Example 1
Inputnormalized_monthly_revenue_cents(["active,monthly,4900", "active,annual,120000", "trialing,monthly,4900"])
Output14900
Example 2
Inputnormalized_monthly_revenue_cents(["active,annual,100"])
Output8
Example 3
Inputnormalized_monthly_revenue_cents([])
Output0