/** * Calculate average stride length * @return int [cm] */ public function average() { if (empty($this->Strides)) { return 0; } $Series = new TimeSeries($this->Strides, $this->Trackdata->time()); $Series->calculateStatistic(); return round($Series->mean()); }
/** * Calculate average Vertical Ratio * @return int [%o] */ public function average() { if (empty($this->VerticalRatio)) { return 0; } if (!$this->Trackdata->has(Trackdata\Entity::TIME)) { return round(array_sum($this->VerticalRatio) / $this->Trackdata->num()); } $Series = new TimeSeries($this->VerticalRatio, $this->Trackdata->time()); $Series->calculateStatistic(); return round($Series->mean()); }
/** * Run fast smoothing for step size * * Although this does not look nice and is not the cleanest code, * direct access to the arrays is approx. 5-times faster. * (0.02s vs 0.11s for an array of 10.000 elements) */ protected function runFastSmoothingForSteps() { $distance = $this->Trackdata->distance(); $time = $this->Trackdata->time(); $lastDist = 0; $lastTime = 0; foreach ($distance as $i => $dist) { if ($i != 0 && $i % $this->StepSize == 0) { $pace = $dist - $lastDist > 0 ? round(($time[$i] - $lastTime) / ($dist - $lastDist)) : 0; if ($this->KeepArraySize) { for ($j = 0; $j < $this->StepSize; ++$j) { $this->Smoothed[] = $pace; } } else { $this->Smoothed[] = $pace; } $lastDist = $dist; $lastTime = $time[$i]; } } if ($this->KeepArraySize && !empty($distance)) { $pace = $dist - $lastDist > 0 ? round(($time[$i] - $lastTime) / ($dist - $lastDist)) : 0; for ($j = count($this->Smoothed), $num = $this->Trackdata->num(); $j < $num; ++$j) { $this->Smoothed[] = $pace; } } }
/** * Calculate trimp * @return int */ public function calculateTrimp() { if ($this->knowsTrackdata() && $this->Trackdata->has(Model\Trackdata\Entity::HEARTRATE)) { $Collector = new Trimp\DataCollector($this->Trackdata->heartRate(), $this->Trackdata->time()); $data = $Collector->result(); } elseif ($this->Activity->hrAvg() > 0) { $data = array($this->Activity->hrAvg() => $this->Activity->duration()); } else { $Factory = Context::Factory(); if ($this->Activity->typeid() > 0) { $data = array($Factory->type($this->Activity->typeid())->hrAvg() => $this->Activity->duration()); } else { $data = array($Factory->sport($this->Activity->sportid())->avgHR() => $this->Activity->duration()); } } $Athlete = Context::Athlete(); $Calculator = new Trimp\Calculator($Athlete, $data); return round($Calculator->value()); }