import { useState, useEffect } from 'react'; import { Separator } from '../ui/separator'; import { api } from '../../api'; import type { StatisticsResponse } from '../../types'; function formatPercent(value: number): string { return `${value.toFixed(1)}%`; } export function SettingsStatisticsSection({ className }: { className?: string }) { const [stats, setStats] = useState(null); const [statsLoading, setStatsLoading] = useState(false); const [statsError, setStatsError] = useState(false); useEffect(() => { let cancelled = false; setStatsLoading(true); setStatsError(false); api.getStatistics().then( (data) => { if (!cancelled) { setStats(data); setStatsLoading(false); } }, () => { if (!cancelled) { setStatsError(true); setStatsLoading(false); } } ); return () => { cancelled = true; }; }, []); return (
{statsLoading && !stats ? (
Loading statistics... this can take a while if you have a lot of stored packets.
) : stats ? (
{/* Network */}

Network

{stats.contact_count}
Contacts
{stats.repeater_count}
Repeaters
{stats.channel_count}
Channels
{/* Messages */}

Messages

{stats.total_dms}
Direct Messages
{stats.total_channel_messages}
Channel Messages
{stats.total_outgoing}
Sent (Outgoing)
{/* Packets */}

Packets

Total stored {stats.total_packets}
Decrypted {stats.decrypted_packets}
Undecrypted {stats.undecrypted_packets}

Path Hash Width (24h)

Parsed stored raw packets from the last 24 hours:{' '} {stats.path_hash_width_24h.total_packets}
1-byte hops {stats.path_hash_width_24h.single_byte} ( {formatPercent(stats.path_hash_width_24h.single_byte_pct)})
2-byte hops {stats.path_hash_width_24h.double_byte} ( {formatPercent(stats.path_hash_width_24h.double_byte_pct)})
3-byte hops {stats.path_hash_width_24h.triple_byte} ( {formatPercent(stats.path_hash_width_24h.triple_byte_pct)})
{/* Activity */}

Activity

1h 24h 7d
Contacts heard {stats.contacts_heard.last_hour} {stats.contacts_heard.last_24_hours} {stats.contacts_heard.last_week}
Repeaters heard {stats.repeaters_heard.last_hour} {stats.repeaters_heard.last_24_hours} {stats.repeaters_heard.last_week}
{/* Busiest Channels */} {stats.busiest_channels_24h.length > 0 && ( <>

Busiest Channels (24h)

{stats.busiest_channels_24h.map((ch, i) => (
{i + 1}. {ch.channel_name} {ch.message_count} msgs
))}
)}
) : statsError ? (
Failed to load statistics.
) : null}
); }