Class: Athar::Dashboard::KpiCalculator
- Inherits:
-
Object
- Object
- Athar::Dashboard::KpiCalculator
- Defined in:
- lib/athar/dashboard/kpi_calculator.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#call(connection: ActiveRecord::Base.connection) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(model:, now: Time.current, registry: nil) ⇒ KpiCalculator
constructor
A new instance of KpiCalculator.
Constructor Details
#initialize(model:, now: Time.current, registry: nil) ⇒ KpiCalculator
Returns a new instance of KpiCalculator.
16 17 18 19 20 |
# File 'lib/athar/dashboard/kpi_calculator.rb', line 16 def initialize(model:, now: Time.current, registry: nil) @model = model @now = now @registry = registry end |
Instance Method Details
#call(connection: ActiveRecord::Base.connection) ⇒ Object
rubocop:disable Metrics/AbcSize
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/athar/dashboard/kpi_calculator.rb', line 22 def call(connection: ActiveRecord::Base.connection) # rubocop:disable Metrics/AbcSize aggregates = aggregate(connection) truncates_30d = truncate_count(connection) Result.new( # scope_total covers the same universe the feed UNIONs over: row # deletions plus all table events for the model's tables (not just # the last 30d), so "filtered N of M" never overshoots M. scope_total: aggregates["scope_total"].to_i + table_event_total(connection), last_24h: aggregates["last_24h"].to_i, last_7d: aggregates["last_7d"].to_i, prior_7d: aggregates["prior_7d"].to_i, distinct_actors_30d: aggregates["distinct_actors_30d"].to_i, truncates_30d: truncates_30d, sparkline: Sparkline.new(model: @model, now: @now).buckets(connection: connection) ) end |