Created
December 8, 2010 10:55
-
-
Save pupca/733141 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == 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