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

Pass rate per prompt version, with a 95 percent Wilson score range, and a comparison
with a baseline version.

Input is a CSV with the columns `case_id`, `version` (a label such as v1) and `passed`
(`yes` or `no`, any case: whether the output passed YOUR check). Extra columns are ignored.
A `(case_id, version)` pair may appear only once. Version labels are compared as written
(after trimming), so `v1` and `V1` are two versions.

The Wilson score range for `k` passes out of `n` cases, with `p = k / n` and `z = 1.96`
(fixed), is

    centre = (p + z^2 / (2n)) / (1 + z^2 / n)
    half   = z * sqrt(p (1 - p) / n + z^2 / (4 n^2)) / (1 + z^2 / n)
    range  = centre - half  to  centre + half

Pass rates and differences are exact (integer arithmetic, rounded half up to 1 decimal).
The Wilson ends are computed in floating point and rounded to 1 decimal. Two ranges
"overlap" when, on the 1-decimal ends as printed, each one starts at or below the point
where the other ends. The tool decides nothing: a small number of cases cannot support
a conclusion.

# `row`

```elixir
@type row() :: %{case_id: String.t(), version: String.t(), passed: boolean()}
```

# `difference`

```elixir
@spec difference(map(), map()) :: String.t()
```

Signed difference in percentage points, version minus baseline, exact, 1 decimal.

# `overlap?`

```elixir
@spec overlap?(map(), map()) :: boolean()
```

True when two summaries' 1-decimal Wilson ranges overlap.

# `parse`

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

Parse the CSV text into a list of rows.

# `ratio`

```elixir
@spec ratio(non_neg_integer(), non_neg_integer(), pos_integer(), non_neg_integer()) ::
  String.t()
```

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

# `render`

```elixir
@spec render([row()], String.t() | nil) :: {:ok, String.t()} | {:error, String.t()}
```

Printable report. `baseline` must be a version present in the rows, otherwise
`{:error, message}` is returned.

# `summarize`

```elixir
@spec summarize([row()]) :: [map()]
```

Per-version summary sorted by label: `version`, `cases`, `passed`, and the Wilson ends
`low` and `high` in tenths of a percent (integers).

# `wilson`

```elixir
@spec wilson(non_neg_integer(), pos_integer()) :: {float(), float()}
```

95 percent Wilson score range for `k` passes out of `n` cases (`n > 0`), as
`{low, high}` in percent, floats clamped to 0 and 100.

---

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