Class: LlmCostTracker::Dashboard::TagBreakdown
- Inherits:
-
Object
- Object
- LlmCostTracker::Dashboard::TagBreakdown
- Defined in:
- app/services/llm_cost_tracker/dashboard/tag_breakdown.rb
Defined Under Namespace
Classes: Row
Constant Summary collapse
- DEFAULT_LIMIT =
100
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Class Method Summary collapse
Instance Method Summary collapse
- #distinct_values ⇒ Object
-
#initialize(scope:, key:, limit:) ⇒ TagBreakdown
constructor
A new instance of TagBreakdown.
- #rows ⇒ Object
- #tagged_calls ⇒ Object
- #total_calls ⇒ Object
Constructor Details
#initialize(scope:, key:, limit:) ⇒ TagBreakdown
Returns a new instance of TagBreakdown.
17 18 19 20 21 22 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 17 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
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
15 16 17 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 15 def limit @limit end |
Class Method Details
.call(key:, scope: LlmCostTracker::Call.all, limit: DEFAULT_LIMIT) ⇒ Object
10 11 12 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 10 def call(key:, scope: LlmCostTracker::Call.all, limit: DEFAULT_LIMIT) new(scope: scope, key: key, limit: limit) end |
Instance Method Details
#distinct_values ⇒ Object
48 49 50 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 48 def distinct_values summary_counts.distinct_values.to_i end |
#rows ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 24 def rows @rows ||= begin total = tagged_calls scope.klass.find_by_sql(rows_sql).map do |row| calls = row.calls.to_i Row.new( value: row.value, calls: calls, total_cost: row.total_cost, average_cost_per_call: row.average_cost_per_call, share_percent: percentage(calls, total) ) end end end |
#tagged_calls ⇒ Object
44 45 46 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 44 def tagged_calls summary_counts.tagged_calls.to_i end |
#total_calls ⇒ Object
40 41 42 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 40 def total_calls summary_counts.total_calls.to_i end |