コード例 #1
0
ファイル: InserterTest.php プロジェクト: 9x/Runalyze
 protected function tearDown()
 {
     $this->PDO->exec('DELETE FROM `' . PREFIX . 'training`');
     $this->PDO->exec('DELETE FROM `' . PREFIX . 'sport`');
     $this->PDO->exec('DELETE FROM `' . PREFIX . 'equipment_type`');
     $Factory = new Model\Factory(0);
     $Factory->clearCache('sport');
     \Cache::clean();
 }
コード例 #2
0
ファイル: Context.php プロジェクト: rob-st/Runalyze
 /**
  * Set activity
  * @param \Runalyze\Model\Activity\Entity $object activity object
  */
 public function setActivity(Model\Activity\Entity $object)
 {
     $this->Activity = $object;
     $this->Dataview = new Dataview($object);
     $this->Linker = new Linker($object);
     $this->Sport = $this->Activity->sportid() > 0 ? $this->Factory->sport($this->Activity->sportid()) : null;
     $this->Type = $this->Activity->typeid() > 0 ? $this->Factory->type($this->Activity->typeid()) : null;
     $this->ActivityData = $this->Activity->completeData();
     $this->IsRunning = $this->hasSport() && $this->Sport->id() == \Runalyze\Configuration::General()->runningSport();
 }
コード例 #3
0
 /**
  * Construct updater
  * @param \PDO $connection
  * @param int $accountID
  * @param \Runalyze\Model\Activity\Object $activity
  * @param \Runalyze\Model\Factory $factory
  */
 public function __construct(\PDO $connection, $accountID, Object $activity, Model\Factory $factory)
 {
     $this->PDO = $connection;
     $this->AccountID = $accountID;
     $this->Activity = $activity;
     $this->Trackdata = $factory->trackdata($activity->id());
     $this->OldTrackdata = clone $this->Trackdata;
     $this->Route = $factory->route($activity->get(Object::ROUTEID));
     $this->OldRoute = clone $this->Route;
 }
コード例 #4
0
ファイル: DataSeriesRemover.php プロジェクト: 9x/Runalyze
 /**
  * Construct updater
  * @param \PDO $connection
  * @param int $accountID
  * @param \Runalyze\Model\Activity\Object $activity
  * @param \Runalyze\Model\Factory $factory
  */
 public function __construct(\PDO $connection, $accountID, Object $activity, Model\Factory $factory)
 {
     $this->PDO = $connection;
     $this->AccountID = $accountID;
     $this->Activity = $activity;
     $this->OldActivity = clone $activity;
     $this->Trackdata = $factory->trackdata($activity->id());
     $this->OldTrackdata = clone $this->Trackdata;
     $this->Route = $factory->route($activity->get(Object::ROUTEID));
     $this->OldRoute = clone $this->Route;
     $this->ActivityKeysForTrackdataKeys = [Model\Trackdata\Object::HEARTRATE => Model\Activity\Object::HR_AVG, Model\Trackdata\Object::CADENCE => Model\Activity\Object::CADENCE, Model\Trackdata\Object::VERTICAL_OSCILLATION => Model\Activity\Object::VERTICAL_OSCILLATION, Model\Trackdata\Object::GROUNDCONTACT => Model\Activity\Object::GROUNDCONTACT, Model\Trackdata\Object::POWER => Model\Activity\Object::POWER, Model\Trackdata\Object::TEMPERATURE => Model\Activity\Object::TEMPERATURE];
 }
コード例 #5
0
ファイル: ChosenInserter.php プロジェクト: guancio/Runalyze
 private function checkForNewTags()
 {
     $Factory = new Model\Factory(\SessionAccountHandler::getId());
     $allTagIDs = array_map(function ($tag) {
         return $tag->id();
     }, $Factory->allTags());
     foreach ($this->TagArrayFromChosen as $key => $Tag) {
         if (!in_array($Tag, $allTagIDs)) {
             $this->setObjectwithTag($Tag);
             $this->TagArrayFromChosen[$key] = $this->insertNewTag();
         }
     }
     $Factory->clearCache('tag');
 }
