/** * Init data */ protected function initData() { $this->paceUnit = $this->Context->sport()->paceUnit(); $Zones = $this->computeZones(); $hrMax = Runalyze\Configuration::Data()->HRmax(); $Pace = new Pace(0, 1, $this->paceUnit); $HR = new HeartRate(0, Runalyze\Context::Athlete()); foreach ($Zones as $paceInSeconds => $Info) { if ($Info['time'] > parent::MINIMUM_TIME_IN_ZONE) { $Pace->setTime($paceInSeconds); $HR->setBPM($Info['time'] > 0 ? $Info['hr'] / $Info['time'] : 0); $this->Data[] = array('zone' => $paceInSeconds == 0 ? __('faster') : '> ' . $Pace->valueWithAppendix(), 'time' => $Info['time'], 'distance' => $Info['distance'], 'average' => $HR->asBPM() > 0 ? $HR->string() : '-'); } } }
/** * @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; }