Class: GroupMetrics::WeeklyCount
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- GroupMetrics::WeeklyCount
show all
- Defined in:
- app/models/group_metrics/weekly_count.rb
Overview
Tabulate count of records (within a study week) for a Group.
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.fetch(group_id) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/models/group_metrics/weekly_count.rb', line 10
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, COUNT(1)\n SQL\n )\n .merge(Participant.not_moderator)\n .merge(Membership.where(group_id: group_id))\n .group(:week)\nend\n"
|
Instance Method Details
#count ⇒ Object
31
32
33
|
# File 'app/models/group_metrics/weekly_count.rb', line 31
def count
attributes["count"]
end
|
#week ⇒ Object
27
28
29
|
# File 'app/models/group_metrics/weekly_count.rb', line 27
def week
attributes["week"]
end
|