1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use super::Command;
use colored::Colorize;
use clap::{SubCommand, App, ArgMatches};
pub struct StatCommand;
impl Command for StatCommand {
fn usage<'a, 'stat>() -> App<'a, 'stat> {
SubCommand::with_name("stat")
.about("Show simple chart about submissions")
.visible_alias("s")
}
fn handler(_m: &ArgMatches) -> Result<(), crate::err::Error> {
use crate::{Cache, helper::Digit};
let cache = Cache::new()?;
let res = cache.get_problems()?;
let mut easy: f64 = 0.00;
let mut easy_ac: f64 = 0.00;
let mut medium: f64 = 0.00;
let mut medium_ac: f64 = 0.00;
let mut hard: f64 = 0.00;
let mut hard_ac: f64 = 0.00;
for i in res.into_iter() {
match i.level {
1 => {
easy += 1.00;
if i.status == "ac".to_string() {
easy_ac += 1.00;
}
},
2 => {
medium += 1.00;
if i.status == "ac".to_string() {
medium_ac += 1.00;
}
},
3 => {
hard += 1.00;
if i.status == "ac".to_string() {
hard_ac += 1.00;
}
},
_ => {}
}
}
println!(
"\n{}",
" Level Count Percent Chart".bright_black()
);
println!(
"{}",
" -----------------------------------------------------------------".bright_black()
);
for (i, l) in vec![
(easy, easy_ac),
(medium, medium_ac),
(hard, hard_ac)
].iter().enumerate() {
match i {
0 => {
print!(" {}", "Easy".bright_green());
print!("{}", " ".digit(4));
},
1 => {
print!(" {}", "Medium".bright_yellow());
print!("{}", " ".digit(2));
},
2 => {
print!(" {}", "Hard".bright_red());
print!("{}", " ".digit(4));
},
_ => continue
}
let count = format!("{}/{}", l.1, l.0);
let pct = format!("( {:.2} %)", ((100.0 * l.1) / l.0));
let mut line = "".to_string();
line.push_str(&" ".digit(8 - (count.len() as i32)));
line.push_str(&count);
line.push_str(&" ".digit(12 - (pct.len() as i32)));
line.push_str(&pct);
print!("{}", line);
print!(" ");
let done = "░".repeat(
((32.00 * l.1) / l.0) as usize
).bright_green();
let udone = "░".repeat(
32 - ((32.00 * l.1) / l.0) as usize
).red();
print!("{}", done);
println!("{}", udone);
}
println!("");
Ok(())
}
}