Class: Pathways::Session
- Inherits:
-
Object
- Object
- Pathways::Session
- Includes:
- MongoMapper::Document
- Defined in:
- lib/pathways/session.rb
Class Method Summary collapse
- .controller_map ⇒ Object
- .controller_reduce ⇒ Object
- .find_by_path(path, opts = {}) ⇒ Object
- .finder_build(opts = {}) ⇒ Object
-
.path_map ⇒ Object
Other stuff…
- .path_reduce ⇒ Object
- .popular_pages(opts = {}) ⇒ Object
Class Method Details
.controller_map ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pathways/session.rb', line 41 def self.controller_map <<-MAP function() { id = this.ip this.visits.forEach(function(visit) { emit(visit.controller + ":" + visit.action, { id: visit.session_id }); }); } MAP end |
.controller_reduce ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pathways/session.rb', line 52 def self.controller_reduce <<-REDUCE function(key, values) { var sum = new Array(); values.forEach(function(f) { sum.push(f.id); }); return { sessions: sum}; }; REDUCE end |
.find_by_path(path, opts = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/pathways/session.rb', line 73 def self.find_by_path(path,opts={}) opts.merge!({ :out => {:inline => true}, :raw => true }) results = self.finder_build(opts).find() sessions = [] results.to_a.first.last.each do | result | id = result["_id"] next unless id == path sessions = Pathways::Session.find_all_by_id(result["value"]["sessions"].try(:uniq)) end return sessions end |
.finder_build(opts = {}) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/pathways/session.rb', line 65 def self.finder_build(opts={}) if opts[:filter] == "controller_action" self.collection.map_reduce(self.controller_map, self.controller_reduce, opts) else self.collection.map_reduce(self.path_map, self.path_reduce, opts) end end |
.path_map ⇒ Object
Other stuff…
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pathways/session.rb', line 18 def self.path_map <<-MAP function() { id = this.ip this.visits.forEach(function(visit) { emit(visit.path, { id: visit.session_id }); }); } MAP end |
.path_reduce ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pathways/session.rb', line 29 def self.path_reduce <<-REDUCE function(key, values) { var sum = new Array(); values.forEach(function(f) { sum.push(f.id); }); return { sessions: sum}; }; REDUCE end |
.popular_pages(opts = {}) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/pathways/session.rb', line 88 def self.popular_pages(opts={}) opts.merge!({ :out => {:inline => true}, :raw => true }) results = self.finder_build(opts).find() pages = {} results.to_a.first.last.each do | result | id = result["_id"] sessions = result["value"]["sessions"].try(:uniq) next if sessions.nil? pages[id] = sessions end return pages.sort_by{|k,v|-v.size} end |