Class: Snapstats::EventReader::Activity
- Inherits:
-
Object
- Object
- Snapstats::EventReader::Activity
- Extended by:
- EventReaderHelpers
- Defined in:
- lib/event_reader/event_reader.rb
Class Method Summary collapse
- .fetch(from = 0, to = Time.now) ⇒ Object
- .fetch_all_chart ⇒ Object
- .fetch_all_chart_scale(aprx = 5) ⇒ Object
- .fetch_flat_chart(aprx = 5) ⇒ Object
Methods included from EventReaderHelpers
Class Method Details
.fetch(from = 0, to = Time.now) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/event_reader/event_reader.rb', line 21 def self.fetch from=0, to=Time.now Snapstats.redis.zrangebyscore(Snapstats.mday("activity"), from.to_i, to.to_i).map do |i| v = JSON.parse(i, :symbolize_names => true) self.new(email: v[:email], path: v[:path], controller: v[:ctrl], action: v[:actn], runtimes: v[:rntm], os: v[:os], browser: v[:brwsr], version: v[:brver], ip: v[:ip], render_time: v[:total], date: Time.at(v[:date].to_i)) end end |
.fetch_all_chart ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/event_reader/event_reader.rb', line 39 def self.fetch_all_chart # after 5 minutes i forgot how it works fetch(Time.now.beginning_of_day).map{ |i| i.runtimes.reduce({}){ |sum, (k,v)| sum[k] = { value: v, date: i.date.to_i }; sum } }.reduce({}){ |sum, i| i.keys.each{ |rt| sum[rt].present? ? sum[rt] << i[rt] : sum[rt] = [ i[rt] ] } sum } end |
.fetch_all_chart_scale(aprx = 5) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/event_reader/event_reader.rb', line 54 def self.fetch_all_chart_scale aprx=5 charts = fetch_all_chart charts.keys.each { |runtime| charts[runtime] = charts[runtime].group_by{ |i| floor_time(i[:date].to_i, aprx.minutes) }.map{|k,v| { :date => k, :value => v.max_by{|i| i[:value]}[:value] }} } charts end |
.fetch_flat_chart(aprx = 5) ⇒ Object
64 65 66 |
# File 'lib/event_reader/event_reader.rb', line 64 def self.fetch_flat_chart aprx=5 fetch(Time.now.beginning_of_day).group_by{ |i| floor_time(i[:date].to_i, aprx.minutes) }.map{|k,v| { :date => k, :value => v.max_by{|i| i.render_time.to_f }.render_time }}#.map{ |i| { date: i.date.to_i, value: i.render_time } } end |