Class: Snapstats::EventReader::Cpm

Inherits:
Object
  • Object
show all
Defined in:
lib/event_reader/event_reader.rb

Class Method Summary collapse

Class Method Details

.fetch_allObject



102
103
104
# File 'lib/event_reader/event_reader.rb', line 102

def self.fetch_all
	Snapstats.redis.hgetall(Snapstats.mday("cpm"))
end

.fetch_all_chartObject



118
119
120
# File 'lib/event_reader/event_reader.rb', line 118

def self.fetch_all_chart
	fetch_all.map{ |k, v| { date: k, value: v } }
end

.fetch_all_hashObject



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/event_reader/event_reader.rb', line 106

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