Skip to content

Commit

Permalink
Implemented displays and split up modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan561 committed Oct 29, 2020
1 parent 7a97d96 commit 79cf52d
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 174 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "r6stats_client"
version = "0.2.0"
version = "0.2.1"
authors = ["Jan Adä <jan561.github@gmail.com>"]
edition = "2018"
description = "Client for the r6stats API."
Expand Down
17 changes: 4 additions & 13 deletions src/stats/model/generic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//! Module for generic stats.
mod queue_mode;

pub use self::queue_mode::QueueMode;

use chrono::{DateTime, Utc};
use serde::Deserialize;
use std::collections::HashMap;
Expand Down Expand Up @@ -81,19 +85,6 @@ pub struct GeneralStatsInfo {
pub wl: f32,
}

/// The queue mode.
#[derive(Deserialize, Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum QueueMode {
/// Casual Queue
Casual,
/// Ranked Queue
Ranked,
/// Unranked Queue and other
Other,
}

/// Deserialized info for the [`QueueMode`].
///
/// [`QueueMode`]: enum.QueueMode.html
Expand Down
25 changes: 25 additions & 0 deletions src/stats/model/generic/queue_mode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use serde::Deserialize;
use std::fmt::{self, Display, Formatter};

/// The queue mode.
#[derive(Deserialize, Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum QueueMode {
/// Casual Queue
Casual,
/// Ranked Queue
Ranked,
/// Unranked Queue and other
Other,
}

impl Display for QueueMode {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::Casual => write!(f, "Casual"),
Self::Ranked => write!(f, "Ranked"),
Self::Other => write!(f, "Other"),
}
}
}
168 changes: 8 additions & 160 deletions src/stats/model/seasonal.rs
Original file line number Diff line number Diff line change
@@ -1,172 +1,20 @@
//! Module for seasonal stats.
mod match_result;
mod rank;
mod season;

pub use self::match_result::MatchResult;
pub use self::rank::Rank;
pub use self::season::Season;

use crate::internals::utils::serde_parse_f64_option;
use crate::region::Region;
use chrono::{DateTime, NaiveDate, Utc};
use int_enum::IntEnum;
use serde::{Deserialize, Deserializer};
use serde_repr::Deserialize_repr;
use std::collections::HashMap;

/// The rank of the player.
#[derive(Deserialize_repr, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum Rank {
// Unranked
Unranked = 0,

//Copper
CopperV = 1,
CopperIV = 2,
CopperIII = 3,
CopperII = 4,
CopperI = 5,

// Bronze
BronzeV = 6,
BronzeIV = 7,
BronzeIII = 8,
BronzeII = 9,
BronzeI = 10,

// Silver
SilverV = 11,
SilverIV = 12,
SilverIII = 13,
SilverII = 14,
SilverI = 15,

// Gold
GoldIII = 16,
GoldII = 17,
GoldI = 18,

// Platinum
PlatinumIII = 19,
PlatinumII = 20,
PlatinumI = 21,

// Diamond+
Diamond = 22,
Champions = 23,
}

impl Rank {
/// Returns true if [`Rank`] is unranked.
///
/// [`Rank`]: struct.Rank.html
pub fn is_unranked(self) -> bool {
Self::Unranked == self
}

/// Returns true if [`Rank`] is copper.
///
/// [`Rank`]: struct.Rank.html
pub fn is_copper(self) -> bool {
matches!(
self,
Self::CopperI | Self::CopperII | Self::CopperIII | Self::CopperIV | Self::CopperV
)
}

/// Returns true if [`Rank`] is bronze.
///
/// [`Rank`]: struct.Rank.html
pub fn is_bronze(self) -> bool {
matches!(
self,
Self::BronzeI | Self::BronzeII | Self::BronzeIII | Self::BronzeIV | Self::BronzeV
)
}

/// Returns true if [`Rank`] is silver.
///
/// [`Rank`]: struct.Rank.html
pub fn is_silver(self) -> bool {
matches!(
self,
Self::SilverI | Self::SilverII | Self::SilverIII | Self::SilverIV | Self::SilverV
)
}

/// Returns true if [`Rank`] is gold.
///
/// [`Rank`]: struct.Rank.html
pub fn is_gold(self) -> bool {
matches!(self, Self::GoldI | Self::GoldII | Self::GoldIII)
}

/// Returns true if [`Rank`] is platinum.
///
/// [`Rank`]: struct.Rank.html
pub fn is_platinum(self) -> bool {
matches!(self, Self::PlatinumI | Self::PlatinumII | Self::PlatinumIII)
}

/// Returns true if [`Rank`] is diamond.
///
/// [`Rank`]: struct.Rank.html
pub fn is_diamond(self) -> bool {
Self::Diamond == self
}

/// Returns true if [`Rank`] is champion.
///
/// [`Rank`]: struct.Rank.html
pub fn is_champion(self) -> bool {
Self::Champions == self
}
}

/// All seasons available in the api.
#[derive(IntEnum, Deserialize, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
#[repr(u8)]
pub enum Season {
// Year 2
Health = 6,
BloodOrchid = 7,
WhiteNoise = 8,

// Year 3
Chimera = 9,
ParaBellum = 10,
GrimSky = 11,
WindBastion = 12,

// Year 4
BurntHorizon = 13,
PhantomSight = 14,
EmberRise = 15,
ShiftingTides = 16,

// Year 5
VoidEdge = 17,
SteelWave = 18,
ShadowLegacy = 19,

/// For new seasons not yet implemented in this client.
#[serde(other)]
Unknown = 20,
}

impl Season {
pub const fn current_season() -> Self {
Self::ShadowLegacy
}
}

/// The match result.
#[derive(Deserialize_repr, Copy, Clone, Debug)]
#[repr(u8)]
pub enum MatchResult {
NotAvailable = 0,
Win = 1,
Loss = 2,
Abandoned = 3,
}

/// Deserialized seasonal stats.
#[derive(Deserialize, Clone, Debug)]
#[non_exhaustive]
Expand Down
23 changes: 23 additions & 0 deletions src/stats/model/seasonal/match_result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use serde_repr::Deserialize_repr;
use std::fmt::{self, Display, Formatter};

/// The match result.
#[derive(Deserialize_repr, Copy, Clone, Debug)]
#[repr(u8)]
pub enum MatchResult {
NotAvailable = 0,
Win = 1,
Loss = 2,
Abandoned = 3,
}

impl Display for MatchResult {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::NotAvailable => write!(f, "Not Available"),
Self::Win => write!(f, "Win"),
Self::Loss => write!(f, "Loss"),
Self::Abandoned => write!(f, "Abandoned"),
}
}
}
Loading

0 comments on commit 79cf52d

Please sign in to comment.