Ejemplo n.º 1
0
 /**
  * Read request
  */
 protected function readPropertiesFromRequest()
 {
     if ((double) Request::param('distance') > 0) {
         $this->LapDistance = min($this->Context->trackdata()->totalDistance(), (double) Request::param('distance'));
     }
     if (strlen(Request::param('time')) > 0) {
         $Time = new Duration(Request::param('time'));
         $this->LapTime = min($this->Context->trackdata()->totalTime(), $Time->seconds());
     }
     if (strlen(Request::param('demanded-time')) > 0) {
         $this->DemandedTime->fromString(Request::param('demanded-time'));
         if ($this->LapDistance > 0) {
             $this->DemandedPace->setTime($this->DemandedTime->seconds() / $this->LapDistance);
         }
     } elseif ($this->LapDistance > 0) {
         $this->DemandedTime->fromSeconds($this->Context->trackdata()->totalTime() / $this->Context->trackdata()->totalDistance() * $this->LapDistance);
         $this->DemandedPace->setTime($this->DemandedTime->seconds() / $this->LapDistance);
     }
     if (strlen(Request::param('demanded-pace')) > 0) {
         $this->DemandedPace->fromMinPerKm(Request::param('demanded-pace'));
         $this->DemandedTime->fromSeconds($this->LapDistance * $this->DemandedPace->secondsPerKm());
     } elseif ($this->DemandedPace->secondsPerKm() == 0) {
         $this->DemandedPace = $this->Context->dataview()->pace();
     }
     if (strlen(Request::param('manual-distances')) > 0) {
         $this->ManualDistances = Calculator::getDistancesFromString(Request::param('manual-distances'));
     }
     if (strlen(Request::param('manual-times')) > 0) {
         $this->ManualTimes = Calculator::getTimesFromString(Request::param('manual-times'));
     }
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * @param int $num
  */
 protected function manipulateData($num)
 {
     $distanceUnit = \Runalyze\Configuration::General()->distanceUnitSystem()->distanceUnit();
     $Pace = new PaceObject(0, 1);
     $Pace->setUnit($this->PaceUnit);
     foreach ($this->Data as $key => $val) {
         if ($num > 35) {
             $this->Labels[$key] = array($key, round($this->Labels[$key], 1));
         } elseif ($num >= 15) {
             $this->Labels[$key] = array($key, number_format($this->Labels[$key], 1, '.', ''));
         } elseif ($num > 10) {
             $this->Labels[$key] = array($key, $this->Labels[$key] . $distanceUnit);
         } else {
             $this->Labels[$key] = array($key, $this->Labels[$key] . ' ' . $distanceUnit);
         }
         $Pace->setTime($val);
         if ($this->PaceUnit->isTimeFormat()) {
             $this->Data[$key] = 1000 * round($Pace->secondsPerKm() * $this->PaceUnit->factorForUnit());
         } else {
             $this->Data[$key] = (double) str_replace(',', '.', $Pace->value());
         }
     }
     $this->Plot->Data[] = array('label' => $this->title, 'data' => $this->Data);
 }
Ejemplo n.º 4
0
 /**
  * @param int $num
  * @param enum $paceUnit
  */
 protected function manipulateData($num, $paceUnit)
 {
     $paceInTime = $paceUnit == APace::MIN_PER_KM || $paceUnit == APace::MIN_PER_100M || $paceUnit == APace::MIN_PER_500M;
     $pace = new APace(0, 1, $paceUnit);
     foreach ($this->Data as $key => $val) {
         if ($num > 35) {
             $this->Labels[$key] = array($key, round($this->Labels[$key], 1));
         } elseif ($num >= 20) {
             $this->Labels[$key] = array($key, number_format($this->Labels[$key], 1, '.', ''));
         } elseif ($num > 10) {
             $this->Labels[$key] = array($key, $this->Labels[$key] . 'k');
         } else {
             $this->Labels[$key] = array($key, $this->Labels[$key] . ' km');
         }
         $pace->setTime($val);
         if ($paceInTime) {
             $this->Data[$key] = 1000 * $pace->secondsPerKm();
             if ($paceUnit == APace::MIN_PER_100M) {
                 $this->Data[$key] /= 10;
             } elseif ($paceUnit == APace::MIN_PER_500M) {
                 $this->Data[$key] /= 2;
             }
         } else {
             $this->Data[$key] = (double) str_replace(',', '.', $pace->value());
         }
     }
     $this->Plot->Data[] = array('label' => $this->title, 'data' => $this->Data);
 }
Ejemplo n.º 5
0
 /**
  * Compare
  * Both pace objects must have the same unit and the unit must be comparable.
  * @param \Runalyze\Activity\Pace $other
  * @param boolean $raw [optional]
  * @throws \InvalidArgumentException
  * @return string
  */
 public function compareTo(Pace $other, $raw = false)
 {
     if ($this->unitEnum() != $other->unitEnum()) {
         throw new \InvalidArgumentException('Pace objects must have the same unit.');
     }
     if ($this->secondsPerKm() == 0 || $other->secondsPerKm() == 0) {
         return '';
     }
     $comparisonInSecondsPerKm = $this->UnitObject->compare($this->secondsPerKm(), $other->secondsPerKm());
     $isPositive = $comparisonInSecondsPerKm >= 0;
     if ($comparisonInSecondsPerKm == 0 && $this->UnitObject->isTimeFormat()) {
         return $this->formatComparison('0:00', $isPositive, $raw);
     }
     return $this->formatComparison($this->UnitObject->format(abs($comparisonInSecondsPerKm)), $isPositive, $raw);
 }