chore(growth): name ets tables with score modules
This commit is contained in:
parent
52c1d0c028
commit
025ab1537d
@ -4,15 +4,14 @@ defmodule Growth.Indicators.Load do
|
||||
|
||||
For each measurement an ets table is created, so the system has the following tables:
|
||||
|
||||
* `:arm_circumference_for_age`
|
||||
* `:bmi_for_age`
|
||||
* `:head_circumference_for_age`
|
||||
* `:height_for_age`
|
||||
* `:subscapular_skinfold_for_age`
|
||||
* `:telemetry_handler_table`
|
||||
* `:triceps_skinfold_for_age`
|
||||
* `:weight_for_age`
|
||||
* `:weight_for_height`
|
||||
* `Growth.Score.ArmCircumference`
|
||||
* `Growth.Score.BMI`
|
||||
* `Growth.Score.HeadCircumference`
|
||||
* `Growth.Score.Height`
|
||||
* `Growth.Score.SubscapularSkinfold`
|
||||
* `Growth.Score.TricepsSkinfold`
|
||||
* `Growth.Score.Weight`
|
||||
* `Growth.Score.WeightForHeight`
|
||||
|
||||
The rows in the csv files are converted to two tuple, representing the a key and value, with the following format:
|
||||
|
||||
@ -33,6 +32,19 @@ defmodule Growth.Indicators.Load do
|
||||
|
||||
"""
|
||||
|
||||
alias Growth.Score
|
||||
|
||||
@measure_to_score [
|
||||
arm_circumference_for_age: Score.ArmCircumference,
|
||||
bmi_for_age: Score.BMI,
|
||||
head_circumference_for_age: Score.HeadCircumference,
|
||||
height_for_age: Score.Height,
|
||||
subscapular_skinfold_for_age: Score.SubscapularSkinfold,
|
||||
triceps_skinfold_for_age: Score.TricepsSkinfold,
|
||||
weight_for_age: Score.Weight,
|
||||
weight_for_height: Score.WeightForHeight
|
||||
]
|
||||
|
||||
@spec all :: [[boolean()]]
|
||||
@doc """
|
||||
Load indicators csv files into their own ets tables.
|
||||
@ -45,14 +57,19 @@ defmodule Growth.Indicators.Load do
|
||||
|> Task.await_many()
|
||||
end
|
||||
|
||||
@spec create_ets(String.t()) :: {:atom, String.t()}
|
||||
@spec create_ets(String.t()) :: {atom(), String.t()}
|
||||
@doc """
|
||||
Create a public ets table for the csv filename, using the file name as the table name.
|
||||
|
||||
Returns a tuple with table name as an atom and the filename.
|
||||
"""
|
||||
def create_ets(filename) do
|
||||
measure = filename |> Path.basename() |> Path.rootname() |> String.to_atom()
|
||||
measure =
|
||||
filename
|
||||
|> Path.basename()
|
||||
|> Path.rootname()
|
||||
|> String.to_atom()
|
||||
|> then(&Keyword.get(@measure_to_score, &1, &1))
|
||||
|
||||
try do
|
||||
:ets.new(measure, [:set, :public, :named_table])
|
||||
@ -64,7 +81,7 @@ defmodule Growth.Indicators.Load do
|
||||
{measure, filename}
|
||||
end
|
||||
|
||||
@spec load_measure({:atom, String.t()}) :: [boolean()]
|
||||
@spec load_measure({atom(), String.t()}) :: [boolean()]
|
||||
@doc """
|
||||
Read, convert, and load a measure/filename into the proper ets table.
|
||||
"""
|
||||
@ -110,7 +127,7 @@ defmodule Growth.Indicators.Load do
|
||||
as_float(t)
|
||||
end
|
||||
|
||||
key = {gender, unit, converted_t}
|
||||
key = {String.to_existing_atom(gender), unit, converted_t}
|
||||
|
||||
value = %{
|
||||
l: as_float(l),
|
||||
|
Loading…
x
Reference in New Issue
Block a user