/** * Tasks before insertion */ protected function before() { parent::before(); if ($this->hasChanged(Object::ELEVATIONS_ORIGINAL) || $this->hasChanged(Object::ELEVATIONS_CORRECTED)) { $Calculator = new Calculator($this->NewObject); $Calculator->calculateElevation(); } }
/** * Remove single series from route * @param enum $key */ public function removeFromRoute($key) { $this->Route->set($key, array()); if ($key == Model\Route\Object::ELEVATIONS_ORIGINAL || $key == Model\Route\Object::ELEVATIONS_CORRECTED) { $Calculator = new Calculator($this->Route); $Calculator->calculateElevation(); } }
/** * Tasks before insertion */ protected function before() { parent::before(); $Calculator = new Calculator($this->Object); if (Configuration::ActivityForm()->correctElevation() && !$this->Object->hasCorrectedElevations()) { $Calculator->tryToCorrectElevation(); } $Calculator->calculateElevation(); }
public function testCalculationFromCorrectedData() { $Route = new Route\Object(array(Route\Object::ELEVATIONS_ORIGINAL => array(100, 100, 100, 100), Route\Object::ELEVATIONS_CORRECTED => array(100, 120, 150, 140))); $Calc = new Calculator($Route); $Calc->calculateElevation(); $this->assertGreaterThan(0, $Route->elevation()); $this->assertGreaterThan(0, $Route->elevationUp()); $this->assertGreaterThan(0, $Route->elevationDown()); }
/** * Tasks before insertion */ protected function before() { parent::before(); $Calculator = new Calculator($this->Object); if (Configuration::ActivityForm()->correctElevation() && !$this->Object->hasCorrectedElevations()) { try { $Calculator->tryToCorrectElevation(); } catch (NoValidStrategyException $e) { // Well, obviously that did not work. Probably all API limits have been reached. } } $Calculator->calculateElevation(); }
use Runalyze\View\Activity\Linker; use Runalyze\Data\Elevation\Correction\NoValidStrategyException; $Frontend = new Frontend(); $Factory = Context::Factory(); $Activity = $Factory->activity(Request::sendId()); $ActivityOld = clone $Activity; $Route = $Factory->route($Activity->get(Activity\Object::ROUTEID)); $RouteOld = clone $Route; try { $Calculator = new Calculator($Route); $result = $Calculator->tryToCorrectElevation(Request::param('strategy')); } catch (NoValidStrategyException $Exception) { $result = false; } if ($result) { $Calculator->calculateElevation(); $Activity->set(Activity\Object::ELEVATION, $Route->elevation()); $UpdaterRoute = new Route\Updater(DB::getInstance(), $Route, $RouteOld); $UpdaterRoute->setAccountID(SessionAccountHandler::getId()); $UpdaterRoute->update(); $UpdaterActivity = new Activity\Updater(DB::getInstance(), $Activity, $ActivityOld); $UpdaterActivity->setAccountID(SessionAccountHandler::getId()); $UpdaterActivity->update(); echo __('Elevation data has been corrected.'); Ajax::setReloadFlag(Ajax::$RELOAD_DATABROWSER_AND_TRAINING); echo Ajax::getReloadCommand(); echo Ajax::wrapJS('if($("#ajax").is(":visible") && $("#training").length)Runalyze.Overlay.load(\'' . Linker::EDITOR_URL . '?id=' . Request::sendId() . '\')'); echo Ajax::wrapJS('if($("#ajax").is(":visible") && $("#gps-results").length)Runalyze.Overlay.load(\'' . Linker::ELEVATION_INFO_URL . '?id=' . Request::sendId() . '\')'); } else { echo __('Elevation data could not be retrieved.'); }