diff options
author | Marius Peter <dev@marius-peter.com> | 2025-09-04 20:55:03 +0200 |
---|---|---|
committer | Marius Peter <dev@marius-peter.com> | 2025-09-04 20:55:03 +0200 |
commit | 8ba568ae0ebe715b5da453681eb141886f1977a8 (patch) | |
tree | 3bf3a3d5b41286d0a6da8895857314393bae1db2 /app/services/target_nutrient_calculator.rb | |
parent | 8f8cea2a0408918629dc8bab03495530861a71f3 (diff) |
Start small, address critical customer needs, /then/ scale.
Diffstat (limited to 'app/services/target_nutrient_calculator.rb')
-rw-r--r-- | app/services/target_nutrient_calculator.rb | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/app/services/target_nutrient_calculator.rb b/app/services/target_nutrient_calculator.rb deleted file mode 100644 index e6cd378..0000000 --- a/app/services/target_nutrient_calculator.rb +++ /dev/null @@ -1,33 +0,0 @@ -class TargetNutrientCalculator - # Derive nutrient columns from the NutrientMeasurement table - NUTRIENT_COLUMNS = (NutrientMeasurement.column_names - %w[id measured_on created_at updated_at]) - .map!(&:to_sym) - .freeze - - # Returns an unsaved NutrientMeasurement with target concentrations (e.g., mg/L) - def self.call - rafts = Raft.includes(:crop).where.not(crop_id: nil) - total = rafts.count - return empty_measurement if total.zero? - - sums = Hash.new(0.0) - - rafts.each do |raft| - NUTRIENT_COLUMNS.each do |col| - v = raft.crop.public_send(col) - sums[col] += v.to_f if v - end - end - - targets = sums.transform_values { |s| s / total } - NutrientMeasurement.new({ measured_on: Date.current }.merge(targets)) - end - - private - - def empty_measurement - NutrientMeasurement.new( - { measured_on: Date.current }.merge(NUTRIENT_COLUMNS.index_with { 0.0 }) - ) - end -end |