Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mock speedtest constructor #828

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion coverage_point_calculator/src/speedtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,34 @@ pub struct Speedtest {
}

impl Speedtest {
/// Construct the minimum required speedtests for a given tier
pub fn mock(tier: SpeedtestTier) -> Vec<Speedtest> {
// 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 {
let upload = SpeedtestTier::from_upload(self.upload_speed);
let download = SpeedtestTier::from_download(self.download_speed);
Expand Down Expand Up @@ -125,7 +153,7 @@ impl SpeedtestTier {

fn from_latency(millis: Millis) -> Self {
match millis {
00..=49 => Self::Good,
0..=49 => Self::Good,
50..=59 => Self::Acceptable,
60..=74 => Self::Degraded,
75..=99 => Self::Poor,
Expand Down
33 changes: 3 additions & 30 deletions coverage_point_calculator/tests/coverage_point_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(),
)
Expand All @@ -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(),
)
Expand All @@ -403,33 +403,6 @@ impl BoostedHexMap for NoBoostedHexes {
}
}

fn speedtests(tier: SpeedtestTier) -> Vec<Speedtest> {
// 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)
}
Expand Down