Module: DmCore::Concerns::UserSiteProfile::ClassMethods

Defined in:
app/models/dm_core/concerns/user_site_profile.rb

Instance Method Summary collapse

Instance Method Details

#access_last_30_daysObject

Count the number of accessing users in the last 30 days. returns a hash with the total, and a json list of 15 values indicating how many were accessed every 2 days eg: { total: 35, list: “0,0,0,0,0,0,0,0,0,0,2,4,2,5,22” }




54
55
56
57
58
59
# File 'app/models/dm_core/concerns/user_site_profile.rb', line 54

def access_last_30_days
  items = 28.step(0, -2).map do |date| 
    where('last_access_at <= ? AND last_access_at > ? AND account_id = ?', date.days.ago.to_datetime, (date + 2).days.ago.to_datetime, Account.current.id).count
  end
  return { total: items.inject(:+), list: items.join(',') }
end

#new_last_30_daysObject

Count the number of new users in the last 30 days. returns a hash with the total, and a json list of 15 values indicating how many were created every 2 days eg: { total: 36, list: “0,0,0,0,0,0,0,0,0,2,13,10,6,1,4” }




42
43
44
45
46
47
# File 'app/models/dm_core/concerns/user_site_profile.rb', line 42

def new_last_30_days
  items = 28.step(0, -2).map do |date| 
    self.where('created_at <= ? AND created_at > ? AND account_id = ?', date.days.ago.to_datetime, (date + 2).days.ago.to_datetime, Account.current.id).count
  end
  return { total: items.inject(:+), list: items.join(',') }
end