Class: ParticipantMetrics::WeeklyCount

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/participant_metrics/weekly_count.rb

Overview

Calculate weekly (by enrollment week) of records.

Direct Known Subclasses

WeeklyLoginsCount

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fetch(group_id) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/participant_metrics/weekly_count.rb', line 11

def self.fetch(group_id)
  pg_timezone = ActiveSupport::TimeZone[Time.zone.name].tzinfo.name

  joins(memberships: :participant)
    .select("      ( FLOOR ( EXTRACT ( EPOCH FROM (\n        ( \#{connection.quote_table_name(table_name)}.created_at\n          AT TIME ZONE 'UTC' ) AT TIME ZONE \#{connection.quote(pg_timezone)}\n        - memberships.start_date ) ) / 604800 ) + 1\n      )::int AS week, memberships.participant_id, COUNT(1)\n    SQL\n           )\n    .merge(Participant.not_moderator)\n    .merge(Membership.where(group_id: group_id))\n    .group(\"week, memberships.participant_id\")\nend\n"

Instance Method Details

#countObject



36
37
38
# File 'app/models/participant_metrics/weekly_count.rb', line 36

def count
  attributes["count"]
end

#participant_idObject



32
33
34
# File 'app/models/participant_metrics/weekly_count.rb', line 32

def participant_id
  attributes["participant_id"]
end

#weekObject



28
29
30
# File 'app/models/participant_metrics/weekly_count.rb', line 28

def week
  attributes["week"]
end