1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Runalyze Age Grade. |
5
|
|
|
* |
6
|
|
|
* (c) RUNALYZE <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Runalyze\AgeGrade; |
13
|
|
|
|
14
|
|
|
use Runalyze\AgeGrade\Table\TableInterface; |
15
|
|
|
|
16
|
|
|
class Lookup |
17
|
|
|
{ |
18
|
|
|
/** @var TableInterface */ |
19
|
|
|
protected $Table; |
20
|
|
|
|
21
|
|
|
/** @var int [years] */ |
22
|
|
|
protected $Age; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param TableInterface $table |
26
|
|
|
* @param int $age [years] |
27
|
|
|
* |
28
|
|
|
* @throws \InvalidArgumentException |
29
|
|
|
*/ |
30
|
5 |
|
public function __construct(TableInterface $table, $age) |
31
|
|
|
{ |
32
|
5 |
|
if (!is_numeric($age) || $age <= 0) { |
33
|
1 |
|
throw new \InvalidArgumentException('Provided age must be numerical and positive.'); |
34
|
|
|
} |
35
|
|
|
|
36
|
4 |
|
$this->Table = $table; |
37
|
4 |
|
$this->Age = (int) $age; |
38
|
4 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param float $distance [km] |
42
|
|
|
* @param int $timeInSeconds [s] |
43
|
|
|
* @param int $yearsAgo [years] will be subtracted from internal age |
44
|
|
|
* @return float |
45
|
|
|
*/ |
46
|
4 |
|
public function getAgePerformance($distance, $timeInSeconds, $yearsAgo = 0) |
47
|
|
|
{ |
48
|
4 |
|
return $this->Table->getAgePerformance($this->Age - $yearsAgo, $distance, $timeInSeconds); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param float $distance [km] |
53
|
|
|
* @param int $timeInSeconds [s] |
54
|
|
|
* @param int $yearsAgo [years] will be subtracted from internal age |
55
|
|
|
* @return AgeGrade |
56
|
|
|
*/ |
57
|
1 |
|
public function getAgeGrade($distance, $timeInSeconds, $yearsAgo = 0) |
58
|
|
|
{ |
59
|
1 |
|
return $this->Table->getAgeGrade($this->Age - $yearsAgo, $distance, $timeInSeconds); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return float [km] |
64
|
|
|
*/ |
65
|
|
|
public function getMinimalDistance() |
66
|
|
|
{ |
67
|
|
|
return $this->Table->getMinimalDistance(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|