Class: LlmCostTracker::Storage::ActiveRecordRollups

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_cost_tracker/storage/active_record_rollups.rb

Constant Summary collapse

PERIODS =
{
  monthly: "month",
  daily:   "day"
}.freeze

Class Method Summary collapse

Class Method Details

.daily_total(time: Time.now.utc) ⇒ Object



27
28
29
# File 'lib/llm_cost_tracker/storage/active_record_rollups.rb', line 27

def daily_total(time: Time.now.utc)
  period_total(:daily, time)
end

.increment!(event) ⇒ Object



16
17
18
19
20
21
# File 'lib/llm_cost_tracker/storage/active_record_rollups.rb', line 16

def increment!(event)
  return unless event.cost&.total_cost
  return unless period_totals_enabled?

  PERIODS.each_key { |period| increment_period_total(period, event) }
end

.monthly_total(time: Time.now.utc) ⇒ Object



23
24
25
# File 'lib/llm_cost_tracker/storage/active_record_rollups.rb', line 23

def monthly_total(time: Time.now.utc)
  period_total(:monthly, time)
end

.reset!Object



12
13
14
# File 'lib/llm_cost_tracker/storage/active_record_rollups.rb', line 12

def reset!
  remove_instance_variable(:@period_totals_enabled) if instance_variable_defined?(:@period_totals_enabled)
end