This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2021-10-14 11:44:59 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Metrics::Measure::ActiveUsersMeasure < Admin::Metrics::Measure::BaseMeasure
|
|
|
|
def key
|
|
|
|
'active_users'
|
|
|
|
end
|
|
|
|
|
|
|
|
def total
|
|
|
|
activity_tracker.sum(time_period.first, time_period.last)
|
|
|
|
end
|
|
|
|
|
|
|
|
def previous_total
|
|
|
|
activity_tracker.sum(previous_time_period.first, previous_time_period.last)
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
activity_tracker.get(time_period.first, time_period.last).map { |date, value| { date: date.to_time(:utc).iso8601, value: value.to_s } }
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def activity_tracker
|
|
|
|
@activity_tracker ||= ActivityTracker.new('activity:logins', :unique)
|
|
|
|
end
|
|
|
|
|
|
|
|
def time_period
|
2021-11-25 04:07:38 -08:00
|
|
|
(@start_at.to_date..@end_at.to_date)
|
2021-10-14 11:44:59 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def previous_time_period
|
2021-11-25 04:07:38 -08:00
|
|
|
((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period))
|
2021-10-14 11:44:59 -07:00
|
|
|
end
|
|
|
|
end
|