Fix analytics pass rate calculation and add Analysis Errors stat

- Exclude errors from pass rate denominator since they weren't successfully reviewed
- Add missing Analysis Errors stat card to display error count
- Update grid layout to accommodate 5 stat cards

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
michael 2026-01-24 09:19:44 -06:00
parent a4d67fdf46
commit caf4539e1d

View file

@ -4,6 +4,7 @@ import { TrendingUpIcon } from './icons/TrendingUpIcon';
import { BugIcon } from './icons/BugIcon';
import { ClockIcon } from './icons/ClockIcon';
import { LightbulbIcon } from './icons/LightbulbIcon';
import { ExclamationTriangleIcon } from './icons/StatusIcons';
import apiService, { AnalyticsResponse } from '../services/apiService';
// Agent performance is still static for now - would need separate API
@ -47,14 +48,19 @@ export const Analytics: React.FC = () => {
}, []);
// Calculate stats from API data
const passRate = analytics && analytics.total_reviews > 0
? Math.round((analytics.passed / analytics.total_reviews) * 100)
// Exclude errors from denominator since they weren't successfully reviewed
const reviewedCount = analytics
? (analytics.passed || 0) + (analytics.failed || 0) + (analytics.legal_review || 0)
: 0;
const passRate = reviewedCount > 0
? Math.round((analytics!.passed / reviewedCount) * 100)
: 0;
const stats = [
{ name: 'Proofs Reviewed', value: analytics?.total_reviews?.toString() || '0', icon: UploadIcon },
{ name: 'Pass Rate', value: `${passRate}%`, icon: TrendingUpIcon },
{ name: 'Failed Reviews', value: analytics?.failed?.toString() || '0', icon: BugIcon },
{ name: 'Analysis Errors', value: analytics?.errors?.toString() || '0', icon: ExclamationTriangleIcon },
{ name: 'Legal Review Required', value: analytics?.legal_review?.toString() || '0', icon: ClockIcon },
];
@ -67,7 +73,7 @@ export const Analytics: React.FC = () => {
{/* Stats Cards */}
<section>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-6">
{stats.map((stat) => {
const Icon = stat.icon;
return (