1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The outcome of an {@link Activity} achieved by an {@link Agent}. |
16
|
|
|
* |
17
|
|
|
* @author Christian Flothmann <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
final class Score |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var float The scaled score (a number between -1 and 1) |
23
|
|
|
*/ |
24
|
|
|
private $scaled; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var float The Agent's score (a number between min and max) |
28
|
|
|
*/ |
29
|
|
|
private $raw; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var float The minimum score being possible |
33
|
|
|
*/ |
34
|
|
|
private $min; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var float The maximum score being possible |
38
|
|
|
*/ |
39
|
|
|
private $max; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param float $scaled |
43
|
|
|
* @param float $raw |
44
|
|
|
* @param float $min |
45
|
|
|
* @param float $max |
46
|
|
|
*/ |
47
|
|
|
public function __construct($scaled = null, $raw = null, $min = null, $max = null) |
48
|
|
|
{ |
49
|
|
|
$this->scaled = $scaled; |
50
|
|
|
$this->raw = $raw; |
51
|
|
|
$this->min = $min; |
52
|
|
|
$this->max = $max; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param float $scaled |
57
|
|
|
* |
58
|
|
|
* @return Score |
59
|
|
|
*/ |
60
|
|
|
public function withScaled($scaled) |
61
|
|
|
{ |
62
|
|
|
$score = clone $this; |
63
|
|
|
$score->scaled = $scaled; |
64
|
|
|
|
65
|
|
|
return $score; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param float $raw |
70
|
|
|
* |
71
|
|
|
* @return Score |
72
|
|
|
*/ |
73
|
|
|
public function withRaw($raw) |
74
|
|
|
{ |
75
|
|
|
$score = clone $this; |
76
|
|
|
$score->raw = $raw; |
77
|
|
|
|
78
|
|
|
return $score; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param float $min |
83
|
|
|
* |
84
|
|
|
* @return Score |
85
|
|
|
*/ |
86
|
|
|
public function withMin($min) |
87
|
|
|
{ |
88
|
|
|
$score = clone $this; |
89
|
|
|
$score->min = $min; |
90
|
|
|
|
91
|
|
|
return $score; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param float $max |
96
|
|
|
* |
97
|
|
|
* @return Score |
98
|
|
|
*/ |
99
|
|
|
public function withMax($max) |
100
|
|
|
{ |
101
|
|
|
$score = clone $this; |
102
|
|
|
$score->max = $max; |
103
|
|
|
|
104
|
|
|
return $score; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns the Agent's scaled score (a number between -1 and 1). |
109
|
|
|
* |
110
|
|
|
* @return float The scaled score |
111
|
|
|
*/ |
112
|
|
|
public function getScaled() |
113
|
|
|
{ |
114
|
|
|
return $this->scaled; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Returns the Agent's score. |
119
|
|
|
* |
120
|
|
|
* @return float The score |
121
|
|
|
*/ |
122
|
|
|
public function getRaw() |
123
|
|
|
{ |
124
|
|
|
return $this->raw; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Returns the lowest possible score. |
129
|
|
|
* |
130
|
|
|
* @return float The lowest possible score |
131
|
|
|
*/ |
132
|
|
|
public function getMin() |
133
|
|
|
{ |
134
|
|
|
return $this->min; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns the highest possible score. |
139
|
|
|
* |
140
|
|
|
* @return float The highest possible score |
141
|
|
|
*/ |
142
|
|
|
public function getMax() |
143
|
|
|
{ |
144
|
|
|
return $this->max; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Checks if another score is equal. |
149
|
|
|
* |
150
|
|
|
* Two scores are equal if and only if all of their properties are equal. |
151
|
|
|
* |
152
|
|
|
* @param Score $score The score to compare with |
153
|
|
|
* |
154
|
|
|
* @return bool True if the scores are equal, false otherwise |
155
|
|
|
*/ |
156
|
|
|
public function equals(Score $score) |
157
|
|
|
{ |
158
|
|
|
if (null !== $this->scaled xor null !== $score->scaled) { |
159
|
|
|
return false; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
if ((float) $this->scaled !== (float) $score->scaled) { |
163
|
|
|
return false; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
if (null !== $this->raw xor null !== $score->raw) { |
167
|
|
|
return false; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
if ((float) $this->raw !== (float) $score->raw) { |
171
|
|
|
return false; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
if (null !== $this->min xor null !== $score->min) { |
175
|
|
|
return false; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
if ((float) $this->min !== (float) $score->min) { |
179
|
|
|
return false; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
if (null !== $this->max xor null !== $score->max) { |
183
|
|
|
return false; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
if ((float) $this->max !== (float) $score->max) { |
187
|
|
|
return false; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
return true; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|