public function testGeneralFunctionality() { $this->insert(1.0, 3 * 60 + 0); $this->insert(3.0, 10 * 60 + 0); $this->insert(3.0, 10 * 60 + 27); $this->insert(5.0, 17 * 60 + 52); $this->insert(5.0, 18 * 60 + 13); $this->insert(5.1, 19 * 60 + 0); $this->insert(21.1, 1 * 60 * 60 + 19 * 60 + 0); $this->Container->fetchData(); $this->assertEquals(7, $this->Container->num()); $this->assertEquals(array('1', '3', '5', '5.1', '21.1'), $this->Container->distances()); $Races1k = $this->Container->races(1.0); $Races3k = $this->Container->races(3.0); $Races5k = $this->Container->races(5.0); $Races51 = $this->Container->races(5.1); $RacesHM = $this->Container->races(21.1); $this->assertEquals(1, count($Races1k)); $this->assertEquals(2, count($Races3k)); $this->assertEquals(2, count($Races5k)); $this->assertEquals(1, count($Races51)); $this->assertEquals(1, count($RacesHM)); $this->assertEquals(10 * 60 + 0, $Races3k[0]['s']); $this->assertEquals(10 * 60 + 27, $Races3k[1]['s']); }
/** * Display comparison for all years for personal bests */ private function displayPersonalBestYears() { $year = array(); $dists = array(); $kms = is_array($this->Configuration()->value('pb_distances')) ? $this->Configuration()->value('pb_distances') : array(3, 5, 10, 21.1, 42.2); foreach ($kms as $km) { $dists[$km] = array('sum' => 0, 'pb' => INFINITY); } if ($this->RaceContainer->num() == 0) { return; } foreach ($this->RaceContainer->allRaces() as $wk) { $wk['y'] = date('Y', $wk['time']); if (!isset($year[$wk['y']])) { $year[$wk['y']] = $dists; $year[$wk['y']]['sum'] = 0; $year['sum'] = 0; } $year[$wk['y']]['sum']++; foreach ($kms as $km) { if ($km == $wk['distance']) { $year[$wk['y']][$km]['sum']++; if ($wk['s'] < $year[$wk['y']][$km]['pb']) { $year[$wk['y']][$km]['pb'] = $wk['s']; } } } } echo '<table class="fullwidth zebra-style">'; echo '<thead>'; echo '<tr>'; echo '<th></th>'; $Years = array_keys($year); sort($Years); foreach ($Years as $y) { if ($y != 'sum') { echo '<th>' . $y . '</th>'; } } echo '</tr>'; echo '</thead>'; echo '<tbody>'; PersonalBest::activateStaticCache(); PersonalBest::lookupDistances($kms); foreach ($kms as $km) { echo '<tr class="r"><td class="b">' . (new Distance($km))->stringAuto(true, 1) . '</td>'; foreach ($Years as $key) { $y = $year[$key]; if ($key != 'sum') { if ($y[$km]['sum'] != 0) { $PB = new PersonalBest($km); $distance = Duration::format($y[$km]['pb']); if ($PB->seconds() == $y[$km]['pb']) { $distance = '<strong>' . $distance . '</strong>'; } echo '<td>' . $distance . ' <small>' . $y[$km]['sum'] . 'x</small></td>'; } else { echo '<td><em><small>---</small></em></td>'; } } } echo '</tr>'; } echo '<tr class="top-spacer no-zebra r">'; echo '<td class="b">' . __('In total') . '</td>'; foreach ($Years as $key) { if ($key != 'sum') { echo '<td>' . $year[$key]['sum'] . 'x</td>'; } } echo '</tr>'; echo '</tbody>'; echo '</table>'; }