/*
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, { useMemo } from 'react';
import { Button, Skeleton, Tooltip } from '@/components/ui';
import { useActualTheme } from '../../context/Theme';
import { VChart } from '@visactor/react-vchart';
import { Activity, AlertTriangle, Info, PieChart } from 'lucide-react';
import {
DEGRADE_TEXT,
FAULTS,
OUTCOMES,
fmtInt,
fmtMs,
fmtTs,
outcomeColors,
pct,
qualityErrorText,
readCssVar,
toneColor,
} from './qualityConstants';
const Delta = ({ current, previous, higherIsBetter = true, asRate, t }) => {
if (previous === undefined || previous === null) return null;
const diff = current - previous;
if (!Number.isFinite(diff) || Math.abs(diff) < (asRate ? 0.0005 : 0.5)) {
return {t('与上一周期持平')};
}
const good = higherIsBetter ? diff > 0 : diff < 0;
const text = asRate
? `${diff > 0 ? '+' : ''}${(diff * 100).toFixed(1)}pp`
: `${diff > 0 ? '+' : ''}${fmtInt(Math.round(diff))}`;
return (
{t('环比')} {text}
);
};
/** 数据来源 / 降级 / 完整度提示条 */
export const QualityMetaNotice = ({ meta, scope, t }) => {
if (!meta) return null;
const notes = [];
// 未知原因码不直显(避免英文内部标识出现在界面上)
const reasons = String(meta.degraded_reason || '')
.split(',')
.filter((r) => DEGRADE_TEXT[r])
.map((r) => t(DEGRADE_TEXT[r]));
if (reasons.length > 0 || meta.data_source === 'logs') {
notes.push({
tone: 'info',
text:
reasons.join(';') ||
t('当前条件下直接统计调用日志,时间范围最长 7 天'),
});
}
if (meta.narrowed) {
notes.push({
tone: 'info',
text: t(
'已按结局 / 责任方收窄:耗时分位与用量为收窄前的整体值,仅供参考',
),
});
}
const c = meta.completeness || {};
if (scope !== 'org' && c.enabled === false) {
notes.push({
tone: 'warn',
text: t(
'质量采集已关闭(MONITOR_QUALITY_ENABLED=false),新调用不会进入看板',
),
});
}
if (scope !== 'org' && (c.dropped_events > 0 || c.dropped_rows > 0)) {
notes.push({
tone: 'warn',
text: t(
'本节点自启动以来丢弃了 {{events}} 条事件 / {{rows}} 行聚合,统计可能偏低',
{
events: fmtInt(c.dropped_events),
rows: fmtInt(c.dropped_rows),
},
),
});
}
if (meta.detail_available === false) {
notes.push({
tone: 'warn',
text: t('日志表尚未完成质量字段升级,明细与按用户 / 令牌分析暂不可用'),
});
}
if (notes.length === 0) return null;
return (