2021-10-15 05:44:59 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Measure::BaseMeasure
|
2021-11-25 23:07:38 +11:00
|
|
|
def self.with_params?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(start_at, end_at, params)
|
2021-10-15 05:44:59 +11:00
|
|
|
@start_at = start_at&.to_datetime
|
|
|
|
@end_at = end_at&.to_datetime
|
2021-11-25 23:07:38 +11:00
|
|
|
@params = params
|
2021-10-15 05:44:59 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
def key
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def total
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def previous_total
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.model_name
|
|
|
|
self.class.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_attribute_for_serialization(key)
|
|
|
|
send(key) if respond_to?(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def time_period
|
2021-11-25 23:07:38 +11:00
|
|
|
(@start_at..@end_at)
|
2021-10-15 05:44:59 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
def previous_time_period
|
2021-11-25 23:07:38 +11:00
|
|
|
((@start_at - length_of_period)..(@end_at - length_of_period))
|
2021-10-15 05:44:59 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
def length_of_period
|
|
|
|
@length_of_period ||= @end_at - @start_at
|
|
|
|
end
|
2021-11-25 23:07:38 +11:00
|
|
|
|
|
|
|
def params
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
2021-10-15 05:44:59 +11:00
|
|
|
end
|