Implement recent

This commit is contained in:
Natsu Kagami 2020-01-13 17:28:51 -05:00
parent 4020405801
commit 3af0b56755
4 changed files with 235 additions and 8 deletions

View file

@ -17,9 +17,13 @@ impl<'de> Deserialize<'de> for Score {
user_id: parse_from_str(&raw.user_id)?,
date: parse_date(&raw.date)?,
beatmap_id: raw.beatmap_id.map(parse_from_str).transpose()?.unwrap_or(0),
replay_available: parse_bool(&raw.replay_available)?,
replay_available: raw
.replay_available
.map(parse_bool)
.transpose()?
.unwrap_or(false),
score: parse_from_str(&raw.score)?,
pp: parse_from_str(&raw.pp)?,
pp: raw.pp.map(parse_from_str).transpose()?,
rank: parse_from_str(&raw.rank)?,
mods: {
let v: u64 = parse_from_str(&raw.enabled_mods)?;

View file

@ -159,6 +159,14 @@ impl Beatmap {
self.beatmapset_id, NEW_MODE_NAMES[self.mode as usize], self.beatmap_id
)
}
/// Link to the cover image of the beatmap.
pub fn cover_url(&self) -> String {
format!(
"https://assets.ppy.sh/beatmaps/{}/covers/cover.jpg",
self.beatmapset_id
)
}
}
#[derive(Debug)]
@ -198,6 +206,16 @@ pub struct User {
pub accuracy: f64,
}
impl User {
pub fn link(&self) -> String {
format!("https://osu.ppy.sh/users/{}", self.id)
}
pub fn avatar_url(&self) -> String {
format!("https://a.ppy.sh/{}", self.id)
}
}
#[derive(Debug)]
pub enum Rank {
SS,
@ -244,7 +262,7 @@ pub struct Score {
pub beatmap_id: u64,
pub score: u64,
pub pp: f64,
pub pp: Option<f64>,
pub rank: Rank,
pub mods: Mods, // Later
@ -257,3 +275,41 @@ pub struct Score {
pub max_combo: u64,
pub perfect: bool,
}
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
}
}
}
}

View file

@ -93,6 +93,6 @@ pub(crate) struct Score {
pub user_id: String,
pub date: String,
pub rank: String,
pub pp: String,
pub replay_available: String,
pub pp: Option<String>,
pub replay_available: Option<String>,
}