From 69ef8fa74727ccab52528a5774bb489c54924e7f Mon Sep 17 00:00:00 2001 From: "Matt K. Fu" Date: Tue, 27 Aug 2013 13:48:52 +0800 Subject: [PATCH] fix dash broad counter --- lib/orbit_app/module/visitor_counter_eval.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/orbit_app/module/visitor_counter_eval.rb b/lib/orbit_app/module/visitor_counter_eval.rb index 6d952bc8f..9d1e30584 100644 --- a/lib/orbit_app/module/visitor_counter_eval.rb +++ b/lib/orbit_app/module/visitor_counter_eval.rb @@ -4,24 +4,33 @@ module OrbitApp Version = "0.1" def display_visitors(options={}) - impressions = Impression.where(options).and(:referrer.ne => nil).distinct(:session_hash).count + map = "function(){ emit( this.referrer,{session_hash: this.session_hash,created_at: this.created_at}); };" + reduce = "function(key, values){ var sum = 0; values.forEach(function(doc){sum += doc.amount; }); return {amount: sum};};" + if options.blank? + impressions = Impression.count #collection.map_reduce(map, reduce,read: :primary, out: "vr") + else + query = Impression.where(options).selector + impressions = Impression.where(options).collection.map_reduce(map, reduce,read: :primary, out: "vr",:query=>query) + end + impressions.count end def display_visitors_today - display_visitors(created_at: {'$gte' => Date.today.beginning_of_day, '$lte' => Date.today.end_of_day}) + display_visitors(created_at: {'$gte' => Date.today.beginning_of_day , '$lte' => DateTime.now}) end def display_visitors_this_week - display_visitors(created_at: {'$gte' => Date.today.beginning_of_week, '$lte' => Date.today.end_of_week}) + display_visitors(created_at: {'$gte' => Date.today.beginning_of_day - 7.days, '$lte' => DateTime.now}) end def display_visitors_this_month - display_visitors(created_at: {'$gte' => Date.today.beginning_of_month, '$lte' => Date.today.end_of_month}) + display_visitors(created_at: {'$gte' => Date.today.beginning_of_day - 1.month, '$lte' => DateTime.now}) end def display_visitors_this_year - display_visitors(created_at: {'$gte' => Date.today.beginning_of_year, '$lte' => Date.today.end_of_year}) + display_visitors(created_at: {'$gte' => Date.today.beginning_of_day - 1.year, '$lte' =>DateTime.now}) end end # end of VisitorCounterEval end # of Module end # of OrbitApp +