コード例 #6
0
 /**
  * Construct updater
  * @param \PDO $connection
  * @param int $accountID
  * @param \Runalyze\Model\Activity\Entity $activity
  * @param \Runalyze\Model\Factory $factory
  */
 public function __construct(\PDO $connection, $accountID, Entity $activity, Model\Factory $factory)
 {
     $this->PDO = $connection;
     $this->AccountID = $accountID;
     $this->Activity = $activity;
     $this->OldActivity = clone $activity;
     $this->Trackdata = $factory->trackdata($activity->id());
     $this->OldTrackdata = clone $this->Trackdata;
     $this->Route = $factory->route($activity->get(Entity::ROUTEID));
     $this->OldRoute = clone $this->Route;
     // TODO: What's with STRIDE_LENGTH and VERTICAL_RATIO?
     // - so far, there are updateStrideLength() and updateVerticalRatio() in Activity\Updater
     $this->ActivityKeysForTrackdataKeys = [Model\Trackdata\Entity::HEARTRATE => Model\Activity\Entity::HR_AVG, Model\Trackdata\Entity::CADENCE => Model\Activity\Entity::CADENCE, Model\Trackdata\Entity::VERTICAL_OSCILLATION => Model\Activity\Entity::VERTICAL_OSCILLATION, Model\Trackdata\Entity::GROUNDCONTACT => Model\Activity\Entity::GROUNDCONTACT, Model\Trackdata\Entity::POWER => Model\Activity\Entity::POWER, Model\Trackdata\Entity::TEMPERATURE => Model\Activity\Entity::TEMPERATURE];
 }
コード例 #7
0
ファイル: DataSeriesRemoverTest.php プロジェクト: 9x/Runalyze
 public function testRemovingAverageValues()
 {
     $id = $this->insert(array(Object::TIMESTAMP => time(), Object::HR_AVG => 150, Object::TEMPERATURE => 18), array(Route\Object::ELEVATIONS_CORRECTED => array(200, 250, 200)), array(Trackdata\Object::TEMPERATURE => array(20, 20, 20), Trackdata\Object::HEARTRATE => array(150, 170, 130)));
     $OldActivity = $this->Factory->activity($id);
     $Remover = new DataSeriesRemover($this->PDO, 0, $OldActivity, $this->Factory);
     $Remover->removeFromTrackdata(Trackdata\Object::TEMPERATURE);
     $Remover->removeFromTrackdata(Trackdata\Object::HEARTRATE);
     $Remover->saveChanges();
     $Activity = $this->Factory->activity($id);
     $this->assertEquals(18, $Activity->weather()->temperature()->value());
     $this->assertEquals(0, $Activity->hrAvg());
 }
コード例 #8
0
 public function testIfRouteWillBeDeleted()
 {
     $id = $this->insert(array(Object::TIMESTAMP => time()), array(Route\Object::LATITUDES => array(49.6, 49.7, 49.8), Route\Object::LONGITUDES => array(7.6, 7.7, 7.8), Route\Object::ELEVATIONS_CORRECTED => array(200, 250, 200), Route\Object::ELEVATION => 50, Route\Object::ELEVATION_UP => 50, Route\Object::ELEVATION_DOWN => 50), array());
     $OldActivity = $this->Factory->activity($id);
     $RouteID = $OldActivity->get(Object::ROUTEID);
     $Remover = new DataSeriesRemover($this->PDO, 0, $OldActivity, $this->Factory);
     $Remover->removeGPSpathFromRoute();
     $Remover->removeFromRoute(Route\Object::ELEVATIONS_CORRECTED);
     $Remover->saveChanges();
     $Activity = $this->Factory->activity($id);
     $Route = $this->Factory->route($RouteID);
     $this->assertEquals(0, $Activity->get(Object::ROUTEID));
     $this->assertTrue($Route->isEmpty());
 }
