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, $raw, $min, $max) |
48
|
|
|
{ |
49
|
|
|
$this->scaled = (float) $scaled; |
50
|
|
|
$this->raw = (float) $raw; |
51
|
|
|
$this->min = (float) $min; |
52
|
|
|
$this->max = (float) $max; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns the Agent's scaled score (a number between -1 and 1). |
57
|
|
|
* |
58
|
|
|
* @return float The scaled score |
59
|
|
|
*/ |
60
|
|
|
public function getScaled() |
61
|
|
|
{ |
62
|
|
|
return $this->scaled; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the Agent's score. |
67
|
|
|
* |
68
|
|
|
* @return float The score |
69
|
|
|
*/ |
70
|
|
|
public function getRaw() |
71
|
|
|
{ |
72
|
|
|
return $this->raw; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns the lowest possible score. |
77
|
|
|
* |
78
|
|
|
* @return float The lowest possible score |
79
|
|
|
*/ |
80
|
|
|
public function getMin() |
81
|
|
|
{ |
82
|
|
|
return $this->min; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns the highest possible score. |
87
|
|
|
* |
88
|
|
|
* @return float The highest possible score |
89
|
|
|
*/ |
90
|
|
|
public function getMax() |
91
|
|
|
{ |
92
|
|
|
return $this->max; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Checks if another score is equal. |
97
|
|
|
* |
98
|
|
|
* Two scores are equal if and only if all of their properties are equal. |
99
|
|
|
* |
100
|
|
|
* @param Score $score The score to compare with |
101
|
|
|
* |
102
|
|
|
* @return bool True if the scores are equal, false otherwise |
103
|
|
|
*/ |
104
|
|
|
public function equals(Score $score) |
105
|
|
|
{ |
106
|
|
|
if ($this->scaled !== $score->scaled) { |
107
|
|
|
return false; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if ($this->raw !== $score->raw) { |
111
|
|
|
return false; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if ($this->min !== $score->min) { |
115
|
|
|
return false; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if ($this->max !== $score->max) { |
119
|
|
|
return false; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return true; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|