Display set counts in player info
This commit is contained in:
parent
db85674601
commit
14b5b2cafd
|
@ -383,6 +383,25 @@ pub fn get_player_rating_data(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_player_set_counts(
|
||||||
|
connection: &Connection,
|
||||||
|
dataset: &str,
|
||||||
|
player: PlayerId,
|
||||||
|
) -> sqlite::Result<(u64, u64)> {
|
||||||
|
let query = format!(
|
||||||
|
r#"SELECT sets_count_won, sets_count_lost FROM "{}_players" WHERE id = ?"#,
|
||||||
|
dataset
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut statement = connection.prepare(&query)?;
|
||||||
|
statement.bind((1, player.0 as i64))?;
|
||||||
|
statement.next()?;
|
||||||
|
Ok((
|
||||||
|
statement.read::<i64, _>("sets_count_won")? as u64,
|
||||||
|
statement.read::<i64, _>("sets_count_lost")? as u64,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_player_data(
|
pub fn set_player_data(
|
||||||
connection: &Connection,
|
connection: &Connection,
|
||||||
dataset: &str,
|
dataset: &str,
|
||||||
|
@ -751,8 +770,7 @@ CREATE TABLE IF NOT EXISTS sets (
|
||||||
|
|
||||||
add_players(&connection, "test", &vec![players(2)], Timestamp(0))?;
|
add_players(&connection, "test", &vec![players(2)], Timestamp(0))?;
|
||||||
|
|
||||||
let mut statement =
|
let mut statement = connection.prepare("SELECT * FROM players WHERE id = 1")?;
|
||||||
connection.prepare("SELECT * FROM dataset_test_players WHERE id = 1")?;
|
|
||||||
statement.next()?;
|
statement.next()?;
|
||||||
assert_eq!(statement.read::<i64, _>("id")?, 1);
|
assert_eq!(statement.read::<i64, _>("id")?, 1);
|
||||||
assert_eq!(statement.read::<String, _>("name")?, "1");
|
assert_eq!(statement.read::<String, _>("name")?, "1");
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -470,6 +470,9 @@ fn player_info(dataset: Option<String>, player: String) {
|
||||||
let (deviation, volatility, _) = get_player_rating_data(&connection, &dataset, id)
|
let (deviation, volatility, _) = get_player_rating_data(&connection, &dataset, id)
|
||||||
.unwrap_or_else(|_| error("Could not find player", 1));
|
.unwrap_or_else(|_| error("Could not find player", 1));
|
||||||
|
|
||||||
|
let (won, lost) = get_player_set_counts(&connection, &dataset, id)
|
||||||
|
.unwrap_or_else(|_| error("Could not find player", 1));
|
||||||
|
|
||||||
println!();
|
println!();
|
||||||
if let Some(pre) = prefix {
|
if let Some(pre) = prefix {
|
||||||
print!("\x1b[2m{}\x1b[22m ", pre);
|
print!("\x1b[2m{}\x1b[22m ", pre);
|
||||||
|
@ -479,8 +482,15 @@ fn player_info(dataset: Option<String>, player: String) {
|
||||||
\x1b[1m{0}\x1b[22m\x1b]8;;\x1b\\\x1b[0m ({1})",
|
\x1b[1m{0}\x1b[22m\x1b]8;;\x1b\\\x1b[0m ({1})",
|
||||||
name, discrim
|
name, discrim
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("\x1b[1mID:\x1b[0m {}", id.0);
|
println!("\x1b[1mID:\x1b[0m {}", id.0);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"\n\x1b[1mSet Count:\x1b[0m {} - {} ({:.3}%)",
|
||||||
|
won,
|
||||||
|
lost,
|
||||||
|
(won as f64 / (won + lost) as f64) * 100.0
|
||||||
|
);
|
||||||
|
|
||||||
println!("\n\x1b[1mDeviation:\x1b[0m {}", deviation);
|
println!("\n\x1b[1mDeviation:\x1b[0m {}", deviation);
|
||||||
println!("\x1b[1mVolatility:\x1b[0m {}", volatility);
|
println!("\x1b[1mVolatility:\x1b[0m {}", volatility);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,15 @@ pub enum StringOrInt {
|
||||||
Int(u64),
|
Int(u64),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl StringOrInt {
|
||||||
|
pub fn from_string(s: &str) -> Self {
|
||||||
|
match s.parse::<u64>() {
|
||||||
|
Ok(x) => StringOrInt::Int(x),
|
||||||
|
Err(_) => StringOrInt::String(s.to_owned()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for StringOrInt {
|
impl Display for StringOrInt {
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -323,7 +323,7 @@ pub fn sync_dataset(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::database::tests::*;
|
use crate::datasets::tests::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn glicko_single() -> sqlite::Result<()> {
|
fn glicko_single() -> sqlite::Result<()> {
|
||||||
|
|
|
@ -30,6 +30,8 @@ pub fn read_string() -> String {
|
||||||
line.trim().to_owned()
|
line.trim().to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Player Input
|
||||||
|
|
||||||
pub enum PlayerInput {
|
pub enum PlayerInput {
|
||||||
Id(PlayerId),
|
Id(PlayerId),
|
||||||
Discrim(String),
|
Discrim(String),
|
||||||
|
|
Loading…
Reference in a new issue