'use client'; import { useEffect, useState } from 'react'; import { getExperimentStatistics } from '@/app/actions/experiment'; import AnnotationDistribution from './AnnotationDistribution'; interface ExperimentStatisticsProps { experimentId: number; onboardingEnabled: boolean; calibrationEnabled: boolean; } interface Statistics { participants: { total: number; completedOnboarding: number; completedCalibration: number; }; entries: { total: number; }; annotations: { total: number; entriesWithAnnotations: number; entriesWithoutAnnotations: number; averagePerEntry: number; maxPerEntry: number; minPerEntry: number; }; } export default function ExperimentStatistics({ experimentId, onboardingEnabled, calibrationEnabled, }: ExperimentStatisticsProps) { const [statistics, setStatistics] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchStatistics = async () => { try { const stats = await getExperimentStatistics(experimentId); setStatistics(stats); setError(null); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to load statistics'); } finally { setLoading(false); } }; fetchStatistics(); }, [experimentId]); if (loading) { return (
Loading statistics...
); } if (error) { return (
Error: {error}
); } if (!statistics) { return (
No statistics available
); } return (

Statistics

{/* Participants Section */}

Participants

Total Participants
{statistics.participants.total}
{onboardingEnabled && (
Completed Onboarding
{statistics.participants.completedOnboarding}
{statistics.participants.total > 0 ? ( (statistics.participants.completedOnboarding / statistics.participants.total) * 100 ).toFixed(1) : 0} %
)} {calibrationEnabled && (
Completed Calibration
{statistics.participants.completedCalibration}
{statistics.participants.total > 0 ? ( (statistics.participants.completedCalibration / statistics.participants.total) * 100 ).toFixed(1) : 0} %
)}
{/* Annotations Section */}

Sample Annotations

Total Samples {statistics.entries.total}
Total Annotations {statistics.annotations.total}
Samples with Annotations {statistics.annotations.entriesWithAnnotations} ({statistics.entries.total > 0 ? ( (statistics.annotations.entriesWithAnnotations / statistics.entries.total) * 100 ).toFixed(1) : 0} %)
Samples without Annotations {statistics.annotations.entriesWithoutAnnotations}
Average Annotations per Sample {statistics.annotations.averagePerEntry.toFixed(2)}
{/* Annotation Distribution Diagram */}
); }