Commit 426817e8 authored by Your Name's avatar Your Name

Fix: Cost overview now correctly uses selected time range instead of hardcoded 24h

- Simplified get_cost_overview to use tokens from provider stats (which already respect date range)
- Removed redundant get_token_usage_by_date_range call
- Cost overview now properly reflects selected time period filter
parent f7720492
...@@ -890,18 +890,13 @@ class Analytics: ...@@ -890,18 +890,13 @@ class Analytics:
for provider in providers: for provider in providers:
provider_id = provider['provider_id'] provider_id = provider['provider_id']
tokens = provider['tokens']
# Get token usage for this provider in the date range # Get token usage for this provider in the date range
if from_datetime or to_datetime: # Always use the tokens from provider stats which already respect the date range
provider_usage = self.get_token_usage_by_date_range(provider_id, start, end) total_tokens = tokens['total']
total_tokens = provider_usage['total_tokens'] prompt_tokens = tokens.get('prompt', 0)
else: completion_tokens = tokens.get('completion', 0)
tokens = provider['tokens']
total_tokens = tokens['TPD'] # Use daily tokens for cost estimation
# Get actual prompt/completion tokens from provider stats
prompt_tokens = tokens.get('prompt', 0) if not (from_datetime or to_datetime) else None
completion_tokens = tokens.get('completion', 0) if not (from_datetime or to_datetime) else None
# Use actual cost if available, otherwise estimate # Use actual cost if available, otherwise estimate
actual_cost = provider.get('actual_cost', 0) actual_cost = provider.get('actual_cost', 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment