public function mainpage()
 {
     $oTemplate = new Templater('overview.html');
     $oCurrent = $this->model->getCurrent();
     $oCurrent->Temperature = Formater::formatFloat($oCurrent->Temperature, 0);
     $oCurrent->Humidity = Formater::formatFloat($oCurrent->Humidity, 0);
     $oTemplate->add($oCurrent);
     $oTemplate->add('LastReadout', $oCurrent->Date);
     $oData = $this->model->getAverage(1);
     $oTemplate->add('1dTempAvg', Formater::formatFloat($oData->Temperature, 2));
     $oTemplate->add('1dHumidityAvg', Formater::formatFloat($oData->Humidity, 2));
     $oData = $this->model->getMin(1);
     $oTemplate->add('1dTempMin', Formater::formatFloat($oData->Temperature, 2));
     $oTemplate->add('1dHumidityMin', Formater::formatFloat($oData->Humidity, 2));
     $oData = $this->model->getMax(1);
     $oTemplate->add('1dTempMax', Formater::formatFloat($oData->Temperature, 2));
     $oTemplate->add('1dHumidityMax', Formater::formatFloat($oData->Humidity, 2));
     $oData = $this->model->getAverage(7);
     $oTemplate->add('7dTempAvg', Formater::formatFloat($oData->Temperature, 2));
     $oTemplate->add('7dHumidityAvg', Formater::formatFloat($oData->Humidity, 2));
     $oData = $this->model->getMin(7);
     $oTemplate->add('7dTempMin', Formater::formatFloat($oData->Temperature, 2));
     $oTemplate->add('7dHumidityMin', Formater::formatFloat($oData->Humidity, 2));
     $oData = $this->model->getMax(7);
     $oTemplate->add('7dTempMax', Formater::formatFloat($oData->Temperature, 2));
     $oTemplate->add('7dHumidityMax', Formater::formatFloat($oData->Humidity, 2));
     /*
      * External data from Open Weather Map
      */
     $oOpenWeatherMap = new \Model\OpenWeatherMap();
     $oCurrent = $oOpenWeatherMap->getCurrent();
     $oCurrent->Pressure = Formater::formatFloat($oCurrent->Pressure, 0);
     $oCurrent->WindSpeed = Formater::formatFloat($oCurrent->WindSpeed, 0);
     $oCurrent->WindDirection = Formater::formatFloat(round($oCurrent->WindDirection / 10) * 10, 0);
     $oTemplate->add($oCurrent);
     $oData = $oOpenWeatherMap->getAverage(1);
     $oTemplate->add('1dPressureAvg', Formater::formatFloat($oData->Pressure, 2));
     $oTemplate->add('1dWindAvg', Formater::formatFloat($oData->WindSpeed, 2));
     $oData = $oOpenWeatherMap->getMin(1);
     $oTemplate->add('1dPressureMin', Formater::formatFloat($oData->Pressure, 2));
     $oTemplate->add('1dWindMin', Formater::formatFloat($oData->WindSpeed, 2));
     $oData = $oOpenWeatherMap->getMax(1);
     $oTemplate->add('1dPressureMax', Formater::formatFloat($oData->Pressure, 2));
     $oTemplate->add('1dWindMax', Formater::formatFloat($oData->WindSpeed, 2));
     $oData = $oOpenWeatherMap->getAverage(7);
     $oTemplate->add('7dPressureAvg', Formater::formatFloat($oData->Pressure, 2));
     $oTemplate->add('7dWindAvg', Formater::formatFloat($oData->WindSpeed, 2));
     $oData = $oOpenWeatherMap->getMin(7);
     $oTemplate->add('7dPressureMin', Formater::formatFloat($oData->Pressure, 2));
     $oTemplate->add('7dWindMin', Formater::formatFloat($oData->WindSpeed, 2));
     $oData = $oOpenWeatherMap->getMax(7);
     $oTemplate->add('7dPressureMax', Formater::formatFloat($oData->Pressure, 2));
     $oTemplate->add('7dWindMax', Formater::formatFloat($oData->WindSpeed, 2));
     $proxyFactory = new \Factory\Proxy();
     $oTemplate->add('proxyCurrent', $proxyFactory->create('Current')->get());
     $oTemplate->add('proxyForecast', $proxyFactory->create('Forecast')->get());
     return (string) $oTemplate;
 }
 public function mainpage()
 {
     $oTemplate = new Templater('forecast.html');
     $proxyFactory = new \Factory\Proxy();
     $oTemplate->add('proxyForecast', $proxyFactory->create('Forecast')->get());
     return (string) $oTemplate;
 }
