Files
treeandClaude Opus 5.5 f8d1ccc526 初始提交:5G 基站退服时长智能分析与故障闭环管控系统
Flask + SQLite 后端,免构建 React + ECharts 前端,含合成样例数据。
测试参考数据(FOR-TEST-ONLY)与运行时数据库不入库。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 14:01:48 +08:00

62 lines
3.1 KiB
JavaScript

import {html, useState} from 'vendor';
import {useApp, useFetch} from '../api.js';
import {accentMax, CAUSE_COLOR, num, shortSite} from '../format.js';
import {EChart} from '../components/EChart.js';
import {DataTable} from '../components/DataTable.js';
import {Loading, Section, Select} from '../components/ui.js';
const DIMS = [
{value: 'scene', label: '场景'}, {value: 'region', label: '片区'}, {value: 'site_type', label: '站型'},
{value: 'vendor', label: '厂家'}, {value: 'month', label: '月份'}, {value: 'root_cause', label: '判定根因'},
{value: 'cause_category', label: '上报原因'}, {value: 'cause_code', label: '原因码'},
{value: 'level', label: '断站分级'}, {value: 'site_name', label: '基站'},
];
const COLUMNS = [
{key: 'key', title: '维度值'}, {key: 'count', title: '退服次数', sortable: true},
{key: 'total_min', title: '累计时长(分)', sortable: true}, {key: 'avg_min', title: '平均时长(分)', sortable: true},
{key: 'max_min', title: '最长单次(分)', sortable: true}, {key: 'long_count', title: '超长次数', sortable: true},
{key: 'long_ratio', title: '超长占比(%)', sortable: true}, {key: 'sites', title: '涉及站点', sortable: true},
{key: 'users', title: '受影响用户', sortable: true, render: num}, {key: 'loss_gb', title: '业务损失(GB)', sortable: true, render: num},
];
/** 多维统计:选择维度 → 后端分组聚合;点击表头切换排序指标,图表同步显示该指标前 20 名 */
export default function Stats() {
const {filters} = useApp();
const [dim, setDim] = useState('scene');
const [sort, setSort] = useState({key: 'total_min', asc: false});
const {data} = useFetch('/api/stats', {...filters, dim, sort: sort.key, asc: sort.asc ? 1 : 0});
const onSort = key => setSort(s => ({key, asc: s.key === key ? !s.asc : false}));
const top = data ? data.rows.slice(0, 20) : [];
const metric = COLUMNS.find(c => c.key === sort.key).title;
// 按根因统计时每根柱子用各自的根因色(全站统一);其他维度只把第一名标成强调色
let barData;
if (dim === 'root_cause') {
barData = top.map(r => ({value: r[sort.key], itemStyle: {color: CAUSE_COLOR[r.key]}}));
} else {
barData = accentMax(top.map(r => r[sort.key]));
}
const chart = {
tooltip: {trigger: 'axis', axisPointer: {type: 'shadow'}},
xAxis: {type: 'category', data: top.map(r => (dim === 'site_name' ? shortSite(r.key) : r.key)),
axisLabel: {rotate: top.length > 8 ? 30 : 0}},
yAxis: {type: 'value', name: metric},
series: [{type: 'bar', name: metric, barMaxWidth: 34, data: barData}],
};
return html`
<${Section}>
<div className="row toolbar">
<${Select} label="统计维度" showLabel options=${DIMS} value=${dim} onChange=${setDim}/>
<span className="grow"></span>
<span className="hint">点击表头排序,图表同步切换指标</span>
</div>
${data ? html`
<div>
<${EChart} option=${chart}/>
<${DataTable} rowKey="key" columns=${COLUMNS} rows=${data.rows} sort=${sort} onSort=${onSort}/>
</div>` : html`<${Loading}/>`}
</${Section}>`;
}