コード例 #1
0
ファイル: Temperature.php プロジェクト: guancio/Runalyze
 /**
  * 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 '';
 }
コード例 #2
0
ファイル: TemperatureTest.php プロジェクト: Nugman/Runalyze
 public function testEmptyTemperatureAfterChanging()
 {
     $Temperature = new Temperature(13);
     $Temperature->setInPreferredUnit(null);
     $this->assertTrue($Temperature->isEmpty());
     $this->assertNull($Temperature->value());
     $this->assertNull($Temperature->celsius());
     $this->assertNull($Temperature->fahrenheit());
 }
コード例 #3
0
ファイル: Plot.Year.php プロジェクト: guancio/Runalyze
<?php

/**
 * Draw weather-plot
 * Call:   include 'Plot.Year.php'
 * @package Runalyze\Plugins\Stats
 */
use Runalyze\Activity\Temperature;
$Temperature = new Temperature();
$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);
コード例 #4
0
ファイル: Plot.Average.php プロジェクト: guancio/Runalyze
<?php

/**
 * Draw weather-plot
 * Call:   include 'Plot.Average.php'
 * @package Runalyze\Plugins\Stats
 */
use Runalyze\Util\Time;
use Runalyze\Activity\Temperature;
$Temperature = new Temperature();
$Months = array();
$Temperatures = array();
for ($m = 1; $m <= 12; $m++) {
    $Months[] = array($m - 1, Time::month($m, true));
    for ($y = START_YEAR, $n = date('Y'); $y <= $n; $y++) {
        $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);
コード例 #5
0
ファイル: MonthwiseTable.php プロジェクト: guancio/Runalyze
 /**
  * @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);
 }
コード例 #6
0
ファイル: class.Dataset.php プロジェクト: Nugman/Runalyze
 /**
  * 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 '';
 }
コード例 #7
0
    /**
     * 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>';
    }
コード例 #8
0
 /**
  * Add weather
  */
 protected function addWeather()
 {
     $WeatherObject = $this->Context->activity()->weather();
     if (!$WeatherObject->isEmpty()) {
         $WeatherIcon = $WeatherObject->condition()->icon();
         if ($this->Context->activity()->isNight()) {
             $WeatherIcon->setAsNight();
         }
         $Temperature = new Temperature($WeatherObject->temperature()->value());
         $Weather = new BoxedValue($WeatherObject->condition()->string(), '', __('Weather condition'), $WeatherIcon->code());
         $Weather->defineAsFloatingBlock('w50');
         $Temp = new BoxedValue($Temperature->string(false, false), $Temperature->unit(), __('Temperature'));
         $Temp->defineAsFloatingBlock('w50');
         $this->BoxedValues[] = $Weather;
         $this->BoxedValues[] = $Temp;
         if (!$WeatherObject->windSpeed()->isUnknown()) {
             $WindSpeed = new Box\WeatherWindSpeed($this->Context);
             $WindSpeed->defineAsFloatingBlock('w50');
             $this->BoxedValues[] = $WindSpeed;
         }
         if (!$WeatherObject->windDegree()->isUnknown()) {
             $WindDegree = new Box\WeatherWindDegree($this->Context);
             $WindDegree->defineAsFloatingBlock('w50');
             $this->BoxedValues[] = $WindDegree;
         }
         if (!$WeatherObject->humidity()->isUnknown()) {
             $Humidity = new Box\WeatherHumidity($this->Context);
             $Humidity->defineAsFloatingBlock('w50');
             $this->BoxedValues[] = $Humidity;
         }
         if (!$WeatherObject->pressure()->isUnknown()) {
             $Pressure = new Box\WeatherPressure($this->Context);
             $Pressure->defineAsFloatingBlock('w50');
             $this->BoxedValues[] = $Pressure;
         }
         if (!$WeatherObject->windSpeed()->isUnknown() && !$WeatherObject->temperature()->isUnknown() && $this->Context->activity()->distance() > 0 && $this->Context->activity()->duration() > 0) {
             $WindChill = new Box\WeatherWindChillFactor($this->Context);
             $WindChill->defineAsFloatingBlock('w50');
             $this->BoxedValues[] = $WindChill;
         }
     }
 }
コード例 #9
0
 /**
  * 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>';
 }
コード例 #10
0
 /**
  * Add weather
  */
 protected function addWeather()
 {
     if (!$this->Context->activity()->weather()->isEmpty()) {
         $Temperature = new Temperature($this->Context->activity()->weather()->temperature()->value());
         $Weather = new BoxedValue($this->Context->activity()->weather()->condition()->string(), '', __('Weather condition'), $this->Context->activity()->weather()->condition()->icon()->code());
         $Weather->defineAsFloatingBlock('w50');
         $Temp = new BoxedValue($Temperature->string(false, false), $Temperature->unit(), __('Temperature'));
         $Temp->defineAsFloatingBlock('w50');
         $this->BoxedValues[] = $Weather;
         $this->BoxedValues[] = $Temp;
     }
 }
コード例 #11
0
ファイル: WindChillFactor.php プロジェクト: rob-st/Runalyze
 /**
  * Format temperature as string
  * @param bool $withUnit [optional] show unit?
  * @param bool|int $decimals [optional] number of decimals
  * @return string
  */
 public function string($withUnit = true, $decimals = 0)
 {
     return $this->AdjustedTemperature->string($withUnit, $decimals);
 }
コード例 #12
0
 /**
  * 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>';
 }