From 072d05164107d05f0cd1bd8025bfb0133e1a31dc Mon Sep 17 00:00:00 2001 From: Andrew McKenzie Date: Fri, 29 Sep 2023 15:48:36 +0100 Subject: [PATCH] tweaks --- mobile_verifier/src/cell_type.rs | 23 ++++++++++++----------- mobile_verifier/src/heartbeats/mod.rs | 21 ++++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/mobile_verifier/src/cell_type.rs b/mobile_verifier/src/cell_type.rs index 1d4f47429..0009d789b 100644 --- a/mobile_verifier/src/cell_type.rs +++ b/mobile_verifier/src/cell_type.rs @@ -27,7 +27,7 @@ pub enum CellType { pub enum CellTypeLabel { CellTypeLabelNone = 0, CBRS = 1, - Wifi = 2, + WifiIndoor = 2, } impl CellType { @@ -50,7 +50,7 @@ impl CellType { Self::SercommIndoor => CellTypeLabel::CBRS, Self::SercommOutdoor => CellTypeLabel::CBRS, Self::CellTypeNone => CellTypeLabel::CellTypeLabelNone, - Self::NovaGenericWifiIndoor => CellTypeLabel::Wifi, + Self::NovaGenericWifiIndoor => CellTypeLabel::WifiIndoor, } } @@ -87,15 +87,6 @@ impl CellType { _ => dec!(1.0), } } - - pub fn from_asserted(device_type: &String) -> Option { - // TODO: currently only handling wifi indoor, handle other cell types - // when foundation device type values are in use - match device_type { - device_type if device_type.eq("wifiIndoor") => Some(CellType::NovaGenericWifiIndoor), - _ => None, - } - } } impl From for CellTypeProto { @@ -111,3 +102,13 @@ impl From for CellTypeProto { } } } + +impl CellTypeLabel { + pub fn from_asserted(device_type: &String) -> Option { + match device_type { + device_type if device_type.eq("wifiIndoor") => Some(CellTypeLabel::WifiIndoor), + device_type if device_type.eq("cbrs") => Some(CellTypeLabel::CBRS), + _ => None, + } + } +} diff --git a/mobile_verifier/src/heartbeats/mod.rs b/mobile_verifier/src/heartbeats/mod.rs index a0d8ee109..0734af034 100644 --- a/mobile_verifier/src/heartbeats/mod.rs +++ b/mobile_verifier/src/heartbeats/mod.rs @@ -24,7 +24,7 @@ const MINIMUM_HEARTBEAT_COUNT: i64 = 12; #[derive(Clone, PartialEq)] pub enum HBType { Cbrs = 0, - Wifi = 1, + WifiIndoor = 1, } #[derive(Clone)] @@ -54,7 +54,7 @@ impl Heartbeat { .ok_or_else(|| anyhow!("expected cbsd_id, found none"))?; Ok((cbsd_id, ts)) } - HBType::Wifi => Ok((self.hotspot_key.to_string(), ts)), + HBType::WifiIndoor => Ok((self.hotspot_key.to_string(), ts)), } } @@ -83,7 +83,7 @@ impl From for Heartbeat { impl From for Heartbeat { fn from(value: WifiHeartbeatIngestReport) -> Self { Self { - hb_type: HBType::Wifi, + hb_type: HBType::WifiIndoor, hotspot_key: value.report.pubkey, cbsd_id: None, operation_mode: value.report.operation_mode, @@ -122,7 +122,7 @@ impl HeartbeatReward { .cbsd_id .clone() .ok_or_else(|| anyhow!("expected cbsd_id, found none"))?), - CellTypeLabel::Wifi => Ok(self.hotspot_key.to_string()), + CellTypeLabel::WifiIndoor => Ok(self.hotspot_key.to_string()), _ => Err(anyhow!("failed to derive label from cell type")), } } @@ -285,7 +285,7 @@ impl ValidatedHeartbeat { pub async fn save(self, exec: &mut Transaction<'_, Postgres>) -> anyhow::Result { match self.report.hb_type { HBType::Cbrs => self.save_cbrs_hb(exec).await, - HBType::Wifi => self.save_wifi_hb(exec).await, + HBType::WifiIndoor => self.save_wifi_hb(exec).await, } } @@ -370,7 +370,7 @@ pub async fn validate_heartbeat( }, // for wifi HBs temporary assume we have an indoor wifi spot // this will be better/properly handled when coverage reports are live - HBType::Wifi => CellType::NovaGenericWifiIndoor, + HBType::WifiIndoor => CellType::NovaGenericWifiIndoor, }; if !heartbeat.operation_mode { @@ -400,11 +400,14 @@ pub async fn validate_heartbeat( )); }; - if CellType::from_asserted(&metadata.device_type) != Some(cell_type) { + let asserted_celltype_label = CellTypeLabel::from_asserted(&metadata.device_type); + if asserted_celltype_label == Some(CellTypeLabel::WifiIndoor) + && Some(cell_type.to_label()) != asserted_celltype_label + { return Ok((cell_type, proto::HeartbeatValidity::BadCellType, None)); - } + }; - let distance_to_asserted = if heartbeat.hb_type == HBType::Wifi { + let distance_to_asserted = if heartbeat.hb_type == HBType::WifiIndoor { Some(heartbeat.asserted_distance(metadata.location)?) } else { None