Module: LlmCostTracker::Dashboard::OverviewStats

Defined in:
app/services/llm_cost_tracker/dashboard/overview_stats.rb

Class Method Summary collapse

Class Method Details

.call(scope: LlmCostTracker::Call.all, previous_scope: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'app/services/llm_cost_tracker/dashboard/overview_stats.rb', line 7

def call(scope: LlmCostTracker::Call.all, previous_scope: nil)
  return scope.select(aggregate_selects).take unless previous_scope

  scope.klass
       .from("(#{scope.unscope(:select, :order).to_sql}) AS current_calls")
       .joins("CROSS JOIN (#{previous_aggregate_sql(previous_scope)}) AS previous_stats")
       .select(aggregate_selects(table_name: "current_calls", previous: true))
       .take
end