コード例 #9
0
ファイル: Context.php プロジェクト: n0rthface/Runalyze
 /**
  * Construct context
  * @var int $activityID
  * @var in $accountID
  */
 public function __construct($activityID, $accountID)
 {
     $Factory = new Factory((int) $accountID);
     $this->Activity = $Factory->activity((int) $activityID);
     $this->Trackdata = $Factory->trackdata((int) $activityID);
     $this->Swimdata = $Factory->swimdata((int) $activityID);
     $this->Route = $this->Activity->get(Activity\Object::ROUTEID) ? $Factory->route($this->Activity->get(Activity\Object::ROUTEID)) : null;
     $this->HRV = $Factory->hrv((int) $activityID);
     $this->Sport = $Factory->sport($this->Activity->sportid());
     $this->Swimdata->fillDistanceArray($this->Trackdata);
     $this->Swimdata->fillSwolfArray($this->Trackdata);
     $this->Dataview = new Dataview($this->Activity);
 }
コード例 #10
0
 /**
  * @param int $num
  * @return string
  */
 protected function exampleEquipmentIDs($num = 1)
 {
     $Sport = $this->Factory->sport(Configuration::General()->runningSport());
     if ($Sport->mainEquipmentTypeID() > 0) {
         $IDs = $this->Factory->equipmentForEquipmentType($Sport->mainEquipmentTypeID(), true);
         if (!empty($IDs)) {
             return $IDs[0];
         }
     }
     $AllEquipments = $this->Factory->allEquipments();
     if (!empty($AllEquipments)) {
         $max = min($num, count($AllEquipments));
         $ids = array();
         for ($i = 0; $i < $max; ++$i) {
             $ids[] = $AllEquipments[$i]->id();
         }
         return implode(',', $ids);
     }
     return '';
 }
