ContactsPerDomainCap (contacts_per_domain_cap v1.0.0)

Copy Markdown View Source

Mark the contacts that go over a per-domain cap in a CSV you supply.

Input columns: contact_id and email. The domain is the text after the last @, trimmed and lower-cased. In input order the first cap contacts of each domain are keep, later ones are over cap. Extra columns are ignored.

Every domain is counted the same, including a domain that belongs to a mailbox provider rather than a company: you decide what to do with those. The library reads no outside data.

Summary

Functions

Apply the cap. Returns a map with :cap, :contacts, :domains, :rows (each row plus :decision, "keep" or "over cap", in input order), :over_domains (list of {domain, ids}, count desc then domain) and :over_contacts.

The default cap (3). It is only a default: set it with --cap.

Parse CSV text into rows. Errors name the row (data rows are counted from 1, header excluded).

Percentage with one decimal, rounded half up, as text such as 30.8%.

Render the analysis as text.

The decisions as CSV text (contact_id,email,domain,decision), in input order.

Types

row()

@type row() :: %{
  row: pos_integer(),
  id: String.t(),
  email: String.t(),
  domain: String.t()
}

Functions

analyze(rows, cap)

@spec analyze([row()], pos_integer()) :: map()

Apply the cap. Returns a map with :cap, :contacts, :domains, :rows (each row plus :decision, "keep" or "over cap", in input order), :over_domains (list of {domain, ids}, count desc then domain) and :over_contacts.

default_cap()

The default cap (3). It is only a default: set it with --cap.

parse(text)

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

Parse CSV text into rows. Errors name the row (data rows are counted from 1, header excluded).

pct(n, total)

Percentage with one decimal, rounded half up, as text such as 30.8%.

render(a)

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

Render the analysis as text.

to_csv(a)

@spec to_csv(map()) :: String.t()

The decisions as CSV text (contact_id,email,domain,decision), in input order.