1
0
mirror of https://github.com/mastodon/mastodon synced 2024-12-23 19:18:41 +09:00
mastodon/app/lib/admin/metrics/measure/active_users_measure.rb

34 lines
848 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class Admin::Metrics::Measure::ActiveUsersMeasure < Admin::Metrics::Measure::BaseMeasure
def key
'active_users'
end
2022-02-22 23:27:08 +09:00
protected
def perform_total_query
activity_tracker.sum(time_period.first, time_period.last)
end
2022-02-22 23:27:08 +09:00
def perform_previous_total_query
activity_tracker.sum(previous_time_period.first, previous_time_period.last)
end
2022-02-22 23:27:08 +09:00
def perform_data_query
activity_tracker.get(time_period.first, time_period.last).map { |date, value| { date: date.to_time(:utc).iso8601, value: value.to_s } }
end
def activity_tracker
@activity_tracker ||= ActivityTracker.new('activity:logins', :unique)
end
def time_period
(@start_at.to_date..@end_at.to_date)
end
def previous_time_period
((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period))
end
end