ListSplitAssign (list_split_assign v1.0.0)

Copy Markdown View Source

Split a CSV list of ids into groups with a seeded hash.

Input is a CSV with the columns id and segment. The id is trimmed and compared case-insensitively; the segment is a label (trimmed, case-insensitive, the first spelling is the one shown).

The group of an id is :erlang.phash2({seed, String.downcase(id)}, groups), mapped to the letters A, B, C and so on. The same id and seed always give the same group, whatever the row order. A hash split is only approximately balanced: small lists can be far from even. :erlang.phash2/2 is the Erlang term hash.

Summary

Functions

Assign every row to a group. Returns a map with :ids, :groups (the letters), :seed, :assigned (rows with their :group, in input order), :by_group and :by_segment.

The group letter of an id for a seed and a number of groups (2 to 26).

Parse the CSV text into a list of rows.

Render the report as text.

The assignment as CSV text: id,segment,group, in input order.

Types

row()

@type row() :: %{
  id: String.t(),
  key: String.t(),
  segment: String.t(),
  row: pos_integer()
}

Functions

analyze(rows, groups \\ 2, seed \\ "seed")

Assign every row to a group. Returns a map with :ids, :groups (the letters), :seed, :assigned (rows with their :group, in input order), :by_group and :by_segment.

default_groups()

default_seed()

group_of(id, seed, groups)

@spec group_of(String.t(), String.t(), 2..26) :: String.t()

The group letter of an id for a seed and a number of groups (2 to 26).

parse(text)

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

Parse the CSV text into a list of rows.

render(a)

Render the report as text.

to_csv(a)

The assignment as CSV text: id,segment,group, in input order.