Further optimized nutrient calculation defaults
This commit is contained in:
parent
c1771d44d7
commit
b6c453c37c
@ -55,7 +55,7 @@ class Ingredient < ActiveRecord::Base
|
|||||||
|
|
||||||
# quantity not computable (no formula) or not requiring calculation/computed
|
# quantity not computable (no formula) or not requiring calculation/computed
|
||||||
if q.formula.blank? || (nutrients[q.name].length == ingredients.count)
|
if q.formula.blank? || (nutrients[q.name].length == ingredients.count)
|
||||||
completed_q[q.name] = nutrients.delete(q.name) || {}
|
completed_q[q.name] = nutrients.delete(q.name) { {} }
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -73,10 +73,10 @@ class Ingredient < ActiveRecord::Base
|
|||||||
[
|
[
|
||||||
i,
|
i,
|
||||||
input_q.map do |i_q|
|
input_q.map do |i_q|
|
||||||
nutrient_data = (completed_q[i_q.name] || nutrients[i_q.name])[i.id]
|
|
||||||
# FIXME: result for computation with nil values (substituted with 0s)
|
# FIXME: result for computation with nil values (substituted with 0s)
|
||||||
# should be marked as not precise
|
# should be marked as not precise
|
||||||
[i_q.name, (nutrient_data || [0, nil])[0]]
|
nutrient_data = completed_q[i_q.name][i.id] || [0, nil]
|
||||||
|
[i_q.name, nutrient_data[0]]
|
||||||
end.to_h
|
end.to_h
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user