WIP: Targets configurable with Quantities
This commit is contained in:
@@ -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
|
||||
|
||||
19
db/seeds.rb
19
db/seeds.rb
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user