Exemplo n.º 1
0
 /**
  * Constructor
  * @param \Runalyze\View\Activity\Context $Context
  */
 public function __construct(\Runalyze\View\Activity\Context $Context)
 {
     if ($Context->hasRoute()) {
         $upDown = '+' . ElevationBase::format($Context->route()->elevationUp(), false) . '/-' . ElevationBase::format($Context->route()->elevationDown(), false);
     } else {
         $upDown = '+' . ElevationBase::format($Context->activity()->elevation(), false) . '/-' . ElevationBase::format($Context->activity()->elevation(), false);
     }
     parent::__construct($upDown, Configuration::General()->distanceUnitSystem()->elevationUnit(), __('Elevation up/down'));
 }
Exemplo n.º 2
0
 /**
  * Init data
  * @var \Runalyze\View\Activity\Context $context
  * @var boolean $forceOriginal
  */
 protected function initDataWithRoute(Activity\Context $context, $forceOriginal)
 {
     if (!$context->hasRoute()) {
         $this->Data = array();
         return;
     }
     $key = $context->route()->hasCorrectedElevations() && !$forceOriginal ? Route::ELEVATIONS_CORRECTED : Route::ELEVATIONS_ORIGINAL;
     if (!$context->route()->has($key)) {
         $this->Data = array();
         return;
     }
     $Collector = new DataCollectorWithRoute($context->trackdata(), $key, $context->route());
     $this->Data = $Collector->data();
     $this->XAxis = $Collector->xAxis();
 }
