ddapi-rs 1.0.1

A simple Rust library to get data from DDNet and DDStats APIs
Documentation
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
use crate::scheme::DDSTATS_BASE_URL;
use crate::util::prelude::{encode, seconds_to_hours, slugify2};
use serde::{Deserialize, Serialize};

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Player {
    pub points_graph: Vec<PointsGraph>,
    pub recent_finishes: Vec<RecentFinish>,
    pub favourite_teammates: Vec<FavouriteTeammate>,
    pub profile: Profile,
    pub is_mapper: bool,
    pub finishes: Vec<Finish>,
    pub unfinished_maps: Vec<UnfinishedMap>,
    pub points: Points,
    #[serde(default)]
    pub completion_progress: Vec<CompletionProgress>,
    pub recent_activity: Vec<RecentActivity>,
    pub recent_player_info: Vec<RecentPlayerInfo>,
    pub most_played_maps: Vec<MostPlayedMap>,
    pub most_played_gametypes: Vec<MostPlayed>,
    pub most_played_categories: Vec<MostPlayed>,
    pub most_played_locations: Vec<MostPlayed>,
    pub playtime_per_month: Vec<PlaytimePerMonth>,
    pub general_activity: Option<GeneralActivity>,
    pub favourite_rank1s_teammates: Vec<FavouriteRank1sTeammates>,
    pub all_top_10s: Vec<AllTop10>,
    pub recent_top_10s: Vec<RecentTop10>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CompletionProgress {
    pub category: String,
    pub maps_finished: u64,
    pub maps_total: u64,
}

impl Player {
    pub fn url(&self) -> String {
        format!(
            "https://{}/player/{}",
            DDSTATS_BASE_URL,
            encode(&self.profile.name)
        )
    }

    pub fn url_with_name(player: &str) -> String {
        format!("https://{}/player/{}", DDSTATS_BASE_URL, encode(player))
    }

    pub fn api(player: &str) -> String {
        format!(
            "https://{}/player/json?player={}",
            DDSTATS_BASE_URL,
            encode(player)
        )
    }
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PointsGraph {
    pub date: String,
    pub points: i64,
    pub rank_points: i64,
    pub team_points: i64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RecentFinish {
    pub map: StatsMap,
    pub name: String,
    pub time: f64,
    pub timestamp: String,
    pub server: String,
    pub cp1: f64,
    pub cp2: f64,
    pub cp3: f64,
    pub cp4: f64,
    pub cp5: f64,
    pub cp6: f64,
    pub cp7: f64,
    pub cp8: f64,
    pub cp9: f64,
    pub cp10: f64,
    pub cp11: f64,
    pub cp12: f64,
    pub cp13: f64,
    pub cp14: f64,
    pub cp15: f64,
    pub cp16: f64,
    pub cp17: f64,
    pub cp18: f64,
    pub cp19: f64,
    pub cp20: f64,
    pub cp21: f64,
    pub cp22: f64,
    pub cp23: f64,
    pub cp24: f64,
    pub cp25: f64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StatsMap {
    pub map: String,
    pub server: String,
    pub points: u8,
    pub stars: u8,
    pub mapper: String,
    pub timestamp: Option<String>,
}

impl StatsMap {
    pub fn url(&self) -> String {
        format!(
            "https://{}/map/{}",
            DDSTATS_BASE_URL,
            encode(&slugify2(&self.map))
        )
    }

    pub fn url_with_name(map: &str) -> String {
        format!(
            "https://{}/map/{}",
            DDSTATS_BASE_URL,
            encode(&slugify2(map))
        )
    }

    pub fn api() -> String {
        format!("https://{}/maps/json", DDSTATS_BASE_URL)
    }
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FavouriteTeammate {
    pub name: String,
    pub ranks_together: i64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Profile {
    pub name: String,
    pub points: i32,
    pub clan: Option<String>,
    pub country: Option<i32>,
    pub skin_name: Option<String>,
    pub skin_color_body: Option<i32>,
    pub skin_color_feet: Option<i32>,
    pub most_played_location: Option<String>,
}

impl Profile {
    pub fn url(&self) -> String {
        format!("https://{}/player/{}", DDSTATS_BASE_URL, encode(&self.name))
    }

    pub fn url_with_name(player: &str) -> String {
        format!("https://{}/player/{}", DDSTATS_BASE_URL, encode(player))
    }

    pub fn api(player: &str) -> String {
        format!(
            "https://{}/profile/json?player={}",
            DDSTATS_BASE_URL,
            encode(player)
        )
    }
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Finish {
    pub map: StatsMap,
    pub name: String,
    pub time: f64,
    pub timestamp: String,
    pub server: String,
    pub rank: u64,
    pub team_rank: Option<u64>,
    pub seconds_played: Option<u64>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UnfinishedMap {
    pub map: StatsMap,
    pub finishes: u64,
    pub finishes_rank: Option<u64>,
    pub median_time: Option<f64>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Points {
    pub weekly_points: Option<PPoints>,
    pub monthly_points: Option<PPoints>,
    pub yearly_points: Option<PPoints>,
    pub points: StatsPoints,
    pub rank_points: StatsPoints,
    pub team_points: StatsPoints,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PPoints {
    pub points: i64,
    pub rank: i64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct StatsPoints {
    pub moderate: Option<Type>,
    pub insane: Option<Type>,
    pub oldschool: Option<Type>,
    pub fun: Option<Type>,
    pub race: Option<Type>,
    pub total: Option<Type>,
    #[serde(rename = "DDmaX.Easy")]
    pub ddmax_easy: Option<Type>,
    pub novice: Option<Type>,
    pub dummy: Option<Type>,
    #[serde(rename = "DDmaX.Pro")]
    pub ddmax_pro: Option<Type>,
    pub brutal: Option<Type>,
    #[serde(rename = "DDmaX.Nut")]
    pub ddmax_nut: Option<Type>,
    pub solo: Option<Type>,
    #[serde(rename = "DDmaX.Next")]
    pub ddmax_next: Option<Type>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Type {
    pub points: i64,
    pub rank: i64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RecentActivity {
    pub name: String,
    pub date: String,
    pub map_name: String,
    pub map: Option<StatsMap>,
    pub seconds_played: i64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RecentPlayerInfo {
    pub name: String,
    pub clan: String,
    pub country: i32,
    pub skin_name: Option<String>,
    pub skin_color_body: Option<u64>,
    pub skin_color_feet: Option<u64>,
    pub last_seen: String,
    pub seconds_played: u64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MostPlayedMap {
    pub map_name: String,
    pub seconds_played: u64,
    pub map: Option<StatsMap>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MostPlayed {
    pub key: String,
    pub seconds_played: u64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaytimePerMonth {
    pub year_month: String,
    pub month: String,
    pub seconds_played: u64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GeneralActivity {
    pub total_seconds_played: u64,
    pub start_of_playtime: String,
    pub average_seconds_played: u64,
}

impl GeneralActivity {
    pub fn total_seconds_played_to_hours(&self) -> f64 {
        seconds_to_hours(self.total_seconds_played as f64)
    }

    pub fn average_seconds_played_to_hours(&self) -> f64 {
        seconds_to_hours(self.average_seconds_played as f64)
    }
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FavouriteRank1sTeammates {
    pub name: String,
    pub ranks_together: u64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AllTop10 {
    pub map: StatsMap,
    pub name: String,
    pub time: f64,
    pub rank: u64,
    pub team_rank: Option<u64>,
    pub team_time: Option<f64>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RecentTop10 {
    pub rank_type: String,
    pub map: String,
    pub time: f64,
    pub rank: u64,
    pub timestamp: String,
    pub server: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct InfoSMap {
    pub map: StatsMap,
    pub finishes: u64,
    pub finishes_rank: u64,
    pub median_time: f64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RankingSMap {
    pub rank: u64,
    pub timestamp: Option<String>,
    pub name: String,
    pub time: f64,
    pub map: String,
    pub server: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TeamRankingSMap {
    pub rank: u64,
    pub timestamp: Option<String>,
    pub id: Vec<u64>,
    pub players: Vec<String>,
    pub time: f64,
    pub map: String,
    pub server: String,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TimeCpsSMap {
    pub name: String,
    pub cp1: f64,
    pub cp2: f64,
    pub cp3: f64,
    pub cp4: f64,
    pub cp5: f64,
    pub cp6: f64,
    pub cp7: f64,
    pub cp8: f64,
    pub cp9: f64,
    pub cp10: f64,
    pub cp11: f64,
    pub cp12: f64,
    pub cp13: f64,
    pub cp14: f64,
    pub cp15: f64,
    pub cp16: f64,
    pub cp17: f64,
    pub cp18: f64,
    pub cp19: f64,
    pub cp20: f64,
    pub cp21: f64,
    pub cp22: f64,
    pub cp23: f64,
    pub cp24: f64,
    pub cp25: f64,
    pub time: f64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlaytimeSMap {
    pub name: String,
    pub seconds_played: u64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Map {
    pub info: InfoSMap,
    pub rankings: Vec<RankingSMap>,
    pub team_rankings: Vec<TeamRankingSMap>,
    pub time_cps: Vec<TimeCpsSMap>,
    pub playtime: Vec<PlaytimeSMap>,
}

impl Map {
    pub fn url(&self) -> String {
        format!(
            "https://{}/map/{}",
            DDSTATS_BASE_URL,
            encode(&self.info.map.map)
        )
    }

    pub fn url_with_name(map: &str) -> String {
        format!("https://{}/map/{}", DDSTATS_BASE_URL, encode(map))
    }

    pub fn api(map: &str) -> String {
        format!("https://{}/map/json?map={}", DDSTATS_BASE_URL, encode(map))
    }
}