From a158e8fbe18920cfb2fc6e4e31984087dee9e201 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Wed, 19 Jun 2024 20:25:08 +0200 Subject: [PATCH] Add score endpoint and expose more apiv2 stuff --- Cargo.lock | 2 +- youmubot-osu/Cargo.toml | 2 +- youmubot-osu/src/lib.rs | 9 ++++++++ youmubot-osu/src/models/mod.rs | 40 ++++++--------------------------- youmubot-osu/src/models/rosu.rs | 3 +++ 5 files changed, 21 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2a5b29..7282d1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1804,7 +1804,7 @@ dependencies = [ [[package]] name = "rosu-v2" version = "0.8.0" -source = "git+https://github.com/MaxOhn/rosu-v2?rev=d2cd3ff8417e66890f0cd8ca38bc34717a9629dd#d2cd3ff8417e66890f0cd8ca38bc34717a9629dd" +source = "git+https://github.com/MaxOhn/rosu-v2?branch=lazer#4fb91316a00f78c322fc43a71b25ab6b4d080b16" dependencies = [ "bytes", "dashmap", diff --git a/youmubot-osu/Cargo.toml b/youmubot-osu/Cargo.toml index 7078b62..c0228a9 100644 --- a/youmubot-osu/Cargo.toml +++ b/youmubot-osu/Cargo.toml @@ -15,7 +15,7 @@ lazy_static = "1.4.0" regex = "1.5.6" reqwest = "0.11.10" rosu-pp = "1.0" -rosu-v2 = { git = "https://github.com/MaxOhn/rosu-v2", rev = "d2cd3ff8417e66890f0cd8ca38bc34717a9629dd" } +rosu-v2 = { git = "https://github.com/MaxOhn/rosu-v2", branch = "lazer" } rosu-map = "0.1" time = "0.3" serde = { version = "1.0.137", features = ["derive"] } diff --git a/youmubot-osu/src/lib.rs b/youmubot-osu/src/lib.rs index ec87269..f58948b 100644 --- a/youmubot-osu/src/lib.rs +++ b/youmubot-osu/src/lib.rs @@ -95,4 +95,13 @@ impl Client { f(&mut r); r.build(self).await } + + pub async fn score(&self, score_id: u64) -> Result, Error> { + let s = match self.rosu.score(score_id).await { + Ok(v) => v, + Err(rosu_v2::error::OsuError::NotFound) => return Ok(None), + e @ _ => e?, + }; + Ok(Some(s.into())) + } } diff --git a/youmubot-osu/src/models/mod.rs b/youmubot-osu/src/models/mod.rs index 54aac59..7bdbfe1 100644 --- a/youmubot-osu/src/models/mod.rs +++ b/youmubot-osu/src/models/mod.rs @@ -558,43 +558,17 @@ pub struct Score { pub max_combo: u64, pub perfect: bool, + // Some APIv2 stats + pub server_accuracy: f64, + pub global_rank: Option, + pub effective_pp: Option, + pub lazer_build_id: Option, } impl Score { /// Given the play's mode, calculate the score's accuracy. - pub fn accuracy(&self, mode: Mode) -> f64 { - 100.0 - * match mode { - Mode::Std => { - (6 * self.count_300 + 2 * self.count_100 + self.count_50) as f64 - / (6.0 - * (self.count_300 + self.count_100 + self.count_50 + self.count_miss) - as f64) - } - Mode::Taiko => { - (2 * self.count_300 + self.count_100) as f64 - / 2.0 - / (self.count_300 + self.count_100 + self.count_miss) as f64 - } - Mode::Catch => { - (self.count_300 + self.count_100) as f64 - / (self.count_300 + self.count_100 + self.count_miss + self.count_katu/* # of droplet misses */) - as f64 - } - Mode::Mania => { - ((self.count_geki /* MAX */ + self.count_300) * 6 - + self.count_katu /* 200 */ * 4 - + self.count_100 * 2 - + self.count_50) as f64 - / 6.0 - / (self.count_geki - + self.count_300 - + self.count_katu - + self.count_100 - + self.count_50 - + self.count_miss) as f64 - } - } + pub fn accuracy(&self, _mode: Mode) -> f64 { + self.server_accuracy } } diff --git a/youmubot-osu/src/models/rosu.rs b/youmubot-osu/src/models/rosu.rs index a95864c..75f138e 100644 --- a/youmubot-osu/src/models/rosu.rs +++ b/youmubot-osu/src/models/rosu.rs @@ -124,6 +124,9 @@ impl From for Score { normalized_score: s.score, pp: s.pp.map(|v| v as f64), rank: if s.passed { s.grade.into() } else { Rank::F }, + server_accuracy: s.accuracy as f64, + global_rank: s.rank_global, + effective_pp: s.weight.map(|w| w.pp as f64), mods: s .mods .iter()