Skip to content

Commit

Permalink
Use different strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
maplant committed Jun 13, 2024
1 parent f74d1da commit b3d8b05
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 47 deletions.
48 changes: 31 additions & 17 deletions coverage_point_calculator/src/speedtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
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

0 comments on commit b3d8b05

Please sign in to comment.