Ejemplo n.º 1
0
    /**
     * 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');
        }
    }
Ejemplo n.º 2
0
 /**
  * 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());
     }
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * @return string
  */
 public function distance()
 {
     if ($this->Activity->distance() > 0) {
         return $this->Dataview->distance();
     }
     return '';
 }
Ejemplo n.º 5
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());
 }
Ejemplo n.º 6
0
 /**
  * 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) . ' %';
 }
Ejemplo n.º 7
0
 /**
  * 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);
 }
Ejemplo n.º 8
0
 /**
  * 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());
 }
Ejemplo n.º 9
0
 /**
  * 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());
     }
 }
Ejemplo n.º 10
0
    /**
     * 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');
        }
    }