Class: LlmCostTracker::Dashboard::DataQuality

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

Class Method Summary collapse

Class Method Details

.call(scope: LlmCostTracker::LlmApiCall.all) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/llm_cost_tracker/dashboard/data_quality.rb', line 19

def call(scope: LlmCostTracker::LlmApiCall.all)
  total = scope.count
  latency_present = LlmCostTracker::LlmApiCall.latency_column?
  stream_present = LlmCostTracker::LlmApiCall.stream_column?

  DataQualityStats.new(
    total_calls: total,
    unknown_pricing_count: scope.unknown_pricing.count,
    untagged_calls_count: total - scope.with_json_tags.count,
    missing_latency_count: latency_present ? scope.where(latency_ms: nil).count : nil,
    latency_column_present: latency_present,
    streaming_count: stream_present ? scope.streaming.count : nil,
    streaming_missing_usage_count: streaming_missing_usage_count(scope, stream_present),
    stream_column_present: stream_present,
    unknown_pricing_by_model: scope.unknown_pricing
                              .group(:model)
                              .order(Arel.sql("COUNT(*) DESC"))
                              .count
                              .first(10)
                              .to_h
  )
end