wip(growth): calculate key metrics for growth
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
1. calculate age in days, weeks, and months 2. calculate body mass index for metric and english unities 3. calculate z-score for a given measurement and box-cox parameters (l, m, s) 4. calculate centile score for a given measurement and box-cox parameters
This commit is contained in:
29
lib/growth/calc/bmi.ex
Normal file
29
lib/growth/calc/bmi.ex
Normal file
@@ -0,0 +1,29 @@
|
||||
defmodule Growth.Calc.BMI do
|
||||
@moduledoc """
|
||||
Calculate body mass index
|
||||
"""
|
||||
|
||||
@inch_to_centimeter 2.54
|
||||
@pound_to_kilogram 0.453592
|
||||
|
||||
@doc """
|
||||
Calculate the body mass index for a given weight and height.
|
||||
|
||||
Measurements taken in english unit (pounds and inches) are converted to their metric equivalents (kilograms and centimeters).
|
||||
"""
|
||||
@spec calculate(:english | :metric, number, number) :: number
|
||||
|
||||
def calculate(:english, weight, height) do
|
||||
metric_weight = pound_to_kilogram(weight)
|
||||
metric_height = inches_to_centimeters(height)
|
||||
calculate(:metric, metric_weight, metric_height)
|
||||
end
|
||||
|
||||
def calculate(:metric, weight, height) do
|
||||
weight / :math.pow(height / 100.0, 2)
|
||||
end
|
||||
|
||||
defp inches_to_centimeters(height), do: height * @inch_to_centimeter
|
||||
|
||||
defp pound_to_kilogram(weight), do: weight * @pound_to_kilogram
|
||||
end
|
Reference in New Issue
Block a user