Add graphs and retention metrics to admin dashboard (#16829)
This commit is contained in:
parent
959f7fc580
commit
07341e7aa6
46 changed files with 1650 additions and 257 deletions
46
app/lib/admin/metrics/measure/base_measure.rb
Normal file
46
app/lib/admin/metrics/measure/base_measure.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Admin::Metrics::Measure::BaseMeasure
|
||||
def initialize(start_at, end_at)
|
||||
@start_at = start_at&.to_datetime
|
||||
@end_at = end_at&.to_datetime
|
||||
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
|
||||
(@start_at...@end_at)
|
||||
end
|
||||
|
||||
def previous_time_period
|
||||
((@start_at - length_of_period)...(@end_at - length_of_period))
|
||||
end
|
||||
|
||||
def length_of_period
|
||||
@length_of_period ||= @end_at - @start_at
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue