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- SORT_OPTIONS =
%w[value calls cost avg_cost].freeze
- DEFAULT_DIRECTIONS =
{ "value" => "asc", "calls" => "desc", "cost" => "desc", "avg_cost" => "desc" }.freeze
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:, sort: "cost", direction: nil) ⇒ TagBreakdown
constructor
A new instance of TagBreakdown.
- #rows ⇒ Object
- #tagged_calls ⇒ Object
- #total_calls ⇒ Object
Constructor Details
#initialize(scope:, key:, limit:, sort: "cost", direction: nil) ⇒ TagBreakdown
Returns a new instance of TagBreakdown.
19 20 21 22 23 24 25 26 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 19 def initialize(scope:, key:, limit:, sort: "cost", direction: nil) @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 @sort = SORT_OPTIONS.include?(sort.to_s) ? sort.to_s : "cost" @direction = Sort::DIRECTIONS.include?(direction.to_s) ? direction.to_s : DEFAULT_DIRECTIONS[@sort] end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
17 18 19 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 17 def limit @limit end |
Class Method Details
.call(key:, scope: LlmCostTracker::Call.all, limit: DEFAULT_LIMIT, sort: "cost", direction: nil) ⇒ Object
12 13 14 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 12 def call(key:, scope: LlmCostTracker::Call.all, limit: DEFAULT_LIMIT, sort: "cost", direction: nil) new(scope: scope, key: key, limit: limit, sort: sort, direction: direction) end |
Instance Method Details
#distinct_values ⇒ Object
52 53 54 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 52 def distinct_values summary_counts.distinct_values.to_i end |
#rows ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 28 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
48 49 50 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 48 def tagged_calls summary_counts.tagged_calls.to_i end |
#total_calls ⇒ Object
44 45 46 |
# File 'app/services/llm_cost_tracker/dashboard/tag_breakdown.rb', line 44 def total_calls summary_counts.total_calls.to_i end |