Example #1
0
 public function testStaticMethod()
 {
     Configuration::General()->temperatureUnit()->set(TemperatureUnit::CELSIUS);
     $unit = ' ' . Configuration::General()->TemperatureUnit()->unit();
     $this->assertEquals('10.0' . $unit, Temperature::format(10, true, 1));
     $this->assertEquals('12.35' . $unit, Temperature::format(12.3456, true, 2));
 }
Example #2
0
 /**
  * Get string to display this dataset value
  * @param \Runalyze\Dataset\Context $context
  * @return string
  */
 public function stringFor(Context $context)
 {
     if (!$context->activity()->weather()->temperature()->isUnknown() && !($context->hasSport() && !$context->sport()->isOutside())) {
         return \Runalyze\Activity\Temperature::format($context->activity()->weather()->temperature()->value(), true, false);
     }
     return '';
 }
Example #3
0
$Year = (int) $_GET['y'];
$Temperatures = array();
$Query = '
	SELECT
		time*1000 as time,
		DAYOFYEAR(FROM_UNIXTIME(`time`)) as `d`,
		AVG(`temperature`) as `temp`
	FROM `' . PREFIX . 'training`
	WHERE
		!ISNULL(`temperature`) AND
		`time` BETWEEN UNIX_TIMESTAMP(\'' . (int) $Year . '-01-01\') AND UNIX_TIMESTAMP(\'' . ((int) $Year + 1) . '-01-01\')-1
	GROUP BY `d`
	ORDER BY `d` ASC';
$Data = DB::getInstance()->query($Query)->fetchAll();
foreach ($Data as $dat) {
    $Temperatures[$dat['time']] = $Temperature->format((int) $dat['temp'], false);
}
$Plot = new Plot("year" . $Year, 780, 240);
$Plot->Data[] = array('label' => __('Temperatures') . ' ' . $Year, 'data' => $Temperatures);
$Plot->setMarginForGrid(5);
$Plot->setXAxisAsTime();
$Plot->setXAxisLimitedTo($Year);
$Plot->addYAxis(1, 'left');
$Plot->addYUnit(1, $Temperature->unit(), 0);
$Plot->setYTicks(1, 5, 0);
$Plot->addThreshold('y', 0);
$Plot->addMarkingArea('y', -99, 0);
$Plot->showPoints(2);
$Plot->smoothing(false);
if (empty($Data)) {
    $Plot->raiseError(__('No data available.'));
Example #4
0
        $Temperatures[$y] = array(null, null, null, null, null, null, null, null, null, null, null, null);
    }
}
$Query = '
	SELECT
		YEAR(FROM_UNIXTIME(`time`)) as `y`,
		MONTH(FROM_UNIXTIME(`time`)) as `m`,
		AVG(`temperature`) as `temp`
	FROM `' . PREFIX . 'training`
	WHERE
		!ISNULL(`temperature`)
	GROUP BY `y`, `m`
	ORDER BY `y` ASC, `m` ASC';
$Data = DB::getInstance()->query($Query)->fetchAll();
foreach ($Data as $dat) {
    $Temperatures[$dat['y']][$dat['m'] - 1] = $Temperature->format((int) $dat['temp'], false);
}
$Plot = new Plot("average", 780, 240);
for ($y = START_YEAR, $n = date('Y'); $y <= $n; $y++) {
    if (min($Temperatures[$y]) != null || max($Temperatures[$y]) != null) {
        $Plot->Data[] = array('label' => $y, 'data' => $Temperatures[$y]);
    }
}
$Plot->setMarginForGrid(5);
$Plot->setXLabels($Months);
$Plot->addYAxis(1, 'left');
$Plot->addYUnit(1, $Temperature->unit(), 1);
$Plot->setYTicks(1, 5, 0);
$Plot->addThreshold('y', 0);
$Plot->addMarkingArea('y', -99, 0);
$Plot->lineWithPoints();
Example #5
0
 /**
  * @return array
  */
 protected function generateDataForAverageTemperature()
 {
     $Temperature = new Temperature();
     $Statement = $this->createStatementToFetchAverageTemperatures();
     $data = array();
     while ($row = $Statement->fetch()) {
         $data[$row['m']] = $Temperature->format(round($row['temp']));
     }
     return array($Temperature->unit() => $data);
 }
