Class: LlmCostTracker::Dashboard::Filter

Inherits:
Object
  • Object
show all
Defined in:
app/services/llm_cost_tracker/dashboard/filter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope:, params:) ⇒ Filter

Returns a new instance of Filter.



14
15
16
17
# File 'app/services/llm_cost_tracker/dashboard/filter.rb', line 14

def initialize(scope:, params:)
  @scope = scope
  @params = LlmCostTracker::ParameterHash.with_indifferent_access(params)
end

Class Method Details

.call(scope: LlmCostTracker::LlmApiCall.all, params: {}) ⇒ Object



9
10
11
# File 'app/services/llm_cost_tracker/dashboard/filter.rb', line 9

def call(scope: LlmCostTracker::LlmApiCall.all, params: {})
  new(scope: scope, params: params).relation
end

Instance Method Details

#relationObject



19
20
21
22
23
24
25
26
27
# File 'app/services/llm_cost_tracker/dashboard/filter.rb', line 19

def relation
  filtered_scope = scope
  filtered_scope = apply_date_filters(filtered_scope)
  filtered_scope = apply_exact_filter(filtered_scope, :provider)
  filtered_scope = apply_exact_filter(filtered_scope, :model)
  filtered_scope = apply_stream_filter(filtered_scope)
  filtered_scope = apply_usage_source_filter(filtered_scope)
  apply_tag_filters(filtered_scope)
end