Class: LlmCostTracker::Dashboard::TagBreakdown

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

Constant Summary collapse

DEFAULT_LIMIT =
100

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope:, key:, limit:) ⇒ TagBreakdown

Returns a new instance of TagBreakdown.



16
17
18
19
20
21
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 16

def initialize(scope:, key:, limit:)
  @scope = scope
  @key = LlmCostTracker::Tags::Key.validate!(key, error_class: LlmCostTracker::InvalidFilterError)
  limit = limit.to_i
  @limit = limit.positive? ? [limit, DEFAULT_LIMIT].min : DEFAULT_LIMIT
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



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

def limit
  @limit
end

Class Method Details

.call(key:, scope: LlmCostTracker::Ledger::Call.all, limit: DEFAULT_LIMIT) ⇒ Object



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

def call(key:, scope: LlmCostTracker::Ledger::Call.all, limit: DEFAULT_LIMIT)
  new(scope: scope, key: key, limit: limit)
end

Instance Method Details

#distinct_valuesObject



35
36
37
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 35

def distinct_values
  summary_counts.distinct_values.to_i
end

#rowsObject



23
24
25
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 23

def rows
  @rows ||= scope.klass.find_by_sql(rows_sql)
end

#tagged_callsObject



31
32
33
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 31

def tagged_calls
  summary_counts.tagged_calls.to_i
end

#total_callsObject



27
28
29
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 27

def total_calls
  summary_counts.total_calls.to_i
end