FormLengthConversion (form_length_conversion v1.0.0)

Copy Markdown View Source

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.

Summary

Functions

Bucket name for a field count.

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

Parse the CSV text into a list of form rows.

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

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

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

Types

form_row()

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

Functions

bucket(fields, mid_from \\ 4, long_from \\ 7)

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

Bucket name for a field count.

check_limits(mid_from, long_from)

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

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

parse(text)

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

Parse the CSV text into a list of form rows.

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(rows, mid_from \\ 4, long_from \\ 7)

@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(rows, mid_from \\ 4, long_from \\ 7)

@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).