Numeric/statistical helpers shared by the engine, formatter, and third-party analysis modules.
Everything here is Decimal-aware: Decimal structs do not implement
Kernel.+/2 or Elixir's structurally-correct ordering, so sums, averages,
percentiles, and comparisons all branch on representation. These helpers are
public so custom AshDyan.Analysis implementations can reuse them instead of
re-implementing the Decimal handling.
Summary
Functions
Decimal-aware addition so cumulative totals work on decimal metrics.
Decimal-aware mean; returns nil for an empty list.
Share-of-total percentage for a single value, as a float.
Linear-interpolated percentile of a list (Decimal-aware); nil when empty.
Min of a list, ignoring nils; nil when empty.
Population standard deviation; nil for an empty list.
Sum a list of values, branching on whether they are Decimals. Enum.sum/1
raises ArithmeticError on Decimal structs, so we reduce with Decimal.add.
Population variance; nil for an empty list.
Functions
Decimal-aware addition so cumulative totals work on decimal metrics.
Decimal-aware mean; returns nil for an empty list.
Numeric comparison that works for Decimal, numbers, and nil. Elixir's
:asc/:desc sorter compares structs structurally, which is wrong for
Decimal (it would order by the underlying map fields, not the value).
Share-of-total percentage for a single value, as a float.
Linear-interpolated percentile of a list (Decimal-aware); nil when empty.
Min of a list, ignoring nils; nil when empty.
Population standard deviation; nil for an empty list.
Sum a list of values, branching on whether they are Decimals. Enum.sum/1
raises ArithmeticError on Decimal structs, so we reduce with Decimal.add.
Population variance; nil for an empty list.