Skip to content

Commit

Permalink
Merge branch 'main' into kurotych/speedtest_avg_radio_reward_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
kurotych committed Aug 14, 2024
2 parents fa114a9 + 8dc6c15 commit a5caddf
Show file tree
Hide file tree
Showing 34 changed files with 1,330 additions and 78 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

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 @@ -88,12 +88,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
1 change: 1 addition & 0 deletions file_store/src/cli/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ impl Cmd {
Some(Reward::SubscriberReward(reward)) => print_json(&json!({
"subscriber_id": reward.subscriber_id,
"discovery_location_amount": reward.discovery_location_amount,
"verification_mapping_amount": reward.verification_mapping_amount,
}))?,
Some(Reward::ServiceProviderReward(reward)) => print_json(&json!({
"service_provider": reward.service_provider_id,
Expand Down
1 change: 1 addition & 0 deletions file_store/src/cli/dump_mobile_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl Cmd {
SubscriberReward(reward) => subscriber_reward.push(json!({
"subscriber_id": uuid::Uuid::from_slice(&reward.subscriber_id).unwrap(),
"discovery_location_amount": reward.discovery_location_amount,
"verification_mapping_amount": reward.verification_mapping_amount,
})),
ServiceProviderReward(reward) => service_provider_reward.push(json!({
"service_provider": reward.service_provider_id,
Expand Down
24 changes: 24 additions & 0 deletions file_store/src/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ pub const LANDTYPE_DATA_SET: &str = "landtype";
pub const SP_BOOSTED_REWARDS_BANNED_RADIO: &str = "service_provider_boosted_rewards_banned_radio";
pub const VERIFIED_SP_BOOSTED_REWARDS_BANNED_RADIO: &str =
"verified_service_provider_boosted_rewards_banned_radio";
pub const SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT: &str =
"subscriber_verified_mapping_ingest_report";
pub const VERIFIED_SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT: &str =
"verified_subscriber_verified_mapping_ingest_report";

#[derive(Debug, PartialEq, Eq, Clone, Serialize, Copy, strum::EnumCount)]
#[serde(rename_all = "snake_case")]
Expand Down Expand Up @@ -214,6 +218,8 @@ pub enum FileType {
VerifiedInvalidatedRadioThresholdIngestReport,
SPBoostedRewardsBannedRadioIngestReport,
VerifiedSPBoostedRewardsBannedRadioIngestReport,
SubscriberVerifiedMappingEventIngestReport,
VerifiedSubscriberVerifiedMappingEventIngestReport,
}

impl fmt::Display for FileType {
Expand Down Expand Up @@ -279,6 +285,12 @@ impl fmt::Display for FileType {
Self::VerifiedSPBoostedRewardsBannedRadioIngestReport => {
VERIFIED_SP_BOOSTED_REWARDS_BANNED_RADIO
}
Self::SubscriberVerifiedMappingEventIngestReport => {
SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT
}
Self::VerifiedSubscriberVerifiedMappingEventIngestReport => {
VERIFIED_SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT
}
};
f.write_str(s)
}
Expand Down Expand Up @@ -347,6 +359,12 @@ impl FileType {
Self::VerifiedSPBoostedRewardsBannedRadioIngestReport => {
VERIFIED_SP_BOOSTED_REWARDS_BANNED_RADIO
}
Self::SubscriberVerifiedMappingEventIngestReport => {
SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT
}
Self::VerifiedSubscriberVerifiedMappingEventIngestReport => {
VERIFIED_SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT
}
}
}
}
Expand Down Expand Up @@ -415,6 +433,12 @@ impl FromStr for FileType {
VERIFIED_SP_BOOSTED_REWARDS_BANNED_RADIO => {
Self::VerifiedSPBoostedRewardsBannedRadioIngestReport
}
SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT => {
Self::SubscriberVerifiedMappingEventIngestReport
}
VERIFIED_SUBSCRIBER_VERIFIED_MAPPING_INGEST_REPORT => {
Self::VerifiedSubscriberVerifiedMappingEventIngestReport
}
_ => return Err(Error::from(io::Error::from(io::ErrorKind::InvalidInput))),
};
Ok(result)
Expand Down
3 changes: 3 additions & 0 deletions file_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ pub mod mobile_transfer;
pub mod reward_manifest;
mod settings;
pub mod speedtest;
pub mod subscriber_verified_mapping_event;
pub mod subscriber_verified_mapping_event_ingest_report;
pub mod traits;
pub mod verified_subscriber_verified_mapping_event_ingest_report;
pub mod wifi_heartbeat;

pub use crate::file_store::FileStore;
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
58 changes: 58 additions & 0 deletions file_store/src/subscriber_verified_mapping_event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use crate::{
traits::{MsgDecode, MsgTimestamp, TimestampDecode, TimestampEncode},
Error, Result,
};
use chrono::{DateTime, Utc};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::SubscriberVerifiedMappingEventReqV1;
use serde::{Deserialize, Serialize};

#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)]
pub struct SubscriberVerifiedMappingEvent {
pub subscriber_id: Vec<u8>,
pub total_reward_points: u64,
pub timestamp: DateTime<Utc>,
pub carrier_mapping_key: PublicKeyBinary,
}

impl MsgDecode for SubscriberVerifiedMappingEvent {
type Msg = SubscriberVerifiedMappingEventReqV1;
}

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

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

impl From<SubscriberVerifiedMappingEvent> for SubscriberVerifiedMappingEventReqV1 {
fn from(v: SubscriberVerifiedMappingEvent) -> Self {
let timestamp = v.timestamp();
SubscriberVerifiedMappingEventReqV1 {
subscriber_id: v.subscriber_id,
total_reward_points: v.total_reward_points,
timestamp,
carrier_mapping_key: v.carrier_mapping_key.into(),
signature: vec![],
}
}
}

impl TryFrom<SubscriberVerifiedMappingEventReqV1> for SubscriberVerifiedMappingEvent {
type Error = Error;
fn try_from(v: SubscriberVerifiedMappingEventReqV1) -> Result<Self> {
let timestamp = v.timestamp()?;
Ok(Self {
subscriber_id: v.subscriber_id,
total_reward_points: v.total_reward_points,
timestamp,
carrier_mapping_key: v.carrier_mapping_key.into(),
})
}
}
62 changes: 62 additions & 0 deletions file_store/src/subscriber_verified_mapping_event_ingest_report.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use crate::{
subscriber_verified_mapping_event::SubscriberVerifiedMappingEvent,
traits::{MsgDecode, MsgTimestamp, TimestampDecode, TimestampEncode},
Error, Result,
};
use chrono::{DateTime, Utc};
use helium_proto::services::poc_mobile::{
SubscriberVerifiedMappingEventIngestReportV1, SubscriberVerifiedMappingEventReqV1,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)]
pub struct SubscriberVerifiedMappingEventIngestReport {
pub received_timestamp: DateTime<Utc>,
pub report: SubscriberVerifiedMappingEvent,
}

impl MsgDecode for SubscriberVerifiedMappingEventIngestReport {
type Msg = SubscriberVerifiedMappingEventIngestReportV1;
}

impl MsgTimestamp<Result<DateTime<Utc>>> for SubscriberVerifiedMappingEventIngestReportV1 {
fn timestamp(&self) -> Result<DateTime<Utc>> {
self.received_timestamp.to_timestamp()
}
}

impl MsgTimestamp<u64> for SubscriberVerifiedMappingEventIngestReport {
fn timestamp(&self) -> u64 {
self.received_timestamp.encode_timestamp()
}
}

impl From<SubscriberVerifiedMappingEventIngestReport>
for SubscriberVerifiedMappingEventIngestReportV1
{
fn from(v: SubscriberVerifiedMappingEventIngestReport) -> Self {
let received_timestamp = v.timestamp();
let report: SubscriberVerifiedMappingEventReqV1 = v.report.into();
Self {
received_timestamp,
report: Some(report),
}
}
}

impl TryFrom<SubscriberVerifiedMappingEventIngestReportV1>
for SubscriberVerifiedMappingEventIngestReport
{
type Error = Error;
fn try_from(v: SubscriberVerifiedMappingEventIngestReportV1) -> Result<Self> {
Ok(Self {
received_timestamp: v.timestamp()?,
report: v
.report
.ok_or_else(|| {
Error::not_found("ingest SubscriberVerifiedMappingEventIngestReport report")
})?
.try_into()?,
})
}
}
3 changes: 2 additions & 1 deletion file_store/src/traits/msg_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use helium_crypto::{PublicKey, Verify};
use helium_proto::services::{
iot_config, mobile_config,
poc_lora::{LoraBeaconReportReqV1, LoraStreamSessionInitV1, LoraWitnessReportReqV1},
poc_mobile::ServiceProviderBoostedRewardsBannedRadioReqV1,
poc_mobile::{self, ServiceProviderBoostedRewardsBannedRadioReqV1},
};
use helium_proto::{
services::poc_mobile::{
Expand Down Expand Up @@ -94,6 +94,7 @@ impl_msg_verify!(mobile_config::GatewayInfoStreamResV1, signature);
impl_msg_verify!(mobile_config::BoostedHexInfoStreamReqV1, signature);
impl_msg_verify!(mobile_config::BoostedHexModifiedInfoStreamReqV1, signature);
impl_msg_verify!(mobile_config::BoostedHexInfoStreamResV1, signature);
impl_msg_verify!(poc_mobile::SubscriberVerifiedMappingEventReqV1, signature);

#[cfg(test)]
mod test {
Expand Down
Loading

0 comments on commit a5caddf

Please sign in to comment.