summaryrefslogtreecommitdiff
path: root/app/controllers/dashboard_controller.rb
diff options
context:
space:
mode:
authorMarius Peter <dev@marius-peter.com>2025-11-23 17:54:45 +0100
committerMarius Peter <dev@marius-peter.com>2025-11-23 17:54:45 +0100
commitfa77a691ce0cc8941fe470a762f352b27f4f0563 (patch)
tree08916174840a7896fc59633cc59fab931e7012c2 /app/controllers/dashboard_controller.rb
parent73283f2f5153c77f72b6a29e98f173628f5e1057 (diff)
Last commit.HEADmaster
Diffstat (limited to 'app/controllers/dashboard_controller.rb')
-rw-r--r--app/controllers/dashboard_controller.rb43
1 files changed, 2 insertions, 41 deletions
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index a315eda..fc8cbd8 100644
--- a/app/controllers/dashboard_controller.rb
+++ b/app/controllers/dashboard_controller.rb
@@ -1,50 +1,11 @@
class DashboardController < ApplicationController
def index
- # Raft allocation by crop type
- # @raft_data = raft_data_series
-
- @nutrient_profiles = NutrientProfile.order(:name)
-
- # Nutrient target table
- # @latest_measurement = NutrientMeasurement.order(measured_on: :desc, created_at: :desc).first
- # @target = TargetNutrientCalculator.call
+ @latest_measurement = NutrientMeasurement.order(measured_on: :desc).first
+ @latest_target = Target.order(created_at: :desc).first
# Measurement history table
@measurements = NutrientMeasurement.order(measured_on: :desc).limit(10)
@npk_measurement_data = NutrientMeasurement.data_series_for(:nno3, :p, :k)
@ammonium_measurement_data = NutrientMeasurement.data_series_for(:nnh4)
-
- @weighted = Target.first.weighted_requirements # => { "nno3"=>..., "p"=>..., ... }
-
- last = NutrientMeasurement.order(measured_on: :desc, created_at: :desc).first
- @latest_measurements = {}
-
- if last
- # Use the same keys as NutrientProfile to keep naming consistent.
- keys = (NutrientProfile::NUTRIENT_KEYS rescue []).map(&:to_s)
- keys.each do |k|
- @latest_measurements[k] = last.send(k) if last.respond_to?(k)
- end
- end
- end
-
- private
-
- def raft_data_series
- data_series = []
-
- counts = Raft.left_outer_joins(:crop)
- .group("crops.name", "crops.crop_type")
- .count
-
- counts.each do |(crop_name, crop_type), count|
- name = (crop_name || "unassigned").titleize
- type = (crop_type || "unassigned").titleize
- data = { type => count }
- data_series << { name:, data: }
- end
-
- unassigned, assigned = data_series.partition { |s| s[:name].casecmp("unassigned").zero? }
- assigned + unassigned
end
end
Copyright 2019--2026 Marius PETER