Skip to content

Commit

Permalink
clipify things
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Aug 2, 2023
1 parent a9b971c commit 5423436
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 58 deletions.
56 changes: 28 additions & 28 deletions mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,54 +540,54 @@ mod test {
fn acceptable_speedtest(pubkey: PublicKeyBinary, timestamp: DateTime<Utc>) -> Speedtest {
Speedtest {
report: CellSpeedtest {
pubkey,
timestamp,
upload_speed: bytes_per_s(10),
download_speed: bytes_per_s(100),
latency: 25,
serial: "".to_string(),
pubkey,
timestamp,
upload_speed: bytes_per_s(10),
download_speed: bytes_per_s(100),
latency: 25,
serial: "".to_string(),
},
}
}
}

fn degraded_speedtest(pubkey: PublicKeyBinary, timestamp: DateTime<Utc>) -> Speedtest {
Speedtest {
report: CellSpeedtest {
pubkey,
timestamp,
upload_speed: bytes_per_s(5),
download_speed: bytes_per_s(60),
latency: 60,
serial: "".to_string(),
pubkey,
timestamp,
upload_speed: bytes_per_s(5),
download_speed: bytes_per_s(60),
latency: 60,
serial: "".to_string(),
},
}
}
}

fn failed_speedtest(pubkey: PublicKeyBinary, timestamp: DateTime<Utc>) -> Speedtest {
Speedtest {
report: CellSpeedtest {
pubkey,
timestamp,
upload_speed: bytes_per_s(1),
download_speed: bytes_per_s(20),
latency: 110,
serial: "".to_string(),
pubkey,
timestamp,
upload_speed: bytes_per_s(1),
download_speed: bytes_per_s(20),
latency: 110,
serial: "".to_string(),
},
}
}
}

fn poor_speedtest(pubkey: PublicKeyBinary, timestamp: DateTime<Utc>) -> Speedtest {
Speedtest {
report: CellSpeedtest {
pubkey,
timestamp,
upload_speed: bytes_per_s(2),
download_speed: bytes_per_s(40),
latency: 90,
serial: "".to_string(),
pubkey,
timestamp,
upload_speed: bytes_per_s(2),
download_speed: bytes_per_s(40),
latency: 90,
serial: "".to_string(),
},
}
}
}

#[tokio::test]
async fn test_radio_weights() {
Expand Down
13 changes: 4 additions & 9 deletions mobile_verifier/src/speedtests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,16 @@ impl Speedtest {
.is_ok()
{
Some(Speedtest {
report: report.report.into(),
report: report.report,
})
}
else {
} else {
None
}
}
})
}

pub async fn save(
&self,
exec: &mut Transaction<'_, Postgres>,
) -> Result<(), sqlx::Error> {
pub async fn save(&self, exec: &mut Transaction<'_, Postgres>) -> Result<(), sqlx::Error> {
sqlx::query(
r#"
insert into speedtests (pubkey, upload_speed, download_speed, latency, serial, timestamp)
Expand All @@ -155,7 +151,6 @@ impl Speedtest {
}
}


pub async fn get_latest_speedtests_for_pubkey(
pubkey: &PublicKeyBinary,
exec: &mut Transaction<'_, Postgres>,
Expand All @@ -177,7 +172,7 @@ pub async fn get_latest_speedtests_for_pubkey(

pub async fn aggregate_epoch_speedtests<'a>(
epoch_end: DateTime<Utc>,
exec: &sqlx::Pool<sqlx::Postgres>
exec: &sqlx::Pool<sqlx::Postgres>,
) -> Result<EpochSpeedTests, sqlx::Error> {
let mut speedtests = EpochSpeedTests::new();
// pull the last N most recent speedtests from prior to the epoch end for each pubkey
Expand Down
38 changes: 17 additions & 21 deletions mobile_verifier/src/speedtests_average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ where
let mut sum_download = 0;
let mut sum_latency = 0;

for Speedtest {
report,
..
} in speedtests_without_lapsed(iter.into_iter(), Duration::hours(SPEEDTEST_LAPSE))
for Speedtest { report, .. } in
speedtests_without_lapsed(iter.into_iter(), Duration::hours(SPEEDTEST_LAPSE))
{
id = report.pubkey.as_ref().to_vec(); // eww!
sum_upload += report.upload_speed as u64;
sum_download += report.download_speed as u64;
sum_latency += report.latency as u32;
sum_upload += report.upload_speed;
sum_download += report.download_speed;
sum_latency += report.latency;
window_size += 1;
}

Expand Down Expand Up @@ -109,9 +107,9 @@ impl SpeedtestAverage {
)
.map(|st| proto::Speedtest {
timestamp: st.report.timestamp.timestamp() as u64,
upload_speed_bps: st.report.upload_speed as u64,
download_speed_bps: st.report.download_speed as u64,
latency_ms: st.report.latency as u32,
upload_speed_bps: st.report.upload_speed,
download_speed_bps: st.report.download_speed,
latency_ms: st.report.latency,
})
.collect(),
validity: self.validity as i32,
Expand Down Expand Up @@ -466,17 +464,15 @@ mod test {
download_speed: u64,
latency: u32,
) -> Speedtest {
Speedtest{
report:
CellSpeedtest {
pubkey,
timestamp,
upload_speed,
download_speed,
latency,
serial: "".to_string(),
Speedtest {
report: CellSpeedtest {
pubkey,
timestamp,
upload_speed,
download_speed,
latency,
serial: "".to_string(),
},
}
}
}
}

0 comments on commit 5423436

Please sign in to comment.