mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 08:48:54 +00:00
Add score endpoint and expose more apiv2 stuff
This commit is contained in:
parent
e61cbb327a
commit
a158e8fbe1
5 changed files with 21 additions and 35 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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"] }
|
||||
|
|
|
@ -95,4 +95,13 @@ impl Client {
|
|||
f(&mut r);
|
||||
r.build(self).await
|
||||
}
|
||||
|
||||
pub async fn score(&self, score_id: u64) -> Result<Option<Score>, 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()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<u32>,
|
||||
pub effective_pp: Option<f64>,
|
||||
|
||||
pub lazer_build_id: Option<u32>,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,6 +124,9 @@ impl From<rosu::score::Score> 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()
|
||||
|
|
Loading…
Add table
Reference in a new issue