Exemplo n.º 1
0
 /**
  * @return array
  */
 protected function computeZones()
 {
     // TODO
     // - move this a calculation class
     // - make zones configurable
     $Zones = array();
     $SmoothTrackdata = clone $this->Context->trackdata();
     $Smoother = new PaceSmoother($SmoothTrackdata, true);
     $SmoothTrackdata->set(Trackdata\Object::PACE, $Smoother->smooth(self::STEP_SIZE, PaceSmoother::MODE_STEP));
     $hasHR = $this->Context->trackdata()->has(Trackdata\Object::HEARTRATE);
     $Distribution = new TimeSeriesForTrackdata($SmoothTrackdata, Trackdata\Object::PACE, array(Trackdata\Object::DISTANCE), $hasHR ? array(Trackdata\Object::HEARTRATE) : array());
     $Data = $Distribution->data();
     foreach ($Distribution->histogram() as $paceInSeconds => $seconds) {
         $pace = $this->zoneFor($paceInSeconds);
         if (!isset($Zones[$pace])) {
             $Zones[$pace] = array('time' => $seconds, 'distance' => $Data[$paceInSeconds][Trackdata\Object::DISTANCE], 'hr' => $hasHR ? $Data[$paceInSeconds][Trackdata\Object::HEARTRATE] * $seconds : 0);
         } else {
             $Zones[$pace]['time'] += $seconds;
             $Zones[$pace]['distance'] += $Data[$paceInSeconds][Trackdata\Object::DISTANCE];
             $Zones[$pace]['hr'] += $hasHR ? $Data[$paceInSeconds][Trackdata\Object::HEARTRATE] * $seconds : 0;
         }
     }
     ksort($Zones, SORT_NUMERIC);
     return $Zones;
 }
 /**
  * @return array
  */
 protected function computeZones()
 {
     // TODO
     // - move this a calculation class
     // - make zones configurable
     $Zones = array();
     $hrMax = Runalyze\Configuration::Data()->HRmax();
     $hasDistance = $this->Context->trackdata()->has(Trackdata\Entity::DISTANCE);
     $Distribution = new TimeSeriesForTrackdata($this->Context->trackdata(), Trackdata\Entity::HEARTRATE, $hasDistance ? array(Trackdata\Entity::DISTANCE) : array());
     $Data = $Distribution->data();
     foreach ($Distribution->histogram() as $bpm => $seconds) {
         $hf = $this->zoneFor($bpm, $hrMax);
         if (!isset($Zones[$hf])) {
             $Zones[$hf] = array('time' => $seconds, 'distance' => $hasDistance ? $Data[$bpm][Trackdata\Entity::DISTANCE] : 0);
         } else {
             $Zones[$hf]['time'] += $seconds;
             $Zones[$hf]['distance'] += $hasDistance ? $Data[$bpm][Trackdata\Entity::DISTANCE] : 0;
         }
     }
     ksort($Zones, SORT_NUMERIC);
     return $Zones;
 }
 public function testSimpleArray()
 {
     $Dist = new TimeSeriesForTrackdata(new Trackdata\Object(array(Trackdata\Object::TIME => array(30, 60, 90, 120, 150, 180, 210, 240, 270, 300), Trackdata\Object::HEARTRATE => array(120, 120, 150, 150, 150, 180, 150, 180, 150, 120), Trackdata\Object::DISTANCE => array(0.1, 0.2, 0.35, 0.5, 0.65, 0.85, 1.0, 1.2, 1.35, 1.45), Trackdata\Object::CADENCE => array(80, 84, 85, 90, 95, 100, 95, 100, 95, 85), Trackdata\Object::GROUNDCONTACT => array(200, 185, 170, 160, 150, 120, 200, 120, 200, 200))), Trackdata\Object::HEARTRATE, array(Trackdata\Object::DISTANCE), array(Trackdata\Object::CADENCE, Trackdata\Object::GROUNDCONTACT));
     $this->assertEquals(array(120 => 90, 150 => 150, 180 => 60), $Dist->histogram());
     $this->assertEquals(array(120 => array(Trackdata\Object::DISTANCE => 0.3, Trackdata\Object::CADENCE => 83, Trackdata\Object::GROUNDCONTACT => 195), 150 => array(Trackdata\Object::DISTANCE => 0.75, Trackdata\Object::CADENCE => 92, Trackdata\Object::GROUNDCONTACT => 176), 180 => array(Trackdata\Object::DISTANCE => 0.4, Trackdata\Object::CADENCE => 100, Trackdata\Object::GROUNDCONTACT => 120)), $Dist->data());
 }