Class: UserStats

Inherits:
ApplicationRecord show all
Defined in:
app/models/user_stats.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

active_between, aggregate_of, all_except, defaults, #delete, #destroy!, enum_prefixed_translations_for, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, teaser_on, #update_and_notify!, update_or_create!, whitelist_attributes, with_pg_retry, with_temporary_token

Methods included from WithPgLock

#with_pg_lock

Class Method Details

.exp_for(user) ⇒ Object



9
10
11
# File 'app/models/user_stats.rb', line 9

def self.exp_for(user)
  self.stats_for(user).exp
end

.stats_for(user) ⇒ Object



5
6
7
# File 'app/models/user_stats.rb', line 5

def self.stats_for(user)
  UserStats.find_or_initialize_by(user: user, organization: Organization.current)
end

Instance Method Details

#activity(date_range = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/user_stats.rb', line 13

def activity(date_range = nil)
  date_filter = { submitted_at: date_range }.compact
  {
      exercises: {
          solved_count: organization_exercises
                            .joins(:assignments)
                            .where(assignments: { top_submission_status: [:passed, :skipped], submitter: user, organization: organization }.merge(date_filter))
                            .count,
          count: organization_exercises.count
      },
      messages: messages_in_discussions_count(date_range)
  }
end

#add_exp!(points) ⇒ Object



27
28
29
# File 'app/models/user_stats.rb', line 27

def add_exp!(points)
  self.exp += points
end