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

Deal size bands from a CSV with the columns `deal,amount,outcome` (`outcome` is `won` or `lost`).

Band edges default to `5000,20000,50000`, which gives four bands: under 5,000; 5,000 to 19,999;
20,000 to 49,999; 50,000 and over. A deal whose amount equals an edge belongs to the band that
starts at that edge. Amounts must be non-negative numbers.

# `band`

```elixir
@type band() :: %{
  label: String.t(),
  deals: non_neg_integer(),
  won: non_neg_integer(),
  win_rate: float() | nil,
  won_revenue: number(),
  share: float() | nil
}
```

# `deal`

```elixir
@type deal() :: %{deal: String.t(), amount: number(), won: boolean()}
```

# `band_index`

```elixir
@spec band_index(number(), [non_neg_integer()]) :: non_neg_integer()
```

Index of the band an amount falls in, for the given ascending edges.

# `bands`

```elixir
@spec bands([deal()], [non_neg_integer()]) :: [band()]
```

Per-band deals, wins, win rate and share of won revenue.

# `default_edges`

The default band edges.

# `labels`

```elixir
@spec labels([non_neg_integer()]) :: [String.t()]
```

Band labels for the given edges.

# `median_won`

```elixir
@spec median_won([deal()]) :: number() | nil
```

Median won deal size, or nil when nothing was won.

# `parse`

```elixir
@spec parse(String.t()) :: {:ok, [deal()]} | {:error, String.t()}
```

Parse the CSV text into deals.

# `parse_edges`

```elixir
@spec parse_edges(String.t()) :: {:ok, [non_neg_integer()]} | {:error, String.t()}
```

Parse a comma separated edge list such as `5000,20000,50000` (strictly ascending whole numbers, at least one).

# `render`

```elixir
@spec render([band()], number() | nil) :: String.t()
```

Printable table followed by the median won deal size.

---

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