/** * Load data * @param \Runalyze\View\Activity\Context $context */ protected function loadData(Activity\Context $context) { if (!$context->trackdata()->has(Trackdata\Object::DISTANCE) || !$context->trackdata()->has(Trackdata\Object::TIME)) { $this->Plot->raiseError(__('No GPS-data available. Can\\\'t compute laps.')); return; } $RawData = $this->computeRounds($context); $num = count($RawData); $Pace = new PaceObject(0, 1); $Pace->setUnit($this->PaceUnit); foreach ($RawData as $key => $val) { $km = $key + 1; if ($num < 30) { $label = $km; } elseif ($num < 50) { $label = $km % 2 == 1 && $km > 0 ? $km : ''; } elseif ($num < 100) { $label = $km % 5 == 0 && $km > 0 ? $km : ''; } else { $label = $km % 10 == 0 && $km > 0 ? $km : ''; } $this->Labels[$key] = array($key, $label); $Pace->setDistance($val['km'])->setTime($val['s']); if ($this->PaceUnit->isTimeFormat()) { $this->Data[$key] = 1000 * round($Pace->secondsPerKm() * $this->PaceUnit->factorForUnit()); } else { $this->Data[$key] = (double) str_replace(',', '.', $Pace->value()); } } $avgPace = new PaceObject($context->activity()->duration(), $context->activity()->distance()); $this->achievedPace = $avgPace->secondsPerKm(); $this->Plot->Data[] = array('label' => $this->title, 'data' => $this->Data); }
/** * Init data */ protected function initData() { $Zones = $this->computeZones(); $Pace = new Pace(0, 0, $this->Context->sport()->paceUnit()); foreach ($Zones as $hf => $Info) { if ($Info['time'] > parent::MINIMUM_TIME_IN_ZONE) { $Pace->setTime($Info['time']); $Pace->setDistance($Info['distance']); $this->Data[] = array('zone' => '< ' . $hf . ' %', 'time' => $Info['time'], 'distance' => $Info['distance'], 'average' => $Pace->value() > 0 ? $Pace->valueWithAppendix() : '-'); } } }
public function testMethodChaining() { $Pace = new Pace(0, 1, PaceUnit::MIN_PER_KM); $this->assertEquals('3:00', $Pace->setTime(180)->value()); $this->assertEquals('6:00', $Pace->setDistance(0.5)->value()); }