1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace KriKrixs\object\user; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
|
7
|
|
|
class UserStats |
8
|
|
|
{ |
9
|
|
|
private object $stats; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Create a new UserStats object |
13
|
|
|
* @param object $stats |
14
|
|
|
*/ |
15
|
|
|
public function __construct(object $stats) |
16
|
|
|
{ |
17
|
|
|
$this->stats = $stats; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Get user stats total upvotes |
22
|
|
|
* @return int |
23
|
|
|
*/ |
24
|
|
|
public function getTotalUpvotes(): int |
25
|
|
|
{ |
26
|
|
|
return $this->stats->totalUpvotes; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get user stats total downvotes |
31
|
|
|
* @return int |
32
|
|
|
*/ |
33
|
|
|
public function getTotalDownvotes(): int |
34
|
|
|
{ |
35
|
|
|
return $this->stats->totalDownvotes; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get user stats total maps |
40
|
|
|
* @return int |
41
|
|
|
*/ |
42
|
|
|
public function getTotalMaps(): int |
43
|
|
|
{ |
44
|
|
|
return $this->stats->totalMaps; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get user stats total ranked maps |
49
|
|
|
* @return int |
50
|
|
|
*/ |
51
|
|
|
public function getTotalRankedMaps(): int |
52
|
|
|
{ |
53
|
|
|
return $this->stats->rankedMaps; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get user stats average bpm |
58
|
|
|
* @return float |
59
|
|
|
*/ |
60
|
|
|
public function getAverageBPM(): float |
61
|
|
|
{ |
62
|
|
|
return $this->stats->avgBpm; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get user stats average score |
67
|
|
|
* @return float |
68
|
|
|
*/ |
69
|
|
|
public function getAverageScore(): float |
70
|
|
|
{ |
71
|
|
|
return $this->stats->avgScore; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get user stats average duration |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
|
|
public function getAverageDuration(): int |
79
|
|
|
{ |
80
|
|
|
return $this->stats->avgDuration; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get user stats first upload date |
85
|
|
|
* @return DateTime|null |
86
|
|
|
*/ |
87
|
|
|
public function getFirstUploadDate(): ?DateTime |
88
|
|
|
{ |
89
|
|
|
try { |
90
|
|
|
return new DateTime($this->stats->firstUpload); |
91
|
|
|
} catch (\Exception $e) { |
92
|
|
|
return null; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get user stats last upload date |
98
|
|
|
* @return DateTime|null |
99
|
|
|
*/ |
100
|
|
|
public function getLastUploadDate(): ?DateTime |
101
|
|
|
{ |
102
|
|
|
try { |
103
|
|
|
return new DateTime($this->stats->lastUpload); |
104
|
|
|
} catch (\Exception $e) { |
105
|
|
|
return null; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Get UserStatsDifficulties object |
111
|
|
|
* @return UserStatsDifficulties |
112
|
|
|
*/ |
113
|
|
|
public function getDifficulties(): UserStatsDifficulties |
114
|
|
|
{ |
115
|
|
|
return new UserStatsDifficulties($this->stats->diffStats); |
116
|
|
|
} |
117
|
|
|
} |