This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
2013-04-24 11:21:11 +00:00
|
|
|
class DashboardCounter < Resque::Plugins::RestrictionJob
|
|
|
|
@queue = :high
|
|
|
|
|
|
|
|
def self.perform(*args)
|
|
|
|
site = Site.first
|
|
|
|
obj = new(*args)
|
|
|
|
site.dashboard_counter[:visitors_this_week] = obj.display_visitors_this_week
|
|
|
|
site.dashboard_counter[:visitors_this_month] = obj.display_visitors_this_month
|
|
|
|
site.dashboard_counter[:visitors_this_year] = obj.display_visitors_this_year
|
|
|
|
site.save
|
2013-05-14 02:29:11 +00:00
|
|
|
OrbitLogger.info "DashboardCounter done #{site.dashboard_counter.to_s}"
|
2013-04-24 11:21:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def display_visitors(options={})
|
|
|
|
impressions = Impression.where(options).and(:referrer.ne => nil)
|
|
|
|
impressions.map{|i| i[:session_hash]}.uniq.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_visitors_today
|
|
|
|
display_visitors(created_at: {'$gte' => Date.today.beginning_of_day, '$lte' => Date.today.end_of_day})
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_visitors_this_week
|
|
|
|
display_visitors(created_at: {'$gte' => Date.today.beginning_of_week, '$lte' => Date.today.end_of_week})
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_visitors_this_month
|
|
|
|
display_visitors(created_at: {'$gte' => Date.today.beginning_of_month, '$lte' => Date.today.end_of_month})
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_visitors_this_year
|
|
|
|
display_visitors(created_at: {'$gte' => Date.today.beginning_of_year, '$lte' => Date.today.end_of_year})
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|