Complémentation

<%= link_to "Nouvelle cible", new_target_path, class: "btn btn-sm btn-primary" %> <%= link_to "Voir la recette", root_path, class: "btn btn-sm btn-secondary" %>
<% wr = @weighted || {} %> <% lm = @latest_measurements || {} %> <% keys = (wr.keys + lm.keys).map(&:to_s).uniq.sort %> <% keys.each do |nut| %> <% measured = lm[nut] %> <% target = wr[nut] %> <% delta = (measured.to_f - target.to_f) if measured || target %> <% end %>
Nutriment Relevé Cible Delta
<%= nut.upcase %> <% if measured.nil? %> <% else %> <%= number_with_precision(measured, precision: 2) %> <% end %> <% if target.nil? %> <% else %> <%= number_with_precision(target, precision: 2) %> <% end %> <% if measured.nil? && target.nil? %> <% else %> <% badge = if delta.nil? "text-bg-secondary" elsif delta.abs <= 0.01 "text-bg-success" elsif delta > 0 "text-bg-warning" else "text-bg-danger" end %> <%= number_with_precision(delta.to_f, precision: 2) %> <% end %>