Class: Snapstats::EventReader::Cpm
- Inherits:
-
Object
- Object
- Snapstats::EventReader::Cpm
- Extended by:
- EventReaderHelpers
- Defined in:
- lib/event_reader/event_reader.rb
Class Method Summary collapse
Methods included from EventReaderHelpers
Class Method Details
.fetch_all ⇒ Object
117 118 119 |
# File 'lib/event_reader/event_reader.rb', line 117 def self.fetch_all Snapstats.redis.hgetall(Snapstats.mday("cpm")) end |
.fetch_all_chart(aprx = 10) ⇒ Object
133 134 135 |
# File 'lib/event_reader/event_reader.rb', line 133 def self.fetch_all_chart aprx=10 fetch_all.group_by{|k, v| floor_time(k.to_i, aprx.minutes) }.reduce({}){ |sum, (k,v)| sum[k] = v.reduce(0){|s, i| s += i.last.to_i }; sum }.map{ |k, v| { date: k, value: v } } end |
.fetch_all_hash ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/event_reader/event_reader.rb', line 121 def self.fetch_all_hash data = Snapstats.redis.hgetall(Snapstats.mday("cpm")) cpm = data[Time.now.beginning_of_minute.to_i.to_s] || 0 cpd = data.values.reduce(0){ |sum, i| sum + i.to_i } # cph = data.group_by{ |k, v| Time.at(k.to_i).beginning_of_hour }.reduce({}){|sum, (k, v)| sum[k] = v.map{|i| i.last.to_i}.reduce(:+); sum } # cph = cph.values.reduce(:+) / cph.keys.count { cpm: cpm, cph: 0, cpd: cpd } end |