diff options
author | Marius Peter <dev@marius-peter.com> | 2025-09-08 21:21:56 +0200 |
---|---|---|
committer | Marius Peter <dev@marius-peter.com> | 2025-09-08 21:21:56 +0200 |
commit | 7116826b854188604e21e2a613ac6672b6fd81f3 (patch) | |
tree | 33150bf2e04e69b8e1fa7d37901d2643b1955534 /app/models/nutrient_measurement.rb | |
parent | 8ba568ae0ebe715b5da453681eb141886f1977a8 (diff) |
Create Target and nutrient target table on dashboard.
Diffstat (limited to 'app/models/nutrient_measurement.rb')
-rw-r--r-- | app/models/nutrient_measurement.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/models/nutrient_measurement.rb b/app/models/nutrient_measurement.rb index f1d6d5b..1139af7 100644 --- a/app/models/nutrient_measurement.rb +++ b/app/models/nutrient_measurement.rb @@ -1,4 +1,18 @@ class NutrientMeasurement < ApplicationRecord + NUTRIENT_FIELDS = %i[ + nno3 p k ca mg s na cl si fe zn b mn cu mo nnh4 + ].freeze + validates :measured_on, presence: true validates :measured_on, uniqueness: true + + def self.data_series_for(*nutrients) + nutrients.map do |formula| + { name: formula, data: self.order(:measured_on).pluck(:measured_on, formula) } + end + end + + def self.nutrient_fields + NUTRIENT_FIELDS + end end |