fixes
This commit is contained in:
1 parent
6586722652
commit
1e7c7bbfbb
65 files changed
+1345
-640
No files matched your search
@@ -151,13 +151,16 @@ func (s *Server) handleAdminAnalytics(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
tokenByDay := map[string]adminDayPoint{}
|
||||
tokRows, err := s.Pool.Query(ctx, `
|
||||
SELECT (created_at AT TIME ZONE 'UTC')::date AS d,
|
||||
COALESCE(SUM(COALESCE(total_tokens, 0)), 0)::bigint,
|
||||
COUNT(*)::bigint
|
||||
FROM processed_products
|
||||
WHERE created_at >= $1
|
||||
GROUP BY 1
|
||||
ORDER BY 1`, since)
|
||||
WITH tokens AS (
|
||||
SELECT day AS d, COALESCE(SUM(total_tokens),0)::bigint AS tok
|
||||
FROM ai_usage_daily WHERE day >= $1::date GROUP BY 1
|
||||
), products AS (
|
||||
SELECT (created_at AT TIME ZONE 'UTC')::date AS d, COUNT(*)::bigint AS cnt
|
||||
FROM processed_products WHERE created_at >= $1 GROUP BY 1
|
||||
)
|
||||
SELECT COALESCE(t.d,p.d) AS d, COALESCE(t.tok,0)::bigint, COALESCE(p.cnt,0)::bigint
|
||||
FROM tokens t FULL OUTER JOIN products p ON t.d=p.d
|
||||
ORDER BY 1`, since)
|
||||
if err != nil {
|
||||
Error(w, http.StatusInternalServerError, "analytics token series failed")
|
||||
return
|
||||
@@ -326,7 +329,7 @@ func (s *Server) handleAdminAnalytics(w http.ResponseWriter, r *http.Request) {
|
||||
"providers": providers,
|
||||
"tokens_by_provider_detail": providerDetail,
|
||||
"notes": []string{
|
||||
"Tokens come from processed_products.total_tokens (LLM usage recorded per product).",
|
||||
"Tokens come from the durable ai_usage_daily call ledger (input + output), including multiple calls per product.",
|
||||
"Provider classes use processed_products.ai_provider_mode: internal | popular:<name> | custom (blank/unknown rolled into the internal card).",
|
||||
"Job tokens use processing_jobs.estimated_tokens (running tally during jobs).",
|
||||
"Jobs stuck = status running with updated_at older than 2 hours (same threshold as diagnostics).",
|
||||
@@ -353,12 +356,12 @@ func (s *Server) loadAdminAnalyticsSummary(ctx context.Context, since time.Time)
|
||||
(SELECT COUNT(*)::bigint FROM companies WHERE created_at >= $1),
|
||||
(SELECT COALESCE(SUM(total_credits), 0)::bigint FROM credit_balances),
|
||||
(SELECT COALESCE(SUM(used_credits), 0)::bigint FROM credit_balances),
|
||||
(SELECT COALESCE(SUM(COALESCE(total_tokens, 0)), 0)::bigint FROM processed_products),
|
||||
(SELECT COALESCE(SUM(total_tokens), 0)::bigint FROM ai_usage_daily),
|
||||
(SELECT COUNT(*)::bigint FROM processed_products),
|
||||
(SELECT COUNT(*)::bigint FROM raw_products),
|
||||
(SELECT COUNT(*)::bigint FROM input_feeds),
|
||||
(SELECT COUNT(*)::bigint FROM export_feeds),
|
||||
(SELECT COALESCE(SUM(COALESCE(total_tokens, 0)), 0)::bigint FROM processed_products WHERE created_at >= $1),
|
||||
(SELECT COALESCE(SUM(total_tokens), 0)::bigint FROM ai_usage_daily WHERE day >= $1::date),
|
||||
(SELECT COUNT(*)::bigint FROM processing_jobs WHERE created_at >= $1 AND status = 'failed'),
|
||||
(SELECT COUNT(*)::bigint FROM processing_jobs WHERE created_at >= $1 AND status = 'completed'),
|
||||
(SELECT COUNT(*)::bigint FROM processing_jobs
|
||||
|
||||
Reference in new issue
Block a user