Module: OpenRouterUsageTracker::Trackable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/open_router_usage_tracker/trackable.rb
Instance Method Summary collapse
-
#daily_usage_summary_for(day:, provider:, model:) ⇒ OpenRouterUsageTracker::DailySummary?
Finds a specific daily summary for a given day, provider, and model.
-
#total_cost_in_range(range, provider:, model: nil) ⇒ BigDecimal
Calculates the total cost from the daily summaries within a given date range.
Instance Method Details
#daily_usage_summary_for(day:, provider:, model:) ⇒ OpenRouterUsageTracker::DailySummary?
Finds a specific daily summary for a given day, provider, and model. This is the primary, high-performance method for usage checks.
19 20 21 |
# File 'app/models/concerns/open_router_usage_tracker/trackable.rb', line 19 def daily_usage_summary_for(day:, provider:, model:) daily_summaries.find_by(day: day, provider: provider, model: model) end |
#total_cost_in_range(range, provider:, model: nil) ⇒ BigDecimal
Calculates the total cost from the daily summaries within a given date range. It can be filtered by provider and, optionally, by model.
30 31 32 33 34 |
# File 'app/models/concerns/open_router_usage_tracker/trackable.rb', line 30 def total_cost_in_range(range, provider:, model: nil) summaries = daily_summaries.where(day: range, provider: provider) summaries = summaries.where(model: model) if model summaries.sum(:cost) end |