blob: de98dc3bcfc4d51334d8fc879798263e22e6ece3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
|