/** * 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()); }
/** * Calculate strides array * @return array */ public function calculate() { if (!$this->Trackdata->has(Trackdata\Entity::TIME) || !$this->Trackdata->has(Trackdata\Entity::DISTANCE) || !$this->Trackdata->has(Trackdata\Entity::CADENCE)) { return []; } $Time = $this->Trackdata->time(); $Distance = $this->Trackdata->distance(); $Cadence = $this->Trackdata->cadence(); $Size = $this->Trackdata->num(); $this->Strides[] = $Cadence[0] > 0 && $Time[0] > 0 ? round($Distance[0] * 1000 * 100 / ($Cadence[0] * 2 / 60 * $Time[0])) : 0; for ($i = 1; $i < $Size; ++$i) { $this->Strides[] = $Cadence[$i] > 0 && $Time[$i] - $Time[$i - 1] > 0 ? round(($Distance[$i] - $Distance[$i - 1]) * 1000 * 100 / ($Cadence[$i] * 2 / 60 * ($Time[$i] - $Time[$i - 1]))) : 0; } return $this->Strides; }
/** * 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; } } }
/** * Prepare loops */ protected function prepareLoops() { $stepSize = (int) Configuration::ActivityView()->routePrecision()->value(); $this->RouteLoop = new Route\Loop($this->Route); $this->RouteLoop->setStepSize($stepSize); if (!is_null($this->Trackdata) && $this->Route->num() == $this->Trackdata->num() && $this->Trackdata->has(Trackdata\Entity::TIME)) { $this->TrackdataLoop = new Trackdata\Loop($this->Trackdata); $this->TrackdataLoop->setStepSize($stepSize); } }
/** * Construct time series for trackdata object * @param \Runalyze\Model\Trackdata\Entity $trackdata * @param int $indexKey enum * @param int[] $sumDifferencesKeys enums * @param int[] $avgValuesKeys enums * @throws \InvalidArgumentException */ public function __construct(Trackdata\Entity $trackdata, $indexKey, $sumDifferencesKeys = array(), $avgValuesKeys = array()) { $this->Trackdata = $trackdata; $this->IndexKey = $indexKey; $this->SumDifferencesKeys = $sumDifferencesKeys; $this->AvgValuesKeys = $avgValuesKeys; foreach (array_merge($sumDifferencesKeys, $avgValuesKeys) as $key) { if (!$trackdata->has($key)) { $trackdata->set($key, array_fill(0, $trackdata->num(), 0)); } } parent::__construct($trackdata->get($indexKey), $trackdata->get(Trackdata\Entity::TIME)); $this->collectData(); }
/** * Calculate swim values */ protected function calculateSwimValues() { if (null !== $this->Trackdata && null !== $this->Swimdata) { if ($this->Swimdata->stroke()) { $this->Object->set(Entity::TOTAL_STROKES, array_sum($this->Swimdata->stroke())); } if ($this->Object->totalStrokes() && $this->Trackdata->totalTime()) { $num = $this->Trackdata->num(); $totaltime = $this->Trackdata->totalTime(); $totalstrokes = $this->Object->totalStrokes(); if (!empty($totalstrokes) && !empty($totaltime) & !empty($num) && $totalstrokes != 0) { $this->Object->set(Entity::SWOLF, round(($totalstrokes + $totaltime) / $num)); } } } }
/** * Set step size * @param \Runalyze\Model\Trackdata\Entity $trackdata */ protected function defineStepSize(Trackdata $trackdata) { if ($this->Precision->byPoints() && $trackdata->num() > $this->Precision->numberOfPoints()) { $this->Loop->setStepSize(round($trackdata->num() / $this->Precision->numberOfPoints())); } elseif ($this->Precision->byDistance()) { $this->StepDistance = $this->Precision->distanceStep() / 1000; } }
/** * Calculator for activity properties * @param \Runalyze\Model\Trackdata\Entity $trackdata * @param \Runalyze\Model\Route\Entity $route */ public function __construct(Trackdata\Entity $trackdata, Route\Entity $route = null) { $this->Trackdata = $trackdata; $this->Route = $route; $this->Size = $trackdata->num(); }