Skip to content

Commit

Permalink
requirements originating from verification mapping verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck authored and jeffgrunewald committed Aug 13, 2024
1 parent 2dc6162 commit 8f02efa
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion coverage_point_calculator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ use service_provider_boosting::{MAX_AVERAGE_DISTANCE, MIN_WIFI_TRUST_MULTIPLIER}
mod hexes;
mod location;
mod service_provider_boosting;
mod speedtest;
pub mod speedtest;

pub type Result<T = ()> = std::result::Result<T, Error>;

Expand Down
12 changes: 7 additions & 5 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;

const MIN_REQUIRED_SPEEDTEST_SAMPLES: usize = 2;
const MAX_ALLOWED_SPEEDTEST_SAMPLES: usize = 6;
pub const MIN_REQUIRED_SPEEDTEST_SAMPLES: usize = 2;
pub const MAX_ALLOWED_SPEEDTEST_SAMPLES: usize = 6;

type Millis = u32;

Expand Down Expand Up @@ -86,12 +86,14 @@ impl Speedtest {
}

pub fn multiplier(&self) -> Decimal {
self.tier().multiplier()
}

pub fn tier(&self) -> SpeedtestTier {
let upload = SpeedtestTier::from_upload(self.upload_speed);
let download = SpeedtestTier::from_download(self.download_speed);
let latency = SpeedtestTier::from_latency(self.latency_millis);

let tier = upload.min(download).min(latency);
tier.multiplier()
upload.min(download).min(latency)
}

pub fn avg(speedtests: &[Self]) -> Self {
Expand Down
53 changes: 53 additions & 0 deletions file_store/src/speedtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use chrono::{DateTime, TimeZone, Utc};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::{
Speedtest, SpeedtestAvg, SpeedtestAvgValidity, SpeedtestIngestReportV1, SpeedtestReqV1,
SpeedtestVerificationResult, VerifiedSpeedtest as VerifiedSpeedtestProto,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -34,6 +35,10 @@ impl MsgDecode for CellSpeedtestIngestReport {
type Msg = SpeedtestIngestReportV1;
}

impl MsgDecode for VerifiedSpeedtest {
type Msg = VerifiedSpeedtestProto;
}

impl MsgTimestamp<Result<DateTime<Utc>>> for SpeedtestReqV1 {
fn timestamp(&self) -> Result<DateTime<Utc>> {
self.timestamp.to_timestamp()
Expand All @@ -58,6 +63,18 @@ impl MsgTimestamp<u64> for CellSpeedtestIngestReport {
}
}

impl MsgTimestamp<u64> for VerifiedSpeedtest {
fn timestamp(&self) -> u64 {
self.timestamp.encode_timestamp_millis()
}
}

impl MsgTimestamp<Result<DateTime<Utc>>> for VerifiedSpeedtestProto {
fn timestamp(&self) -> Result<DateTime<Utc>> {
self.timestamp.to_timestamp_millis()
}
}

impl From<CellSpeedtest> for SpeedtestReqV1 {
fn from(v: CellSpeedtest) -> Self {
let timestamp = v.timestamp();
Expand Down Expand Up @@ -112,6 +129,42 @@ impl From<CellSpeedtestIngestReport> for SpeedtestIngestReportV1 {
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct VerifiedSpeedtest {
pub timestamp: DateTime<Utc>,
pub report: CellSpeedtestIngestReport,
pub result: SpeedtestVerificationResult,
}

impl TryFrom<VerifiedSpeedtestProto> for VerifiedSpeedtest {
type Error = Error;
fn try_from(v: VerifiedSpeedtestProto) -> Result<Self> {
let result = SpeedtestVerificationResult::try_from(v.result).map_err(|_| {
DecodeError::unsupported_status_reason("verified_speedtest_proto", v.result)
})?;
Ok(Self {
timestamp: v.timestamp()?,
report: v
.report
.ok_or_else(|| Error::not_found("ingest verified speedtest report"))?
.try_into()?,
result,
})
}
}

impl From<VerifiedSpeedtest> for VerifiedSpeedtestProto {
fn from(v: VerifiedSpeedtest) -> Self {
let timestamp = v.timestamp();
let report: SpeedtestIngestReportV1 = v.report.into();
Self {
timestamp,
report: Some(report),
result: v.result as i32,
}
}
}

pub mod cli {
use super::*;

Expand Down

0 comments on commit 8f02efa

Please sign in to comment.