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