diff --git a/coverage_point_calculator/src/speedtest.rs b/coverage_point_calculator/src/speedtest.rs index d184b58ce..000623e68 100644 --- a/coverage_point_calculator/src/speedtest.rs +++ b/coverage_point_calculator/src/speedtest.rs @@ -2,8 +2,8 @@ use chrono::{DateTime, Utc}; use rust_decimal::Decimal; use rust_decimal_macros::dec; -pub const MIN_REQUIRED_SPEEDTEST_SAMPLES: usize = 2; -pub const MAX_ALLOWED_SPEEDTEST_SAMPLES: usize = 6; +const MIN_REQUIRED_SPEEDTEST_SAMPLES: usize = 2; +const MAX_ALLOWED_SPEEDTEST_SAMPLES: usize = 6; type Millis = u32; @@ -53,14 +53,32 @@ pub struct Speedtest { } impl Speedtest { - /// Construct a maximally acceptable speedtest for mocking - pub fn mock() -> Self { - Self { - upload_speed: BytesPs::mbps(MIN_GOOD_UPLOAD_SPEED_MBPS), - download_speed: BytesPs::mbps(MIN_GOOD_DOWNLOAD_SPEED_MBPS), - latency_millis: BEST_LATENCY, - timestamp: Utc::now(), - } + /// Construct the minimum required speedtests for a given tier + pub fn mock(tier: SpeedtestTier) -> Vec { + // SpeedtestTier is determined solely by upload_speed. + // Other values are far surpassing ::Good. + let upload_speed = BytesPs::mbps(match tier { + SpeedtestTier::Good => 10, + SpeedtestTier::Acceptable => 8, + SpeedtestTier::Degraded => 5, + SpeedtestTier::Poor => 2, + SpeedtestTier::Fail => 0, + }); + + vec![ + Speedtest { + upload_speed, + download_speed: BytesPs::mbps(150), + latency_millis: 0, + timestamp: Utc::now(), + }, + Speedtest { + upload_speed, + download_speed: BytesPs::mbps(150), + latency_millis: 0, + timestamp: Utc::now(), + }, + ] } pub fn multiplier(&self) -> Decimal { @@ -102,10 +120,6 @@ pub enum SpeedtestTier { Fail = 0, } -const MIN_GOOD_DOWNLOAD_SPEED_MBPS: u64 = 100; -const MIN_GOOD_UPLOAD_SPEED_MBPS: u64 = 10; -const BEST_LATENCY: Millis = 0; - impl SpeedtestTier { pub fn multiplier(self) -> Decimal { match self { @@ -119,7 +133,7 @@ impl SpeedtestTier { fn from_download(bytes: BytesPs) -> Self { match bytes.as_mbps() { - MIN_GOOD_DOWNLOAD_SPEED_MBPS.. => Self::Good, + 100.. => Self::Good, 75.. => Self::Acceptable, 50.. => Self::Degraded, 30.. => Self::Poor, @@ -129,7 +143,7 @@ impl SpeedtestTier { fn from_upload(bytes: BytesPs) -> Self { match bytes.as_mbps() { - MIN_GOOD_UPLOAD_SPEED_MBPS.. => Self::Good, + 10.. => Self::Good, 8.. => Self::Acceptable, 5.. => Self::Degraded, 2.. => Self::Poor, @@ -139,7 +153,7 @@ impl SpeedtestTier { fn from_latency(millis: Millis) -> Self { match millis { - BEST_LATENCY..=49 => Self::Good, + 0..=49 => Self::Good, 50..=59 => Self::Acceptable, 60..=74 => Self::Degraded, 75..=99 => Self::Poor, diff --git a/coverage_point_calculator/tests/coverage_point_calculator.rs b/coverage_point_calculator/tests/coverage_point_calculator.rs index 2ab08a945..0a7723bac 100644 --- a/coverage_point_calculator/tests/coverage_point_calculator.rs +++ b/coverage_point_calculator/tests/coverage_point_calculator.rs @@ -241,7 +241,7 @@ fn cbrs_outdoor_with_mixed_signal_level_coverage() -> Result { let radio = CoveragePoints::new( RadioType::OutdoorCbrs, RadioThreshold::Verified, - speedtests(SpeedtestTier::Good), + Speedtest::mock(SpeedtestTier::Good), vec![], // Location Trust is ignored for Cbrs vec![ top_ranked_coverage(0x8c2681a3064d9ff, SignalLevel::High), @@ -373,7 +373,7 @@ fn indoor_cbrs_radio( CoveragePoints::new( RadioType::IndoorCbrs, RadioThreshold::Verified, - speedtests(speedtest_tier), + Speedtest::mock(speedtest_tier), vec![], coverage.to_owned(), ) @@ -386,7 +386,7 @@ fn outdoor_cbrs_radio( CoveragePoints::new( RadioType::OutdoorCbrs, RadioThreshold::Verified, - speedtests(speedtest_tier), + Speedtest::mock(speedtest_tier), vec![], coverage.to_owned(), ) @@ -403,33 +403,6 @@ impl BoostedHexMap for NoBoostedHexes { } } -fn speedtests(tier: SpeedtestTier) -> Vec { - // SpeedtestTier is determined solely by upload_speed. - // Other values are far surpassing ::Good. - let upload_speed = BytesPs::mbps(match tier { - SpeedtestTier::Good => 10, - SpeedtestTier::Acceptable => 8, - SpeedtestTier::Degraded => 5, - SpeedtestTier::Poor => 2, - SpeedtestTier::Fail => 0, - }); - - vec![ - Speedtest { - upload_speed, - download_speed: BytesPs::mbps(150), - latency_millis: 0, - timestamp: Utc::now(), - }, - Speedtest { - upload_speed, - download_speed: BytesPs::mbps(150), - latency_millis: 0, - timestamp: Utc::now(), - }, - ] -} - fn top_ranked_coverage(hex: u64, signal_level: SignalLevel) -> RankedCoverage { ranked_coverage(hex, 1, signal_level) }