feat(realtime): 增加目标接收计数与频率计算支持

- 在 Target 结构体中新增 received_count 字段,用于跟踪每个目标在当前内存轨迹中的接收更新次数。
- 实现 ReceptionRate 结构体,计算目标更新频率,并在 State 中维护每个目标的接收率。
- 更新相关测试,确保接收计数和频率计算的准确性。
- 修改 Web UI 以显示目标的接收频率,提升用户体验。
- 升级协议版本至 4,确保后端、Worker 和前端的一致性。
This commit is contained in:
2026-11-02 17:32:44 +08:00
parent 7af8fb32cf
commit 1d6d7a277e
9 changed files with 194 additions and 34 deletions
+5 -5
View File
@@ -173,14 +173,14 @@ function markerCoordinate(id,index){
if(id===selected&&rawFocus&&passesFilters(id))return {coordinate:rawFocus,unverified:true};
return null;
}
function markerAge(value){if(!liveConnected)return '连接断开';if(!Number.isFinite(value)||value<0)return '—';if(value<1000)return `${Math.round(value)} ms`;if(value<10000)return `${(value/1000).toFixed(1)} 秒`;return `${Math.round(value/1000)} 秒`;}
function markerFrequency(value){if(!liveConnected)return '连接断开';if(!Number.isFinite(value)||value<0)return '—';if(value===0)return '0 Hz';if(value<0.1)return `${value.toFixed(2)} Hz`;if(value<100)return `${value.toFixed(1)} Hz`;return `${Math.round(value)} Hz`;}
function createTargetMarker(id,coordinate){
const root=document.createElement('div');root.className='rt-target-pin';
const card=document.createElement('div');card.className='rt-target-info';
const header=document.createElement('div');header.className='rt-target-info-head';
const name=document.createElement('span');name.className='rt-target-info-id';name.textContent=id;name.title=id;
const age=document.createElement('span');age.className='rt-target-info-age';age.title='该目标最近一次接收数据到服务端生成推送数据的时间,不代表定位精度或完整传输延迟';
header.append(name,age);
const frequency=document.createElement('span');frequency.className='rt-target-info-frequency';frequency.title='服务端接受的目标数据更新频率;多个接收来源合计,5 秒无更新时显示 0 Hz';
header.append(name,frequency);
const coordinates=document.createElement('div');coordinates.className='rt-target-info-coordinates';
const longitude=document.createElement('span');const latitude=document.createElement('span');coordinates.append(longitude,latitude);
const height=document.createElement('div');height.className='rt-target-info-height';
@@ -192,7 +192,7 @@ function createTargetMarker(id,coordinate){
const point=document.createElement('i');point.className='rt-drone-point';
root.append(card,icon,point);
const marker=new maplibre.Marker({element:root,anchor:'bottom'}).setLngLat(coordinate).addTo(map);
return {marker,root,card,name,age,longitude,latitude,height,verification,icon,coordinate:[...coordinate]};
return {marker,root,card,name,frequency,longitude,latitude,height,verification,icon,coordinate:[...coordinate]};
}
function syncTargetMarkers(force=false){
if(!map||!latest)return;
@@ -225,7 +225,7 @@ function syncTargetMarkers(force=false){
const value=markerInfos?.[index*3+1],heightKind=markerInfos?.[index*3+2];
const label=({1:'高度',2:'几何高度',3:'离地高度',4:'相对高度(原始)',5:'气压高度'})[heightKind]||'高度';
entry.height.textContent=`${label} ${Number.isFinite(value)?`${value.toFixed(1)} m`:'—'}`;
entry.age.textContent=`数据年龄 ${markerAge(markerInfos?.[index*3])}`;
entry.frequency.textContent=`数据频率 ${markerFrequency(markerInfos?.[index*3])}`;
entry.verification.textContent=position.unverified?'坐标待核实':'';
}
if(updateText)lastMarkerText=now;