From b1e7236460eaea7c12801d61ce2e4b467f88ba65 Mon Sep 17 00:00:00 2001
From: cryptogopher <%= f.text_field :description, style: "width: 100%;" %> <%= ff.text_field :code, placeholder: t('.formula_placeholder'),
- style: "width: 100%;" %>
<%= ff.check_box :zero_nil, {label: ''} %><%= t('.zero_nil') %>
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 6db430e..b000a28 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -123,6 +123,7 @@ en: null_parent: '- none -' formula_placeholder: 'provide if value of quantity has to be computed in terms of other quantities' + zero_nil: 'substitute missing formula values with 0?' units: index: heading: 'Units' diff --git a/db/migrate/002_load_defaults.rb b/db/migrate/002_load_defaults.rb index 9830e50..1306e41 100644 --- a/db/migrate/002_load_defaults.rb +++ b/db/migrate/002_load_defaults.rb @@ -13,6 +13,8 @@ class LoadDefaults < ActiveRecord::Migration # https://www.fsai.ie/legislation/food_legislation/food_information_fic/nutrition_labelling.html e1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Energy", description: "Total energy" + e2 = Quantity.create project: nil, domain: :diet, parent: e1, name: "Calculated", + description: "Total energy calculated from macronutrients" p1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Proteins", description: "Total amount of proteins" @@ -141,10 +143,9 @@ class LoadDefaults < ActiveRecord::Migration b9 = Quantity.create project: nil, domain: :measurement, parent: b1, name: "VF", description: "Visceral fat" - # Calculated quantities go at the and to make sure dependencies exist - e2 = Quantity.create project: nil, domain: :diet, parent: e1, name: "Calculated", - description: "Total energy calculated from macronutrients", - formula_attributes: {code: "4*Proteins + 9*Fats + 4*Carbohydrates", zero_nil: true} + # Formulas go at the and to make sure dependencies exist + e2.create_formula code: "4*Proteins + 9*Fats + 4*Carbohydrates", zero_nil: true + b3.create_formula code: "'% fat' * 'Weight'", zero_nil: true Source.create project: nil, name: "nutrition label", description: "nutrition facts taken from package nutrition label"