| Class | Stats |
| In: |
app/models/stats.rb
|
| Parent: | Object |
| DRB | = | 'http://localhost:5984/ilog2' |
# File app/models/stats.rb, line 32
32: def self.last_googles
33: dbr=CouchRest.database(Stats::DRB)
34: googles = []
35: begin
36: ag=dbr.view('select/extref', { :descending => true,
37: :limit => 10,
38: :endkey => [2010, 1, 1, 0, 0] })
39: rescue => err
40: ActiveRecord::Base.logger.error "Could not get data form CouchDB: #{err}"
41: googles << "No hay conexion con la base de datos"
42: else
43: ag['rows'].each do |r|
44: # pp r['key'], r['value']
45: referer = r['value']
46: isgoogle = Regexp.compile(/\.google\./)
47: if /\.google\./ =~ referer then
48: sterms0 = referer.gsub(/.*?[&?]q=([^&]+)&?.*$/, '\1')
49: sterms = CGI.unescape(sterms0)
50: # puts referer
51: googles << sterms
52: # puts "---"
53: end
54: end
55: end
56: return googles
57: end
# File app/models/stats.rb, line 89
89: def self.last_ips_counter
90: dbr=CouchRest.database(Stats::DRB)
91: ips = Hash.new(0)
92: begin
93: ag=dbr.view('counter/ips', { :descending => true,
94: :limit => 10000,
95: :group => true,
96: :endkey => [Time.now.year, Time.now.month, Time.now.day, Time.now.hour, Time.now.min-5, "" ] })
97: rescue => err
98: ActiveRecord::Base.logger.error "Could not get data form CouchDB: #{err}"
99: else
100: ag['rows'].each do |r|
101: ip = r['key'][5]
102: ips[ip] += 1
103: end
104: end
105: return ips.size
106: end
# File app/models/stats.rb, line 5
5: def self.last_referers(since_hours)
6: dbr=CouchRest.database(Stats::DRB)
7:
8: refs=Hash.new(0)
9: begin
10: ag=dbr.view('select/extref', { :descending => true,
11: :limit => 10000,
12: :endkey => [Time.now.year, Time.now.month, Time.now.day, Time.now.hour-since_hours, 0] })
13: rescue => err
14: ActiveRecord::Base.logger.error "Could not get data form CouchDB: #{err}"
15: refs["No hay conexión con la base de datos"] = 0
16: else
17: ag['rows'].each do |r|
18: # p r['key'], r['value']
19: referer = r['value']
20: isgoogle = Regexp.compile(/\.google\./)
21: if !(/\.google\./ =~ referer) then
22: # site = referer.gsub(/http:\/\/([^\/]+)\/.*$/, '\1')
23: # puts referer, site
24: refs[referer]+=1
25: end
26: end
27: end
28: referers = refs.sort {|a,b| b[1] <=> a[1]}[0..9]
29: end
# File app/models/stats.rb, line 60
60: def self.top_pages(since_hours)
61: dbr=CouchRest.database(Stats::DRB)
62: # the most recent, back to :endkey
63: totv=Hash.new(0)
64: begin
65: ag=dbr.view('counter/pages', { :descending => true,
66: :limit => 10000,
67: :endkey => [Time.now.year, Time.now.month, Time.now.day, Time.now.hour-since_hours, ''],
68: :group => true })
69: rescue => err
70: ActiveRecord::Base.logger.error "Could not get data form CouchDB: #{err}"
71: totv["No hay conexión con la base de datos"] = ""
72: else
73: ag['rows'].each do |r|
74: # pp r['key'], r['value']
75: path = r['key'][4]
76: ntimes = r['value']
77: if !( (/news\/image/ =~ path) ||
78: (/news\/photo/ =~ path) ||
79: (/site\/change_locale/ =~ path) ||
80: (/site\/search/ =~ path) ) then
81: # pp path, ntimes
82: totv[path] += ntimes
83: end
84: end
85: end
86: topp = totv.sort {|a,b| b[1] <=> a[1]}[0..9]
87: end