コード例 #11
0
ファイル: class.Dataset.php プロジェクト: Nugman/Runalyze
 /**
  * Get content for a given dataset
  * @param string $name
  * @return string
  */
 public function getDataset($name)
 {
     switch ($name) {
         case 'sportid':
             if (!is_null($this->Sport)) {
                 return $this->Sport->icon()->code();
             }
             return '';
         case 'typeid':
             if (!is_null($this->Type)) {
                 if ($this->Type->isQualitySession()) {
                     return '<strong>' . $this->Type->abbreviation() . '</strong>';
                 }
                 return $this->Type->abbreviation();
             }
             return '';
         case 'time':
             return $this->Dataview->daytime();
         case 'distance':
             return $this->Dataview->distance() . $this->distanceComparison();
         case 's':
             return $this->Dataview->duration()->string();
         case 'pace':
             if ($this->Activity->distance() > 0) {
                 if (isset($this->ActivityData['s_sum_with_distance'])) {
                     if ($this->ActivityData['s_sum_with_distance'] > 0) {
                         $Pace = new Pace($this->ActivityData['s_sum_with_distance'], $this->Activity->distance(), SportFactory::getSpeedUnitFor($this->Activity->sportid()));
                         return $Pace->valueWithAppendix();
                     }
                     return '';
                 }
                 return $this->Dataview->pace()->valueWithAppendix();
             }
             return '';
         case 'elevation':
             if ($this->Activity->elevation() > 0) {
                 return $this->Dataview->elevation()->string();
             }
             return '';
         case 'kcal':
             return $this->Dataview->calories();
         case 'pulse_avg':
             if ($this->Activity->hrAvg() > 0) {
                 return $this->Dataview->hrAvg()->string();
             }
             return '';
         case 'pulse_max':
             if ($this->Activity->hrMax() > 0) {
                 return $this->Dataview->hrMax()->string();
             }
             return '';
         case 'trimp':
             return $this->Dataview->trimp();
         case 'cadence':
             if ($this->Dataview->cadence()->value() > 0) {
                 return $this->Dataview->cadence()->asString();
             }
             return '';
         case 'stride_length':
             if ($this->Dataview->strideLength()->value() > 0) {
                 return $this->Dataview->strideLength()->string();
             }
             return '';
         case 'groundcontact':
             return $this->Dataview->groundcontact();
         case 'vertical_oscillation':
             return $this->Dataview->verticalOscillation();
         case 'power':
             return $this->Dataview->power();
         case 'temperature':
             if (!$this->Activity->weather()->temperature()->isUnknown() && (is_null($this->Sport) || $this->Sport->isOutside())) {
                 return Temperature::format($this->Activity->weather()->temperature()->value(), true, false);
             }
             return '';
         case 'weatherid':
             if (!$this->Activity->weather()->isEmpty() && (is_null($this->Sport) || $this->Sport->isOutside())) {
                 return $this->Activity->weather()->condition()->icon()->code();
             }
             return '';
         case 'routeid':
             if ($this->Activity->get(Activity\Object::ROUTEID) > 0) {
                 return $this->cut($this->Factory->route($this->Activity->get(Activity\Object::ROUTEID))->name());
             }
             return '';
         case 'splits':
             if (!$this->Activity->splits()->isEmpty()) {
                 if ($this->Activity->splits()->hasActiveAndInactiveLaps() || round($this->Activity->splits()->totalDistance()) != round($this->Activity->distance()) || !is_null($this->Type) && $this->Type->id() == Configuration::General()->competitionType()) {
                     // TODO: Icon with tooltip?
                     $Icon = new Icon(Icon::CLOCK);
                     return $Icon->code();
                 }
             }
             return '';
         case 'comment':
             return $this->cut($this->Activity->comment());
         case 'partner':
             return $this->cut($this->Activity->partner()->asString());
         case 'abc':
             return $this->Dataview->abcIcon();
         case 'vdoticon':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport()) {
                 return $this->Dataview->vdotIcon();
             }
             return '';
         case 'vdot':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport() && $this->Activity->vdotByHeartRate() > 0) {
                 if (!$this->Activity->usesVDOT()) {
                     return '<span class="unimportant">' . $this->Dataview->vdot()->value() . '</span>';
                 }
                 return $this->Dataview->vdot()->value();
             }
             return '';
         case 'jd_intensity':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport()) {
                 return $this->Dataview->jdIntensityWithStresscolor();
             }
             return '';
         case 'fit_vdot_estimate':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport()) {
                 return $this->Dataview->fitVdotEstimate();
             }
             return '';
         case 'fit_recovery_time':
             return $this->Dataview->fitRecoveryTime();
         case 'fit_hrv_analysis':
             return $this->Dataview->fitHRVscore();
     }
     return '';
 }
コード例 #12
0
 /**
  * Get field options for data series to remove
  * @return \FormularCheckbox[]
  */
 protected function fieldOptionsForDataSeriesToRemove()
 {
     $Factory = new Factory(SessionAccountHandler::getId());
     $Trackdata = $Factory->trackdata($this->dataObject->id());
     $Route = $Factory->route($this->dataObject->get('routeid'));
     $Fields = array();
     $TrackdataKeys = array(Trackdata::TIME => __('Time'), Trackdata::DISTANCE => __('Distance'), Trackdata::HEARTRATE => __('Heart rate'), Trackdata::CADENCE => __('Cadence'), Trackdata::VERTICAL_OSCILLATION => __('Vertical oscillation'), Trackdata::GROUNDCONTACT => __('Ground contact time'), Trackdata::POWER => __('Power'), Trackdata::TEMPERATURE => __('Temperature'));
     foreach ($TrackdataKeys as $key => $text) {
         if ($Trackdata->has($key)) {
             $Fields[] = new FormularCheckbox(self::POST_KEY_REMOVE_TRACKDATA . '[' . $key . ']', $text);
         }
     }
     $RouteKeys = array(Route::ELEVATIONS_ORIGINAL => __('Original elevation'), Route::ELEVATIONS_CORRECTED => __('Corrected elevation'));
     if ($Route->hasPositionData()) {
         $Fields[] = new FormularCheckbox(self::POST_KEY_REMOVE_ROUTE . '[' . self::POST_KEY_REMOVE_ROUTE_GPS . ']', __('GPS path'));
     }
     foreach ($RouteKeys as $key => $text) {
         if ($Route->has($key)) {
             $Fields[] = new FormularCheckbox(self::POST_KEY_REMOVE_ROUTE . '[' . $key . ']', $text);
         }
     }
     return $Fields;
 }
