Skip to content

Commit c5bc5f9

Browse files
committed
add steps total / earned info
1 parent 416a343 commit c5bc5f9

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

compute/src/node/diagnostic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ impl DriaComputeNode {
3131

3232
// print steps
3333
if let Ok(steps) = get_steps(&self.config.address).await {
34+
let earned = steps.score - self.initial_steps;
3435
diagnostics.push(format!(
35-
"Steps: {} (top {}%)",
36-
steps.score, steps.percentile
36+
"Steps: {} total (+{} this run), within top {}%",
37+
steps.score, earned, steps.percentile
3738
));
3839
}
3940

compute/src/node/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tokio::{sync::mpsc, time::Instant};
1313
use crate::{
1414
config::*,
1515
gossipsub::*,
16-
utils::{crypto::secret_to_keypair, refresh_dria_nodes, SpecCollector},
16+
utils::{crypto::secret_to_keypair, get_steps, refresh_dria_nodes, SpecCollector},
1717
workers::task::{TaskWorker, TaskWorkerInput, TaskWorkerMetadata, TaskWorkerOutput},
1818
};
1919

@@ -56,6 +56,8 @@ pub struct DriaComputeNode {
5656
completed_tasks_batch: usize,
5757
/// Specifications collector.
5858
spec_collector: SpecCollector,
59+
/// Initial steps count.
60+
initial_steps: u64,
5961
}
6062

6163
impl DriaComputeNode {
@@ -114,6 +116,12 @@ impl DriaComputeNode {
114116
};
115117

116118
let model_names = config.workflows.get_model_names();
119+
120+
let initial_steps = get_steps(&config.address)
121+
.await
122+
.map(|s| s.score)
123+
.unwrap_or_default();
124+
117125
Ok((
118126
DriaComputeNode {
119127
config,
@@ -132,6 +140,7 @@ impl DriaComputeNode {
132140
completed_tasks_single: 0,
133141
completed_tasks_batch: 0,
134142
// others
143+
initial_steps,
135144
spec_collector: SpecCollector::new(model_names),
136145
last_pinged_at: Instant::now(),
137146
},

compute/src/utils/steps.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
use eyre::Context;
2-
use serde::{Deserialize, Serialize};
2+
use serde::Deserialize;
33

44
const STEPS_API_BASE_URL: &str = "https://dkn.dria.co/dashboard/supply/v0/leaderboard/steps";
55

6-
#[derive(Debug, Serialize, Deserialize)]
6+
#[derive(Debug, Deserialize)]
77
pub struct StepsScore {
8+
#[serde(deserialize_with = "deserialize_percentile")]
89
/// Indicates in which top percentile your steps are.
9-
pub percentile: String,
10+
pub percentile: u64,
1011
/// The total number of steps you have accumulated.
1112
pub score: u64,
1213
}
1314

15+
// the API returns a stringified number due to frontend issues, so we need to parse it
16+
fn deserialize_percentile<'de, D>(deserializer: D) -> Result<u64, D::Error>
17+
where
18+
D: serde::Deserializer<'de>,
19+
{
20+
let s: String = String::deserialize(deserializer)?;
21+
let parsed = s.parse().map_err(serde::de::Error::custom)?;
22+
23+
if parsed > 100 {
24+
return Err(serde::de::Error::custom(
25+
"percentile must be between 0 and 100",
26+
));
27+
}
28+
29+
Ok(parsed)
30+
}
31+
1432
/// Returns the steps for the given address.
1533
pub async fn get_steps(address: &str) -> eyre::Result<StepsScore> {
1634
// the address can have 0x or not, we add it ourselves here

0 commit comments

Comments
 (0)