Skip to content

Commit

Permalink
feat: add star rating to the clan wars maps
Browse files Browse the repository at this point in the history
  • Loading branch information
motzel committed Mar 2, 2024
1 parent 985d618 commit fb3fad8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bl-bot"
version = "0.17.3"
version = "0.17.4"
description = "Beat Leader Discord Bot"
readme = "README.md"
repository = "https://github.com/motzel/bl-bot"
Expand Down
6 changes: 4 additions & 2 deletions src/discord/bot/beatleader/clan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ use crate::beatleader::clan::{
Clan, ClanId, ClanMap, ClanMapParam, ClanMapScore, ClanMapsParam, ClanMapsSort, ClanTag,
};
use crate::beatleader::error::Error as BlError;
use crate::beatleader::player::PlayerId;
use crate::beatleader::player::{Difficulty, PlayerId};
use crate::beatleader::pp::{
calculate_acc_from_pp, calculate_pp_boundary, StarRating, CLAN_WEIGHT_COEFFICIENT,
};
use crate::beatleader::{BlContext, DataWithMeta, SortOrder};
use crate::discord::bot::beatleader::player::Player;
use crate::discord::bot::beatleader::score::{MapRatingModifier, MapRatings};
use crate::storage::player::PlayerRepository;
use crate::storage::player_scores::PlayerScoresRepository;
use crate::storage::{StorageKey, StorageValue};
Expand Down Expand Up @@ -252,7 +253,7 @@ impl ClanMapWithScores {
impl Display for ClanMapWithScores {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f,
"### **#{} [{} / {}](https://www.beatleader.xyz/leaderboard/clanranking/{}/{})**\n{} score{} / {:.2}pp / **{:.2} raw pp**\n {} SS / **{}** / {} FS / {} SF\n",
"### **#{} [{} / {}](https://www.beatleader.xyz/leaderboard/clanranking/{}/{})**\n{} score{} / {:.2}pp / **{:.2} raw pp**\n{}\n {} SS / **{}** / {} FS / {} SF\n",
self.map.rank,
self.map.leaderboard.song.name,
self
Expand All @@ -266,6 +267,7 @@ impl Display for ClanMapWithScores {
if self.scores.len() > 1 { "s" } else { "" },
self.map.pp,
self.pp_boundary,
<&Difficulty as Into<MapRatings>>::into(&self.map.leaderboard.difficulty).to_stars_string(Some(MapRatingModifier::None)),
match self.acc_boundary.ss {
None => "Not possible".to_owned(),
Some(acc) => format!("{:.2}%", acc * 100.0),
Expand Down
59 changes: 58 additions & 1 deletion src/discord/bot/beatleader/score.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::fmt;
use std::fmt::Display;
use std::fmt::{Display, Formatter};
use std::sync::Arc;

use chrono::serde::ts_seconds;
Expand Down Expand Up @@ -401,6 +401,59 @@ pub struct MapRatings {
pub sf: Option<MapRating>,
}

impl MapRatings {
pub fn to_stars_string(&self, bold_modifier: Option<MapRatingModifier>) -> String {
let ss = self
.ss
.as_ref()
.map_or_else(|| "-".to_owned(), |s| s.to_stars_string());
let none = self
.none
.as_ref()
.map_or_else(|| "-".to_owned(), |s| s.to_stars_string());
let fs = self
.fs
.as_ref()
.map_or_else(|| "-".to_owned(), |s| s.to_stars_string());
let sf = self
.sf
.as_ref()
.map_or_else(|| "-".to_owned(), |s| s.to_stars_string());

format!(
"{} SS / {} / {} FS / {} SF",
if bold_modifier.is_some()
&& bold_modifier.as_ref().unwrap() == &MapRatingModifier::SlowerSong
{
format!("**{}**", ss)
} else {
ss
},
if bold_modifier.is_some()
&& bold_modifier.as_ref().unwrap() == &MapRatingModifier::None
{
format!("**{}**", none)
} else {
none
},
if bold_modifier.is_some()
&& bold_modifier.as_ref().unwrap() == &MapRatingModifier::FasterSong
{
format!("**{}**", fs)
} else {
fs
},
if bold_modifier.is_some()
&& bold_modifier.as_ref().unwrap() == &MapRatingModifier::SuperFastSong
{
format!("**{}**", sf)
} else {
sf
},
)
}
}

impl From<&Difficulty> for MapRatings {
fn from(value: &Difficulty) -> Self {
Self {
Expand Down Expand Up @@ -487,6 +540,10 @@ impl MapRating {
}
}

pub fn to_stars_string(&self) -> String {
format!("{:.2}⭐", self.stars)
}

pub fn from_ai_ratings_and_modifier(ratings: &AiRatings, modifier: MapRatingModifier) -> Self {
match modifier {
MapRatingModifier::None => Self {
Expand Down

0 comments on commit fb3fad8

Please sign in to comment.