Beispiel #3
0
 /**
  * API methods return current condition based on internal readouts as well as OpenWeatherMap
  *
  * @param $aParams
  * @param $aRetVal
  */
 public function current($aParams, &$aRetVal)
 {
     $oModel = new \Model\Readout();
     $aRetVal = (array) $oModel->getCurrent();
     $oModel = new OpenWeatherMap();
     $aData = (array) $oModel->getCurrent();
     if ($aData) {
         $aData['ExternalDate'] = $aData['Date'];
         unset($aData['Date']);
         $aRetVal = array_merge($aRetVal, $aData);
     }
     /*
      * Get additional data
      */
     $proxyFactory = new \Factory\Proxy();
     $oCurrent = $proxyFactory->create('Current')->get();
     $jCurrent = json_decode($oCurrent);
     $aRetVal['WeatherIcon'] = $jCurrent->weather[0]->icon;
     $aRetVal['WeatherCode'] = $jCurrent->weather[0]->id;
     $aRetVal['TempMax'] = $jCurrent->main->temp_max;
     $aRetVal['TempMin'] = $jCurrent->main->temp_min;
     if ($jCurrent->clouds) {
         $aRetVal['Clouds'] = $jCurrent->clouds->all;
     } else {
         $aRetVal['Clouds'] = 0;
     }
     if (isset($jCurrent->rain) && isset($jCurrent->rain->{'3h'})) {
         $aRetVal['Rain'] = $jCurrent->rain->{'3h'};
     } else {
         $aRetVal['Rain'] = 0;
     }
     if (isset($jCurrent->rain) && isset($jCurrent->rain->{'1h'})) {
         $aRetVal['Rain'] = $jCurrent->rain->{'1h'};
     } else {
         $aRetVal['Rain'] = 0;
     }
     if (isset($jCurrent->snow) && isset($jCurrent->snow->{'3h'})) {
         $aRetVal['Snow'] = $jCurrent->snow->{'3h'};
     } else {
         $aRetVal['Snow'] = 0;
     }
     if (isset($jCurrent->snow) && isset($jCurrent->snow->{'1h'})) {
         $aRetVal['Snow'] = $jCurrent->snow->{'1h'};
     } else {
         $aRetVal['Snow'] = 0;
     }
     $oForecast = $proxyFactory->create('Forecast')->get();
     $jForecast = json_decode($oForecast);
     $aData = array();
     foreach ($jForecast->list as $iKey => $oDay) {
         $aData[$iKey]['Date'] = date('Y-m-d', $oDay->dt);
         $aData[$iKey]['WeekDay'] = date('w', $oDay->dt);
         $aData[$iKey]['WeatherIcon'] = $oDay->weather[0]->icon;
         $aData[$iKey]['WeatherCode'] = $oDay->weather[0]->id;
         $aData[$iKey]['TempMax'] = $oDay->temp->max;
         $aData[$iKey]['TempMin'] = $oDay->temp->min;
         $aData[$iKey]['TempDay'] = $oDay->temp->day;
         $aData[$iKey]['TempNight'] = $oDay->temp->night;
         $aData[$iKey]['Clouds'] = $oDay->clouds;
         $aData[$iKey]['Humidity'] = $oDay->humidity;
         $aData[$iKey]['Pressure'] = $oDay->pressure;
         $aData[$iKey]['WindSpeed'] = $oDay->speed;
         $aData[$iKey]['WindDirection'] = $oDay->deg;
         if (isset($oDay->rain)) {
             $aData[$iKey]['Rain'] = $oDay->rain;
         } else {
             $aData[$iKey]['Rain'] = 0;
         }
         if (isset($oDay->snow)) {
             $aData[$iKey]['Snow'] = $oDay->snow;
         } else {
             $aData[$iKey]['Snow'] = 0;
         }
     }
     $aRetVal['Forecast'] = $aData;
 }
Beispiel #4
0
<?php

use psDebug\Debug;
require_once 'common.php';
$aProxies = array('Forecast', 'Current');
$proxyFactory = new \Factory\Proxy();
foreach ($aProxies as $sProxy) {
    try {
        $proxyFactory->create($sProxy)->forceReload();
    } catch (\Exception $e) {
        Debug::cThrow(null, $e, array());
    }
}