Example #6
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 table for clothes
     */
    private function displayClothesTable()
    {
        /*if (!$this->Configuration()->value('for_clothes'))
        		return;*/
        echo '<table class="fullwidth zebra-style">
			<thead><tr>
				<th></th>
				<th>' . __('Temperatures') . '</th>
				<th>&Oslash;</th>
				<th colspan="2"></th>
				<th>' . __('Temperatures') . '</th>
				<th>&Oslash;</th>
				<th colspan="2"></th>
				<th>' . __('Temperatures') . '</th>
				<th>&Oslash;</th>
			</tr></thead>';
        echo '<tr class="r">';
        $EquipmentQuery = DB::getInstance()->query('SELECT
				AVG(`temperature`) as `avg`,
				MAX(`temperature`) as `max`,
				MIN(`temperature`) as `min`,
				eq.equipmentid
			FROM `' . PREFIX . 'training`
			LEFT JOIN runalyze_activity_equipment eq ON id=eq.activityid
			WHERE eq.activityid IS NOT NULL GROUP BY eq.equipmentid
				' . $this->getSportAndYearDependenceForQuery())->fetchAll();
        $EquipmentsTemperatures = array();
        foreach ($EquipmentQuery as $Equipment) {
            $EquipmentsTemperatures[$Equipment['equipmentid']] = $Equipment;
        }
        $i = 0;
        if (!empty($this->Equipment)) {
            foreach ($this->Equipment as $equipment) {
                echo $i % 3 == 0 ? '</tr><tr class="r">' : '<td>&nbsp;&nbsp;</td>';
                echo '<td class="l">' . $equipment->name() . '</td>';
                if (isset($EquipmentsTemperatures[$equipment->id()])) {
                    $Temperatures = $EquipmentsTemperatures[$equipment->id()];
                    echo '<td>' . Temperature::format($Temperatures['min'], true) . ' ' . __('to') . ' ' . Temperature::format($Temperatures['max'], true) . '</td>';
                    echo '<td>' . Temperature::format(round($Temperatures['avg']), true) . '</td>';
                } else {
                    echo '<td colspan="2" class="c"><em>-</em></td>';
                }
                $i++;
            }
        }
        for (; $i % 3 != 2; $i++) {
            echo HTML::emptyTD(3);
        }
        echo '</tr>';
        echo '</table>';
    }
 /**
  * Display extreme trainings
  */
 protected function displayExtremeTrainings()
 {
     $hot = DB::getInstance()->query('SELECT `temperature`, `id`, `time` FROM `' . PREFIX . 'training` WHERE `temperature` IS NOT NULL ' . $this->getSportAndYearDependenceForQuery() . ' AND accountid = ' . SessionAccountHandler::getId() . ' ORDER BY `temperature` DESC LIMIT 5')->fetchAll();
     $cold = DB::getInstance()->query('SELECT `temperature`, `id`, `time` FROM `' . PREFIX . 'training` WHERE `temperature` IS NOT NULL ' . $this->getSportAndYearDependenceForQuery() . ' AND accountid = ' . SessionAccountHandler::getId() . ' ORDER BY `temperature` ASC LIMIT 5')->fetchAll();
     foreach ($hot as $i => $h) {
         $hot[$i] = Temperature::format($h['temperature'], true) . ' ' . __('on') . ' ' . Ajax::trainingLink($h['id'], date('d.m.Y', $h['time']));
     }
     foreach ($cold as $i => $c) {
         $cold[$i] = Temperature::format($c['temperature'], true) . ' ' . __('on') . ' ' . Ajax::trainingLink($c['id'], date('d.m.Y', $c['time']));
     }
     echo '<p>';
     echo '<strong>' . __('Hottest activities') . ':</strong> ';
     echo (empty($hot) ? __('none') : implode(', ', $hot)) . '<br>';
     echo (empty($hot) ? __('none') : '<strong>' . __('Coldest activities')) . ':</strong> ';
     echo implode(', ', $cold) . '<br>';
     echo '</p>';
 }
 /**
  * Display table body
  */
 protected function displayBody()
 {
     echo '<tbody><tr class="r">';
     $Statement = $this->createStatement();
     $i = 0;
     while ($data = $Statement->fetch()) {
         echo $i % 3 == 0 ? '<tr class="r">' : '<td>&nbsp;&nbsp;</td>';
         echo '<td class="l">' . $data['name'] . '</td>';
         echo '<td>' . Temperature::format($data['min'], true) . ' ' . __('to') . ' ' . Temperature::format($data['max'], true) . '</td>';
         echo '<td>' . Temperature::format(round($data['avg']), true) . '</td>';
         echo ++$i % 3 == 0 ? '</tr>' : '';
     }
     if ($i % 3 != 0) {
         echo '<td colspan="' . 3 * (3 - $i % 3) . '">&nbsp;</td></tr>';
     } elseif (empty($data)) {
         echo '<td colspan="11" class="c"><em>' . __('No data found.') . '</em></td>';
     }
     echo '</tbody>';
 }