From cbe77615580b3f6a3874a0d22674355bb50cbc6d Mon Sep 17 00:00:00 2001
From: admin
Date: Wed, 25 Feb 2026 12:05:25 -0500
Subject: [PATCH] fix: query documents table for analytics instead of empty
events table
The document_processing_events table was never populated. Analytics
endpoints now query the documents table directly using status and
timestamp columns. Also updated upload page labels to remove outdated
"Agentic RAG" references.
Co-Authored-By: Claude Opus 4.6
---
backend/src/services/analyticsService.ts | 49 +++++++++++-----------
frontend/src/components/Analytics.tsx | 4 +-
frontend/src/components/DocumentUpload.tsx | 11 +++--
3 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/backend/src/services/analyticsService.ts b/backend/src/services/analyticsService.ts
index b425bca..6fdeabd 100644
--- a/backend/src/services/analyticsService.ts
+++ b/backend/src/services/analyticsService.ts
@@ -170,8 +170,9 @@ export interface SessionAnalytics {
}
/**
- * Returns per-day session statistics from document_processing_events.
- * Groups upload_started events by date, then joins completed/failed counts.
+ * Returns per-day session statistics from the documents table.
+ * Groups documents by creation date, counts by status, and derives processing time
+ * from (updated_at - created_at) for completed documents.
*/
export async function getSessionAnalytics(days: number): Promise {
const pool = getPostgresPool();
@@ -186,11 +187,14 @@ export async function getSessionAnalytics(days: number): Promise(`
SELECT
DATE(created_at) AS date,
- COUNT(*) FILTER (WHERE event_type = 'upload_started') AS total_sessions,
- COUNT(*) FILTER (WHERE event_type = 'completed') AS successful_sessions,
- COUNT(*) FILTER (WHERE event_type = 'failed') AS failed_sessions,
- COALESCE(AVG(duration_ms) FILTER (WHERE event_type = 'completed'), 0) AS avg_processing_time
- FROM document_processing_events
+ COUNT(*) AS total_sessions,
+ COUNT(*) FILTER (WHERE status = 'completed') AS successful_sessions,
+ COUNT(*) FILTER (WHERE status = 'failed') AS failed_sessions,
+ COALESCE(
+ AVG(EXTRACT(EPOCH FROM (updated_at - created_at)) * 1000)
+ FILTER (WHERE status = 'completed'), 0
+ ) AS avg_processing_time
+ FROM documents
WHERE created_at >= NOW() - $1::interval
GROUP BY DATE(created_at)
ORDER BY date DESC
@@ -230,7 +234,7 @@ export interface ProcessingStatsFromEvents {
}
/**
- * Returns processing pipeline statistics from document_processing_events.
+ * Returns processing pipeline statistics from the documents table.
*/
export async function getProcessingStatsFromEvents(): Promise {
const pool = getPostgresPool();
@@ -241,10 +245,11 @@ export async function getProcessingStatsFromEvents(): Promise(`
SELECT
- COUNT(DISTINCT document_id) AS total_documents,
- COUNT(*) FILTER (WHERE event_type = 'completed') AS succeeded,
- AVG(duration_ms) FILTER (WHERE event_type = 'completed') AS avg_processing_ms
- FROM document_processing_events
+ COUNT(*) AS total_documents,
+ COUNT(*) FILTER (WHERE status = 'completed') AS succeeded,
+ AVG(EXTRACT(EPOCH FROM (updated_at - created_at)) * 1000)
+ FILTER (WHERE status = 'completed') AS avg_processing_ms
+ FROM documents
`);
const row = rows[0]!;
@@ -256,7 +261,7 @@ export async function getProcessingStatsFromEvents(): Promise {
@@ -293,18 +298,14 @@ export async function getHealthFromEvents(): Promise {
}>(`
SELECT
COUNT(*) AS total,
- COUNT(*) FILTER (WHERE event_type = 'completed') AS succeeded,
- COUNT(*) FILTER (WHERE event_type = 'failed') AS failed,
- AVG(duration_ms) FILTER (WHERE event_type = 'completed') AS avg_processing_ms,
+ COUNT(*) FILTER (WHERE status = 'completed') AS succeeded,
+ COUNT(*) FILTER (WHERE status = 'failed') AS failed,
+ AVG(EXTRACT(EPOCH FROM (updated_at - created_at)) * 1000)
+ FILTER (WHERE status = 'completed') AS avg_processing_ms,
COUNT(*) FILTER (
- WHERE event_type = 'processing_started'
- AND document_id NOT IN (
- SELECT document_id FROM document_processing_events
- WHERE event_type IN ('completed', 'failed')
- AND created_at >= NOW() - INTERVAL '24 hours'
- )
+ WHERE status NOT IN ('completed', 'failed')
) AS active
- FROM document_processing_events
+ FROM documents
WHERE created_at >= NOW() - INTERVAL '24 hours'
`);
diff --git a/frontend/src/components/Analytics.tsx b/frontend/src/components/Analytics.tsx
index ec4af84..6ed061c 100644
--- a/frontend/src/components/Analytics.tsx
+++ b/frontend/src/components/Analytics.tsx
@@ -226,7 +226,7 @@ const Analytics: React.FC = () => {
Average Processing Time
- Document AI + Agentic RAG
+ Single-Pass + Quality Check
{formatTime(processingStats.averageProcessingTime?.documentAiAgenticRag ?? 0)}
@@ -236,7 +236,7 @@ const Analytics: React.FC = () => {
Processing Method
- Document AI + Agentic RAG
+ Single-Pass + Quality Check
diff --git a/frontend/src/components/DocumentUpload.tsx b/frontend/src/components/DocumentUpload.tsx
index 4d6af77..c5cec04 100644
--- a/frontend/src/components/DocumentUpload.tsx
+++ b/frontend/src/components/DocumentUpload.tsx
@@ -325,7 +325,7 @@ const DocumentUpload: React.FC = ({
case 'uploaded':
return 'Uploaded to Cloud Storage ✓';
case 'processing':
- return 'Processing with Document AI + Optimized Agentic RAG...';
+ return 'Processing with AI-Powered CIM Analysis...';
case 'completed':
return 'Completed ✓ (PDF automatically deleted)';
case 'error':
@@ -344,10 +344,9 @@ const DocumentUpload: React.FC = ({
-
Document AI + Optimized Agentic RAG Processing
+
AI-Powered CIM Analysis Processing
- All documents are automatically processed using Google Document AI for extraction and our advanced optimized agentic RAG system for analysis,
- including intelligent chunking, vectorization, and multi-agent CIM review. PDFs are automatically deleted after processing.
+ All documents are automatically processed using AI-powered extraction and structured CIM review analysis. PDFs are automatically deleted after processing.
@@ -372,7 +371,7 @@ const DocumentUpload: React.FC = ({
Drag and drop PDF files here, or click to browse
- Maximum file size: 50MB • Supported format: PDF • Stored securely in Cloud Storage • Automatic Document AI + Optimized Agentic RAG Processing • PDFs deleted after processing
+ Maximum file size: 50MB • Supported format: PDF • Stored securely in Cloud Storage • Automatic AI-Powered CIM Analysis Processing • PDFs deleted after processing
@@ -401,7 +400,7 @@ const DocumentUpload: React.FC = ({
Upload Complete
Files have been uploaded successfully! You can now navigate away from this page.
- Processing will continue in the background using Document AI + Optimized Agentic RAG. This can take several minutes. PDFs will be automatically deleted after processing to save costs.
+ Processing will continue in the background using AI-Powered CIM Analysis. This can take several minutes. PDFs will be automatically deleted after processing to save costs.