/**
  * 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>';
 }
 /**
  * Lookup all personal bests at once
  */
 protected function lookupPersonalBests()
 {
     PersonalBest::activateStaticCache();
     $this->NumberOfPBs = PersonalBest::lookupDistances($this->getDistances());
 }
Beispiel #3
0
 public function testMultiLookupWithDetailsForIdenticalResults()
 {
     PersonalBest::activateStaticCache();
     $date1 = mktime(12, 0, 0, 6, 1, 2010);
     $date2 = mktime(12, 0, 0, 6, 2, 2010);
     $first = $this->insert(1.0, 180, $date1);
     $second = $this->insert(1.0, 180, $date2);
     $this->assertEquals(1, PersonalBest::lookupDistances(array(1.0), $this->PDO, true));
     $PDO = new \PDO('sqlite::memory:');
     $PB = new PersonalBest(1, $PDO, true, true);
     $this->assertEquals(180, $PB->seconds());
     $this->assertEquals($date1, $PB->timestamp());
     $this->assertEquals($first, $PB->activityId());
 }