初始提交:5G 基站退服时长智能分析与故障闭环管控系统
Flask + SQLite 后端,免构建 React + ECharts 前端,含合成样例数据。 测试参考数据(FOR-TEST-ONLY)与运行时数据库不入库。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f8d1ccc526
39 files changed
+29010
No files matched your search
@@ -0,0 +1,126 @@
|
||||
import {Fragment, GlassButton, html, useState, useToast} from 'vendor';
|
||||
import {api, download, useApp, useFetch} from '../api.js';
|
||||
import {BLUE_SCALE, CAUSE_COLOR, heatLabelColor, num} from '../format.js';
|
||||
import {EChart} from '../components/EChart.js';
|
||||
import {DataTable, Pager} from '../components/DataTable.js';
|
||||
import {Cause, LevelTag, Loading, Section, Select, StatusTag} from '../components/ui.js';
|
||||
|
||||
const PAGE_SIZE = 15;
|
||||
|
||||
export default function RootCause() {
|
||||
const {filters, isAdmin} = useApp();
|
||||
const toast = useToast();
|
||||
const {data: confusion} = useFetch('/api/confusion', filters);
|
||||
const {data: stats} = useFetch('/api/stats', {...filters, dim: 'root_cause'});
|
||||
const [lastRun, setLastRun] = useState(null);
|
||||
const [running, setRunning] = useState(false);
|
||||
|
||||
const runAnalysis = async () => {
|
||||
setRunning(true);
|
||||
try {
|
||||
const r = await api('/api/analyze', {method: 'POST'});
|
||||
setLastRun(r);
|
||||
toast({message: `全量分析完成:${num(r.n)} 条,耗时 ${r.elapsed}s,准确率 ${r.acc}%`, tone: 'success'});
|
||||
} catch (e) {
|
||||
toast({message: e.message, tone: 'error'});
|
||||
}
|
||||
setRunning(false);
|
||||
};
|
||||
|
||||
if (!confusion || !stats) return html`<${Loading}/>`;
|
||||
|
||||
// 交叉矩阵:matrix[i][j] = 上报原因 i、系统判定 j 的条数;对角线 i === j 为判定一致
|
||||
const {causes, matrix} = confusion;
|
||||
const n = causes.length;
|
||||
let total = 0;
|
||||
let hit = 0;
|
||||
let maxCount = 1;
|
||||
for (const row of matrix) {
|
||||
maxCount = Math.max(maxCount, ...row);
|
||||
}
|
||||
// 热力图数据 value = [列, 行, 条数];行号倒过来,让第一个原因显示在最上面;深色格子用白字
|
||||
const cells = [];
|
||||
for (let i = 0; i < n; i++) {
|
||||
for (let j = 0; j < n; j++) {
|
||||
const count = matrix[i][j];
|
||||
total += count;
|
||||
if (i === j) hit += count;
|
||||
cells.push({value: [j, n - 1 - i, count], label: {color: heatLabelColor(count, maxCount)}});
|
||||
}
|
||||
}
|
||||
|
||||
const matrixChart = {
|
||||
tooltip: {formatter: s => `上报:${causes[n - 1 - s.value[1]]}<br>判定:${causes[s.value[0]]}<br><b>${s.value[2]} 条</b>`},
|
||||
grid: {left: 12, right: 12, top: 10, bottom: 30, containLabel: true},
|
||||
xAxis: {type: 'category', data: causes, name: '判定', nameLocation: 'center', nameGap: 26},
|
||||
yAxis: {type: 'category', data: [...causes].reverse()},
|
||||
visualMap: {show: false, min: 0, max: maxCount, inRange: {color: BLUE_SCALE}},
|
||||
series: [{type: 'heatmap', data: cells, label: {show: true},
|
||||
itemStyle: {borderColor: 'transparent', borderWidth: 2, borderRadius: 6}}],
|
||||
};
|
||||
const causeChart = {
|
||||
tooltip: {trigger: 'axis', axisPointer: {type: 'shadow'}, formatter: ([s]) => {
|
||||
const r = stats.rows[s.dataIndex];
|
||||
return `${r.key}<br>次数 ${r.count}<br>平均时长 <b>${r.avg_min} min</b><br>超长占比 ${r.long_ratio}%`;
|
||||
}},
|
||||
xAxis: {type: 'category', data: stats.rows.map(r => r.key)},
|
||||
yAxis: {type: 'value'},
|
||||
series: [{type: 'bar', barMaxWidth: 40, label: {show: true, position: 'top'},
|
||||
data: stats.rows.map(r => ({value: r.avg_min, itemStyle: {color: CAUSE_COLOR[r.key]}}))}],
|
||||
};
|
||||
const runButton = isAdmin && html`
|
||||
<${GlassButton} variant="glassProminent" loading=${running} onClick=${runAnalysis}>全量重新分析</${GlassButton}>`;
|
||||
|
||||
return html`
|
||||
<div className="grid">
|
||||
<${Section} span=${5} title="根因判定规则" extra=${runButton}>
|
||||
<div className="note">
|
||||
<b>第一级 · 告警衍生关系</b>:“小区退服”告警若带 parent_alarm_id,直接取父告警类别作为根因。<br/>
|
||||
<b>第二级 · 时间窗关联</b>:回溯同站在退服前仍未清除的告警,按优先级取首个命中:<br/>
|
||||
① 割接施工 30 分钟 ② 电源故障 300 分钟(考虑蓄电池后备)③ 机房环境 180 分钟(考虑过热保护延时)<br/>
|
||||
④ 传输中断 15 分钟 ⑤ 天馈故障 30 分钟 ⑥ 设备硬件 15 分钟<br/>
|
||||
停电衍生的传输告警因优先级归为电源故障;均未命中判为“其他”,派单现场核查。
|
||||
</div>
|
||||
<div className="chips">
|
||||
<div className="chip"><span>参与校验</span>${num(total)} 条</div>
|
||||
<div className="chip" data-tone="green"><span>判定准确率</span>${total ? (hit / total * 100).toFixed(2) : 0}%</div>
|
||||
<div className="chip"><span>上次分析</span>${lastRun ? `${num(lastRun.n)} 条 / ${lastRun.elapsed}s` : '—'}</div>
|
||||
</div>
|
||||
</${Section}>
|
||||
<${Section} span=${7} title="上报原因 × 系统判定根因 交叉矩阵" hint="对角线为判定一致"><${EChart} option=${matrixChart}/></${Section}>
|
||||
<${Section} title="根因维度统计" hint="柱高为平均退服时长(分钟)"><${EChart} height=${260} option=${causeChart}/></${Section}>
|
||||
<${AdviceList}/>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
/** 超长退服记录 + 分级处置建议(分页) */
|
||||
function AdviceList() {
|
||||
const {meta, filters} = useApp();
|
||||
const [cause, setCause] = useState('');
|
||||
const [page, setPage] = useState(1);
|
||||
const params = {...filters, long: 1, root_cause: cause};
|
||||
const {data} = useFetch('/api/outages', {...params, sort: 'duration_min', page, size: PAGE_SIZE});
|
||||
|
||||
const tools = html`<${Fragment}>
|
||||
<${Select} label="根因" all="全部根因" options=${meta.causes} value=${cause} onChange=${v => { setCause(v); setPage(1); }}/>
|
||||
<${GlassButton} onClick=${() => download('/api/export/advice', params)}>导出建议清单</${GlassButton}>
|
||||
</${Fragment}>`;
|
||||
const columns = [
|
||||
{key: 'ne_id', title: '基站编号'}, {key: 'site_name', title: '基站名称'}, {key: 'scene', title: '场景'},
|
||||
{key: 'start_time', title: '退服开始'}, {key: 'duration_min', title: '时长(分)'},
|
||||
{key: 'root_cause', title: '根因', render: v => html`<${Cause} value=${v}/>`}, {key: 'evidence', title: '关联告警证据'},
|
||||
{key: 'level', title: '分级', render: v => html`<${LevelTag} value=${v}/>`},
|
||||
{key: 'status', title: '状态', render: v => html`<${StatusTag} value=${v}/>`},
|
||||
{key: 'advice', title: '处置建议', wrap: true},
|
||||
];
|
||||
|
||||
return html`
|
||||
<${Section} title="超长退服根因与分级处置建议" extra=${tools}>
|
||||
${data ? html`
|
||||
<div>
|
||||
<${DataTable} rows=${data.rows} columns=${columns}/>
|
||||
<${Pager} page=${page} size=${PAGE_SIZE} total=${data.total} onPage=${setPage}
|
||||
prefix=${`超长退服 ${num(data.total)} 条,100% 已生成处置建议`}/>
|
||||
</div>` : html`<${Loading}/>`}
|
||||
</${Section}>`;
|
||||
}
|
||||
Reference in new issue
Block a user