Using html scoring dance to collect stats

This commit is contained in:
Lukas Wölfer
2025-10-05 00:26:55 +02:00
parent c54d950e30
commit bc57e8cceb
7 changed files with 109 additions and 84 deletions

View File

@@ -1,19 +1,10 @@
use std::fmt;
#[derive(serde::Deserialize, Debug, PartialEq, Eq)]
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
pub enum DanceRole {
Leader,
Follower,
}
impl DanceRole {
pub const fn as_str(&self) -> &str {
match self {
Self::Leader => "Leader",
Self::Follower => "Follower",
}
}
#[allow(dead_code)]
pub const fn other(&self) -> Self {
match self {
@@ -23,29 +14,12 @@ impl DanceRole {
}
}
#[derive(Debug)]
pub struct ParseDanceRoleError;
serde_plain::derive_display_from_serialize!(DanceRole);
serde_plain::derive_fromstr_from_deserialize!(DanceRole);
impl std::fmt::Display for ParseDanceRoleError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "failed to parse DanceRole")
}
}
impl std::error::Error for ParseDanceRoleError {}
impl TryFrom<&str> for DanceRole {
type Error = ParseDanceRoleError;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
"leader" => Ok(Self::Leader),
"follower" => Ok(Self::Follower),
_ => Err(ParseDanceRoleError),
}
}
}
#[derive(serde::Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[derive(
serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy,
)]
pub enum DanceRank {
Newcomer,
Novice,
@@ -56,19 +30,8 @@ pub enum DanceRank {
AllStars,
Champions,
}
impl DanceRank {
pub const fn as_str(&self) -> &str {
match self {
Self::Newcomer => "Newcomer",
Self::Novice => "Novice",
Self::Intermediate => "Intermediate",
Self::Advanced => "Advanced",
Self::AllStars => "All-Stars",
Self::Champions => "Champions",
}
}
}
serde_plain::derive_display_from_serialize!(DanceRank);
serde_plain::derive_fromstr_from_deserialize!(DanceRank);
#[derive(Debug)]
pub struct CompState {