Exemplo n.º 3
0
    /**
     * Display with corrector
     */
    protected function displayWithElevation()
    {
        if ($this->Context->hasRoute() && ($this->Context->route()->elevationUp() > 0 || $this->Context->route()->elevationDown())) {
            $up = $this->Context->route()->elevationUp();
            $down = $this->Context->route()->elevationDown();
        } else {
            $up = $this->Context->activity()->elevation();
            $down = $up;
        }
        $Modifier = new Elevation\DistanceModifier($this->Context->activity()->distance(), $up, $down, Configuration::Vdot());
        $VDOT = new JD\VDOT(0, new JD\VDOTCorrector(Configuration::Data()->vdotFactor()));
        $VDOT->fromPaceAndHR($Modifier->correctedDistance(), $this->Context->activity()->duration(), $this->Context->activity()->hrAvg() / Configuration::Data()->HRmax());
        $Fieldset = new FormularFieldset(__('Correction: considering elevation'));
        $Fieldset->setHtmlCode('
			<p class="warning small ' . (Configuration::Vdot()->useElevationCorrection() ? 'hide' : '') . '">
				' . __('This correction method is currently unused.') . '
			</p>

			<div class="w50">
				<label>' . __('Up/Down') . '</label>
				<span class="as-input">+' . $up . '/-' . $down . '&nbsp;m</span>
			</div>
			<div class="w50 double-height-right">
				<label>&rArr; ' . __('VDOT') . '</label>
				<span class="as-input ' . (!Configuration::Vdot()->useElevationCorrection() ? '' : 'highlight') . '">' . $VDOT->value() . '</span>
			</div>
			<div class="w50">
				<label>' . __('Influence') . '</label>
				<span class="as-input">' . sprintf("%+d", 1000 * $Modifier->additionalDistance()) . 'm = ' . Distance::format($Modifier->correctedDistance(), false, 3) . '</span>
			</div>
		');
        $Fieldset->display();
    }
Exemplo n.º 4
0
 /**
  * Construct plot data
  * @param enum $algorithm
  * @param int $treshold
  * @return array
  */
 protected function constructPlotDataFor($algorithm, $treshold = false)
 {
     $Method = new ElevationMethod();
     $Method->set($algorithm);
     if ($treshold === false) {
         $treshold = Configuration::ActivityView()->elevationMinDiff();
     }
     $Calculator = new Data\Elevation\Calculation\Calculator($this->Context->route()->elevations());
     $Calculator->setMethod($Method);
     $Calculator->setThreshold($treshold);
     $Calculator->calculate();
     $i = 0;
     $Data = array();
     $Points = $Calculator->strategy()->smoothedData();
     $Indices = $Calculator->strategy()->smoothingIndices();
     $hasDistances = $this->Context->trackdata()->get(Trackdata\Entity::DISTANCE);
     $Distances = $this->Context->trackdata()->get(Trackdata\Entity::DISTANCE);
     $Times = $this->Context->trackdata()->get(Trackdata\Entity::TIME);
     $num = $this->Context->trackdata()->num();
     foreach ($Indices as $i => $index) {
         if ($index >= $num) {
             $index = $num - 1;
         }
         if ($hasDistances) {
             $Data[(string) $Distances[$index]] = $Points[$i];
         } else {
             $Data[(string) $Times[$index] . '000'] = $Points[$i];
         }
     }
     $this->manipulateData($Data);
     return $Data;
 }
Exemplo n.º 5
0
 /**
  * Construct laps from trackdata by distances
  */
 protected function constructLapsFromTrackdataByDistances()
 {
     $Distances = $this->ManualDistances;
     if (empty($Distances)) {
         if ($this->LapDistance == 0) {
             $this->LapDistance = 1;
         }
         $LastStep = $this->LapDistance * floor($this->Context->trackdata()->totalDistance() / $this->LapDistance);
         if ($LastStep <= $this->LapDistance) {
             $Distances = array($this->LapDistance);
         } else {
             $Distances = range($this->LapDistance, $LastStep, $this->LapDistance);
         }
     }
     $this->Laps->calculateFrom($Distances, $this->Context->trackdata(), $this->Context->route());
 }
Exemplo n.º 6
0
    /**
     * Display elevation correction
     */
    protected function displayElevationCorrection()
    {
        $Fieldset = new FormularFieldset(__('Elevation correction'));
        if ($this->Context->route()->elevationsCorrected()) {
            $Fieldset->addSmallInfo(__('Elevation data have been corrected.'));
        } else {
            $Linker = new Runalyze\View\Activity\Linker($this->Context->activity());
            // TODO: add link to "reload" if correction has been done via ajax
            $Fieldset->setHtmlCode('<p class="warning small block" id="gps-results">
					' . __('Elevation data has not been corrected.') . '<br>
					<br>
					<a class="ajax" target="gps-results" href="' . $Linker->urlToElevationCorrection() . '"><strong>&raquo; ' . __('correct now') . '</strong></a>
				</p>');
        }
        $Fieldset->display();
    }
Exemplo n.º 7
0
 /**
  * Display course
  */
 public function displayCourse()
 {
     $this->Context = new Context(Request::sendId(), Request::param('account'));
     if (!$this->activityIsValid() || !$this->Context->hasRoute() || !$this->Context->route()->hasPositionData()) {
         die('Don\'t do that!');
     }
     $Linker = new Linker($this->Context->activity());
     echo '<meta property="og:type" content="metadata">' . NL;
     echo '<link rel="origin" href="' . $Linker->publicUrl() . '">' . NL;
     $this->RouteLoop = new Model\Route\Loop($this->Context->route());
     $this->RouteLoop->setStepSize(self::STEP_SIZE);
     $this->TrackdataLoop = new Model\Trackdata\Loop($this->Context->trackdata());
     $this->TrackdataLoop->setStepSize(self::STEP_SIZE);
     do {
         $this->displayActivityDataPoint();
     } while ($this->RouteLoop->nextStep() && $this->TrackdataLoop->nextStep());
 }
Exemplo n.º 8
0
    /**
     * Display elevation correction
     */
    protected function displayElevationCorrection()
    {
        $Url = (new Runalyze\View\Activity\Linker($this->Context->activity()))->urlToElevationCorrection();
        $Fieldset = new FormularFieldset(__('Elevation correction'));
        $Links = array();
        if ($this->Context->route()->elevationsCorrected()) {
            $textInfo = __('Elevation data has been corrected.') . ($this->Context->route()->elevationsSource() != '' ? ' (' . $this->Context->route()->elevationsSource() . ')' : '');
            $rawLinks = $this->getLinksForCorrectionStrategies();
        } else {
            $textInfo = __('Elevation data has not been corrected.');
            $rawLinks = array('' => __('correct now'));
        }
        foreach ($rawLinks as $urlAppendix => $text) {
            $Links[] = '<a class="ajax" target="gps-results" href="' . $Url . $urlAppendix . '"><strong>&raquo; ' . $text . '</strong></a>';
        }
        $Fieldset->setHtmlCode('<p class="info block" id="gps-results">' . $textInfo . '</p>
			<p class="info block">' . implode('<br>', $Links) . '</p>');
        $Fieldset->display();
    }
Exemplo n.º 9
0
 /**
  * @param \Runalyze\View\Activity\Context $context
  * @param int $offset
  * @return \Runalyze\Calculation\NightDetector $this-reference
  */
 public function setFromContext(Context $context, $offset = 0)
 {
     if (!$context->hasRoute()) {
         $this->Value = null;
         return $this;
     }
     return $this->setFromEntities($context->activity(), $context->route(), $offset);
 }