Skip to content

Commit

Permalink
add track tables and world records for 60m to 3000m [PR #2]
Browse files Browse the repository at this point in the history
Fixes #1.
  • Loading branch information
laufhannes authored Jan 2, 2018
1 parent c91059d commit 83bd3e8
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 221 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "runalyze/age-grade",
"description": "Age grading for race results (running) based on tables provided by WMA",
"version": "1.1.0",
"license": "MIT",
"require": {
"php": ">=5.5.9"
Expand Down
34 changes: 20 additions & 14 deletions src/Table/AbstractTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ abstract class AbstractTable implements TableInterface
protected $NumAges;

/** @var float[] available distances [km] */
protected $Distances = [
5.0, 6.0, 6.437376, 8.0, 8.04672, 10, 12, 15, 16.09344, 20, 21.0975, 25, 30, 42.195, 50, 80.46736, 100, 160.9344, 200,
];
protected $Distances = [];

/** @var int[] available ages [from, to] in [years] */
protected $AgeRange = [5, 100];

/** @var int[] open standard times for all available distances in [s] */
/** @var float[] open standard times for all available distances in [s] */
protected $OpenStandard = [];

/** @var float[] for each age an array with factors for all available distances in [0.0 .. 1.0] */
Expand All @@ -52,6 +50,14 @@ public function getAvailableDistances()
return $this->Distances;
}

/**
* @return float[] open standard times for all available distances in [s]
*/
public function getOpenStandard()
{
return $this->OpenStandard;
}

/**
* @return array [from, to] in [years]
*/
Expand All @@ -69,20 +75,20 @@ public function getMinimalDistance()
}

/**
* @param int $age [years]
* @param float $distance [km]
* @param int $timeInSeconds [s]
* @return float age grade in [0.0 .. 1.0]
* @param int $age [years]
* @param float $distance [km]
* @param int|float $timeInSeconds [s]
* @return float age grade in [0.0 .. 1.0]
*/
public function getAgePerformance($age, $distance, $timeInSeconds)
{
return $this->getAgeStandard($age, $distance) / $timeInSeconds;
}

/**
* @param int $age [years]
* @param float $distance [km]
* @param int $timeInSeconds [s]
* @param int $age [years]
* @param float $distance [km]
* @param int|float $timeInSeconds [s]
* @return AgeGrade
*/
public function getAgeGrade($age, $distance, $timeInSeconds)
Expand All @@ -98,9 +104,9 @@ public function getAgeGrade($age, $distance, $timeInSeconds)
}

/**
* @param int $age [years]
* @param float $distance [km]
* @return int age standard by WMA [s]
* @param int $age [years]
* @param float $distance [km]
* @return int|float age standard by WMA [s]
*/
public function getAgeStandard($age, $distance)
{
Expand Down
207 changes: 109 additions & 98 deletions src/Table/FemaleTable.php

Large diffs are not rendered by default.

207 changes: 109 additions & 98 deletions src/Table/MaleTable.php

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions src/Table/TableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ interface TableInterface
*/
public function getAvailableDistances();

/**
* @return float[] open standard times for all available distances in [s]
*/
public function getOpenStandard();

/**
* @return array [from, to] in [years]
*/
Expand All @@ -31,24 +36,24 @@ public function getAvailableAgeRange();
public function getMinimalDistance();

/**
* @param int $age [years]
* @param float $distance [km]
* @return int age standard by WMA [s]
* @param int $age [years]
* @param float $distance [km]
* @return int|float age standard by WMA [s]
*/
public function getAgeStandard($age, $distance);

/**
* @param int $age [years]
* @param float $distance [km]
* @param int $timeInSeconds [s]
* @return float age grade in [0.0 .. 1.0]
* @param int $age [years]
* @param float $distance [km]
* @param int|float $timeInSeconds [s]
* @return float age grade in [0.0 .. 1.0]
*/
public function getAgePerformance($age, $distance, $timeInSeconds);

/**
* @param int $age [years]
* @param float $distance [km]
* @param int $timeInSeconds [s]
* @param int $age [years]
* @param float $distance [km]
* @param int|float $timeInSeconds [s]
* @return AgeGrade
*/
public function getAgeGrade($age, $distance, $timeInSeconds);
Expand Down
8 changes: 8 additions & 0 deletions src/Tests/LookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ public function testThatPerformanceEqualsValueFromAgeGrade()
(new Lookup(new MaleTable(), 30))->getAgeGrade(10.0, 40 * 60)->getPerformance()
);
}

public function testMinimalDistance()
{
$this->assertEquals(
(new Lookup(new MaleTable(), 30))->getMinimalDistance(),
(new MaleTable())->getMinimalDistance()
);
}
}
5 changes: 5 additions & 0 deletions src/Tests/Table/AbstractTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function testAvailableDistances()
$this->assertEquals([5.0, 10.0], $this->Table->getAvailableDistances());
}

public function testOpenStandard()
{
$this->assertEquals([780.0, 1600.0], $this->Table->getOpenStandard());
}

public function testAvailableAgeRange()
{
$this->assertEquals([30, 32], $this->Table->getAvailableAgeRange());
Expand Down
16 changes: 16 additions & 0 deletions src/Tests/Table/FemaleTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,20 @@ public function testSomeValues()
$this->assertEquals(0.8581, round($this->Table->getAgePerformance(42, 42.2, 2 * 60 * 60 + 45 * 60 + 0), 4));
$this->assertEquals(0.4296, round($this->Table->getAgePerformance(54, 10.0, 1 * 60 * 60 + 23 * 60 + 45), 4));
}

public function testSomeOpenStandardValues()
{
$this->assertEquals(6.92, $this->Table->getAgeStandard(25, 0.06));
$this->assertEquals(501.42, $this->Table->getAgeStandard(25, 3.0));
$this->assertEquals(8125.0, $this->Table->getAgeStandard(25, 42.195));
$this->assertEquals(57600.0, $this->Table->getAgeStandard(25, 200.0));
}

public function testConsistency()
{
$this->assertEquals(
count($this->Table->getOpenStandard()),
count($this->Table->getAvailableDistances())
);
}
}
2 changes: 1 addition & 1 deletion src/Tests/Table/Fixtures/VerySimpleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VerySimpleTable extends AbstractTable

/** @var array open standard times for all available distances in [s] */
protected $OpenStandard = [
780, 1600,
780.0, 1600.0,
];

/** @var array for each age an array with factors for all available distances in [0.0 .. 1.0] */
Expand Down
16 changes: 16 additions & 0 deletions src/Tests/Table/MaleTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,20 @@ public function testSomeValues()
$this->assertEquals(0.8555, round($this->Table->getAgePerformance(42, 42.2, 2 * 60 * 60 + 29 * 60 + 59), 4));
$this->assertEquals(0.7329, round($this->Table->getAgePerformance(54, 10.0, 42 * 60 + 25), 4));
}

public function testSomeOpenStandardValues()
{
$this->assertEquals(6.39, $this->Table->getAgeStandard(25, 0.06));
$this->assertEquals(440.67, $this->Table->getAgeStandard(25, 3.0));
$this->assertEquals(7377.0, $this->Table->getAgeStandard(25, 42.195));
$this->assertEquals(52800.0, $this->Table->getAgeStandard(25, 200.0));
}

public function testConsistency()
{
$this->assertEquals(
count($this->Table->getOpenStandard()),
count($this->Table->getAvailableDistances())
);
}
}

0 comments on commit 83bd3e8

Please sign in to comment.