/** * Tasks before insertion */ protected function before() { parent::before(); $Calculator = new Calculator($this->Object); if (Configuration::ActivityForm()->correctElevation() && !$this->Object->hasCorrectedElevations()) { $Calculator->tryToCorrectElevation(); } $Calculator->calculateElevation(); }
/** * Initialize internal sports-array from database */ private static function initAllSports() { self::$AllSports = array(); $sports = self::cacheAllSports(); foreach ($sports as $sport) { self::$AllSports[(string) $sport['id']] = $sport; } Configuration::ActivityForm()->orderSports()->sort(self::$AllSports); }
/** * Initialize internal shoes-array from database */ private static function initAllShoes() { self::$AllShoes = array(); $shoes = Cache::get(self::CACHE_KEY); if (is_null($shoes)) { $shoes = DB::getInstance()->query('SELECT * FROM `' . PREFIX . 'shoe` WHERE accountid = ' . SessionAccountHandler::getId())->fetchAll(); Cache::set(self::CACHE_KEY, $shoes, '3600'); } foreach ($shoes as $shoe) { self::$AllShoes[(string) $shoe['id']] = $shoe; } Configuration::ActivityForm()->orderShoes()->sort(self::$AllShoes); }
/** * Init all types * * IDs will be set as string as indices for correct order */ private static function initAllTypes() { self::$AllTypes = array(); $types = Cache::get('types'); if (is_null($types)) { $types = DB::getInstance()->query('SELECT * FROM `' . PREFIX . 'type` WHERE `accountid` = ' . SessionAccountHandler::getId())->fetchAll(); Cache::set('types', $types, '3600'); } foreach ($types as $data) { self::$AllTypes[(string) $data['id']] = $data; } Configuration::ActivityForm()->orderTypes()->sort(self::$AllTypes); }
/** * 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(); }
/** * Init tabs */ private function initTabs() { $this->Tabs['upload'] = new ImporterWindowTabUpload(); $this->Tabs['garmin'] = new ImporterWindowTabCommunicator(); $this->Tabs['formular'] = new ImporterWindowTabFormular($this->TrainingObjects); if (isset($_GET['date'])) { $this->Tabs['formular']->setVisible(); } elseif (empty($this->TrainingObjects) && Configuration::ActivityForm()->creationMode()->usesUpload()) { $this->Tabs['upload']->setVisible(); } elseif (empty($this->TrainingObjects) && Configuration::ActivityForm()->creationMode()->usesGarminCommunicator()) { $this->Tabs['garmin']->setVisible(); } else { $this->Tabs['formular']->setVisible(); } }
/** * Add info link */ protected function addInfoLink() { if (!Request::isOnSharedPage()) { $Linker = new Linker($this->Context->activity()); $InfoLink = Ajax::window('<a href="' . $Linker->urlToElevationInfo() . '">' . __('More about elevation') . '</a>', 'normal'); $this->Footer = HTML::info($InfoLink); } else { $this->Footer = ''; } if ($this->Context->route()->hasCorrectedElevations()) { $this->Footer .= HTML::info(__('Elevation data were corrected.')); } elseif ($this->Context->route()->hasOriginalElevations() && Configuration::ActivityForm()->correctElevation()) { $this->Footer .= HTML::warning(__('Elevation data are not corrected.')); } // TODO: Add link to correct them now! }
/** * Set weather forecast */ public function setWeatherForecast() { if ($this->trainingIsTooOldToFetchWeatherData() || !Configuration::ActivityForm()->loadWeather()) { return; } $Strategy = new \Runalyze\Data\Weather\Openweathermap(); $Location = new \Runalyze\Data\Weather\Location(); $Location->setTimestamp($this->getTimestamp()); $Location->setLocationName(Configuration::ActivityForm()->weatherLocation()); if ($this->hasPositionData()) { $Location->setPosition($this->getFirstArrayPoint('arr_lat'), $this->getFirstArrayPoint('arr_lon')); } $Forecast = new \Runalyze\Data\Weather\Forecast($Strategy, $Location); $Weather = $Forecast->object(); $Weather->temperature()->toCelsius(); $this->set('weatherid', $Weather->condition()->id()); $this->set('temperature', $Weather->temperature()->value()); }
/** * All categories * @return ConfigurationCategory[] */ private function allCategories() { return array(Configuration::General(), Configuration::Privacy(), Configuration::ActivityView(), Configuration::ActivityForm(), Configuration::Design(), Configuration::DataBrowser(), Configuration::Vdot(), Configuration::Trimp(), Configuration::BasicEndurance(), Configuration::Misc()); }
/** * Set average temperature from array */ private function setTemperatureFromArray() { if (!Configuration::ActivityForm()->loadWeather()) { $array = $this->TrainingObject->getArrayTemperature(); if (!empty($array) && (min($array) != max($array) || min($array) != 0)) { $this->TrainingObject->setTemperature(round(array_sum($array) / count($array))); } } }
/** * Parse one trackpoint * @param SimpleXMLElement $TP */ protected function parseTrackpoint(&$TP) { if ($this->distancesAreEmpty) { $TP->addChild('DistanceMeters', 1000 * $this->distanceToTrackpoint($TP)); } //else if ((float)$TP->DistanceMeters < $this->gps['km']) // $TP->DistanceMeters = 1000*$this->distanceToTrackpoint($TP); $ThisBreakInMeter = (double) $TP->DistanceMeters - $this->lastDistance; $ThisBreakInSeconds = strtotime((string) $TP->Time) - $this->TrainingObject->getTimestamp() - end($this->gps['time_in_s']) - $this->PauseInSeconds; if (Configuration::ActivityForm()->detectPauses()) { $NoMove = $this->lastDistance == (double) $TP->DistanceMeters && !$this->isWithoutDistance; $TooSlow = !$this->lastPointWasEmpty && $ThisBreakInMeter > 0 && $ThisBreakInSeconds / $ThisBreakInMeter > 6; } else { $NoMove = $TooSlow = false; } if (empty($TP->DistanceMeters) && !$this->isWithoutDistance || $NoMove || $TooSlow) { $Ignored = false; if (count($TP->children()) == 1 || $NoMove || $TooSlow) { if ($NoMove && $ThisBreakInSeconds <= self::$IGNORE_NO_MOVE_UNTIL) { $Ignored = true; } else { $this->PauseInSeconds += $ThisBreakInSeconds; $this->wasPause = true; $this->pauseDuration += $ThisBreakInSeconds; } if (self::$DEBUG_SPLITS) { Error::getInstance()->addDebug('PAUSE at ' . (string) $TP->Time . ' of ' . $ThisBreakInSeconds . ', empty point: ' . ($NoMove ? 'no move' . ($Ignored ? ' ignored' : '') : 'empty trackpoint') . ($TooSlow ? ' (too slow, ' . $ThisBreakInMeter . 'm in ' . $ThisBreakInSeconds . 's)' : '')); } } if (!$Ignored) { return; } } if (empty($TP->DistanceMeters) && !empty($this->gps['km'])) { $TP->DistanceMeters = end($this->gps['km']) * 1000; } if ($this->TrainingObject->getTimestamp() == 0) { $this->TrainingObject->setTimestamp(strtotime((string) $TP->Time)); } if ($this->lastPointWasEmpty) { $OldPauseInSeconds = $this->PauseInSeconds; $this->PauseInSeconds = strtotime((string) $TP->Time) - $this->TrainingObject->getTimestamp() - end($this->gps['time_in_s']); $this->pauseDuration += $this->PauseInSeconds - $OldPauseInSeconds; $this->wasPause = true; if (self::$DEBUG_SPLITS) { Error::getInstance()->addDebug('PAUSE at ' . (string) $TP->Time . ' of ' . ($this->PauseInSeconds - $OldPauseInSeconds) . ', last point was empty'); } } if ($this->wasPause) { $this->TrainingObject->Pauses()->add(new \Runalyze\Model\Trackdata\Pause(end($this->gps['time_in_s']), $this->pauseDuration, end($this->gps['heartrate']), !empty($TP->HeartRateBpm) ? round($TP->HeartRateBpm->Value) : 0)); $this->wasPause = false; $this->pauseDuration = 0; } $this->lastPointWasEmpty = false; $this->lastPoint = (int) $TP->DistanceMeters; $this->lastDistance = (double) $TP->DistanceMeters; $this->gps['time_in_s'][] = strtotime((string) $TP->Time) - $this->TrainingObject->getTimestamp() - $this->PauseInSeconds; $this->gps['km'][] = round((double) $TP->DistanceMeters / 1000, ParserAbstract::DISTANCE_PRECISION); $this->gps['altitude'][] = (int) $TP->AltitudeMeters; $this->gps['heartrate'][] = !empty($TP->HeartRateBpm) ? round($TP->HeartRateBpm->Value) : 0; if (!empty($TP->Position)) { $this->gps['latitude'][] = (double) $TP->Position->LatitudeDegrees; $this->gps['longitude'][] = (double) $TP->Position->LongitudeDegrees; } elseif (!empty($this->gps['latitude'])) { $this->gps['latitude'][] = end($this->gps['latitude']); $this->gps['longitude'][] = end($this->gps['longitude']); } else { $this->gps['latitude'][] = 0; $this->gps['longitude'][] = 0; } $this->parseExtensionValues($TP); }
/** * Display after submit */ protected function displayAfterSubmit() { if ($this->submitMode == StandardFormular::$SUBMIT_MODE_CREATE) { $this->displayHeader(); echo HTML::okay(__('The activity has been successfully created.')); echo Ajax::closeOverlay(); if (Configuration::ActivityForm()->showActivity()) { echo Ajax::wrapJS('Runalyze.Training.load(' . $this->dataObject->id() . ');'); } } else { if (Request::param('mode') == 'multi') { echo Ajax::wrapJS('Runalyze.goToNextMultiEditor();'); } else { parent::displayAfterSubmit(); } } }
/** * Set conf value to save current status * @param string $confValue */ public final function setConfValueToSaveStatus($confValue) { $this->confValueToSaveStatus = $confValue; if (!Configuration::ActivityForm()->show($confValue)) { $this->setCollapsed(); } }
public function testUpdatePowerCalculation() { // TODO: Needs configuration setting if (Configuration::ActivityForm()->computePower()) { $OldObject = $this->fetch($this->insert(array(Object::DISTANCE => 10, Object::TIME_IN_SECONDS => 3000, Object::SPORTID => $this->IndoorID))); $NewObject = clone $OldObject; $NewObject->set(Object::SPORTID, $this->OutdoorID); $Result = $this->update($NewObject, $OldObject, new Model\Trackdata\Object(array(Model\Trackdata\Object::TIME => array(1500, 3000), Model\Trackdata\Object::DISTANCE => array(5, 10)))); $this->assertEquals(0, $OldObject->power()); $this->assertNotEquals(0, $NewObject->power()); $this->assertNotEquals(0, $Result->power()); } }
public function testPowerCalculation() { // TODO: Needs configuration setting if (Configuration::ActivityForm()->computePower()) { $ActivityIndoor = new Object(array(Object::DISTANCE => 10, Object::TIME_IN_SECONDS => 3000, Object::SPORTID => $this->IndoorID)); $Trackdata = new Model\Trackdata\Object(array(Model\Trackdata\Object::TIME => array(1500, 3000), Model\Trackdata\Object::DISTANCE => array(5, 10))); $Inserter = new Inserter($this->PDO); $Inserter->setAccountID(0); $Inserter->setTrackdata($Trackdata); $Inserter->insert($ActivityIndoor); $this->assertEquals(0, $this->fetch($Inserter->insertedID())->power()); $ActivityOutdoor = clone $ActivityIndoor; $ActivityOutdoor->set(Object::SPORTID, $this->OutdoorID); $Inserter->insert($ActivityOutdoor); $this->assertNotEquals(0, $this->fetch($Inserter->insertedID())->power()); $this->assertNotEmpty($Trackdata->power()); } }
<?php /** * File for matching activities from Garmin Communicator * Call: ajax.activityMatcher.php */ require_once '../inc/class.Frontend.php'; $Frontend = new Frontend(true); use Runalyze\Activity\DuplicateFinder; header('Content-type: application/json'); $IDs = array(); $Matches = array(); $Array = explode('&', urldecode(file_get_contents('php://input'))); foreach ($Array as $String) { if (substr($String, 0, 12) == 'externalIds=') { $IDs[] = substr($String, 12); } } $IgnoreIDs = \Runalyze\Configuration::ActivityForm()->ignoredActivityIDs(); $DuplicateFinder = new DuplicateFinder(DB::getInstance(), SessionAccountHandler::getId()); $IgnoreIDs = array_map(function ($v) { return (int) floor(strtotime($v) / 60) * 60; }, $IgnoreIDs); foreach ($IDs as $ID) { $dup = $DuplicateFinder->checkForDuplicate((int) floor(strtotime($ID) / 60) * 60); $found = $dup || in_array($ID, $IgnoreIDs); $Matches[$ID] = array('match' => $found); } $Response = array('matches' => $Matches); echo json_encode((object) $Response);
/** * Calculate power */ protected function calculatePower() { if (\Runalyze\Context::Factory()->sport($this->Object->sportid())->hasPower() && Configuration::ActivityForm()->computePower() && NULL !== $this->Trackdata) { $Calculator = new \Runalyze\Calculation\Power\Calculator($this->Trackdata, $this->Route); $Calculator->calculate(); $this->Trackdata->set(Model\Trackdata\Object::POWER, $Calculator->powerData()); $this->Object->set(Object::POWER, $Calculator->average()); } }
/** * Order for full fetch * @param string $tablename * @return string */ protected function orderBy($tablename) { switch ($tablename) { case 'sport': return \Runalyze\Configuration::ActivityForm()->orderSports()->asQuery(); case 'type': return \Runalyze\Configuration::ActivityForm()->orderTypes()->asQuery(); case 'equipment': return \Runalyze\Configuration::ActivityForm()->orderEquipment()->asQuery(); } return ''; }
$("#sportid").change(function(){ jUpdateSportValues(); <?php if (\Runalyze\Configuration::ActivityForm()->computeCalories()) { ?> jUpdateKcal(); <?php } ?> }); $("input[name=distance], input[name=s]").change(function() { jUpdatePace(); jUpdateKmh(); <?php if (\Runalyze\Configuration::ActivityForm()->computeCalories()) { ?> jUpdateKcal(); <?php } ?> }); jUpdateSportValues(); jUpdatePace(); if ($("input[name=kcal]").val() == 0) jUpdateKcal();
<?php /** * File for changing a config-value * Call: ajax.change.Config.php?key=...&value=...[&add] */ require_once '../inc/class.Frontend.php'; $Frontend = new Frontend(); switch ($_GET['key']) { case 'garmin-ignore': \Runalyze\Configuration::ActivityForm()->ignoreActivityID($_GET['value']); break; case 'leaflet-layer': \Runalyze\Configuration::ActivityView()->updateLayer($_GET['value']); break; default: if (substr($_GET['key'], 0, 5) == 'show-') { $key = substr($_GET['key'], 5); \Runalyze\Configuration::ActivityForm()->update($key, $_GET['value']); } }