Sha256: 8a6174ae0c97ee1a04ee2f29d466bac454b2b85bc9af2d0bbbbc54e846189090

Contents?: true

Size: 948 Bytes

Versions: 62

Compression:

Stored size: 948 Bytes

Contents

module Workarea
  module Metrics
    module ByWeek
      extend ActiveSupport::Concern
      include ApplicationDocument
      include Scoring

      included do
        store_in client: :metrics

        field :reporting_on, type: Time, default: -> { Time.current }

        index({ reporting_on: 1 }, { expire_after_seconds: 2.years.seconds.to_i })

        scope :last_week, -> do
          where(
            :reporting_on.gte => Time.current.last_week,
            :reporting_on.lt => Time.current.last_week.end_of_week
          )
        end
      end

      module ClassMethods
        def append!(scope)
          per_page = Workarea.config.insights_aggregation_per_page
          pages = scope.page(1).per(per_page).total_pages

          pages.times do |page|
            models = scope.page(page + 1).per(per_page).to_a
            collection.insert_many(models.map(&:as_document))
          end
        end
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/metrics/by_week.rb
workarea-core-3.5.26 app/models/workarea/metrics/by_week.rb
workarea-core-3.4.45 app/models/workarea/metrics/by_week.rb
workarea-core-3.5.25 app/models/workarea/metrics/by_week.rb
workarea-core-3.5.23 app/models/workarea/metrics/by_week.rb
workarea-core-3.4.44 app/models/workarea/metrics/by_week.rb
workarea-core-3.5.22 app/models/workarea/metrics/by_week.rb
workarea-core-3.4.43 app/models/workarea/metrics/by_week.rb
workarea-core-3.5.21 app/models/workarea/metrics/by_week.rb
workarea-core-3.4.42 app/models/workarea/metrics/by_week.rb
workarea-core-3.5.20 app/models/workarea/metrics/by_week.rb
workarea-core-3.4.41 app/models/workarea/metrics/by_week.rb
workarea-core-3.5.19 app/models/workarea/metrics/by_week.rb
workarea-core-3.4.40 app/models/workarea/metrics/by_week.rb
workarea-core-3.5.18 app/models/workarea/metrics/by_week.rb
workarea-core-3.4.39 app/models/workarea/metrics/by_week.rb
workarea-core-3.5.17 app/models/workarea/metrics/by_week.rb
workarea-core-3.4.38 app/models/workarea/metrics/by_week.rb
workarea-core-3.5.16 app/models/workarea/metrics/by_week.rb
workarea-core-3.4.37 app/models/workarea/metrics/by_week.rb