$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.')); } $Plot->outputJavaScript();
/** * @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); }
/** * Display month-table for temperature */ private function displayMonthTableTemp() { $Temperature = new Temperature(); echo '<tr class="top-spacer"><td>' . $Temperature->unit() . '</td>'; $temps = DB::getInstance()->query(' SELECT AVG(`temperature`) as `temp`, ' . $this->getTimerIndexForQuery() . ' as `m` FROM `' . PREFIX . 'training` WHERE `temperature` IS NOT NULL ' . $this->getSportAndYearDependenceForQuery() . ' GROUP BY ' . $this->getTimerIndexForQuery() . ' ORDER BY ' . $this->getTimerForOrderingInQuery() . ' ASC LIMIT 12')->fetchAll(); $i = 1; if (!empty($temps)) { foreach ($temps as $temp) { for (; $i < $temp['m']; $i++) { echo HTML::emptyTD(); } $i++; echo '<td>' . $Temperature->format(round($temp['temp']), true, false) . '</td>'; } for (; $i <= 12; $i++) { echo HTML::emptyTD(); } } else { echo HTML::emptyTD(12); } echo '</tr>'; }
/** * 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; } } }
/** * 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; } }
/** * Label for value * @return string */ public function unit() { return $this->AdjustedTemperature->unit(); }