Permalink
Browse files

Added Min and Max

  • Loading branch information...
1 parent e64a068 commit bf9ff776762582bb73b6926d42340ea43875ee4b antirez committed Mar 11, 2011
Showing with 5 additions and 1 deletion.
  1. +5 −1 redis-sampler.rb
View
6 redis-sampler.rb
@@ -112,12 +112,15 @@ def render_freq_table(title,hash)
def compute_avg(hash)
# Compute average
+ min = max = nil
avg = 0
items = 0
hash.each{|k,v|
next if k == 'unknown'
avg += k*v
items += v
+ min = k if !min or min > k
+ max = k if !max or max < k
}
avg /= items.to_f
# Compute standard deviation
@@ -127,13 +130,14 @@ def compute_avg(hash)
stddev += ((k-avg)**2)*v
}
stddev = Math.sqrt(stddev/items.to_f)
- return {:avg => avg, :stddev => stddev}
+ return {:avg => avg, :stddev => stddev, :min => min, :max => max}
end
def render_avg(hash)
data = compute_avg(hash)
printf "Average: %.2f Standard Deviation: %.2f",data[:avg],data[:stddev]
puts ""
+ puts "Min: #{data[:min]} Max: #{data[:max]}"
end
def stats

0 comments on commit bf9ff77

Please sign in to comment.