1
0

WIP: Targets configurable with Quantities

This commit is contained in:
cryptogopher
2021-02-07 11:02:41 +01:00
parent 316005bf1f
commit 8b17b33603
23 changed files with 218 additions and 108 deletions

View File

@@ -10,6 +10,8 @@ class CreateSchema <
t.references :parent
t.integer :lft, null: false, index: true
t.integer :rgt, null: false, index: true
# TODO: remove depth (seems to be replaceable by lft)
t.integer :depth, null: false, default: 0
t.timestamps null: false
end
@@ -105,8 +107,8 @@ class CreateSchema <
create_table :targets do |t|
t.references :goal
t.references :quantity
t.references :item, polymorphic: true
t.string :condition
t.string :scope
t.date :effective_from
t.timestamps null: false

View File

@@ -168,6 +168,18 @@ b_ac = Quantity.create name: "RM", domain: :measurement, p
b_ad = Quantity.create name: "VF", domain: :measurement, parent: b_a,
description: "Visceral fat"
# -> Target conditions
t_a = Quantity.create name: "below", domain: :target, parent: nil,
description: "Upper bound"
t_b = Quantity.create name: "above", domain: :target, parent: nil,
description: "Lower bound"
t_ba = Quantity.create name: "and below", domain: :target, parent: t_b,
description: "Range"
t_c = Quantity.create name: "equal", domain: :target, parent: nil,
description: "Exact value"
t_ca = Quantity.create name: "with accuracy of", domain: :target, parent: t_c,
description: "Point range"
# Formulas go at the and to make sure dependencies exist
e_aa.create_formula zero_nil: true, unit: u_b,
code: "4*Proteins + 9*Fats + 4*Carbs + 2*Fibre"
@@ -189,6 +201,13 @@ e_aea.create_formula zero_nil: true, unit: u_c,
b_aaa.create_formula zero_nil: true, unit: u_ac,
code: "'% fat' * Weight"
t_a.create_formula zero_nil: false, code: "value <= below"
t_b.create_formula zero_nil: false, code: "value >= above"
t_ba.create_formula zero_nil: false, code: "(value >= above) && (value <= 'and below')"
t_c.create_formula zero_nil: false, code: "value == equal"
t_ca.create_formula zero_nil: false, code: "(value >= (equal - 'with accuracy of')) && " \
"(value <= (equal + 'with accuracy of'))"
# Sources
s_a = Source.create name: "nutrition label",
description: "nutrition facts taken from package nutrition label"