feat(platform): add vehicle-first statistics overview
This commit is contained in:
@@ -210,6 +210,8 @@ export function Mileage({
|
||||
const closurePassed = closureDeltaKm != null && Math.abs(closureDeltaKm) < 0.01;
|
||||
const confidenceStatus = anomalyRows.length > 0 || pageCoverageRate < 100 ? '需复核' : '可用于 BI';
|
||||
const confidenceColor = confidenceStatus === '可用于 BI' ? 'green' as const : 'orange' as const;
|
||||
const currentEvidenceText = `${summary.vehicleCount.toLocaleString()} 车 / ${summary.sourceCount.toLocaleString()} 来源 / ${rows.length.toLocaleString()} 条明细`;
|
||||
const sourceConsistencyText = summary.sourceCount > 1 ? '可做跨来源核对' : summary.sourceCount === 1 ? '单来源车辆需关注' : '等待来源证据';
|
||||
const maxDateMileage = Math.max(...dateSeries.map((item) => item.value), 0);
|
||||
const maxSourceMileage = Math.max(...sourceSeries.map((item) => item.value), 0);
|
||||
const filterSummary = [
|
||||
@@ -318,6 +320,49 @@ export function Mileage({
|
||||
<Tag color={currentProtocol ? 'blue' : 'green'}>当前来源:{currentProtocol || '全部来源'}</Tag>
|
||||
<Typography.Text type="tertiary">里程统计按当前车辆与来源范围汇总。</Typography.Text>
|
||||
</div>
|
||||
<Card bordered title="车辆统计服务总览" style={{ marginTop: 16 }}>
|
||||
<div className="vp-table-toolbar">
|
||||
<Space wrap>
|
||||
<Tag color="blue">当前统计证据</Tag>
|
||||
<Typography.Text strong>{currentEvidenceText}</Typography.Text>
|
||||
<Typography.Text type="secondary">三类数据源最终汇总为一个车辆服务统计视图</Typography.Text>
|
||||
</Space>
|
||||
</div>
|
||||
<div className="vp-stat-insight-grid">
|
||||
{[
|
||||
{
|
||||
title: '里程统计',
|
||||
value: `${formatKm(summary.totalMileageKm)} km`,
|
||||
color: 'blue' as const,
|
||||
detail: '每日里程、区间里程、异常差值和可审计证据。'
|
||||
},
|
||||
{
|
||||
title: '在线率与离线时长',
|
||||
value: currentVehicleKeyword ? '车辆维度' : '车队维度',
|
||||
color: 'green' as const,
|
||||
detail: '后续接入在线区间聚合,按 VIN 统计在线率、离线时间和无更新时长。'
|
||||
},
|
||||
{
|
||||
title: '数据完整性',
|
||||
value: confidenceStatus,
|
||||
color: confidenceColor,
|
||||
detail: '围绕位置、里程、SOC、速度和来源新鲜度判断统计可信度。'
|
||||
},
|
||||
{
|
||||
title: '来源一致性',
|
||||
value: sourceConsistencyText,
|
||||
color: summary.sourceCount > 1 ? 'green' as const : 'orange' as const,
|
||||
detail: 'GB32960、JT808、Yutong MQTT 只作为同一车辆服务的来源证据。'
|
||||
}
|
||||
].map((item) => (
|
||||
<div key={item.title} className="vp-monitor-metric">
|
||||
<Tag color={item.color}>{item.title}</Tag>
|
||||
<div className="vp-monitor-metric-value">{item.value}</div>
|
||||
<Typography.Text type="secondary">{item.detail}</Typography.Text>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
<Card bordered>
|
||||
<Form key={JSON.stringify(filters)} initValues={filters} layout="horizontal" onSubmit={(values) => {
|
||||
const nextFilters = values as Record<string, string>;
|
||||
|
||||
@@ -6490,7 +6490,7 @@ test('shows mileage statistics workspace with trend source and definition', asyn
|
||||
expect(screen.getAllByText('JT808').length).toBeGreaterThanOrEqual(1);
|
||||
expect(screen.getAllByText('GB32960').length).toBeGreaterThanOrEqual(1);
|
||||
expect(screen.getByText('当前页里程')).toBeInTheDocument();
|
||||
expect(screen.getByText('140 km')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('140 km').length).toBeGreaterThanOrEqual(1);
|
||||
expect(screen.getByText('异常记录')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('1').length).toBeGreaterThanOrEqual(1);
|
||||
expect(screen.getByText('最大单日')).toBeInTheDocument();
|
||||
@@ -6508,6 +6508,61 @@ test('shows mileage statistics workspace with trend source and definition', asyn
|
||||
expect(screen.getByText((content) => content.includes('区间总值应等于各日里程之和'))).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('shows vehicle-first statistics domains for one vehicle service', async () => {
|
||||
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-STATS-SERVICE&protocol=JT808');
|
||||
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||
const path = String(input);
|
||||
if (path.includes('/api/mileage/summary')) {
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: { vehicleCount: 3, recordCount: 6, sourceCount: 2, totalMileageKm: 210, averageMileagePerVin: 70 },
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
}
|
||||
if (path.includes('/api/mileage/daily')) {
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: {
|
||||
items: [
|
||||
{ vin: 'VIN-STATS-SERVICE', plate: '粤A统计服务1', source: 'JT808', date: '2026-07-01', startMileageKm: 100, endMileageKm: 150, dailyMileageKm: 50, anomalySeverity: '' },
|
||||
{ vin: 'VIN-STATS-SERVICE', plate: '粤A统计服务1', source: 'GB32960', date: '2026-07-01', startMileageKm: 200, endMileageKm: 240, dailyMileageKm: 40, anomalySeverity: '' },
|
||||
{ vin: 'VIN-STATS-SERVICE-2', plate: '粤A统计服务2', source: 'JT808', date: '2026-07-02', startMileageKm: 300, endMileageKm: 380, dailyMileageKm: 80, anomalySeverity: 'warning' }
|
||||
],
|
||||
total: 3,
|
||||
limit: 20,
|
||||
offset: 0
|
||||
},
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: { items: [], total: 0, limit: 20, offset: 0 },
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
expect(await screen.findByText('车辆统计服务总览')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('里程统计').length).toBeGreaterThanOrEqual(1);
|
||||
expect(screen.getByText('在线率与离线时长')).toBeInTheDocument();
|
||||
expect(screen.getByText('数据完整性')).toBeInTheDocument();
|
||||
expect(screen.getByText('来源一致性')).toBeInTheDocument();
|
||||
expect(screen.getByText('三类数据源最终汇总为一个车辆服务统计视图')).toBeInTheDocument();
|
||||
expect(screen.getByText('当前统计证据')).toBeInTheDocument();
|
||||
expect(screen.getByText('3 车 / 2 来源 / 3 条明细')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('copies mileage statistics summary for operations reporting', async () => {
|
||||
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-COPY&protocol=JT808&dateFrom=2026-07-01&dateTo=2026-07-03');
|
||||
const writeText = vi.fn(() => Promise.resolve());
|
||||
|
||||
@@ -22,7 +22,7 @@ The platform navigation should use vehicle-service language rather than protocol
|
||||
6. History Query: historical locations, raw frames, and flattened parsed fields with pagination and field trimming.
|
||||
7. Alert Events: alert trigger records, affected vehicles, rule evidence, manual state, notification state, and escalation readiness.
|
||||
8. Notification Rules: alert trigger rules, notification targets, channels, escalation windows, acceptance criteria, and copyable runbooks.
|
||||
9. Statistics: daily/range mileage, online rate, offline duration, data completeness, and source consistency.
|
||||
9. Statistics: one vehicle-service statistics workspace covering daily/range mileage, online rate, offline duration, data completeness, and source consistency.
|
||||
10. Ops Quality: GB32960, JT808, Yutong MQTT, Kafka, NATS, Redis, TDengine, MySQL, AMap, gateway, and runtime health.
|
||||
|
||||
See `docs/vehicle-platform-blueprint.md` for the detailed page-level blueprint and phased implementation plan.
|
||||
@@ -94,6 +94,7 @@ Statistics must stay vehicle-first and evidence-backed:
|
||||
- Online rate should be computed by vehicle and then broken down by source.
|
||||
- Data completeness should report missing location, mileage, SOC, speed, and source freshness.
|
||||
- Source consistency should compare GB32960, JT808, and Yutong MQTT only when the same VIN has multiple sources.
|
||||
- The statistics page should show these four domains together, because all protocol data ultimately supports one vehicle service view.
|
||||
|
||||
## Interaction Rules
|
||||
|
||||
|
||||
@@ -192,6 +192,7 @@ Primary modules:
|
||||
- Online: online rate, offline duration, no update duration, source online distribution.
|
||||
- Completeness: location, mileage, SOC, speed, source freshness.
|
||||
- Consistency: cross-source time delta and mileage delta for multi-source vehicles.
|
||||
- Statistics overview: show the four domains together so operations users understand that GB32960, JT808, and Yutong MQTT are evidence feeding one vehicle service.
|
||||
|
||||
Rule:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user