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

Group web forms by how many fields they show and compare conversion rates.

Input is a CSV with the columns `form`, `fields` (a positive whole number),
`views` and `submissions` (non-negative whole numbers, `submissions <= views`).
Extra columns are ignored. Every form name may appear only once.

Buckets by field count:

  * short: fewer than `mid_from` fields (default: 1 to 3)
  * mid: `mid_from` or more but fewer than `long_from` (default: 4 to 6)
  * long: `long_from` or more (default: 7 or more)

`mid_from` and `long_from` are parameters set by you, not rules. They must satisfy
`2 <= mid_from < long_from`.

Conversion rate is `submissions / views` as a percent, rounded half up to 2 decimals,
and `n/a` when there are no views. Best and worst form of a bucket are picked by exact
conversion rate (ties by form name, alphabetical); forms with 0 views are ignored for
best and worst.

# `form_row`

```elixir
@type form_row() :: %{
  form: String.t(),
  fields: pos_integer(),
  views: non_neg_integer(),
  submissions: non_neg_integer()
}
```

# `bucket`

```elixir
@spec bucket(pos_integer(), pos_integer(), pos_integer()) :: :short | :mid | :long
```

Bucket name for a field count.

# `check_limits`

```elixir
@spec check_limits(integer(), integer()) :: :ok | {:error, String.t()}
```

Check the bucket limits: `2 <= mid_from < long_from`.

# `parse`

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

Parse the CSV text into a list of form rows.

# `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([form_row()], pos_integer(), pos_integer()) :: String.t()
```

Printable report: bucket table with a total row, then best and worst form per bucket.

# `summarize`

```elixir
@spec summarize([form_row()], pos_integer(), pos_integer()) :: [map()]
```

Per-bucket summary. Returns three maps (short, mid, long) with the keys `bucket`,
`forms`, `views`, `submissions`, `best` and `worst` (a form row or `nil`).

---

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