Skip to content

Instantly share code, notes, and snippets.

@pupca
Created December 8, 2010 10:55
Show Gist options
  • Save pupca/733141 to your computer and use it in GitHub Desktop.
Save pupca/733141 to your computer and use it in GitHub Desktop.
# == Schema Information
#
# Table name: person_login_logs
#
# id :integer(4) not null, primary key
# person_id :integer(4)
# login :datetime
# logout :datetime
# created_at :datetime
# updated_at :datetime
#
# Indexes
#
# index_person_login_logs_on_person_id (person_id)
#
class PersonLoginLog < ActiveRecord::Base
belongs_to :person
def self.logged_at_least_x_times_and_one_of_the_login_was_in_last_y_days(x,y)
count = 0
all.group_by{|g| g.person_id}.each do |id,logs|
count += 1 if logs.size >= x && logs.last.login >= y.days.ago
end
puts count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment