Sha256: ef096d98c979c95964368a57abf89aea23dbe188c541d2e5a2658464db9d071e

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

module Prosperity
  class Extractors::Base
    attr_reader :metric, :start_time, :end_time, :period, :option

    def initialize(metric, option, start_time, end_time, period)
      @metric, @option, @start_time, @end_time, @period =
        metric, option, period.floor_date.call(start_time), period.ceil_date.call(end_time), period
    end

    def scope
      @metric.options.fetch(option).block.call(metric.scope)
    end

    def key
      self.class.key
    end

    def uid
      "#{@metric.to_s.underscore}_#{@option}_#{key}"
    end

    def label
      "#{metric.title} by #{key} with option #{option}"
    end

    def aggregate
      metric.aggregate
    end

    private
    def count_up_to_date_with_sql(date)
      fragment = <<-SQL
        WITH prosperity_metric_count AS (
          #{metric.sql}
        )
        SELECT #{aggregate.to_sql} AS RESULT FROM prosperity_metric_count
        WHERE #{metric.group_by} < '#{date.iso8601}'
      SQL
      result = ActiveRecord::Base.connection.execute(fragment)
      result.to_a.first["result"].to_f
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
prosperity-0.0.11 lib/prosperity/extractors/base.rb
prosperity-0.0.10 lib/prosperity/extractors/base.rb
prosperity-0.0.9 lib/prosperity/extractors/base.rb
prosperity-0.0.8 lib/prosperity/extractors/base.rb
prosperity-0.0.7 lib/prosperity/extractors/base.rb
prosperity-0.0.6 lib/prosperity/extractors/base.rb