Sha256: 54de5f182d6debb706449c70cb7de2cc61be1ab43f12377ec899bda58cf858cf
Contents?: true
Size: 1.1 KB
Versions: 13
Compression:
Stored size: 1.1 KB
Contents
# frozen_string_literal: true 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
13 entries across 13 versions & 1 rubygems