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
|
|
|
* Return raw data |
22
|
|
|
* @return object |
23
|
|
|
*/ |
24
|
|
|
public function toJson(): object |
25
|
|
|
{ |
26
|
|
|
return $this->stats; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Return array data |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
public function toArray(): array |
34
|
|
|
{ |
35
|
|
|
return json_decode(json_encode($this->stats), true); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get user stats total upvotes |
40
|
|
|
* @return int |
41
|
|
|
*/ |
42
|
|
|
public function getTotalUpvotes(): int |
43
|
|
|
{ |
44
|
|
|
return $this->stats->totalUpvotes; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get user stats total downvotes |
49
|
|
|
* @return int |
50
|
|
|
*/ |
51
|
|
|
public function getTotalDownvotes(): int |
52
|
|
|
{ |
53
|
|
|
return $this->stats->totalDownvotes; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get user stats total maps |
58
|
|
|
* @return int |
59
|
|
|
*/ |
60
|
|
|
public function getTotalMaps(): int |
61
|
|
|
{ |
62
|
|
|
return $this->stats->totalMaps; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get user stats total ranked maps |
67
|
|
|
* @return int |
68
|
|
|
*/ |
69
|
|
|
public function getTotalRankedMaps(): int |
70
|
|
|
{ |
71
|
|
|
return $this->stats->rankedMaps; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get user stats average bpm |
76
|
|
|
* @return float |
77
|
|
|
*/ |
78
|
|
|
public function getAverageBPM(): float |
79
|
|
|
{ |
80
|
|
|
return $this->stats->avgBpm; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get user stats average score |
85
|
|
|
* @return float |
86
|
|
|
*/ |
87
|
|
|
public function getAverageScore(): float |
88
|
|
|
{ |
89
|
|
|
return $this->stats->avgScore; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get user stats average duration |
94
|
|
|
* @return int |
95
|
|
|
*/ |
96
|
|
|
public function getAverageDuration(): int |
97
|
|
|
{ |
98
|
|
|
return $this->stats->avgDuration; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get user stats first upload date |
103
|
|
|
* @return DateTime|null |
104
|
|
|
*/ |
105
|
|
|
public function getFirstUploadDate(): ?DateTime |
106
|
|
|
{ |
107
|
|
|
try { |
108
|
|
|
return new DateTime($this->stats->firstUpload); |
109
|
|
|
} catch (\Exception $e) { |
110
|
|
|
return null; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get user stats last upload date |
116
|
|
|
* @return DateTime|null |
117
|
|
|
*/ |
118
|
|
|
public function getLastUploadDate(): ?DateTime |
119
|
|
|
{ |
120
|
|
|
try { |
121
|
|
|
return new DateTime($this->stats->lastUpload); |
122
|
|
|
} catch (\Exception $e) { |
123
|
|
|
return null; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Get UserStatsDifficulties object |
129
|
|
|
* @return UserStatsDifficulties |
130
|
|
|
*/ |
131
|
|
|
public function getDifficulties(): UserStatsDifficulties |
132
|
|
|
{ |
133
|
|
|
return new UserStatsDifficulties($this->stats->diffStats); |
134
|
|
|
} |
135
|
|
|
} |