# == Schema Information # # Table name: statistics # # id :integer not null, primary key # dau :integer # created_at :datetime not null # updated_at :datetime not null # wau :integer # mau :integer # class Statistic < ApplicationRecord def self.record users = User.all count = 0 t = Time.now - 1.day # t = Time.now.at_beginning_of_day users.each do |u| if !u.last_login_on.nil? && u.last_login_on >= t count += 1 end end Statistic.create(dau: count) end end