From 85ac329894624031fc1a6fadfbc6d806272f5373 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 24 Feb 2015 09:26:50 -0800 Subject: [PATCH] (QENG-1873) Fix /0 Error Calculate total count before trying to use it in average calculation. --- lib/vmpooler/api.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/vmpooler/api.rb b/lib/vmpooler/api.rb index 9ce012c..96306f2 100644 --- a/lib/vmpooler/api.rb +++ b/lib/vmpooler/api.rb @@ -309,12 +309,15 @@ module Vmpooler # again, calc clone_average if we had clones. unless total_clones_per_day.nil? or total_clones_per_day.length == 0 + # totals + result[:clone][:count][:total] = total_clones_per_day.reduce(:+).to_i + result[:clone][:duration][:total] = total_clone_dur_day.reduce(:+).to_f + + # averages and other things. result[:clone][:duration][:average] = result[:clone][:duration][:total] / result[:clone][:count][:total] result[:clone][:duration][:min], result[:clone][:duration][:max] = min_max_clone_times.minmax - result[:clone][:duration][:total] = total_clone_dur_day.reduce(:+).to_f result[:clone][:count][:min], result[:clone][:count][:max] = total_clones_per_day.minmax result[:clone][:count][:average] = mean(total_clones_per_day) - result[:clone][:count][:total] = total_clones_per_day.reduce(:+).to_i end content_type :json