CreditRunway (credit_runway v1.0.0)

Copy Markdown View Source

Estimate how long a credit balance lasts from your own daily usage.

Input is a CSV with the columns date (yyyy-mm-dd) and credits_used (a non-negative whole number: the credits your data tool spent that day). Several rows for one date are added together. Days without a row between the first and the last date count as 0. Extra columns are ignored.

  • average per day over the whole range = total credits / days covered
  • recent burn rate = credits used in the last window days / window
  • runway in days = balance / recent burn rate
  • run-out date = last date + floor(runway) days

window (default 7) is a parameter set by you, not a rule, and balance is the number of credits left today. All numbers are computed exactly with integers and rounded half up to one decimal. When the recent burn rate is 0 there is no run-out date.

Summary

Functions

Summary for a parsed series. window is the number of days for the recent burn rate and balance the credits left today. Returns {:ok, map} or {:error, message}.

Parse the CSV text into a day-by-day usage series (missing days are 0).

Divide num / den * mult exactly (integers only) and format with decimals places, rounding half up. Returns "n/a" when den is zero.

Printable report.

Types

parsed()

@type parsed() :: %{
  first: Date.t(),
  last: Date.t(),
  days: pos_integer(),
  usage: [non_neg_integer()],
  dates: [Date.t()]
}

Functions

analyze(p, balance, window)

@spec analyze(parsed(), integer(), integer()) :: {:ok, map()} | {:error, String.t()}

Summary for a parsed series. window is the number of days for the recent burn rate and balance the credits left today. Returns {:ok, map} or {:error, message}.

parse(text)

@spec parse(String.t()) :: {:ok, parsed()} | {:error, String.t()}

Parse the CSV text into a day-by-day usage series (missing days are 0).

ratio(num, den, mult, decimals)

@spec ratio(integer(), integer(), integer(), non_neg_integer()) :: String.t()

Divide num / den * mult exactly (integers only) and format with decimals places, rounding half up. Returns "n/a" when den is zero.

render(a)

@spec render(map()) :: String.t()

Printable report.