class Prosperity::Extractors::Base
Attributes
end_time[R]
metric[R]
option[R]
period[R]
start_time[R]
Public Class Methods
new(metric, option, start_time, end_time, period)
click to toggle source
# File lib/prosperity/extractors/base.rb, line 5 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
Public Instance Methods
aggregate()
click to toggle source
# File lib/prosperity/extractors/base.rb, line 26 def aggregate metric.aggregate end
key()
click to toggle source
# File lib/prosperity/extractors/base.rb, line 14 def key self.class.key end
label()
click to toggle source
# File lib/prosperity/extractors/base.rb, line 22 def label "#{metric.title} by #{key} with option #{option}" end
scope()
click to toggle source
# File lib/prosperity/extractors/base.rb, line 10 def scope @metric.options.fetch(option).block.call(metric.scope) end
uid()
click to toggle source
# File lib/prosperity/extractors/base.rb, line 18 def uid "#{@metric.to_s.underscore}_#{@option}_#{key}" end
Private Instance Methods
count_up_to_date_with_sql(date)
click to toggle source
# File lib/prosperity/extractors/base.rb, line 31 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