Sha256: c493d604254d838f7cd7534abad6d60a829b8c29172e4679218a3f2a1c94a953
Contents?: true
Size: 971 Bytes
Versions: 7
Compression:
Stored size: 971 Bytes
Contents
module GroupMetrics # Tabulate count of records (within a study week) for a Group. class WeeklyCount < ActiveRecord::Base self.abstract_class = true has_many :memberships, foreign_key: :participant_id, primary_key: :participant_id def self.fetch(group_id) pg_timezone = ActiveSupport::TimeZone[Time.zone.name].tzinfo.name joins(memberships: :participant) .select(<<-SQL ( FLOOR ( EXTRACT ( EPOCH FROM ( ( #{connection.quote_table_name(table_name)}.created_at AT TIME ZONE 'UTC' ) AT TIME ZONE #{connection.quote(pg_timezone)} - memberships.start_date ) ) / 604800 ) + 1 )::int AS week, COUNT(1) SQL ) .merge(Participant.not_moderator) .merge(Membership.where(group_id: group_id)) .group(:week) end def week attributes["week"] end def count attributes["count"] end end end
Version data entries
7 entries across 7 versions & 1 rubygems