feat(realtime): 增加目标接收计数与频率计算支持
- 在 Target 结构体中新增 received_count 字段,用于跟踪每个目标在当前内存轨迹中的接收更新次数。 - 实现 ReceptionRate 结构体,计算目标更新频率,并在 State 中维护每个目标的接收率。 - 更新相关测试,确保接收计数和频率计算的准确性。 - 修改 Web UI 以显示目标的接收频率,提升用户体验。 - 升级协议版本至 4,确保后端、Worker 和前端的一致性。
This commit is contained in:
@@ -93,6 +93,7 @@ impl Store {
|
||||
observation: observation.clone(),
|
||||
received_at_ms: now_ms,
|
||||
position_generation: 0,
|
||||
received_count: 0,
|
||||
sources: vec![],
|
||||
},
|
||||
sources: HashMap::new(),
|
||||
@@ -125,6 +126,7 @@ impl Store {
|
||||
.sources
|
||||
.retain(|_, s| now_ms.saturating_sub(s.received_at_ms) < self.ttl_ms);
|
||||
refresh(track);
|
||||
track.target.received_count = track.target.received_count.saturating_add(1);
|
||||
track.suppressed = false;
|
||||
if let Some(observer) = &self.observer {
|
||||
observer(&track.target.observation, now_ms);
|
||||
@@ -333,6 +335,31 @@ mod tests {
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn received_count_tracks_only_accepted_updates_per_target() {
|
||||
let mut store = Store::new(4, 20, 30_000, 1);
|
||||
assert!(store.apply(sample("A", 1), 100));
|
||||
assert!(!store.apply(sample("A", 1), 200));
|
||||
let mut invalid = sample("A", 2);
|
||||
invalid.longitude = Some(f64::NAN);
|
||||
assert!(!store.apply(invalid, 300));
|
||||
assert!(store.apply(sample("B", 1), 400));
|
||||
assert!(store.apply(sample("A", 2), 500));
|
||||
let mut second_source = sample("A", 1);
|
||||
second_source.receiver_id = "station-2".into();
|
||||
assert!(store.apply(second_source, 600));
|
||||
let frame = store.frame(Some(1), 600);
|
||||
let counts: HashMap<_, _> = frame
|
||||
.targets
|
||||
.iter()
|
||||
.map(|target| (target.observation.target_id.as_str(), target.received_count))
|
||||
.collect();
|
||||
assert_eq!(counts.get("A"), Some(&3));
|
||||
assert_eq!(counts.get("B"), Some(&1));
|
||||
store.expire(30_600);
|
||||
assert!(store.apply(sample("A", 1), 30_601));
|
||||
assert_eq!(store.frame(None, 30_601).targets[0].received_count, 1);
|
||||
}
|
||||
#[test]
|
||||
fn coalesced_position_loss_still_breaks_the_trail() {
|
||||
let mut store = Store::new(10, 100, 30000, 1);
|
||||
let a = sample("TEST", 1);
|
||||
|
||||
@@ -5,7 +5,7 @@ pub mod geofences;
|
||||
pub mod map_settings;
|
||||
pub mod target_lists;
|
||||
|
||||
pub const PROTOCOL_VERSION: u16 = 3;
|
||||
pub const PROTOCOL_VERSION: u16 = 4;
|
||||
pub const MAX_BATCH: usize = 4096;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||
@@ -70,6 +70,8 @@ pub struct Target {
|
||||
pub received_at_ms: u64,
|
||||
/// Changes on every position availability transition, even between coalesced frames.
|
||||
pub position_generation: u64,
|
||||
/// Accepted updates for this target since its current in-memory track began.
|
||||
pub received_count: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
.rt-target-info{box-sizing:border-box;width:100%;padding:7px 9px;border:1px solid #d6e9f04a;border-radius:6px;background:rgba(9,20,27,.38);backdrop-filter:blur(5px);-webkit-backdrop-filter:blur(5px);text-shadow:0 1px 3px #000,0 0 4px #000}
|
||||
.rt-target-info-head{display:flex;align-items:center;justify-content:space-between;gap:6px;padding-bottom:4px;border-bottom:1px solid #e0f2fa35}
|
||||
.rt-target-info-id{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px;font-weight:600;letter-spacing:.01em}
|
||||
.rt-target-info-age{flex:none;white-space:nowrap;color:#d6e8ee;font-size:10px}
|
||||
.rt-target-info-frequency{flex:none;white-space:nowrap;color:#d6e8ee;font-size:10px}
|
||||
.rt-target-info-coordinates{display:flex;justify-content:space-between;gap:8px;margin-top:4px;font-size:11px;font-variant-numeric:tabular-nums;white-space:nowrap}
|
||||
.rt-target-info-height,.rt-target-info-verification{margin-top:2px;font-size:11px;font-variant-numeric:tabular-nums}
|
||||
.rt-target-info-verification{color:#ffe0a2}.rt-target-info-verification:empty{display:none}
|
||||
|
||||
+135
-16
@@ -23,10 +23,62 @@ pub fn acknowledge(sequence: f64) {
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
targets: BTreeMap<String, Target>,
|
||||
rates: BTreeMap<String, ReceptionRate>,
|
||||
epoch: Option<u64>,
|
||||
sequence: u64,
|
||||
}
|
||||
|
||||
const RATE_WINDOW_MS: u64 = 5_000;
|
||||
|
||||
#[derive(Default)]
|
||||
struct ReceptionRate {
|
||||
baseline: Option<(u64, u64)>,
|
||||
latest: Option<(u64, u64)>,
|
||||
measured_hz: Option<f64>,
|
||||
}
|
||||
|
||||
impl ReceptionRate {
|
||||
fn observe(&mut self, received_at_ms: u64, received_count: u64) {
|
||||
let sample = (received_at_ms, received_count);
|
||||
let Some((last_time, last_count)) = self.latest else {
|
||||
self.baseline = Some(sample);
|
||||
self.latest = Some(sample);
|
||||
return;
|
||||
};
|
||||
if received_at_ms < last_time || received_count < last_count {
|
||||
*self = Self {
|
||||
baseline: Some(sample),
|
||||
latest: Some(sample),
|
||||
measured_hz: None,
|
||||
};
|
||||
return;
|
||||
}
|
||||
if received_count == last_count {
|
||||
return;
|
||||
}
|
||||
self.latest = Some(sample);
|
||||
if let Some((start_time, start_count)) = self.baseline {
|
||||
let elapsed = received_at_ms.saturating_sub(start_time);
|
||||
if elapsed > 0 {
|
||||
self.measured_hz =
|
||||
Some((received_count - start_count) as f64 * 1000.0 / elapsed as f64);
|
||||
if elapsed >= RATE_WINDOW_MS {
|
||||
self.baseline = Some(sample);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn current(&self, server_time_ms: u64) -> Option<f64> {
|
||||
let (latest_time, _) = self.latest?;
|
||||
if server_time_ms.saturating_sub(latest_time) >= RATE_WINDOW_MS {
|
||||
Some(0.0)
|
||||
} else {
|
||||
self.measured_hz
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
fn topology_changed(&self, frame: &Frame) -> bool {
|
||||
self.epoch.is_none()
|
||||
@@ -42,6 +94,9 @@ impl State {
|
||||
return Err("unsupported protocol version");
|
||||
}
|
||||
if frame.snapshot {
|
||||
if self.epoch != Some(frame.epoch) {
|
||||
self.rates.clear();
|
||||
}
|
||||
self.targets.clear();
|
||||
self.epoch = Some(frame.epoch);
|
||||
} else if self.epoch != Some(frame.epoch) || frame.sequence < self.sequence {
|
||||
@@ -50,11 +105,19 @@ impl State {
|
||||
self.sequence = frame.sequence;
|
||||
for id in &frame.removed {
|
||||
self.targets.remove(id);
|
||||
self.rates.remove(id);
|
||||
}
|
||||
for target in &frame.targets {
|
||||
self.rates
|
||||
.entry(target.observation.target_id.clone())
|
||||
.or_default()
|
||||
.observe(target.received_at_ms, target.received_count);
|
||||
self.targets
|
||||
.insert(target.observation.target_id.clone(), target.clone());
|
||||
}
|
||||
if frame.snapshot {
|
||||
self.rates.retain(|id, _| self.targets.contains_key(id));
|
||||
}
|
||||
if self.targets.len() > 10000 {
|
||||
return Err("target capacity exceeded");
|
||||
}
|
||||
@@ -83,13 +146,9 @@ fn marker_height(observation: &Observation) -> (f64, u8) {
|
||||
(f64::NAN, 0)
|
||||
}
|
||||
|
||||
fn marker_info(target: &Target, server_time_ms: u64) -> [f64; 3] {
|
||||
fn marker_info(target: &Target, rate_hz: Option<f64>) -> [f64; 3] {
|
||||
let (height, height_kind) = marker_height(&target.observation);
|
||||
[
|
||||
server_time_ms.saturating_sub(target.received_at_ms) as f64,
|
||||
height,
|
||||
f64::from(height_kind),
|
||||
]
|
||||
[rate_hz.unwrap_or(f64::NAN), height, f64::from(height_kind)]
|
||||
}
|
||||
|
||||
fn post_status(scope: &web_sys::DedicatedWorkerGlobalScope, text: &str) {
|
||||
@@ -144,7 +203,11 @@ pub fn connect(url: &str) -> Result<(), JsValue> {
|
||||
o.altitude_m.map(f64::from).unwrap_or(f64::NAN),
|
||||
o.heading_deg.map(f64::from).unwrap_or(f64::NAN),
|
||||
]);
|
||||
let info = marker_info(target, frame.server_time_ms);
|
||||
let rate = state
|
||||
.rates
|
||||
.get(id)
|
||||
.and_then(|rate| rate.current(frame.server_time_ms));
|
||||
let info = marker_info(target, rate);
|
||||
marker_infos.extend_from_slice(&info);
|
||||
max_age = max_age.max(frame.server_time_ms.saturating_sub(target.received_at_ms));
|
||||
}
|
||||
@@ -238,19 +301,19 @@ mod tests {
|
||||
},
|
||||
received_at_ms,
|
||||
position_generation: 1,
|
||||
received_count: 1,
|
||||
sources: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn marker_info_uses_each_targets_receive_time_and_keeps_height_reference() {
|
||||
fn marker_info_keeps_frequency_and_height_reference() {
|
||||
let mut recent = target(900);
|
||||
let older = target(250);
|
||||
assert_eq!(marker_info(&recent, 1_000)[0], 100.0);
|
||||
assert_eq!(marker_info(&older, 1_000)[0], 750.0);
|
||||
assert!(marker_info(&older, 1_000)[1].is_nan());
|
||||
assert_eq!(marker_info(&older, 1_000)[2], 0.0);
|
||||
assert_eq!(marker_info(&recent, 800)[0], 0.0);
|
||||
assert_eq!(marker_info(&recent, Some(10.0))[0], 10.0);
|
||||
assert!(marker_info(&older, None)[0].is_nan());
|
||||
assert!(marker_info(&older, None)[1].is_nan());
|
||||
assert_eq!(marker_info(&older, None)[2], 0.0);
|
||||
|
||||
recent.observation.telemetry = Some(DeviceTelemetry {
|
||||
geometric_altitude_m: Some(125.0),
|
||||
@@ -258,9 +321,9 @@ mod tests {
|
||||
relative_height_m: Some(20.0),
|
||||
..DeviceTelemetry::default()
|
||||
});
|
||||
assert_eq!(marker_info(&recent, 1_000)[1..], [125.0, 2.0]);
|
||||
assert_eq!(marker_info(&recent, Some(10.0))[1..], [125.0, 2.0]);
|
||||
recent.observation.altitude_m = Some(230.0);
|
||||
assert_eq!(marker_info(&recent, 1_000)[1..], [230.0, 1.0]);
|
||||
assert_eq!(marker_info(&recent, Some(10.0))[1..], [230.0, 1.0]);
|
||||
recent.observation.altitude_m = None;
|
||||
recent
|
||||
.observation
|
||||
@@ -268,7 +331,63 @@ mod tests {
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.geometric_altitude_m = Some(f64::NAN);
|
||||
assert_eq!(marker_info(&recent, 1_000)[1..], [31.0, 3.0]);
|
||||
assert_eq!(marker_info(&recent, Some(10.0))[1..], [31.0, 3.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frequency_counts_coalesced_updates_and_expires_after_silence() {
|
||||
let mut fast = ReceptionRate::default();
|
||||
let mut slow = ReceptionRate::default();
|
||||
fast.observe(1_000, 1);
|
||||
slow.observe(1_000, 1);
|
||||
assert_eq!(fast.current(1_000), None);
|
||||
fast.observe(1_400, 41);
|
||||
slow.observe(2_000, 2);
|
||||
assert_eq!(fast.current(2_000), Some(100.0));
|
||||
assert_eq!(slow.current(2_000), Some(1.0));
|
||||
fast.observe(1_400, 41);
|
||||
assert_eq!(fast.current(6_399), Some(100.0));
|
||||
assert_eq!(fast.current(6_400), Some(0.0));
|
||||
fast.observe(7_000, 42);
|
||||
assert_eq!(fast.current(7_000), Some(41.0 * 1000.0 / 6000.0));
|
||||
fast.observe(500, 1);
|
||||
assert_eq!(
|
||||
fast.current(500),
|
||||
None,
|
||||
"a restarted track starts a new measurement"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decoded_frames_keep_per_target_frequency_through_coalescing() {
|
||||
let mut state = State::default();
|
||||
let mut item = target(1_000);
|
||||
let mut frame = Frame {
|
||||
version: PROTOCOL_VERSION,
|
||||
epoch: 1,
|
||||
sequence: 1,
|
||||
snapshot: true,
|
||||
server_time_ms: 1_000,
|
||||
targets: vec![item.clone()],
|
||||
removed: vec![],
|
||||
};
|
||||
let bytes = postcard::to_allocvec(&frame).unwrap();
|
||||
state.apply(&postcard::from_bytes(&bytes).unwrap()).unwrap();
|
||||
assert_eq!(state.rates["TEST"].current(1_000), None);
|
||||
item.received_at_ms = 1_500;
|
||||
item.received_count = 6;
|
||||
frame.snapshot = false;
|
||||
frame.sequence = 6;
|
||||
frame.server_time_ms = 1_500;
|
||||
frame.targets = vec![item];
|
||||
let bytes = postcard::to_allocvec(&frame).unwrap();
|
||||
state.apply(&postcard::from_bytes(&bytes).unwrap()).unwrap();
|
||||
assert_eq!(state.rates["TEST"].current(1_500), Some(10.0));
|
||||
assert_eq!(state.rates["TEST"].current(6_500), Some(0.0));
|
||||
frame.targets.clear();
|
||||
frame.removed.push("TEST".into());
|
||||
state.apply(&frame).unwrap();
|
||||
assert!(!state.rates.contains_key("TEST"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -88,7 +88,7 @@ flowchart LR
|
||||
|
||||
配置保存在业务数据根目录 `receivers.json`。首次迁移读取旧 `receiver-config.json` 并保留原文件;以后以多机配置为准。配置损坏不覆盖原文件,不启动设备;保存失败不替换运行配置。程序回退时须注意旧版读取的是旧配置,不能直接认为两者同步。
|
||||
|
||||
接收机 ID 由服务端配置注入,不信任报文提供的来源。已知 RID 序列号或 MAC 身份可按既有语义合并;UID 默认使用来源作用域 `SRC-...` 隔离。确认设备协议中的 UID 全局唯一对应无人机后,可在每台对应接收机选择“跨接收机合并”,相同 UID 才会合并为一个目标;不同 UID 仍独立。身份范围切换不会自动迁移已有人工关联或名单。UID 不按备案序列号自动匹配,可人工关联;同一接收机输出相同 UID 且没有其他身份字段时无法可靠区分多架飞机。约定输入的未知身份继续隔离。目标携带各来源观测;各来源按本机接收时间独立在 30 秒后过期。选择最新有效定位,来源切换或定位失效断开轨迹,不进行位置平均或多站定位。WebSocket / Postcard 帧版本为 3,后端、Worker 和页面须一起升级。
|
||||
接收机 ID 由服务端配置注入,不信任报文提供的来源。已知 RID 序列号或 MAC 身份可按既有语义合并;UID 默认使用来源作用域 `SRC-...` 隔离。确认设备协议中的 UID 全局唯一对应无人机后,可在每台对应接收机选择“跨接收机合并”,相同 UID 才会合并为一个目标;不同 UID 仍独立。身份范围切换不会自动迁移已有人工关联或名单。UID 不按备案序列号自动匹配,可人工关联;同一接收机输出相同 UID 且没有其他身份字段时无法可靠区分多架飞机。约定输入的未知身份继续隔离。目标携带各来源观测;各来源按本机接收时间独立在 30 秒后过期。选择最新有效定位,来源切换或定位失效断开轨迹,不进行位置平均或多站定位。WebSocket / Postcard 帧现为版本 4,后端、Worker 和页面须一起升级;目标接收计数及频率计算见合成协议文档。
|
||||
|
||||
## COM16 UID JSON 的验证边界
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 实时通道 v2(共享目标与合成输入)
|
||||
# 实时通道 v4(共享目标与合成输入)
|
||||
|
||||
本协议为本项目实现的测试输入与网页推送契约,不是任何厂商的 RID 无线报文格式,也不包含接收设备驱动。
|
||||
|
||||
@@ -41,7 +41,9 @@ fpv-rid-registry.exe --data-root "D:\独立测试目录" --simulation-api
|
||||
- `GET /api/realtime/ws`:WebSocket 二进制帧;数据结构见 `crates/rid-shared/src/lib.rs` 的 Frame,使用锁定版本 Postcard 编码。
|
||||
- 所有接口只监听 127.0.0.1:8787,拒绝不属于本机登记站的 Origin。没有独立的远程用户鉴权,不能直接转发到公网。
|
||||
|
||||
Frame.version 为 2;epoch 是服务进程会话标识;sequence 是状态水位,而非连续的推送包编号。首次连接发送 snapshot=true;之后每 20 ms 最多一批合并增量。有限变更日志已覆盖客户端游标时会重新发完整快照。targets 为最新状态,removed 为已移除目标 ID。
|
||||
Frame.version 为 4;epoch 是服务进程会话标识;sequence 是状态水位,而非连续的推送包编号。首次连接发送 snapshot=true;之后每 20 ms 最多一批合并增量。有限变更日志已覆盖客户端游标时会重新发完整快照。targets 为最新状态,removed 为已移除目标 ID。
|
||||
|
||||
Target.received_count 是当前内存轨迹中该目标被服务端接受的观测累计次数,同一目标的多个接收来源合计;被拒绝或重复的数据不计入。Worker 使用累计次数与服务端接收时间的差值估计目标更新频率,因此合并推送不会把多条已接受观测误算成一条。首次样本无法计算频率,连续 5 秒没有更新显示 0 Hz。该值不是无线载波频率,也不包含进入服务端之前已经丢失的数据。
|
||||
|
||||
客户端完成解码、合并并提交主线程绘制后,发送文本形式的 sequence 确认。每客户端最多一个未确认批次;发送超时 200 ms、确认超时 1 秒,超过即断开。重连必须从快照开始;当前最多 4 个并发客户端。
|
||||
|
||||
@@ -60,10 +62,10 @@ cargo run --release -p realtime-core --bin rid-simulator -- --targets 1000 --int
|
||||
自动浏览器测试可用 RID_INPUT_FORMAT=binary 调用独立 Rust 生成器,默认使用 HTTP JSON。自动浏览器测试:`node scripts/test-realtime.mjs`。环境变量 RID_TARGETS(最多 10000)和 RID_SOAK_SECONDS(最多 7200)控制负载。该测试使用自己的临时数据目录,并拒绝附着到已经占用 8787 的服务。
|
||||
|
||||
|
||||
## v2 未定位与设备字段
|
||||
## 未定位与设备字段
|
||||
|
||||
Observation 的 longitude/latitude 同时为 null 表示未定位,只缺一个分量则校验失败;altitude_m(椭球高)和 heading_deg 可独立为 null。telemetry 为可选设备字段,定义见共享 crate 的 DeviceTelemetry,各种高度互不替代。设备协议由接收端适配,合成输入不表示真实设备。
|
||||
|
||||
Target.position_generation 在坐标可用性变化时递增,客户端据此中断轨迹,避免快照/增量合并隐藏一次定位失效。v2 WebSocket/Postcard 帧要求同步构建后端和 Worker,旧版本拒绝并重连,不猜测解码。接收设置中的原有 json-lines/postcard 输入仍使用 LegacyObservation 的 v1 线格式,由适配器转换;不要向原有 Postcard 接收模式发送 v2 内部类型。
|
||||
Target.position_generation 在坐标可用性变化时递增,客户端据此中断轨迹,避免快照/增量合并隐藏一次定位失效。v4 WebSocket/Postcard 帧要求同步构建后端和 Worker,旧版本不兼容。接收设置中的原有 json-lines/postcard 输入仍使用 LegacyObservation 的 v1 线格式,由适配器转换;不要向原有 Postcard 接收模式发送内部类型。
|
||||
|
||||
Worker 分别传递全量目标 ID、位置数组和变化条目的详情;地图只绘制有坐标的目标。位置未知时不会误画到原点,高度或航向未知不会阻断合法经纬度绘制。
|
||||
|
||||
@@ -64,15 +64,21 @@ vm.runInContext('window.ridMap.update(new Float64Array([]),[],[]);flush();',cont
|
||||
assert.equal(markers,0,'target expiration removes the unverified marker');
|
||||
vm.runInContext('window.ridMap.setSources(null);',context);
|
||||
context.twoPositions=new Float64Array([120,30,NaN,0,121,31,NaN,0]);
|
||||
context.twoInfos=new Float64Array([390,125,2,2400,NaN,0]);
|
||||
context.twoInfos=new Float64Array([1.5,125,2,0,NaN,0]);
|
||||
vm.runInContext('window.ridMap.update(twoPositions,["TEST","TWO"],[1,1],twoInfos);flush();',context);
|
||||
assert.equal(markers,2,'each located target receives its own card');
|
||||
let entries=vm.runInContext('markers',context);
|
||||
assert.equal(entries.get('TEST').age.textContent,'数据年龄 390 ms');
|
||||
assert.equal(entries.get('TWO').age.textContent,'数据年龄 2.4 秒');
|
||||
assert.equal(entries.get('TEST').frequency.textContent,'数据频率 1.5 Hz');
|
||||
assert.equal(entries.get('TWO').frequency.textContent,'数据频率 0 Hz');
|
||||
assert.equal(entries.get('TEST').height.textContent,'几何高度 125.0 m');
|
||||
assert.equal(entries.get('TWO').height.textContent,'高度 —');
|
||||
assert.equal(entries.get('TEST').longitude.textContent,'经度 120.000000');
|
||||
now+=250;context.twoInfos[0]=NaN;
|
||||
vm.runInContext('window.ridMap.update(twoPositions,undefined,[1,1],twoInfos);flush();',context);
|
||||
assert.equal(entries.get('TEST').frequency.textContent,'数据频率 —','frequency is unknown until enough samples arrive');
|
||||
now+=250;context.twoInfos[0]=0.05;
|
||||
vm.runInContext('window.ridMap.update(twoPositions,undefined,[1,1],twoInfos);flush();',context);
|
||||
assert.equal(entries.get('TEST').frequency.textContent,'数据频率 0.05 Hz','low but nonzero rates are not rounded to zero');
|
||||
vm.runInContext('window.ridMap.select("TWO");',context);
|
||||
assert.equal(entries.get('TWO').root.style.zIndex,'10','selected target renders above other cards');
|
||||
assert.equal(entries.get('TEST').root.style.zIndex,'1');
|
||||
@@ -80,7 +86,7 @@ assert.equal(entries.get('TWO').icon.attributes['aria-pressed'],'true');
|
||||
entries.get('TEST').icon.listeners.click({stopPropagation(){}});
|
||||
assert.equal(events.at(-1).detail,'TEST','clicking a logo requests selection of that target');
|
||||
vm.runInContext('window.ridMap.connection(false);',context);
|
||||
assert.equal(entries.get('TWO').age.textContent,'数据年龄 连接断开');
|
||||
assert.equal(entries.get('TWO').frequency.textContent,'数据频率 连接断开');
|
||||
vm.runInContext('window.ridMap.connection(true);',context);
|
||||
context.longIds=Array.from({length:130},(_,i)=>`T${i}`);
|
||||
context.longPositions=new Float64Array(context.longIds.flatMap((_,i)=>[120+i/10000,30,NaN,0]));
|
||||
@@ -95,4 +101,4 @@ assert.equal(markers,0,'zero coordinate pair must not create a map marker');
|
||||
context.zeroComponent=new Float64Array([0,30,NaN,0]);
|
||||
vm.runInContext('window.ridMap.update(zeroComponent,["ZERO"],[],null);flush();',context);
|
||||
assert.equal(markers,1,'a single zero coordinate component remains valid');
|
||||
console.log(JSON.stringify({status:'PASS',scenarios:['unknown position excluded from GPU and selection','unknown altitude/heading do not block valid position','loss removes marker and trail','recovery starts new trail','coalesced loss breaks trail','source filter hides and restores targets','saved geofence renders on the realtime map','unverified marker follows its lifecycle and ignores zero GPS','per-target card age and height reference','click requests selection and selected card is on top','disconnect state','bounded card rendering']}));
|
||||
console.log(JSON.stringify({status:'PASS',scenarios:['unknown position excluded from GPU and selection','unknown altitude/heading do not block valid position','loss removes marker and trail','recovery starts new trail','coalesced loss breaks trail','source filter hides and restores targets','saved geofence renders on the realtime map','unverified marker follows its lifecycle and ignores zero GPS','per-target card frequency and height reference','click requests selection and selected card is on top','disconnect state','bounded card rendering']}));
|
||||
|
||||
+5
-1
@@ -387,6 +387,7 @@ mod tests {
|
||||
position_generation: 0,
|
||||
observation: o,
|
||||
received_at_ms: time,
|
||||
received_count: 1,
|
||||
}],
|
||||
time,
|
||||
)
|
||||
@@ -561,6 +562,7 @@ mod tests {
|
||||
position_generation: 0,
|
||||
observation: observation(121.0, 5),
|
||||
received_at_ms: 1004,
|
||||
received_count: 1,
|
||||
}];
|
||||
assert_eq!(
|
||||
engine
|
||||
@@ -584,7 +586,8 @@ mod tests {
|
||||
sources: vec![],
|
||||
position_generation: 0,
|
||||
observation: observation(120.0, 6),
|
||||
received_at_ms: 1005
|
||||
received_at_ms: 1005,
|
||||
received_count: 1,
|
||||
}],
|
||||
1006
|
||||
)
|
||||
@@ -633,6 +636,7 @@ mod tests {
|
||||
position_generation: 0,
|
||||
observation: o.clone(),
|
||||
received_at_ms: 1000,
|
||||
received_count: 1,
|
||||
}];
|
||||
assert!(
|
||||
engine
|
||||
|
||||
Reference in New Issue
Block a user