# `CreditRunway`
[🔗](https://github.com/jaizendra-netizen/credit_runway/blob/main/lib/credit_runway.ex#L1)

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.

# `parsed`

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

# `analyze`

```elixir
@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`

```elixir
@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`

```elixir
@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`

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

Printable report.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
