From a950a904541618be3be24d9cff83b18831fc99cd Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Mon, 7 Dec 2020 11:48:23 -0500 Subject: [PATCH 1/3] Avoid direct float comparisons with 0.0. --- app/models/storage.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/storage.rb b/app/models/storage.rb index c75768bab78..32cba0940c1 100644 --- a/app/models/storage.rb +++ b/app/models/storage.rb @@ -581,12 +581,12 @@ def used_space alias_method :v_used_space, :used_space def used_space_percent_of_total - total_space.to_f == 0.0 ? 0.0 : (used_space.to_f / total_space.to_f * 1000.0).round / 10.0 + total_space.to_f.zero? ? 0.0 : (used_space.to_f / total_space.to_f * 1000.0).round / 10.0 end alias_method :v_used_space_percent_of_total, :used_space_percent_of_total def free_space_percent_of_total - total_space.to_f == 0.0 ? 0.0 : (free_space.to_f / total_space.to_f * 1000.0).round / 10.0 + total_space.to_f.zero? ? 0.0 : (free_space.to_f / total_space.to_f * 1000.0).round / 10.0 end alias_method :v_free_space_percent_of_total, :free_space_percent_of_total @@ -618,23 +618,23 @@ def v_total_vms alias_method :v_total_disk_size, :disk_size def v_debris_percent_of_used - used_space.to_f == 0.0 ? 0.0 : (debris_size.to_f / used_space.to_f * 1000.0).round / 10.0 + used_space.to_f.zero? ? 0.0 : (debris_size.to_f / used_space.to_f * 1000.0).round / 10.0 end def v_snapshot_percent_of_used - used_space.to_f == 0.0 ? 0.0 : (snapshot_size.to_f / used_space.to_f * 1000.0).round / 10.0 + used_space.to_f.zero? ? 0.0 : (snapshot_size.to_f / used_space.to_f * 1000.0).round / 10.0 end def v_memory_percent_of_used - used_space.to_f == 0.0 ? 0.0 : (vm_ram_size.to_f / used_space.to_f * 1000.0).round / 10.0 + used_space.to_f.zero? ? 0.0 : (vm_ram_size.to_f / used_space.to_f * 1000.0).round / 10.0 end def v_vm_misc_percent_of_used - used_space.to_f == 0.0 ? 0.0 : (vm_misc_size.to_f / used_space.to_f * 1000.0).round / 10.0 + used_space.to_f.zero? ? 0.0 : (vm_misc_size.to_f / used_space.to_f * 1000.0).round / 10.0 end def v_disk_percent_of_used - used_space.to_f == 0.0 ? 0.0 : (disk_size.to_f / used_space.to_f * 1000.0).round / 10.0 + used_space.to_f.zero? ? 0.0 : (disk_size.to_f / used_space.to_f * 1000.0).round / 10.0 end def v_total_provisioned @@ -642,7 +642,7 @@ def v_total_provisioned end def v_provisioned_percent_of_total - total_space.to_f == 0 ? 0.0 : (v_total_provisioned.to_f / total_space.to_f * 1000.0).round / 10.0 + total_space.to_f.zero? ? 0.0 : (v_total_provisioned.to_f / total_space.to_f * 1000.0).round / 10.0 end # From a6f2bfc3dff69b15642840d80ef2dfe551209aa5 Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Mon, 7 Dec 2020 13:24:19 -0500 Subject: [PATCH 2/3] Fix Style/FloatDivision warnings. --- app/models/storage.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/storage.rb b/app/models/storage.rb index 32cba0940c1..6a6203540b3 100644 --- a/app/models/storage.rb +++ b/app/models/storage.rb @@ -581,12 +581,12 @@ def used_space alias_method :v_used_space, :used_space def used_space_percent_of_total - total_space.to_f.zero? ? 0.0 : (used_space.to_f / total_space.to_f * 1000.0).round / 10.0 + total_space.to_f.zero? ? 0.0 : (used_space.to_f / total_space * 1000.0).round / 10.0 end alias_method :v_used_space_percent_of_total, :used_space_percent_of_total def free_space_percent_of_total - total_space.to_f.zero? ? 0.0 : (free_space.to_f / total_space.to_f * 1000.0).round / 10.0 + total_space.to_f.zero? ? 0.0 : (free_space.to_f / total_space * 1000.0).round / 10.0 end alias_method :v_free_space_percent_of_total, :free_space_percent_of_total @@ -618,23 +618,23 @@ def v_total_vms alias_method :v_total_disk_size, :disk_size def v_debris_percent_of_used - used_space.to_f.zero? ? 0.0 : (debris_size.to_f / used_space.to_f * 1000.0).round / 10.0 + used_space.to_f.zero? ? 0.0 : (debris_size.to_f / used_space * 1000.0).round / 10.0 end def v_snapshot_percent_of_used - used_space.to_f.zero? ? 0.0 : (snapshot_size.to_f / used_space.to_f * 1000.0).round / 10.0 + used_space.to_f.zero? ? 0.0 : (snapshot_size.to_f / used_space * 1000.0).round / 10.0 end def v_memory_percent_of_used - used_space.to_f.zero? ? 0.0 : (vm_ram_size.to_f / used_space.to_f * 1000.0).round / 10.0 + used_space.to_f.zero? ? 0.0 : (vm_ram_size.to_f / used_space * 1000.0).round / 10.0 end def v_vm_misc_percent_of_used - used_space.to_f.zero? ? 0.0 : (vm_misc_size.to_f / used_space.to_f * 1000.0).round / 10.0 + used_space.to_f.zero? ? 0.0 : (vm_misc_size.to_f / used_space * 1000.0).round / 10.0 end def v_disk_percent_of_used - used_space.to_f.zero? ? 0.0 : (disk_size.to_f / used_space.to_f * 1000.0).round / 10.0 + used_space.to_f.zero? ? 0.0 : (disk_size.to_f / used_space * 1000.0).round / 10.0 end def v_total_provisioned @@ -642,7 +642,7 @@ def v_total_provisioned end def v_provisioned_percent_of_total - total_space.to_f.zero? ? 0.0 : (v_total_provisioned.to_f / total_space.to_f * 1000.0).round / 10.0 + total_space.to_f.zero? ? 0.0 : (v_total_provisioned.to_f / total_space * 1000.0).round / 10.0 end # From 1b76d191843d09ae8df9715343150a1ccea6ca31 Mon Sep 17 00:00:00 2001 From: Daniel Berger Date: Wed, 6 Jan 2021 11:20:52 -0500 Subject: [PATCH 3/3] Remove unnecessary .to_f calls. --- app/models/storage.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/storage.rb b/app/models/storage.rb index 6a6203540b3..953e8b51f87 100644 --- a/app/models/storage.rb +++ b/app/models/storage.rb @@ -581,12 +581,12 @@ def used_space alias_method :v_used_space, :used_space def used_space_percent_of_total - total_space.to_f.zero? ? 0.0 : (used_space.to_f / total_space * 1000.0).round / 10.0 + total_space.zero? ? 0.0 : (used_space.to_f / total_space * 1000.0).round / 10.0 end alias_method :v_used_space_percent_of_total, :used_space_percent_of_total def free_space_percent_of_total - total_space.to_f.zero? ? 0.0 : (free_space.to_f / total_space * 1000.0).round / 10.0 + total_space.zero? ? 0.0 : (free_space.to_f / total_space * 1000.0).round / 10.0 end alias_method :v_free_space_percent_of_total, :free_space_percent_of_total @@ -618,23 +618,23 @@ def v_total_vms alias_method :v_total_disk_size, :disk_size def v_debris_percent_of_used - used_space.to_f.zero? ? 0.0 : (debris_size.to_f / used_space * 1000.0).round / 10.0 + used_space.zero? ? 0.0 : (debris_size.to_f / used_space * 1000.0).round / 10.0 end def v_snapshot_percent_of_used - used_space.to_f.zero? ? 0.0 : (snapshot_size.to_f / used_space * 1000.0).round / 10.0 + used_space.zero? ? 0.0 : (snapshot_size.to_f / used_space * 1000.0).round / 10.0 end def v_memory_percent_of_used - used_space.to_f.zero? ? 0.0 : (vm_ram_size.to_f / used_space * 1000.0).round / 10.0 + used_space.zero? ? 0.0 : (vm_ram_size.to_f / used_space * 1000.0).round / 10.0 end def v_vm_misc_percent_of_used - used_space.to_f.zero? ? 0.0 : (vm_misc_size.to_f / used_space * 1000.0).round / 10.0 + used_space.zero? ? 0.0 : (vm_misc_size.to_f / used_space * 1000.0).round / 10.0 end def v_disk_percent_of_used - used_space.to_f.zero? ? 0.0 : (disk_size.to_f / used_space * 1000.0).round / 10.0 + used_space.zero? ? 0.0 : (disk_size.to_f / used_space * 1000.0).round / 10.0 end def v_total_provisioned @@ -642,7 +642,7 @@ def v_total_provisioned end def v_provisioned_percent_of_total - total_space.to_f.zero? ? 0.0 : (v_total_provisioned.to_f / total_space * 1000.0).round / 10.0 + total_space.zero? ? 0.0 : (v_total_provisioned.to_f / total_space * 1000.0).round / 10.0 end #