/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Activity, CreditCard, Hash, Layers, Gauge } from 'lucide-react';
import { renderQuota } from '../../helpers';
const formatNumber = (n) => {
if (n == null || isNaN(n)) return '—';
const v = Number(n);
if (v >= 1_000_000) return (v / 1_000_000).toFixed(1) + 'M';
if (v >= 1_000) return (v / 1_000).toFixed(1) + 'K';
return v.toLocaleString();
};
const formatLatency = (v) => {
if (v == null) return '—';
if (v < 1) return `${Math.round(v * 1000)}ms`;
return `${v.toFixed(2)}s`;
};
const BentoStat = ({ label, value, unit, sub, delta, icon: Icon, className = '' }) => {
return (
{delta != null && (
0
? 'text-red-500 dark:text-red-400'
: 'text-slate-500 dark:text-white/50'
}`}
>
{delta > 0 ? '↑' : delta < 0 ? '↓' : '·'} {Math.abs(delta).toFixed(0)}%
对比上月
)}
{sub && (
{sub}
)}
);
};
const BentoStats = ({ metrics, monthDelta }) => {
return (
<>
{formatNumber(metrics.today.tokens)}
{' '}
tokens
·
{renderQuota(metrics.today.cost)}
}
icon={Activity}
/>
{metrics.month.requests}
{' '}
次调用
·
{formatNumber(metrics.month.tokens)} tokens
}
delta={monthDelta}
icon={CreditCard}
/>
>
);
};
export default BentoStats;