Sha256: d44236ca3496708af29bebe5bbfaf8bc094b169e52bfe5d8b3341179585fb410
Contents?: true
Size: 1.06 KB
Versions: 7
Compression:
Stored size: 1.06 KB
Contents
module ParticipantMetrics # Calculate weekly (by enrollment week) of records. 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, memberships.participant_id, COUNT(1) SQL ) .merge(Participant.not_moderator) .merge(Membership.where(group_id: group_id)) .group("week, memberships.participant_id") end def week attributes["week"] end def participant_id attributes["participant_id"] end def count attributes["count"] end end end
Version data entries
7 entries across 7 versions & 1 rubygems