Aggregated quantity calculation for all ingredients
This commit is contained in:
parent
ce4d839a10
commit
304c8c788d
@ -66,15 +66,16 @@ class Ingredient < ActiveRecord::Base
|
|||||||
|
|
||||||
if deps.empty?
|
if deps.empty?
|
||||||
input_q = q.formula_quantities
|
input_q = q.formula_quantities
|
||||||
ingredients.each do |i|
|
inputs = ingredients.select { |i| nutrients[q.name][i.id].nil? }.map do |i|
|
||||||
next if !nutrients[q.name][i.id].nil?
|
[
|
||||||
inputs = input_q.map do |i_q|
|
i,
|
||||||
default_input = [nil, nil]
|
input_q.map do |i_q|
|
||||||
nutrient_data = (completed_q[i_q.name] || nutrients[i_q.name])[i.id]
|
nutrient_data = (completed_q[i_q.name] || nutrients[i_q.name])[i.id]
|
||||||
[i_q.name, (nutrient_data || [nil, nil])[0]]
|
[i_q.name, (nutrient_data || [nil, nil])[0]]
|
||||||
end
|
end.to_h
|
||||||
nutrients[q.name][i.id] = q.calculate(inputs)
|
]
|
||||||
end
|
end
|
||||||
|
q.calculate(inputs).each { |i, result| nutrients[q.name][i.id] = result }
|
||||||
unchecked_q.unshift([q, deps])
|
unchecked_q.unshift([q, deps])
|
||||||
else
|
else
|
||||||
unchecked_q << [q, deps]
|
unchecked_q << [q, deps]
|
||||||
|
@ -70,6 +70,6 @@ class Quantity < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def calculate(inputs)
|
def calculate(inputs)
|
||||||
[1.0, nil]
|
inputs.map { |i, values| [i, 1.0] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user