1
0

Aggregated quantity calculation for all ingredients

This commit is contained in:
cryptogopher 2019-11-06 22:58:07 +01:00
parent ce4d839a10
commit 304c8c788d
2 changed files with 10 additions and 9 deletions

View File

@ -66,15 +66,16 @@ class Ingredient < ActiveRecord::Base
if deps.empty?
input_q = q.formula_quantities
ingredients.each do |i|
next if !nutrients[q.name][i.id].nil?
inputs = input_q.map do |i_q|
default_input = [nil, nil]
nutrient_data = (completed_q[i_q.name] || nutrients[i_q.name])[i.id]
[i_q.name, (nutrient_data || [nil, nil])[0]]
end
nutrients[q.name][i.id] = q.calculate(inputs)
inputs = ingredients.select { |i| nutrients[q.name][i.id].nil? }.map do |i|
[
i,
input_q.map do |i_q|
nutrient_data = (completed_q[i_q.name] || nutrients[i_q.name])[i.id]
[i_q.name, (nutrient_data || [nil, nil])[0]]
end.to_h
]
end
q.calculate(inputs).each { |i, result| nutrients[q.name][i.id] = result }
unchecked_q.unshift([q, deps])
else
unchecked_q << [q, deps]

View File

@ -70,6 +70,6 @@ class Quantity < ActiveRecord::Base
end
def calculate(inputs)
[1.0, nil]
inputs.map { |i, values| [i, 1.0] }
end
end