summaryrefslogtreecommitdiff
path: root/app/helpers/nutrients_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/nutrients_helper.rb')
-rw-r--r--app/helpers/nutrients_helper.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/helpers/nutrients_helper.rb b/app/helpers/nutrients_helper.rb
new file mode 100644
index 0000000..de98dc3
--- /dev/null
+++ b/app/helpers/nutrients_helper.rb
@@ -0,0 +1,21 @@
+module NutrientsHelper
+ NUTRIENTS = %i[nno3 p k ca mg s na cl si fe zn b mn cu mo nnh4].freeze
+
+ def percent_delta(measured, target)
+ return 0.0 if target.to_f.zero?
+ ((measured.to_f - target.to_f) / target.to_f) * 100.0
+ end
+
+ def fmt(v)
+ number_with_precision(v, precision: 2, strip_insignificant_zeros: true)
+ end
+
+ def delta_badge_class(delta)
+ d = delta.abs
+ case d
+ when d < 0 then "bg-info"
+ when 0..5 then "bg-secondary"
+ else "bg-warning"
+ end
+ end
+end
Copyright 2019--2025 Marius PETER