Skip to content

Commit

Permalink
Added defaults to 0 when values are nil or NaN in inspections. Should f…
Browse files Browse the repository at this point in the history
…ix #1098.
  • Loading branch information
Aquaj committed Sep 20, 2016
1 parent 9a7e6e9 commit a970bd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 2 additions & 3 deletions app/models/inspection_calibration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ def marketable?

[[:items_count, :items, [:unity, :hectare, :unity_per_hectare]], [:net_mass, :mass, [:kilogram, :square_meter, :kilogram_per_square_meter]]].each do |long_name, short_name, unit|
define_method "marketable_#{long_name}" do
if inspection.send("unmarketable_#{short_name}_rate")
send("total_#{long_name}") * (1 - inspection.send("unmarketable_#{short_name}_rate"))
end
return 0.in(unit.first) unless inspection.send("unmarketable_#{short_name}_rate")
send("total_#{long_name}") * (1 - inspection.send("unmarketable_#{short_name}_rate"))
end

define_method "marketable_#{short_name}_yield" do
Expand Down
6 changes: 4 additions & 2 deletions app/models/inspection_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ class InspectionPoint < Ekylibre::Record::Base
scope :unmarketable, -> { where(nature_id: ActivityInspectionPointNature.unmarketable) }

def net_mass_percentage
(100 * (net_mass_in_unit / inspection.net_mass))
ratio = (net_mass_in_unit / inspection.net_mass)
100 * (ratio.nan? ? 0 : ratio)
end

def items_count_percentage
(100 * (items_count_in_unit / inspection.items_count))
ratio = (items_count_in_unit / inspection.items_count)
100 * (ratio.nan? ? 0 : ratio)
end
end

0 comments on commit a970bd0

Please sign in to comment.