Esempio n. 1
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 table with general records
     */
    private function displayRekorde()
    {
        foreach ($this->rekorde as $rekord) {
            echo '<table class="fullwidth zebra-style">';
            echo '<thead><tr><th colspan="11" class="l">' . $rekord['name'] . '</th></tr></thead>';
            echo '<tbody>';
            $output = false;
            $sports = DB::getInstance()->query($rekord['sportquery'])->fetchAll();
            $Request = DB::getInstance()->prepare($rekord['datquery']);
            foreach ($sports as $sport) {
                $Request->bindValue('sportid', $sport['id']);
                $Request->execute();
                $data = $Request->fetchAll();
                if (!empty($data)) {
                    $output = true;
                    echo '<tr class="r">';
                    echo '<td class="b l">' . Icon::getSportIconForGif($sport['img'], $sport['name']) . ' ' . $sport['name'] . '</td>';
                    $j = 0;
                    foreach ($data as $j => $dat) {
                        if ($rekord['speed']) {
                            $Pace = new Pace($dat['s'], $dat['distance'], SportFactory::getSpeedUnitFor($sport['id']));
                            $code = $Pace->valueWithAppendix();
                        } else {
                            $code = $dat['distance'] != 0 ? Distance::format($dat['distance']) : Duration::format($dat['s']);
                        }
                        echo '<td class="small"><span title="' . date("d.m.Y", $dat['time']) . '">
								' . Ajax::trainingLink($dat['id'], $code) . '
							</span></td>';
                    }
                    for (; $j < 9; $j++) {
                        echo HTML::emptyTD();
                    }
                    echo '</tr>';
                }
            }
            if (!$output) {
                echo '<tr><td colspan="11"><em>' . __('No data available') . '</em></td></tr>';
            }
            echo '</tbody>';
            echo '</table>';
        }
    }
    /**
     * Get fieldset for paces
     * @return \FormularFieldset
     */
    public function getFieldsetPaces()
    {
        $Table = '<table class="fullwidth zebra-style">
				<thead>
					<tr>
						<th>' . __('Name') . '</th>
						<th class="small">' . __('Pace') . '</th>
						<th class="small">' . __('Description') . '</th>
					</tr>
				</thead>
				<tbody>';
        $VDOT = new VDOT(Configuration::Data()->vdot());
        $PaceObject = new Runalyze\Activity\Pace(0, 1, SportFactory::getSpeedUnitFor(Configuration::General()->runningSport()));
        foreach ($this->getArrayForPaces() as $Pace) {
            $Table .= '<tr>
						<td class="b">' . $Pace['short'] . '</td>
						<td class=""><em>' . $PaceObject->setTime($VDOT->paceAt($Pace['limit-high'] / 100))->value() . '</em> - <em>' . $PaceObject->setTime($VDOT->paceAt($Pace['limit-low'] / 100))->value() . '</em>' . $PaceObject->appendix() . '</td>
						<td class="">' . $Pace['description'] . '</td>
					</tr>';
        }
        $Table .= '
				</tbody>
			</table>';
        $Fieldset = new FormularFieldset(__('Training paces'));
        $Fieldset->addBlock($Table);
        $Fieldset->addInfo(__('These paces are based on Jack Daniels\' recommendation.'));
        return $Fieldset;
    }
 /**
  * Initialize line-data-array for 'Tempo'
  * @param array $dat
  */
 private function initTempoData($dat)
 {
     $Pace = new Pace($dat['s_sum_with_distance'], $dat['distance'], SportFactory::getSpeedUnitFor($this->sportid));
     $text = $dat['s_sum_with_distance'] == 0 ? NBSP : $Pace->valueWithAppendix();
     $this->TempoData[] = array('i' => $dat['i'], 'text' => $text);
 }
 /**
  * Init calculations
  */
 protected function runCalculations()
 {
     if (!$this->PrognosisObject->isValid()) {
         return;
     }
     foreach ($this->Distances as $km) {
         $Prognosis = $this->PrognosisObject->inSeconds($km);
         $PB = new PersonalBest($km, DB::getInstance(), false);
         $PB->lookupWithDetails();
         $VDOTprognosis = new VDOT();
         $VDOTprognosis->fromPace($km, $Prognosis);
         $VDOTpb = new VDOT();
         $VDOTpb->fromPace($km, $PB->seconds());
         $PacePrognosis = new Pace($Prognosis, $km, SportFactory::getSpeedUnitFor(Configuration::General()->runningSport()));
         $PacePB = new Pace($PB->seconds(), $km, SportFactory::getSpeedUnitFor(Configuration::General()->runningSport()));
         $DateWithLink = Ajax::trainingLink($PB->activityId(), date('d.m.Y', $PB->timestamp()), true);
         $this->Prognoses[] = array('distance' => (new Distance($km))->stringAuto(), 'prognosis' => Duration::format($Prognosis), 'prognosis-pace' => $PacePrognosis->valueWithAppendix(), 'prognosis-vdot' => $VDOTprognosis->uncorrectedValue(), 'diff' => !$PB->exists() ? '-' : ($PB->seconds() > $Prognosis ? '+ ' : '- ') . Duration::format(abs(round($PB->seconds() - $Prognosis))), 'diff-class' => $PB->seconds() > $Prognosis ? 'plus' : 'minus', 'pb' => $PB->seconds() > 0 ? Duration::format($PB->seconds()) : '-', 'pb-pace' => $PB->seconds() > 0 ? $PacePB->valueWithAppendix() : '-', 'pb-vdot' => $PB->seconds() > 0 ? $VDOTpb->uncorrectedValue() : '-', 'pb-date' => $PB->seconds() > 0 ? $DateWithLink : '-');
     }
 }
    /**
     * Show prognosis for a given distance
     * @param double $distance
     */
    protected function showPrognosis($distance)
    {
        $PB = new PersonalBest($distance);
        $PB->lookupWithDetails();
        $PBTime = $PB->exists() ? Duration::format($PB->seconds()) : '-';
        $PBString = $PB->exists() ? Ajax::trainingLink($PB->activityId(), $PBTime, true) : $PBTime;
        $Prognosis = new Duration($this->Prognosis->inSeconds($distance));
        $Distance = new Distance($distance);
        $Pace = new Pace($Prognosis->seconds(), $distance, SportFactory::getSpeedUnitFor(Configuration::General()->runningSport()));
        echo '<p>
				<span class="right">
					' . sprintf(__('<small>from</small> %s <small>to</small> <strong>%s</strong>'), $PBString, $Prognosis->string(Duration::FORMAT_AUTO, 0)) . '
					<small>(' . $Pace->valueWithAppendix() . ')</small>
				</span>
				<strong>' . $Distance->stringAuto(true, 1) . '</strong>
			</p>';
    }
    /**
     * Get array for "Tempobereiche"
     */
    private function getPaceArray()
    {
        $speed_min = $this->Configuration()->value('lowest_pacegroup');
        $speed_max = $this->Configuration()->value('highest_pacegroup');
        $speed_step = $this->Configuration()->value('pacegroup_step');
        $ceil_corr = $speed_min % $speed_step;
        if ($this->sportid != Configuration::General()->runningSport()) {
            $MinMax = DB::getInstance()->query('
				SELECT
					MIN(`s`/`distance`) as `min`,
					MAX(`s`/`distance`) as `max`
				FROM `' . PREFIX . 'training`
				WHERE `sportid`=' . $this->sportid . ' AND ' . PREFIX . 'training.accountid="' . SessionAccountHandler::getId() . '" ' . $this->where_time . ' AND `distance`>0
			')->fetch();
            if (!empty($MinMax)) {
                $speed_min = round((double) $MinMax['max']);
                $speed_max = round((double) $MinMax['min']);
                $speed_step = $speed_min == $speed_max ? 1 : round(($speed_min - $speed_max) / 10);
                $ceil_corr = $speed_min == $speed_max ? 1 : $speed_min % $speed_step;
            }
        }
        $result = DB::getInstance()->query('
			SELECT ' . $this->getTimerIndexForQuery() . ' AS `timer`,
				COUNT(*) AS `num`,
				SUM(`distance`) AS `distance`,
				SUM(`s`) AS `s`,
				FLOOR( (`s`/`distance` - ' . $ceil_corr . ')/' . $speed_step . ')*' . $speed_step . ' + ' . $ceil_corr . ' AS `group`
			FROM `' . PREFIX . 'training`
			WHERE `sportid`=' . $this->sportid . ' AND ' . PREFIX . 'training.accountid="' . SessionAccountHandler::getId() . '" ' . $this->where_time . ' AND `distance`>0
			GROUP BY `group`, ' . $this->group_time . '
			ORDER BY `group` DESC, ' . $this->getTimerForOrderingInQuery() . ' ASC
		')->fetchAll();
        $speed_data = $this->emptyData;
        foreach ($result as $dat) {
            if ($this->sportid == Configuration::General()->runningSport()) {
                if ($dat['group'] > $speed_min) {
                    $dat['group'] = $speed_min;
                } else {
                    if ($dat['group'] < $speed_max) {
                        $dat['group'] = $speed_max;
                    }
                }
            }
            $this->setGroupData($speed_data, $dat);
            $this->setSumData($speed_data, $dat);
        }
        $speed_foreach = array();
        if (!empty($result)) {
            $Pace = new Pace(0, 1, SportFactory::getSpeedUnitFor($this->sportid));
            for ($speed = $speed_min; $speed > $speed_max - $speed_step; $speed -= $speed_step) {
                if ($speed <= $speed_max) {
                    $name = '<small>' . __('faster than') . '</small>&nbsp;' . $Pace->setTime($speed + $speed_step)->valueWithAppendix();
                } else {
                    if ($speed == $speed_min) {
                        $name = '<small>' . __('up to') . '</small>&nbsp;' . $Pace->setTime($speed)->valueWithAppendix();
                    } else {
                        $name = $Pace->setTime($speed + $speed_step)->value() . ' <small>' . __('to') . '</small>&nbsp;' . $Pace->setTime($speed)->valueWithAppendix();
                    }
                }
                $speed_foreach[] = array('name' => $name, 'id' => max($speed, $speed_max));
            }
        }
        return array('name' => __('Pace Zones') . '*', 'array' => $speed_data, 'foreach' => $speed_foreach);
    }