diff options
Diffstat (limited to 'app/controllers/dashboard_controller.rb')
-rw-r--r-- | app/controllers/dashboard_controller.rb | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 6f323a9..a315eda 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -10,10 +10,22 @@ class DashboardController < ApplicationController # @target = TargetNutrientCalculator.call # Measurement history table - # @measurements = NutrientMeasurement.order(measured_on: :desc).limit(10) + @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) - # @npk_measurement_data = measurement_data_series(:nno3, :p, :k) - # @ammonium_measurement_data = measurement_data_series(: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 @@ -35,13 +47,4 @@ class DashboardController < ApplicationController unassigned, assigned = data_series.partition { |s| s[:name].casecmp("unassigned").zero? } assigned + unassigned end - - def measurement_data_series(*nutrients) - nutrients.map do |formula| - { name: Nutrient.find_by!(formula:).name, - data: NutrientMeasurement - .order(:measured_on) - .pluck(:measured_on, formula) } - end - end end |