Skip to content

Commit

Permalink
Update to latest akatsuki-pp-rs (#21)
Browse files Browse the repository at this point in the history
* update to latest akatsuki-pp-rs

* ensure mode conversion failures are not ignored

* update akatsuki-pp-rs again
  • Loading branch information
tsunyoku authored Oct 14, 2024
1 parent 1672f4e commit cfa61c9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 43 deletions.
22 changes: 17 additions & 5 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ bcrypt = "0.13.0"
uuid = { version = "1.2.1", features = ["v4"] }
futures = "0.3.17"
strsim = "0.10.0"
akatsuki-pp-rs = { package = "akatsuki-pp", git = "https://github.com/osuAkatsuki/akatsuki-pp-rs", rev = "b96019f50aa7d09bcbde60016481a69df04315e4", features = [
"async_tokio",
] }
akatsuki-pp-rs = { package = "akatsuki-pp", git = "https://github.com/osuAkatsuki/akatsuki-pp-rs", rev = "a9b4aa4da033e1d72b96e35fd8898e32a23d2002" }
reqwest = "0.11"
async-trait = "0.1.62"
structured-logger = "1.0.3"
Expand Down
6 changes: 3 additions & 3 deletions src/api/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum::{body::Body, http::Response, response::IntoResponse};

pub struct AppError(anyhow::Error);
pub struct AppError();
pub type AppResult<T> = Result<T, AppError>;

impl IntoResponse for AppError {
Expand All @@ -19,7 +19,7 @@ impl<E> From<E> for AppError
where
E: Into<anyhow::Error>,
{
fn from(err: E) -> Self {
Self(err.into())
fn from(_err: E) -> Self {
Self()
}
}
40 changes: 25 additions & 15 deletions src/api/routes/calculate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::usecases;
use crate::{api::error::AppResult, context::Context};
use akatsuki_pp_rs::{Beatmap, BeatmapExt, GameMode, PerformanceAttributes};
use akatsuki_pp_rs::model::mode::GameMode;
use akatsuki_pp_rs::{any::PerformanceAttributes, Beatmap};
use anyhow::anyhow;
use axum::response::IntoResponse;
use axum::{extract::Extension, routing::post, Json, Router};
use reqwest::StatusCode;
Expand Down Expand Up @@ -44,20 +46,20 @@ async fn calculate_relax_pp(
) -> anyhow::Result<CalculateResponse> {
let beatmap_bytes =
usecases::beatmaps::fetch_beatmap_osu_file(request.beatmap_id, context).await?;
let beatmap = Beatmap::from_bytes(&beatmap_bytes).await?;
let beatmap = Beatmap::from_bytes(&beatmap_bytes)?;

let mut calculate = akatsuki_pp_rs::osu_2019::OsuPP::new(&beatmap)
.mods(request.mods as u32)
.combo(request.max_combo as usize);
.combo(request.max_combo as u32);

calculate = calculate.misses(request.miss_count as usize);
calculate = calculate.misses(request.miss_count as u32);
if request.accuracy.is_some() {
calculate = calculate.accuracy(request.accuracy.unwrap());
} else {
calculate = calculate
.n300(request.count_300.unwrap() as usize)
.n100(request.count_100.unwrap() as usize)
.n50(request.count_50.unwrap() as usize);
.n300(request.count_300.unwrap() as u32)
.n100(request.count_100.unwrap() as u32)
.n50(request.count_50.unwrap() as u32);
}

let result = calculate.calculate();
Expand Down Expand Up @@ -89,28 +91,36 @@ async fn calculate_rosu_pp(
) -> anyhow::Result<CalculateResponse> {
let beatmap_bytes =
usecases::beatmaps::fetch_beatmap_osu_file(request.beatmap_id, context).await?;
let beatmap = Beatmap::from_bytes(&beatmap_bytes).await?;
let beatmap = Beatmap::from_bytes(&beatmap_bytes)?;

let mut calculate = beatmap
.pp()
.mode(match request.mode {
.performance()
.try_mode(match request.mode {
0 => GameMode::Osu,
1 => GameMode::Taiko,
2 => GameMode::Catch,
3 => GameMode::Mania,
_ => unreachable!(),
})
.map_err(|_| {
anyhow!(
"failed to set mode {} for beatmap {}",
request.mode,
request.beatmap_id
)
})?
.mods(request.mods as u32)
.combo(request.max_combo as usize);
.lazer(false)
.combo(request.max_combo as u32);

calculate = calculate.n_misses(request.miss_count as usize);
calculate = calculate.misses(request.miss_count as u32);
if request.accuracy.is_some() {
calculate = calculate.accuracy(request.accuracy.unwrap() as f64);
} else {
calculate = calculate
.n300(request.count_300.unwrap() as usize)
.n100(request.count_100.unwrap() as usize)
.n50(request.count_50.unwrap() as usize);
.n300(request.count_300.unwrap() as u32)
.n100(request.count_100.unwrap() as u32)
.n50(request.count_50.unwrap() as u32);
}

let result = calculate.calculate();
Expand Down
43 changes: 26 additions & 17 deletions src/deploy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{context::Context, models::score::RippleScore, usecases};
use akatsuki_pp_rs::{Beatmap, BeatmapExt, GameMode};
use akatsuki_pp_rs::model::mode::GameMode;
use akatsuki_pp_rs::Beatmap;
use anyhow::anyhow;
use redis::AsyncCommands;
use std::{collections::HashMap, ops::DerefMut, sync::Arc, time::SystemTime};

use std::io::Write;
use std::{collections::HashMap, ops::DerefMut, sync::Arc, time::SystemTime};
use tokio::sync::Mutex;

#[derive(serde::Serialize, serde::Deserialize)]
Expand Down Expand Up @@ -49,7 +50,7 @@ async fn calculate_special_pp(
} else {
let beatmap_bytes =
usecases::beatmaps::fetch_beatmap_osu_file(request.beatmap_id, context.clone()).await?;
let beatmap = Beatmap::from_bytes(&beatmap_bytes).await?;
let beatmap = Beatmap::from_bytes(&beatmap_bytes)?;

recalc_mutex
.beatmaps
Expand All @@ -62,11 +63,11 @@ async fn calculate_special_pp(

let result = akatsuki_pp_rs::osu_2019::OsuPP::new(&beatmap)
.mods(request.mods as u32)
.combo(request.max_combo as usize)
.misses(request.miss_count as usize)
.n300(request.count_300 as usize)
.n100(request.count_100 as usize)
.n50(request.count_50 as usize)
.combo(request.max_combo as u32)
.misses(request.miss_count as u32)
.n300(request.count_300 as u32)
.n100(request.count_100 as u32)
.n50(request.count_50 as u32)
.calculate();

let mut pp = round(result.pp as f32, 2);
Expand Down Expand Up @@ -98,7 +99,7 @@ async fn calculate_rosu_pp(
} else {
let beatmap_bytes =
usecases::beatmaps::fetch_beatmap_osu_file(request.beatmap_id, context.clone()).await?;
let beatmap = Beatmap::from_bytes(&beatmap_bytes).await?;
let beatmap = Beatmap::from_bytes(&beatmap_bytes)?;

recalc_mutex
.beatmaps
Expand All @@ -110,20 +111,28 @@ async fn calculate_rosu_pp(
drop(recalc_mutex);

let result = beatmap
.pp()
.mode(match request.mode {
.performance()
.try_mode(match request.mode {
0 => GameMode::Osu,
1 => GameMode::Taiko,
2 => GameMode::Catch,
3 => GameMode::Mania,
_ => unreachable!(),
})
.map_err(|_| {
anyhow!(
"failed to set mode {} for beatmap {}",
request.mode,
request.beatmap_id
)
})?
.mods(request.mods as u32)
.combo(request.max_combo as usize)
.n300(request.count_300 as usize)
.n100(request.count_100 as usize)
.n50(request.count_50 as usize)
.n_misses(request.miss_count as usize)
.lazer(false)
.combo(request.max_combo as u32)
.n300(request.count_300 as u32)
.n100(request.count_100 as u32)
.n50(request.count_50 as u32)
.misses(request.miss_count as u32)
.calculate();

let mut pp = round(result.pp() as f32, 2);
Expand Down

0 comments on commit cfa61c9

Please sign in to comment.