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? 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]

View File

@ -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