chore(growth): move nil logic to scorer behaviour
All checks were successful
continuous-integration/drone/pr Build is passing
All checks were successful
continuous-integration/drone/pr Build is passing
Handle `nil` measurement in `Growth.Score.Scorer`.
This commit is contained in:
@@ -25,7 +25,7 @@ defmodule Growth.Score.Scorer do
|
||||
growth
|
||||
|> lms(indicator)
|
||||
|> Enum.map(fn {precision, {l, m, s}} ->
|
||||
{precision, {z_score(indicator, growth, l, m, s), centile(indicator, growth, l, m, s)}}
|
||||
{precision, scores(indicator, growth, l, m, s)}
|
||||
end)
|
||||
|
||||
%{growth | results: [Map.new([{indicator.measure_name(), result}]) | growth.results]}
|
||||
@@ -58,23 +58,41 @@ defmodule Growth.Score.Scorer do
|
||||
|> Enum.reject(&is_nil/1)
|
||||
end
|
||||
|
||||
@spec z_score(module(), Growth.t(), ZScore.l(), ZScore.m(), ZScore.s()) :: number()
|
||||
@spec scores(module(), Growth.t(), ZScore.l(), ZScore.m(), ZScore.s()) ::
|
||||
{Growth.measure(), number() | :na, nil}
|
||||
@doc """
|
||||
Calculate the z-score and centile of an indicator measurement.
|
||||
"""
|
||||
def scores(indicator, growth, l, m, s) do
|
||||
measure = Map.get(growth, indicator.measure_name())
|
||||
|
||||
{
|
||||
z_score(measure, l, m, s),
|
||||
centile(measure, l, m, s)
|
||||
}
|
||||
end
|
||||
|
||||
@spec z_score(Growth.measure(), ZScore.l(), ZScore.m(), ZScore.s()) :: Growth.measure()
|
||||
@doc """
|
||||
Check `Growth.Calc.ZScore.compute/4`.
|
||||
"""
|
||||
def z_score(indicator, growth, l, m, s) do
|
||||
growth
|
||||
|> Map.get(indicator.measure_name())
|
||||
|> ZScore.compute(l, m, s)
|
||||
def z_score(nil, _, _, _) do
|
||||
nil
|
||||
end
|
||||
|
||||
@spec centile(module(), Growth.t(), ZScore.l(), ZScore.m(), ZScore.s()) :: number() | :na
|
||||
def z_score(value, l, m, s) do
|
||||
ZScore.compute(value, l, m, s)
|
||||
end
|
||||
|
||||
@spec centile(Growth.measure(), ZScore.l(), ZScore.m(), ZScore.s()) :: number() | :na | nil
|
||||
@doc """
|
||||
Check `Growth.Calc.Centile.compute/4`.
|
||||
"""
|
||||
def centile(indicator, growth, l, m, s) do
|
||||
growth
|
||||
|> Map.get(indicator.measure_name())
|
||||
|> Centile.compute(l, m, s)
|
||||
def centile(nil, _, _, _) do
|
||||
nil
|
||||
end
|
||||
|
||||
def centile(value, l, m, s) do
|
||||
Centile.compute(value, l, m, s)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user