コード例 #13
0
ファイル: Dataview.php プロジェクト: rob-st/Runalyze
 /**
  * Title for this training: type or sport name
  * @return string
  */
 public function titleByTypeOrSport()
 {
     $Factory = new Factory(SessionAccountHandler::getId());
     if ($this->Activity->typeid() != 0) {
         return $Factory->type($this->Activity->typeid())->name();
     }
     return $Factory->sport($this->Activity->sportid())->name();
 }
コード例 #14
0
ファイル: class.Dataset.php プロジェクト: n0rthface/Runalyze
 /**
  * Get content for a given dataset
  * @param string $name
  * @return string
  */
 public function getDataset($name)
 {
     switch ($name) {
         case 'sportid':
             if (!is_null($this->Sport)) {
                 return $this->Sport->icon()->code();
             }
             return '';
         case 'typeid':
             if (!is_null($this->Type)) {
                 if ($this->Type->isQualitySession()) {
                     return '<strong>' . $this->Type->abbreviation() . '</strong>';
                 }
                 return $this->Type->abbreviation();
             }
             return '';
         case 'time':
             return $this->Dataview->daytime();
         case 'distance':
             return $this->Dataview->distance() . $this->distanceComparison();
         case 's':
             return $this->Dataview->duration()->string();
         case 'pace':
             if ($this->Activity->distance() > 0) {
                 // TODO: 's_sum_with_distance'
                 //return $this->TrainingObject->DataView()->getSpeedStringForTime( $this->TrainingObject->getTimeInSecondsSumWithDistance() );
                 return $this->Dataview->pace()->valueWithAppendix();
             }
             return '';
         case 'elevation':
             return $this->Dataview->elevation();
         case 'kcal':
             return $this->Dataview->calories();
         case 'pulse_avg':
             if ($this->Activity->hrAvg() > 0) {
                 return $this->Dataview->hrAvg()->string();
             }
             return '';
         case 'pulse_max':
             if ($this->Activity->hrMax() > 0) {
                 return $this->Dataview->hrMax()->string();
             }
             return '';
         case 'trimp':
             return $this->Dataview->trimp();
         case 'cadence':
             if ($this->Dataview->cadence()->value() > 0) {
                 return $this->Dataview->cadence()->asString();
             }
             return '';
         case 'stride_length':
             if ($this->Dataview->strideLength()->inCM() > 0) {
                 return $this->Dataview->strideLength()->string();
             }
             return '';
         case 'groundcontact':
             return $this->Dataview->groundcontact();
         case 'vertical_oscillation':
             return $this->Dataview->verticalOscillation();
         case 'power':
             return $this->Dataview->power();
         case 'temperature':
             if (!$this->Activity->weather()->temperature()->isUnknown() && (is_null($this->Sport) || $this->Sport->isOutside())) {
                 return $this->Activity->weather()->temperature()->asString();
             }
             return '';
         case 'weatherid':
             if (!$this->Activity->weather()->isEmpty() && (is_null($this->Sport) || $this->Sport->isOutside())) {
                 return $this->Activity->weather()->condition()->icon()->code();
             }
             return '';
         case 'routeid':
             if ($this->Activity->get(Activity\Object::ROUTEID) > 0) {
                 return $this->cut($this->Factory->route($this->Activity->get(Activity\Object::ROUTEID))->name());
             }
             return '';
         case 'clothes':
             return $this->cut($this->Dataview->clothes());
         case 'splits':
             if (!$this->Activity->splits()->isEmpty()) {
                 if ($this->Activity->splits()->hasActiveAndInactiveLaps() || round($this->Activity->splits()->totalDistance()) != round($this->Activity->distance()) || !is_null($this->Type) && $this->Type->id() == Configuration::General()->competitionType()) {
                     // TODO: Icon with tooltip?
                     $Icon = new Icon(Icon::CLOCK);
                     return $Icon->code();
                 }
             }
             return '';
         case 'comment':
             return $this->cut($this->Activity->comment());
         case 'partner':
             return $this->cut($this->Activity->partner()->asString());
         case 'abc':
             return $this->Dataview->abcIcon();
         case 'shoeid':
             if ($this->Activity->shoeID() > 0) {
                 return ShoeFactory::NameOf($this->Activity->shoeID());
             }
             return '';
         case 'vdoticon':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport()) {
                 return $this->Dataview->vdotIcon();
             }
             return '';
         case 'vdot':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport() && $this->Activity->vdotByHeartRate() > 0) {
                 if (!$this->Activity->usesVDOT()) {
                     return '<span class="unimportant">' . $this->Dataview->vdot()->value() . '</span>';
                 }
                 return $this->Dataview->vdot()->value();
             }
             return '';
         case 'jd_intensity':
             if (!is_null($this->Sport) && $this->Sport->id() == Configuration::General()->runningSport()) {
                 return $this->Dataview->jdIntensityWithStresscolor();
             }
             return '';
     }
     return '';
 }
