/** * 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()); } }
/** * 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; }
/** * @return string */ public function distance() { if ($this->Activity->distance() > 0) { return $this->Dataview->distance(); } return ''; }
/** * 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()); }
/** * Get gradient * @return string gradient in percent with percent sign */ public function gradientInPercent() { if ($this->Activity->distance() == 0) { return '-'; } return round($this->Activity->elevation() / $this->Activity->distance() / 10, 2) . ' %'; }
/** * Get percentage of last distance * @return int */ private function distanceComparisonPercentage() { if ($this->kmOfLastSet == 0) { return 0; } return round(100 * ($this->Activity->distance() - $this->kmOfLastSet) / $this->kmOfLastSet, 1); }
/** * Prognosis time by shape in seconds * @return int */ public function prognosisByShapeInSeconds() { $Prognosis = new Daniels(); $Prognosis->adjustVDOT(false); $Prognosis->setVDOT($this->Shape); return $Prognosis->inSeconds($this->Activity->distance()); }
/** * Calculate JD intensity * @return int */ public function calculateJDintensity() { JD\Intensity::setVDOTshape(Configuration::Data()->vdot()); JD\Intensity::setHRmax(Configuration::Data()->HRmax()); $Intensity = new JD\Intensity(); if ($this->knowsTrackdata() && $this->Trackdata->has(Model\Trackdata\Object::HEARTRATE) && $this->Trackdata->has(Model\Trackdata\Object::TIME)) { return $Intensity->calculateByHeartrate(new TimeSeries($this->Trackdata->heartRate(), $this->Trackdata->time())); } elseif ($this->Activity->hrAvg() > 0) { return $Intensity->calculateByHeartrateAverage($this->Activity->hrAvg(), $this->Activity->duration()); } else { return $Intensity->calculateByPace($this->Activity->distance(), $this->Activity->duration()); } }
/** * 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'); } }