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
//! Models for the endpoint "Server Statistics".
//!
//! About the endpoint "Server Statistics",
//! see the [API document](https://tetr.io/about/api/#generalstats).
use crate::model::prelude::*;
/// Server Statistics about the TETR.IO.
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct ServerStats {
/// The amount of users on the server,
/// including anonymous accounts.
#[serde(rename = "usercount")]
pub user_count: u64,
/// The amount of users created a second
/// (through the last minute).
#[serde(rename = "usercount_delta")]
pub user_count_delta: f64,
/// The amount of anonymous accounts on the server.
#[serde(rename = "anoncount")]
pub anon_count: u64,
/// The total amount of accounts ever created
/// (including pruned anons etc.).
#[serde(rename = "totalaccounts")]
pub total_accounts: u64,
/// The amount of ranked
/// (visible in TETRA LEAGUE leaderboard) accounts on the server.
#[serde(rename = "rankedcount")]
pub ranked_count: u64,
/// The amount of game records stored on the server.
#[serde(rename = "recordcount")]
pub record_count: u64,
/// The amount of games played across all users,
/// including both off- and online modes.
#[serde(rename = "gamesplayed")]
pub games_play_count: u64,
/// The amount of games played a second
/// (through the last minute).
#[serde(rename = "gamesplayed_delta")]
pub games_play_count_delta: f64,
/// The amount of games played across all users,
/// including both off- and online modes, excluding games that were not completed
/// (e.g. retries)
#[serde(rename = "gamesfinished")]
pub games_finish_count: u64,
/// The amount of seconds spent playing across all users,
/// including both off- and online modes.
#[serde(rename = "gametime")]
pub play_time: f64,
/// The amount of keys pressed across all users,
/// including both off- and online modes.
pub inputs: u64,
/// The amount of pieces placed across all users,
/// including both off- and online modes.
#[serde(rename = "piecesplaced")]
pub pieces_place_count: u64,
}
impl ServerStats {
/// Returns the amount of registered players.
pub fn registered_players(&self) -> u64 {
self.user_count - self.anon_count
}
/// Returns the amount of minutes spent playing across all users.
/// including both off- and online modes. 1*60
pub fn play_time_minutes(&self) -> f64 {
self.play_time / 60.
}
/// Returns the amount of hours spent playing across all users.
/// including both off- and online modes.
pub fn play_time_hours(&self) -> f64 {
self.play_time / 3600.
}
/// Returns the amount of days spent playing across all users.
/// including both off- and online modes.
pub fn play_time_days(&self) -> f64 {
self.play_time / 86400.
}
/// Returns the amount of months spent playing across all users.
/// including both off- and online modes.
pub fn play_time_months(&self) -> f64 {
self.play_time / 2628000.
}
/// Returns the amount of years spent playing across all users.
/// including both off- and online modes.
pub fn play_time_years(&self) -> f64 {
self.play_time / 31536000.0
}
/// Returns the average amount of pieces placed per second.
pub fn avg_pieces_per_second(&self) -> f64 {
self.pieces_place_count as f64 / self.play_time
}
/// Returns the average amount of keys pressed per second.
pub fn avg_keys_per_second(&self) -> f64 {
self.inputs as f64 / self.play_time
}
}
impl AsRef<ServerStats> for ServerStats {
fn as_ref(&self) -> &Self {
self
}
}