21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'app/services/llm_cost_tracker/dashboard/data_quality.rb', line 21
def call(scope: LlmCostTracker::LlmApiCall.all)
total = scope.count
latency_present = LlmCostTracker::LlmApiCall.latency_column?
stream_present = LlmCostTracker::LlmApiCall.stream_column?
provider_response_id_present = LlmCostTracker::LlmApiCall.provider_response_id_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: if stream_present && LlmCostTracker::LlmApiCall.usage_source_column?
scope.streaming_missing_usage.count
end,
stream_column_present: stream_present,
missing_provider_response_id_count: (
provider_response_id_present ? scope.missing_provider_response_id.count : nil
),
provider_response_id_column_present: provider_response_id_present,
unknown_pricing_by_model: scope.unknown_pricing
.group(:model)
.order(Arel.sql("COUNT(*) DESC"))
.count
.first(10)
.to_h
)
end
|