import { useState } from 'react' import { usePoller } from '../hooks/usePoller.ts' import { useI18n } from '../hooks/useI18n.ts' import { monitorApi } from '../api/monitorApi.ts' import type { ThroughputMetrics, DataQuality, HaeguStat } from '../api/types.ts' import MetricCard from '../components/charts/MetricCard.tsx' import StatusBadge from '../components/common/StatusBadge.tsx' import { formatNumber, formatDateTime } from '../utils/formatters.ts' const POLL_INTERVAL = 30_000 export default function AreaStats() { const { t } = useI18n() const [haegu, setHaegu] = useState([]) const [throughput, setThroughput] = useState(null) const [quality, setQuality] = useState(null) usePoller(async () => { const [h, tp, q] = await Promise.allSettled([ monitorApi.getHaeguRealtimeStats(), monitorApi.getThroughput(), monitorApi.getQuality(), ]) if (h.status === 'fulfilled') setHaegu(h.value) if (tp.status === 'fulfilled') setThroughput(tp.value) if (q.status === 'fulfilled') setQuality(q.value) }, POLL_INTERVAL) return (

{t('area.title')}

{/* Summary Cards */}
sum + (h.current_vessels ?? 0), 0))} /> 0 ? (haegu.reduce((sum, h) => sum + (h.avg_density ?? 0), 0) / haegu.length).toFixed(2) : '-'} />
{/* Haegu Stats Table */}
{t('area.haeguStats')}
{haegu.length === 0 ? (
{t('common.noData')}
) : (
{haegu.map(h => ( ))}
{t('area.haeguNo')} {t('area.haeguName')} {t('area.currentVessels')} {t('area.avgSpeed')} {t('area.avgDensityCol')} {t('area.lastUpdate')}
{h.haegu_no} {h.haegu_name} {formatNumber(h.current_vessels)} {(h.avg_speed ?? 0).toFixed(1)} kn {(h.avg_density ?? 0).toFixed(4)} {formatDateTime(h.last_update)}
)}
{/* Throughput + Quality */}
{/* Throughput */}
{t('area.throughput')}
{throughput ? (
{throughput.avgVesselsPerMinute != null && (
{Math.round(throughput.avgVesselsPerMinute)}
{t('area.vesselsPerMin')}
{formatNumber(Math.round(throughput.avgVesselsPerHour ?? 0))}
{t('area.vesselsPerHour')}
)} {throughput.partitionSizes && throughput.partitionSizes.length > 0 && (
{t('area.tableSizes')}
{throughput.partitionSizes.map((p, i) => (
{p.tablename} {p.size}
))}
)} {(!throughput.avgVesselsPerMinute && (!throughput.partitionSizes || throughput.partitionSizes.length === 0)) && (
{t('common.noData')}
)}
) : (
{t('common.loading')}
)}
{/* Data Quality */}
{t('area.dataQualityTitle')}
{quality ? (
{quality.qualityScore}
{t('area.duplicates')}
{formatNumber(quality.duplicateRecords)}
{t('area.stalePositions')}
{formatNumber(quality.stalePositions)}
{t('area.checkedAt')}: {formatDateTime(quality.checkedAt)}
) : (
{t('common.loading')}
)}
) }