/** * Calculate stride length for activity * Use this method if trackdata is not available * @param \Runalyze\Model\Activity\Object $activity * @return int [cm] */ public static function forActivity(Activity\Object $activity) { if ($activity->cadence() > 0 && $activity->duration() > 0) { return round($activity->distance() * 1000 * 100 / ($activity->cadence() * 2 / 60 * $activity->duration())); } return 0; }
/** * Calculate for activity object * * This method does not lookup trackdata of the activity! * If you want an exact intensity value, use `calculateByTrackdata(...)` * * @param \Runalyze\Model\Activity\Object $activity * @return int */ public function calculateByActivity(Activity\Object $activity) { if ($activity->hrAvg() > 0) { return $this->calculateByHeartrateAverage($activity->hrAvg(), $activity->duration()); } return $this->calculateByPace($activity->distance(), $activity->duration()); }
/** * Update equipment */ protected function updateEquipment() { if ($this->Object->shoeID() > 0) { $this->PDO->exec('UPDATE `' . PREFIX . 'shoe` SET `km` = `km` - ' . (double) $this->Object->distance() . ', `time` = `time` - ' . (int) $this->Object->duration() . ' WHERE `id`="' . $this->Object->shoeID() . '" LIMIT 1'); } }
/** * Tasks to run after update */ protected function afterUpdate() { if (null !== $this->NewActivity) { $this->updateEquipment(array_diff($this->OtherIDsNew, $this->OtherIDsOld), $this->NewActivity->distance(), $this->NewActivity->duration()); } if (null !== $this->NewActivity && null !== $this->OldActivity) { $this->updateEquipment(array_intersect($this->OtherIDsNew, $this->OtherIDsOld), $this->NewActivity->distance() - $this->OldActivity->distance(), $this->NewActivity->duration() - $this->OldActivity->duration()); } }
/** * 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)); }
/** * Get elapsed time * @return string */ public function elapsedTime() { if ($this->Activity->elapsedTime() < $this->Activity->duration()) { return '-:--:--'; } return Duration::format($this->Activity->elapsedTime()); }
/** * Calculate calories if empty */ protected function calculateCaloriesIfZero() { if ($this->Object->calories() == 0 && $this->Object->sportid() > 0) { $Factory = \Runalyze\Context::Factory(); $calories = $Factory->sport($this->Object->sportid())->caloriesPerHour() * $this->Object->duration() / 3600; $this->Object->set(Object::CALORIES, $calories); } }
/** * 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); }
/** * 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()); }
/** * Update equipment */ protected function updateEquipment() { if ($this->hasChanged(Object::SHOEID)) { if ($this->knowsOldObject()) { $this->PDO->exec('UPDATE `' . PREFIX . 'shoe` SET `km` = `km` - ' . (double) $this->OldObject->distance() . ', `time` = `time` - ' . (int) $this->OldObject->duration() . ' WHERE `id`="' . $this->OldObject->shoeID() . '" LIMIT 1'); } $this->PDO->exec('UPDATE `' . PREFIX . 'shoe` SET `km` = `km` + ' . (double) $this->NewObject->distance() . ', `time` = `time` + ' . (int) $this->NewObject->duration() . ' WHERE `id`="' . $this->NewObject->shoeID() . '" LIMIT 1'); } elseif ($this->hasChanged(Object::DISTANCE) || $this->hasChanged(Object::TIME_IN_SECONDS)) { $this->PDO->exec('UPDATE `' . PREFIX . 'shoe` SET `km` = `km` + (' . ((double) $this->NewObject->distance() - (double) $this->OldObject->distance()) . '), `time` = `time` + (' . ((int) $this->NewObject->duration() - (double) $this->OldObject->duration()) . ') WHERE `id`="' . $this->NewObject->shoeID() . '" LIMIT 1'); } }
/** * Shape deviation in percent * @return string */ public function shapeDeviation() { $Difference = 100 * ($this->prognosisByShapeInSeconds() - $this->Activity->duration()) / $this->Activity->duration(); return HTML::plusMinus(sprintf("%01.2f", $Difference), 2) . ' %'; }