test: add dx rating calculate check
This commit is contained in:
@@ -15,4 +15,5 @@ serde_json = { workspace = true }
|
||||
spdlog-rs = { workspace = true, optional = true }
|
||||
|
||||
[features]
|
||||
default = ["log"]
|
||||
log = ["dep:spdlog-rs"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{fs::OpenOptions, io::BufReader, sync::LazyLock};
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use rust_decimal::{Decimal, dec, serde::DecimalFromString};
|
||||
use rustc_hash::FxHashMap;
|
||||
@@ -41,18 +41,7 @@ pub fn query_music_level(music_id: u32, level: u32) -> Option<&'static Level> {
|
||||
}
|
||||
|
||||
pub static MUSIC_DB: LazyLock<Option<MusicDB>> = LazyLock::new(|| {
|
||||
let json = OpenOptions::new()
|
||||
.read(true)
|
||||
.create(false)
|
||||
.open("musicDB.json")
|
||||
.inspect_err(|_e| {
|
||||
#[cfg(feature = "log")]
|
||||
spdlog::warn!("failed to load musicDB: {_e}")
|
||||
})
|
||||
.ok()?;
|
||||
let buf_reader = BufReader::new(json);
|
||||
|
||||
let db: Vec<MusicInfo> = serde_json::from_reader(buf_reader)
|
||||
let db: Vec<MusicInfo> = serde_json::from_slice(include_bytes!("musicDB.json"))
|
||||
.inspect_err(|_e| {
|
||||
#[cfg(feature = "log")]
|
||||
spdlog::warn!("failed to load musicDB: {_e}")
|
||||
@@ -78,8 +67,11 @@ impl Level {
|
||||
let difficulty_rank: Decimal = self.difficulty.value;
|
||||
let achievement = Decimal::new(achievement as _, 4);
|
||||
|
||||
#[cfg(feature = "log")]
|
||||
spdlog::info!("factor: {factor}, achievement: {achievement}");
|
||||
|
||||
// when ach > 100.5%, calculate as 100.5%
|
||||
let rating: u32 = (factor * difficulty_rank * achievement.min(dec!(100.5)))
|
||||
let rating: u32 = (factor * difficulty_rank * achievement)
|
||||
.floor()
|
||||
.try_into()
|
||||
.unwrap_or_default();
|
||||
@@ -112,3 +104,14 @@ const RANKS: [(&'static str, i32, Decimal); 23] = [
|
||||
("SSS", 1004999, dec!(0.222)),
|
||||
("SSS+", 1005000, dec!(0.224)),
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::query_music_level;
|
||||
|
||||
#[test]
|
||||
fn test_rating_calculate() {
|
||||
let level = query_music_level(11696, 3).expect("not found");
|
||||
assert_eq!(level.dx_rating(953184), ("AAA", 184));
|
||||
}
|
||||
}
|
||||
|
||||
36666
music_db/src/musicDB.json
Normal file
36666
music_db/src/musicDB.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user