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

HIP-125 #835

Merged
merged 23 commits into from
Jul 9, 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
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 41 additions & 36 deletions coverage_point_calculator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ pub struct CoveragePoints {
pub speedtest_multiplier: Decimal,
/// Input Radio Type
pub radio_type: RadioType,
/// Input RadioThreshold
pub radio_threshold: RadioThreshold,
/// Input ServiceProviderBoostedRewardEligibility
pub service_provider_boosted_reward_eligibility: ServiceProviderBoostedRewardEligibility,
bbalser marked this conversation as resolved.
Show resolved Hide resolved
/// Derived Eligibility for Boosted Hex Rewards
pub boosted_hex_eligibility: BoostedHexStatus,
/// Speedtests used in calculcation
Expand All @@ -136,16 +136,19 @@ pub struct CoveragePoints {
impl CoveragePoints {
pub fn new(
radio_type: RadioType,
radio_threshold: RadioThreshold,
service_provider_boosted_reward_eligibility: ServiceProviderBoostedRewardEligibility,
speedtests: Vec<Speedtest>,
trust_scores: Vec<LocationTrust>,
ranked_coverage: Vec<coverage_map::RankedCoverage>,
) -> Result<CoveragePoints> {
let location_trust_scores = location::clean_trust_scores(trust_scores, &ranked_coverage);
let location_trust_multiplier = location::multiplier(radio_type, &location_trust_scores);

let boost_eligibility =
BoostedHexStatus::new(&radio_type, location_trust_multiplier, &radio_threshold);
let boost_eligibility = BoostedHexStatus::new(
&radio_type,
location_trust_multiplier,
&service_provider_boosted_reward_eligibility,
);

let covered_hexes =
hexes::clean_covered_hexes(radio_type, boost_eligibility, ranked_coverage)?;
Expand All @@ -159,7 +162,7 @@ impl CoveragePoints {
location_trust_multiplier,
speedtest_multiplier,
radio_type,
radio_threshold,
service_provider_boosted_reward_eligibility,
boosted_hex_eligibility: boost_eligibility,
speedtests,
location_trust_scores,
Expand Down Expand Up @@ -207,6 +210,7 @@ impl CoveragePoints {
BoostedHexStatus::Eligible => self.coverage_points.boosted,
BoostedHexStatus::WifiLocationScoreBelowThreshold(_) => dec!(0),
BoostedHexStatus::RadioThresholdNotMet => dec!(0),
BoostedHexStatus::ServiceProviderBanned => dec!(0),
}
}
}
Expand All @@ -216,25 +220,30 @@ pub enum BoostedHexStatus {
Eligible,
WifiLocationScoreBelowThreshold(Decimal),
RadioThresholdNotMet,
ServiceProviderBanned,
}

impl BoostedHexStatus {
fn new(
radio_type: &RadioType,
location_trust_score: Decimal,
radio_threshold: &RadioThreshold,
service_provider_boosted_reward_eligibility: &ServiceProviderBoostedRewardEligibility,
) -> Self {
// hip-93: if radio is wifi & location_trust score multiplier < 0.75, no boosting
if radio_type.is_wifi() && location_trust_score < dec!(0.75) {
return Self::WifiLocationScoreBelowThreshold(location_trust_score);
}

// hip-84: if radio has not met minimum data and subscriber thresholds, no boosting
if !radio_threshold.is_met() {
return Self::RadioThresholdNotMet;
match service_provider_boosted_reward_eligibility {
ServiceProviderBoostedRewardEligibility::Eligible => Self::Eligible,
ServiceProviderBoostedRewardEligibility::ServiceProviderBanned => {
Self::ServiceProviderBanned
}
ServiceProviderBoostedRewardEligibility::RadioThresholdNotMet => {
Self::RadioThresholdNotMet
}
}

Self::Eligible
}

fn is_eligible(&self) -> bool {
Expand Down Expand Up @@ -307,15 +316,10 @@ impl RadioType {
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RadioThreshold {
Verified,
Unverified,
}

impl RadioThreshold {
fn is_met(&self) -> bool {
matches!(self, Self::Verified)
}
pub enum ServiceProviderBoostedRewardEligibility {
Eligible,
ServiceProviderBanned,
RadioThresholdNotMet,
}

#[cfg(test)]
Expand All @@ -342,7 +346,7 @@ mod tests {
) {
let wifi = CoveragePoints::new(
RadioType::IndoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand All @@ -364,10 +368,10 @@ mod tests {

#[test]
fn hip_84_radio_meets_minimum_subscriber_threshold_for_boosted_hexes() {
let calculate_wifi = |radio_verified: RadioThreshold| {
let calculate_wifi = |eligibility: ServiceProviderBoostedRewardEligibility| {
CoveragePoints::new(
RadioType::IndoorWifi,
radio_verified,
eligibility,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand All @@ -389,12 +393,13 @@ mod tests {

// Radio meeting the threshold is eligible for boosted hexes.
// Boosted hex provides radio with more than base_points.
let verified_wifi = calculate_wifi(RadioThreshold::Verified);
let verified_wifi = calculate_wifi(ServiceProviderBoostedRewardEligibility::Eligible);
assert_eq!(base_points * dec!(5), verified_wifi.coverage_points_v1());

// Radio not meeting the threshold is not eligible for boosted hexes.
// Boost from hex is not applied, radio receives base points.
let unverified_wifi = calculate_wifi(RadioThreshold::Unverified);
let unverified_wifi =
calculate_wifi(ServiceProviderBoostedRewardEligibility::RadioThresholdNotMet);
assert_eq!(base_points, unverified_wifi.coverage_points_v1());
}

Expand All @@ -403,7 +408,7 @@ mod tests {
let calculate_wifi = |location_trust_scores: Vec<LocationTrust>| {
CoveragePoints::new(
RadioType::IndoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_scores,
vec![RankedCoverage {
Expand Down Expand Up @@ -441,7 +446,7 @@ mod tests {
let calculate_indoor_cbrs = |speedtests: Vec<Speedtest>| {
CoveragePoints::new(
RadioType::IndoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtests,
location_trust_maximum(),
vec![RankedCoverage {
Expand Down Expand Up @@ -529,7 +534,7 @@ mod tests {
use Assignment::*;
let indoor_cbrs = CoveragePoints::new(
RadioType::IndoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![
Expand Down Expand Up @@ -586,7 +591,7 @@ mod tests {
) {
let outdoor_wifi = CoveragePoints::new(
radio_type,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand Down Expand Up @@ -615,7 +620,7 @@ mod tests {
) {
let indoor_wifi = CoveragePoints::new(
radio_type,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![
Expand Down Expand Up @@ -658,7 +663,7 @@ mod tests {
// Location scores are averaged together
let indoor_wifi = CoveragePoints::new(
RadioType::IndoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_with_scores(&[dec!(0.1), dec!(0.2), dec!(0.3), dec!(0.4)]),
vec![RankedCoverage {
Expand Down Expand Up @@ -702,7 +707,7 @@ mod tests {
];
let indoor_wifi = CoveragePoints::new(
RadioType::IndoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
covered_hexes.clone(),
Expand All @@ -725,7 +730,7 @@ mod tests {
) {
let outdoor_cbrs = CoveragePoints::new(
RadioType::OutdoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand All @@ -752,7 +757,7 @@ mod tests {
) {
let indoor_cbrs = CoveragePoints::new(
RadioType::IndoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand Down Expand Up @@ -781,7 +786,7 @@ mod tests {
) {
let outdoor_wifi = CoveragePoints::new(
RadioType::OutdoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand All @@ -808,7 +813,7 @@ mod tests {
) {
let indoor_wifi = CoveragePoints::new(
RadioType::IndoorWifi,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtest_maximum(),
location_trust_maximum(),
vec![RankedCoverage {
Expand Down
14 changes: 7 additions & 7 deletions coverage_point_calculator/tests/coverage_point_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::num::NonZeroU32;
use chrono::Utc;
use coverage_map::{BoostedHexMap, RankedCoverage, SignalLevel, UnrankedCoverage};
use coverage_point_calculator::{
BytesPs, CoveragePoints, LocationTrust, RadioThreshold, RadioType, Result, Speedtest,
SpeedtestTier,
BytesPs, CoveragePoints, LocationTrust, RadioType, Result,
ServiceProviderBoostedRewardEligibility, Speedtest, SpeedtestTier,
};
use hex_assignments::{assignment::HexAssignments, Assignment};
use rust_decimal_macros::dec;
Expand Down Expand Up @@ -52,7 +52,7 @@ fn base_radio_coverage_points() {
] {
let coverage_points = CoveragePoints::new(
radio_type,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
speedtests.clone(),
location_trust_scores.clone(),
hexes.clone(),
Expand Down Expand Up @@ -113,7 +113,7 @@ fn radios_with_coverage() {
] {
let coverage_points = CoveragePoints::new(
radio_type,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
default_speedtests.clone(),
default_location_trust_scores.clone(),
base_hex_iter.clone().take(num_hexes).collect(),
Expand Down Expand Up @@ -240,7 +240,7 @@ fn cbrs_outdoor_with_mixed_signal_level_coverage() -> Result {

let radio = CoveragePoints::new(
RadioType::OutdoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
Speedtest::mock(SpeedtestTier::Good),
vec![], // Location Trust is ignored for Cbrs
vec![
Expand Down Expand Up @@ -372,7 +372,7 @@ fn indoor_cbrs_radio(
) -> Result<CoveragePoints> {
CoveragePoints::new(
RadioType::IndoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
Speedtest::mock(speedtest_tier),
vec![],
coverage.to_owned(),
Expand All @@ -385,7 +385,7 @@ fn outdoor_cbrs_radio(
) -> Result<CoveragePoints> {
CoveragePoints::new(
RadioType::OutdoorCbrs,
RadioThreshold::Verified,
ServiceProviderBoostedRewardEligibility::Eligible,
Speedtest::mock(speedtest_tier),
vec![],
coverage.to_owned(),
Expand Down
1 change: 1 addition & 0 deletions custom_tracing/src/http_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tower_http::{
};
use tracing::{Level, Span};

#[allow(clippy::type_complexity)]
pub fn new_with_span(
make_span: fn(&Request<Body>) -> Span,
) -> TraceLayer<
Expand Down
2 changes: 1 addition & 1 deletion file_store/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub enum Error {
Io(#[from] std::io::Error),
#[error("encode error")]
Encode(#[from] EncodeError),
#[error("dencode error")]
#[error("decode error")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked it better the old way

Decode(#[from] DecodeError),
#[error("not found")]
NotFound(String),
Expand Down
Loading