Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Sep 29, 2023
1 parent bbea8b1 commit e26e3f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
23 changes: 12 additions & 11 deletions mobile_verifier/src/cell_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum CellType {
pub enum CellTypeLabel {
CellTypeLabelNone = 0,
CBRS = 1,
Wifi = 2,
WifiIndoor = 2,
}

impl CellType {
Expand All @@ -55,7 +55,7 @@ impl CellType {
Self::SercommIndoor => CellTypeLabel::CBRS,
Self::SercommOutdoor => CellTypeLabel::CBRS,
Self::CellTypeNone => CellTypeLabel::CellTypeLabelNone,
Self::NovaGenericWifiIndoor => CellTypeLabel::Wifi,
Self::NovaGenericWifiIndoor => CellTypeLabel::WifiIndoor,
}
}

Expand Down Expand Up @@ -91,15 +91,6 @@ impl CellType {
_ => dec!(1.0),
}
}

pub fn from_asserted(device_type: &String) -> Option<Self> {
// 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<CellType> for CellTypeProto {
Expand All @@ -115,3 +106,13 @@ impl From<CellType> for CellTypeProto {
}
}
}

impl CellTypeLabel {
pub fn from_asserted(device_type: &String) -> Option<Self> {
match device_type {
device_type if device_type.eq("wifiIndoor") => Some(CellTypeLabel::WifiIndoor),
device_type if device_type.eq("cbrs") => Some(CellTypeLabel::CBRS),
_ => None,
}
}
}
23 changes: 13 additions & 10 deletions mobile_verifier/src/heartbeats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const MINIMUM_HEARTBEAT_COUNT: i64 = 12;
#[derive(Clone, PartialEq)]
pub enum HBType {
Cbrs = 0,
Wifi = 1,
WifiIndoor = 1,
}

#[derive(Clone)]
Expand Down Expand Up @@ -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)),
}
}

Expand Down Expand Up @@ -83,7 +83,7 @@ impl From<CbrsHeartbeatIngestReport> for Heartbeat {
impl From<WifiHeartbeatIngestReport> 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,
Expand Down Expand Up @@ -137,13 +137,13 @@ 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")),
}
}

pub fn reward_weight(&self, reward_wifi_hbs: bool) -> Decimal {
if !reward_wifi_hbs && self.cell_type.to_label() == CellTypeLabel::Wifi {
if !reward_wifi_hbs && self.cell_type.to_label() == CellTypeLabel::WifiIndoor {
return Decimal::ZERO;
}
self.reward_weight
Expand Down Expand Up @@ -288,7 +288,7 @@ impl ValidatedHeartbeat {
pub async fn save(self, exec: &mut Transaction<'_, Postgres>) -> anyhow::Result<bool> {
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,
}
}

Expand Down Expand Up @@ -373,7 +373,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 {
Expand Down Expand Up @@ -403,11 +403,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
Expand Down

0 comments on commit e26e3f4

Please sign in to comment.