Ejemplo n.º 1
0
 /**
  * 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->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->Dataview = new Dataview($this->Activity);
 }
Ejemplo n.º 2
0
 /**
  * Update basic endurance
  */
 protected function updateBasicEndurance()
 {
     $timestampLimit = time() - 182 * DAY_IN_S;
     if ($this->Object->sportid() == Configuration::General()->runningSport() && $this->Object->timestamp() > $timestampLimit) {
         BasicEndurance::recalculateValue();
     }
 }
Ejemplo n.º 3
0
 /**
  * Get link with icon as text
  * @return string HTML-link to this training
  */
 public function linkWithSportIcon()
 {
     $Sport = new Sport($this->Activity->sportid());
     $Time = new Duration($this->Activity->duration());
     $tooltip = $Sport->name() . ': ' . $Time->string();
     return $this->link($Sport->Icon($tooltip));
 }
Ejemplo n.º 4
0
 /**
  * Update basic endurance
  */
 protected function updateBasicEndurance()
 {
     $timestampLimit = time() - 182 * DAY_IN_S;
     if (($this->hasChanged(Object::DISTANCE) || $this->hasChanged(Object::TIMESTAMP) || $this->hasChanged(Object::SPORTID)) && ($this->NewObject->sportid() == Configuration::General()->runningSport() && $this->NewObject->timestamp() > $timestampLimit || $this->knowsOldObject() && $this->OldObject->sportid() == Configuration::General()->runningSport() && $this->OldObject->timestamp() > $timestampLimit)) {
         BasicEndurance::recalculateValue();
     }
 }
Ejemplo n.º 5
0
 /**
  * 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();
 }
Ejemplo n.º 6
0
 /**
  * Set activity
  * @param \Runalyze\Model\Activity\Object $object activity object
  */
 public function setActivity(Activity\Object $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;
 }
Ejemplo n.º 7
0
 /**
  * Get link with icon as text
  * @param string $tooltipCssClass optional, e.g. 'atRight'
  * @return string HTML-link to this training
  */
 public function linkWithSportIcon($tooltipCssClass = '')
 {
     $Time = new Duration($this->Activity->duration());
     $Factory = new \Runalyze\Model\Factory(\SessionAccountHandler::getId());
     $Sport = $Factory->sport($this->Activity->sportid());
     $code = $Sport->icon()->code();
     $Tooltip = new \Runalyze\View\Tooltip($Sport->name() . ': ' . $Time->string());
     $Tooltip->setPosition($tooltipCssClass);
     $Tooltip->wrapAround($code);
     return $this->link($code);
 }
Ejemplo n.º 8
0
 /**
  * Calculate trimp
  * @return int
  */
 public function calculateTrimp()
 {
     if ($this->knowsTrackdata() && $this->Trackdata->has(Model\Trackdata\Object::HEARTRATE)) {
         $Collector = new Trimp\DataCollector($this->Trackdata->heartRate(), $this->Trackdata->time());
         $data = $Collector->result();
     } elseif ($this->Activity->hrAvg() > 0) {
         $data = array($this->Activity->hrAvg() => $this->Activity->duration());
     } else {
         $Factory = Context::Factory();
         if ($this->Activity->typeid() > 0) {
             $data = array($Factory->type($this->Activity->typeid())->hrAvg() => $this->Activity->duration());
         } else {
             $data = array($Factory->sport($this->Activity->sportid())->avgHR() => $this->Activity->duration());
         }
     }
     $Athlete = Context::Athlete();
     $Calculator = new Trimp\Calculator($Athlete, $data);
     return round($Calculator->value());
 }
Ejemplo n.º 9
0
 /**
  * Construct preview
  * @param \Runalyze\Model\Activity\Object $activity
  */
 public function __construct(Activity\Object $activity)
 {
     $this->Activity = $activity;
     $this->Dataview = new Dataview($activity);
     $this->Sport = Context::Factory()->sport($this->Activity->sportid());
 }
Ejemplo n.º 10
0
 /**
  * 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 '';
 }
    /**
     * Display the images
     */
    private function displayTable()
    {
        if ($this->sportid > 0) {
            $sports_not_short = $this->sportid . ',';
        } else {
            $sports_not_short = '';
            $sports = DB::getInstance()->query('SELECT `id` FROM `' . PREFIX . 'sport` WHERE `short`=0 AND `accountid` = ' . SessionAccountHandler::getId())->fetchAll();
            foreach ($sports as $sport) {
                $sports_not_short .= $sport['id'] . ',';
            }
        }
        $nights = DB::getInstance()->query('SELECT * FROM (
			SELECT
				id,
				time,
				s,
				sportid,
				distance,
				is_track,
				HOUR(FROM_UNIXTIME(`time`)) as `H`,
				MINUTE(FROM_UNIXTIME(`time`)) as `MIN`
			FROM `' . PREFIX . 'training`
			WHERE
				`sportid` IN(' . substr($sports_not_short, 0, -1) . ') AND
                                `accountid` = ' . SessionAccountHandler::getId() . ' AND
				(HOUR(FROM_UNIXTIME(`time`))!=0 OR MINUTE(FROM_UNIXTIME(`time`))!=0) 
				' . $this->getYearDependenceForQuery() . '
			ORDER BY
				ABS(12-(`H`+10)%24-`MIN`/60) ASC,
				`MIN` DESC LIMIT 20
			) t
		ORDER BY
			(`H`+12)%24 ASC,
			`MIN` ASC')->fetchAll();
        if (empty($nights)) {
            $this->dataIsMissing = true;
            return;
        }
        echo '<table class="fullwidth zebra-style">';
        echo '<thead><tr class="b c"><th colspan="8">' . __('Nightly activities') . '</th></tr></thead>';
        echo '<tbody>';
        foreach ($nights as $i => $data) {
            $Activity = new Activity\Object($data);
            $Linker = new Linker($Activity);
            $View = new Dataview($Activity);
            if ($i % 2 == 0) {
                echo '<tr">';
            }
            echo '<td class="b">' . $View->daytime() . '</td>
				<td>' . $Linker->linkWithSportIcon() . '</td>
				<td>' . $View->distanceOrDuration() . ' ' . SportFactory::name($Activity->sportid()) . '</td>
				<td>' . $Linker->weekLink() . '</td>';
            if ($i % 2 == 1) {
                echo '</tr>';
            }
        }
        echo '</tbody></table>';
        // TODO: Find a better description.
        echo '<p class="text">';
        echo __('2 a.m. is considered as <em>most extreme</em> time for a training. ');
        echo __('The 20 trainings being nearest to that time are listed.');
        echo '</p>';
    }