コード例 #15
0
ファイル: MonthwiseTable.php プロジェクト: guancio/Runalyze
 /**
  * @return array
  */
 protected function generateDataForEquipment()
 {
     if ($this->EquipmentTypeID == 0) {
         return array();
     }
     $RowsByID = array();
     $Rows = array();
     $Factory = new Factory($this->AccountID);
     $Statement = $this->createStatementToFetchEquipment();
     while ($data = $Statement->fetch()) {
         if (!isset($RowsByID[$data['equipmentid']])) {
             $RowsByID[$data['equipmentid']] = array();
         }
         $RowsByID[$data['equipmentid']][$data['m']] = $data['num'] . 'x';
     }
     foreach ($RowsByID as $id => $rowData) {
         $Rows[$Factory->equipment($id)->name()] = $rowData;
     }
     return $Rows;
 }
コード例 #16
0
 /**
  * Show data in table view
  * @param array $data
  * @param array $timeset
  */
 private function showDataInTableView($data, $timeset)
 {
     $Factory = new Factory(SessionAccountHandler::getId());
     if (empty($data)) {
         echo '<p><em>' . __('No data available.') . '</em></p>';
     } else {
         foreach ($data as $dat) {
             $Sport = $Factory->sport($dat['sportid']);
             $result = $dat['count_distance'] >= $dat['count'] / 2 ? Distance::format($dat['distance']) : Duration::format($dat['time_in_s']);
             echo '<p><span class="right"><small><small>(' . sprintf(__('%u-times'), Helper::Unknown($dat['count'], '0')) . ')</small></small> ' . $result . '</span> ';
             echo $Sport->icon()->code() . ' <strong>' . $Sport->name() . '</strong></p>';
         }
     }
     echo '<small class="right">' . __('since') . ' ' . date("d.m.Y", $timeset['start']) . '</small>';
     echo HTML::clearBreak();
 }
コード例 #17
0
 /**
  * Display the content
  * @see PluginPanel::displayContent()
  */
 protected function displayContent()
 {
     $Factory = new Model\Factory(SessionAccountHandler::getId());
     $EquipmentType = $Factory->equipmentType((int) $this->Configuration()->value('type'));
     if ($EquipmentType->isEmpty()) {
         echo HTML::warning(__('Please choose an equipment type in the plugin configuration.'));
         return;
     }
     echo $this->getStyle();
     echo '<div id="equipment">';
     $inuse = true;
     $this->showListFor($EquipmentType, $inuse);
     echo '</div>';
     if (!$inuse) {
         echo Ajax::toggle('<a class="right" href="#equipment" name="equipment">' . __('Show unused equipment') . '</a>', 'hiddenequipment');
     }
     echo HTML::clearBreak();
 }