Skip to content

Commit

Permalink
add accuracy fun
Browse files Browse the repository at this point in the history
  • Loading branch information
tsunyoku committed May 2, 2024
1 parent 5a35eb0 commit f342931
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ simplify-relax = { package = "akatsuki-pp", git = "https://github.com/osuAkatsuk
improved-miss-penalty = { package = "akatsuki-pp", git = "https://github.com/osuAkatsuki/akatsuki-pp-rs", rev = "588f8fe090bbf262cb86cd95ac9c9c9f35b0da03", features = [
"async_tokio",
] }
accuracy-fun = { package = "akatsuki-pp", git = "https://github.com/osuAkatsuki/akatsuki-pp-rs", rev = "099528892c2a8183880c0538fe7e454775751cca", features = [
"async_tokio",
] }

[profile.release]
lto = "fat"
Expand Down
25 changes: 25 additions & 0 deletions src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
usecases,
};

use accuracy_fun::Beatmap as AccuracyFunBeatmap;
use conceptual_rework::{
Beatmap as ConceptualBeatmap, BeatmapExt as ConceptualBeatmapExt,
GameMode as ConceptualGameMode,
Expand Down Expand Up @@ -215,6 +216,29 @@ async fn calculate_improved_miss_penalty_pp(
Ok(pp)
}

async fn calculate_accuracy_fun_pp(
score: &RippleScore,
context: Arc<Context>,
) -> anyhow::Result<f32> {
let beatmap_bytes =
usecases::beatmaps::fetch_beatmap_osu_file(score.beatmap_id, context).await?;
let beatmap = AccuracyFunBeatmap::from_bytes(&beatmap_bytes).await?;

let result = accuracy_fun::osu_2019::OsuPP::new(&beatmap)
.mods(score.mods as u32)
.combo(score.max_combo as usize)
.misses(score.count_misses as usize)
.accuracy(score.accuracy)
.calculate();

let mut pp = round(result.pp as f32, 2);
if pp.is_infinite() || pp.is_nan() {
pp = 0.0;
}

Ok(pp)
}

async fn process_scores(
rework: &Rework,
scores: Vec<RippleScore>,
Expand All @@ -232,6 +256,7 @@ async fn process_scores(
17 => calculate_no_accuracy_pp(score, context.clone()).await?,
18 => calculate_simplfy_relax_pp(score, context.clone()).await?,
19 => calculate_improved_miss_penalty_pp(score, context.clone()).await?,
20 => calculate_accuracy_fun_pp(score, context.clone()).await?,
_ => unreachable!(),
};

Expand Down

0 comments on commit f342931

Please sign in to comment.