ddapi_rs/scheme/
ddstats.rs

1use crate::scheme::DDSTATS_BASE_URL;
2use crate::util::prelude::{encode, seconds_to_hours, slugify2};
3use serde_derive::{Deserialize, Serialize};
4
5#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
6pub struct Player {
7    pub points_graph: Vec<PointsGraph>,
8    pub recent_finishes: Vec<RecentFinish>,
9    pub favourite_teammates: Vec<FavouriteTeammate>,
10    pub profile: Profile,
11    pub is_mapper: bool,
12    pub finishes: Vec<Finish>,
13    pub unfinished_maps: Vec<UnfinishedMap>,
14    pub points: Points,
15    pub recent_activity: Vec<RecentActivity>,
16    pub recent_player_info: Vec<RecentPlayerInfo>,
17    pub most_played_maps: Vec<MostPlayedMap>,
18    pub most_played_gametypes: Vec<MostPlayed>,
19    pub most_played_categories: Vec<MostPlayed>,
20    pub most_played_locations: Vec<MostPlayed>,
21    pub playtime_per_month: Vec<PlaytimePerMonth>,
22    pub general_activity: Option<GeneralActivity>,
23    pub favourite_rank1s_teammates: Vec<FavouriteRank1sTeammates>,
24    pub all_top_10s: Vec<AllTop10>,
25    pub recent_top_10s: Vec<RecentTop10>,
26}
27
28impl Player {
29    pub fn url(&self) -> String {
30        format!(
31            "https://{}/player/{}",
32            DDSTATS_BASE_URL,
33            encode(&self.profile.name)
34        )
35    }
36
37    pub fn url_with_name(player: &str) -> String {
38        format!("https://{}/player/{}", DDSTATS_BASE_URL, encode(player))
39    }
40
41    pub fn api(player: &str) -> String {
42        format!(
43            "https://{}/player/json?player={}",
44            DDSTATS_BASE_URL,
45            encode(player)
46        )
47    }
48}
49
50#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
51pub struct PointsGraph {
52    pub date: String,
53    pub points: i64,
54    pub rank_points: i64,
55    pub team_points: i64,
56}
57
58#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
59pub struct RecentFinish {
60    pub map: StatsMap,
61    pub name: String,
62    pub time: f64,
63    pub timestamp: String,
64    pub server: String,
65    pub cp1: f64,
66    pub cp2: f64,
67    pub cp3: f64,
68    pub cp4: f64,
69    pub cp5: f64,
70    pub cp6: f64,
71    pub cp7: f64,
72    pub cp8: f64,
73    pub cp9: f64,
74    pub cp10: f64,
75    pub cp11: f64,
76    pub cp12: f64,
77    pub cp13: f64,
78    pub cp14: f64,
79    pub cp15: f64,
80    pub cp16: f64,
81    pub cp17: f64,
82    pub cp18: f64,
83    pub cp19: f64,
84    pub cp20: f64,
85    pub cp21: f64,
86    pub cp22: f64,
87    pub cp23: f64,
88    pub cp24: f64,
89    pub cp25: f64,
90}
91
92#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
93pub struct StatsMap {
94    pub map: String,
95    pub server: String,
96    pub points: u8,
97    pub stars: u8,
98    pub mapper: String,
99    pub timestamp: Option<String>,
100}
101
102impl StatsMap {
103    pub fn url(&self) -> String {
104        format!(
105            "https://{}/map/{}",
106            DDSTATS_BASE_URL,
107            encode(&slugify2(&self.map))
108        )
109    }
110
111    pub fn url_with_name(map: &str) -> String {
112        format!(
113            "https://{}/map/{}",
114            DDSTATS_BASE_URL,
115            encode(&slugify2(map))
116        )
117    }
118
119    pub fn api() -> String {
120        format!("https://{}/maps/json", DDSTATS_BASE_URL)
121    }
122}
123
124#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
125pub struct FavouriteTeammate {
126    pub name: String,
127    pub ranks_together: u64,
128}
129
130#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
131pub struct Profile {
132    pub name: String,
133    pub points: u64,
134    pub clan: Option<String>,
135    pub country: Option<u64>,
136    pub skin_name: Option<String>,
137    pub skin_color_body: Option<i64>,
138    pub skin_color_feet: Option<i64>,
139}
140
141impl Profile {
142    pub fn url(&self) -> String {
143        format!("https://{}/player/{}", DDSTATS_BASE_URL, encode(&self.name))
144    }
145
146    pub fn url_with_name(player: &str) -> String {
147        format!("https://{}/player/{}", DDSTATS_BASE_URL, encode(player))
148    }
149
150    pub fn api(player: &str) -> String {
151        format!(
152            "https://{}/profile/json?player={}",
153            DDSTATS_BASE_URL,
154            encode(player)
155        )
156    }
157}
158
159#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
160pub struct Finish {
161    pub map: StatsMap,
162    pub name: String,
163    pub time: f64,
164    pub timestamp: String,
165    pub server: String,
166    pub rank: u64,
167    pub team_rank: Option<u64>,
168    pub seconds_played: Option<u64>,
169}
170
171#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
172pub struct UnfinishedMap {
173    pub map: StatsMap,
174    pub finishes: u64,
175    pub finishes_rank: Option<u64>,
176    pub median_time: Option<f64>,
177}
178
179#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
180pub struct Points {
181    pub weekly_points: Option<PPoints>,
182    pub monthly_points: Option<PPoints>,
183    pub yearly_points: Option<PPoints>,
184    pub points: StatsPoints,
185    pub rank_points: StatsPoints,
186    pub team_points: StatsPoints,
187}
188
189#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
190pub struct PPoints {
191    pub points: i64,
192    pub rank: i64,
193}
194
195#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
196#[serde(rename_all = "PascalCase")]
197pub struct StatsPoints {
198    pub moderate: Option<Type>,
199    pub insane: Option<Type>,
200    pub oldschool: Option<Type>,
201    pub fun: Option<Type>,
202    pub race: Option<Type>,
203    pub total: Option<Type>,
204    #[serde(rename = "DDmaX.Easy")]
205    pub ddmax_easy: Option<Type>,
206    pub novice: Option<Type>,
207    pub dummy: Option<Type>,
208    #[serde(rename = "DDmaX.Pro")]
209    pub ddmax_pro: Option<Type>,
210    pub brutal: Option<Type>,
211    #[serde(rename = "DDmaX.Nut")]
212    pub ddmax_nut: Option<Type>,
213    pub solo: Option<Type>,
214    #[serde(rename = "DDmaX.Next")]
215    pub ddmax_next: Option<Type>,
216}
217
218#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
219pub struct Type {
220    pub points: i64,
221    pub rank: i64,
222}
223
224#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
225pub struct RecentActivity {
226    pub name: String,
227    pub date: String,
228    pub map_name: String,
229    pub map: Option<StatsMap>,
230    pub seconds_played: i64,
231}
232
233#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
234pub struct RecentPlayerInfo {
235    pub name: String,
236    pub clan: String,
237    pub country: i16,
238    pub skin_name: Option<String>,
239    pub skin_color_body: Option<u64>,
240    pub skin_color_feet: Option<u64>,
241    pub last_seen: String,
242    pub seconds_played: u64,
243}
244
245#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
246pub struct MostPlayedMap {
247    pub map_name: String,
248    pub seconds_played: u64,
249    pub map: Option<StatsMap>,
250}
251
252#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
253pub struct MostPlayed {
254    pub key: String,
255    pub seconds_played: u64,
256}
257
258#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
259pub struct PlaytimePerMonth {
260    pub year_month: String,
261    pub month: String,
262    pub seconds_played: u64,
263}
264
265#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
266pub struct GeneralActivity {
267    pub total_seconds_played: u64,
268    pub start_of_playtime: String,
269    pub average_seconds_played: u64,
270}
271
272impl GeneralActivity {
273    pub fn total_seconds_played_to_hours(&self) -> f64 {
274        seconds_to_hours(self.total_seconds_played as f64)
275    }
276
277    pub fn average_seconds_played_to_hours(&self) -> f64 {
278        seconds_to_hours(self.average_seconds_played as f64)
279    }
280}
281
282#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
283pub struct FavouriteRank1sTeammates {
284    pub name: String,
285    pub ranks_together: u64,
286}
287
288#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
289pub struct AllTop10 {
290    pub map: StatsMap,
291    pub name: String,
292    pub time: f64,
293    pub rank: u64,
294    pub team_rank: Option<u64>,
295    pub team_time: Option<f64>,
296}
297
298#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
299pub struct RecentTop10 {
300    pub rank_type: String,
301    pub map: String,
302    pub time: f64,
303    pub rank: u64,
304    pub timestamp: String,
305    pub server: String,
306}
307
308#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
309pub struct InfoSMap {
310    pub map: StatsMap,
311    pub finishes: u64,
312    pub finishes_rank: u64,
313    pub median_time: f64,
314}
315
316#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
317pub struct RankingSMap {
318    pub rank: u64,
319    pub timestamp: Option<String>,
320    pub name: String,
321    pub time: f64,
322    pub map: String,
323    pub server: String,
324}
325
326#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
327pub struct TeamRankingSMap {
328    pub rank: u64,
329    pub timestamp: Option<String>,
330    pub id: Vec<u64>,
331    pub players: Vec<String>,
332    pub time: f64,
333    pub map: String,
334    pub server: String,
335}
336
337#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
338pub struct TimeCpsSMap {
339    pub name: String,
340    pub cp1: f64,
341    pub cp2: f64,
342    pub cp3: f64,
343    pub cp4: f64,
344    pub cp5: f64,
345    pub cp6: f64,
346    pub cp7: f64,
347    pub cp8: f64,
348    pub cp9: f64,
349    pub cp10: f64,
350    pub cp11: f64,
351    pub cp12: f64,
352    pub cp13: f64,
353    pub cp14: f64,
354    pub cp15: f64,
355    pub cp16: f64,
356    pub cp17: f64,
357    pub cp18: f64,
358    pub cp19: f64,
359    pub cp20: f64,
360    pub cp21: f64,
361    pub cp22: f64,
362    pub cp23: f64,
363    pub cp24: f64,
364    pub cp25: f64,
365    pub time: f64,
366}
367
368#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
369pub struct PlaytimeSMap {
370    pub name: String,
371    pub seconds_played: u64,
372}
373
374#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
375pub struct Map {
376    pub info: InfoSMap,
377    pub rankings: Vec<RankingSMap>,
378    pub team_rankings: Vec<TeamRankingSMap>,
379    pub time_cps: Vec<TimeCpsSMap>,
380    pub playtime: Vec<PlaytimeSMap>,
381}
382
383impl Map {
384    pub fn url(&self) -> String {
385        format!(
386            "https://{}/map/{}",
387            DDSTATS_BASE_URL,
388            encode(&self.info.map.map)
389        )
390    }
391
392    pub fn url_with_name(map: &str) -> String {
393        format!("https://{}/map/{}", DDSTATS_BASE_URL, encode(map))
394    }
395
396    pub fn api(map: &str) -> String {
397        format!("https://{}/map/json?map={}", DDSTATS_BASE_URL, encode(map))
398    }
399}