Sha256: 8a57989748ff9d09a9c9e4bf3a1d15e20df55054d2b6f5a91a98d9a8735f6058
Contents?: true
Size: 978 Bytes
Versions: 7
Compression:
Stored size: 978 Bytes
Contents
module SnowmanIO module Utils def self.floor_5sec(time) Time.new(time.year, time.month, time.day, time.hour, time.min, (time.sec/5)*5) end def self.floor_5min(time) Time.new(time.year, time.month, time.day, time.hour, (time.min/5)*5) end def self.avg(arr) if arr.empty? 0.0 else arr.inject(:+).to_f/arr.length end end # `up` value is close to 90 percentile by meaning, but it slightly # depends of every element (weighted avarage). This metric is especially usefull for small arrays. def self.up(arr) sorted = arr.sort if sorted.length <= 1 sorted[0] else sum = 0 amount = 0 sorted.each_with_index { |e, i| w = i.to_f/sorted.length if w <= 0.9 a = w + 0.1 else a = 1.9 - w end sum += e*a amount += a } sum/amount end end end end
Version data entries
7 entries across 7 versions & 1 rubygems