Heating and Ventilation Control
/HV_showWeatherForecast
Keine Erläuterungen gefunden.
<?php /* published under GPL www.gnu.org/licenses/gpl.html */ include_once("HV_config.php"); $debug = FALSE; function HV_showWeatherForecast($weather,$path="./"){ global $debug; $today = date('Y-m-d'); $colNo = mergeWeatherForecasts($today,$path); $varNames = array_keys($colNo); if($debug){ echo "<p><aj>HV_showWeatherForecast</aj><br>"; for($i=0;$i<count($varNames);$i++){ echo $colNo[$varNames[$i]]." _".$varNames[$i]."_<br>"; } } $plot ="set term png size 800,300\n"; $plot.="set output 'weather.png'\n"; $plot.="set grid\n"; $plot.="set datafile missing '-999.00'\n"; $plot.="set key outside\n"; $plot.="set xdata time\n"; $plot.="set timefmt '%Y-%m-%dT%H'\n"; $plot.="set format x '%H'\n"; $plot.="set y2tics ('0' 0, '10' 0.1, '20' 0.2, '30' 0.3, '40' 0.4, '50' 0.5, '60' 0.6, '70' 0.7, '80' 0.8, '90' 0.9, '100' 1) textcolor rgb 'blue'\n"; $plot.="set yrange [-10:30]\n"; $plot.="set y2range [0:1]\n"; $plot.="set style line 2 lt 1 lc rgb '#ff0000' lw 1 pt 7 ps 1\n"; $plot.="set style line 3 lt 1 lc rgb '#00ffff' lw 1 pt 7 ps 0\n"; $plot.="set style line 4 lt 1 lc rgb '#fbbf16' lw 1 pt 7 ps 1\n"; $plot.="set style line 41 lt 1 lc rgb '#ffff00' lw 2 pt 7 ps 0\n"; $plot.="set style line 5 lt 1 lc rgb '#8b008b' lw 1 pt 7 ps 1\n"; $plot.="set style line 6 lt 1 lc rgb '#8b008b' lw 1 pt 7 ps 1\n"; $plot.="set style line 7 lt 1 lc rgb '#0000ff' lw 1 pt 7 ps 0\n"; $plot.="set style line 8 lt 1 lc rgb '#ff00ff' lw 1 pt 7 ps 1\n"; $plot.="set style line 9 lt 1 lc rgb '#000000' lw 3 pt 7 ps 1\n"; $scale = array(); $axis = array(); $lStyle = array(); $title = array(); $title["TAmb"] = "Temperatur [C]"; $scale["TAmb"] = 1; $lStyle["TAmb"] = 2; $axis["TAmb"] = "x1y1"; $title["x"] = "Feuchte [g/kg]"; $scale["x"] = 1; $lStyle["x"] = 3; $axis["x"] = "x1y1"; $title["I"] = "Sonne [%]"; $scale["I"] = 0.001; $lStyle["I"] = 4; $axis["I"] = "x1y2"; $title["clouds"] = "Wolken [%]"; $scale["clouds"] = 0.01; $lStyle["clouds"] = 41; $axis["clouds"] = "x1y2"; $title["phi"] = "Feuchte [%]"; $scale["phi"] = 0.01; $lStyle["phi"] = 6; $axis["phi"] = "x1y2"; $title["rain"] = "Niederschlag [0.1 mm/m2]"; $scale["rain"] = 0.1; $lStyle["rain"] = 7; $axis["rain"] = "x1y2"; $title["windMax"] = "Wind [km/h]"; $scale["windMax"] = 3.6/100; $lStyle["windMax"] = 8; $axis["windMax"] = "x1y2"; $title["storm"] = "Sturm [%]"; $scale["storm"] = 1; $lStyle["storm"] = 9; $axis["storm"] = "x1y2"; $pointintime = date('Y-m-d')."T".date('H'); $plot.=" #set arrow from '2018-10-13T23',1 to '2018-10-13T23',40 nohead lc rgb 'green'\n"; $plot.="set arrow from '".$pointintime."',second 0 to '".$pointintime."',second 1 nohead lw 2 lc rgb 'green'\n"; /* $plot.="plot 'weather.dat' u 1:4 ls 2 w lp ti 'Temperatur [C]',\\\n"; $plot.="'weather.dat' u 1:($11) axes x1y1 ls 3 w lp ti 'Feuchte [g/kg]',\\\n"; $plot.="'weather.dat' u 1:($2/1000) axes x1y2 ls 4 w lp ti 'Sonne [%]',\\\n"; $plot.="'weather.dat' u 1:($7/100) axes x1y2 ls 6 w lp ti 'Feuchte [%]',\\\n"; $plot.="'weather.dat' u 1:(10*$8) axes x1y1 ls 7 w l ti 'Niederschlag [0.1 mm/m2]',\\\n"; $plot.="'weather.dat' u 1:(3.6*$10/100) axes x1y2 ls 8 w l ti 'Wind [km/h]',\\\n"; $plot.="'weather.dat' u 1:($9-0.01) axes x1y2 ls 9 w l ti 'Sturm [%]'\n"; */ $path = ""; $plot.= "plot "; for($i=1; $i<count($varNames); $i++){ $vn = trim($varNames[$i]); $cn = $colNo[$varNames[$i]]+1; if( $vn!="storm" and isset($title[$vn]) ){ $plot.= "'".$path."weather.dat' u 1:($".$cn."*".$scale[$vn].") axes ".$axis[$vn]." ls ".$lStyle[$vn]." w lp ti '".$title[$vn]."',\\\n"; } } $vn = "storm"; $cn = $colNo["storm"]; $plot.= "'".$path."weather.dat' u 1:($".$cn."*".$scale[$vn]."-0.01) axes ".$axis[$vn]." ls ".$lStyle[$vn]." w lp ti '".$title[$vn]."'\n"; #$plot.="#pause -1\n"; #$plot.="replot\n"; $pid = fopen("weather.gp","w"); fputs($pid,$plot); fclose($pid); $cmd = "/usr/bin/gnuplot weather.gp"; exec($cmd, $output, $retVal); #echo"gp return: ".$retVal; #print_r($output); $weatherLogToday = date('Y-m')."/weather_".date('Y-m-d').".log"; if (file_exists($weatherLogToday)) { $updateTime=date("d F Y H:i:s.", filectime($weatherLogToday)); }else{ $updateTime="00:99"; } $weatherString ="\n<div class='weatherText'><p style='color:teal;'>Wettervorhersage von ".$updateTime." Uhr</p>\n"; $weatherString.="<table class='color'>\n"; $weatherString.="<tr><td style='color:teal;'>Temperatur: </td> <td style='color:teal;'>".sprintf("%3.1f ",$weather['TAmb'])." °C </td></tr>\n"; $weatherString.="<tr><td style='color:teal;'>spez. Feuchte:</td> <td style='color:teal;'>".sprintf("%3.1f ",$weather['x'])." g/kg </td></tr>\n"; $weatherString.="<tr><td style='color:teal;'>Sonnenschein: </td> <td style='color:teal;'>".sprintf("%3.1f ",$weather['I'])."W/m2 </td></tr>\n"; $weatherString.="<tr><td style='color:teal;'>Luftdruck: </td> <td style='color:teal;'>".sprintf("%3.1f ",$weather['p'])." kPa </td></tr>\n"; $weatherString.="<tr><td style='color:teal;'>rel. Feuchte: </td> <td style='color:teal;'>".sprintf("%3.1f ",$weather['phi'])." % </td></tr>\n"; $weatherString.="<tr><td style='color:teal;'>Niederschlag: </td> <td style='color:teal;'>".sprintf("%3.1f ",$weather['rain'])." mm/m2 </td></tr>\n"; $weatherString.="<tr><td style='color:teal;'>max. Wind: </td> <td style='color:teal;'>".sprintf("%3.1f ",$weather['windMax'])." m/s </td></tr>\n"; $weatherString.="</table>\n"; $weatherString.="</br></br><a href='https://www.dwd.de/DE/wetter/wetterundklima_vorort/hessen/offenbach/_node.html'>DWD.de > Offenbach</a>"; $weatherString.="</div>\n<div class='weatherFigure'>\n"; $weatherString.="<img src='weather.png' alt='aktuelles Wetter'>"; $weatherString.="</div>\n"; return $weatherString; } function HV_actualWeather($date,$hour,$minutes,$path="./"){ global $debug; if($debug){echo "<p><aj>HV_actualWeather</aj>: ".$date." ".$hour." ".$minutes."</p>";} /* read weather */ $month = substr($date,0,7); $file = $path.$month."/"."weather_".$date.".log"; $weatherStr=array(); if (file_exists($file)) { $sf=fopen($file,"r"); for($t=0;$t<=24;$t++){ $weatherStr[$t] = trim(fgets($sf,2048)); } #t fclose($sf); }else{ echo "<p>FILE ".$file." NOT FOUND</p>"; $weather=array(); $myTime=array(); } #fi #find the relevant lines and interpolate to the minute $varNames = explode("\t",$weatherStr[0]); for($v=0;$v<count($varNames);$v++){ $colNo[$varNames[$v]] = $v; } #v $actWeather = array(); for($t=1;$t<count($weatherStr);$t++){ $weather = explode("\t",$weatherStr[$t]); $thisHour = substr($weather[$colNo['#time']],0,2); if($t==23){ for($v=1;$v<count($varNames);$v++){ $actWeather[$varNames[$v]] = $weather[$colNo[$varNames[$v]]]; } }elseif(1*$thisHour > $hour){ $w = $minutes/60.0; for($v=1;$v<count($varNames);$v++){ $Tnext = $weather[$colNo[$varNames[$v]]]; $Tlast = $weatherLast[$colNo[$varNames[$v]]]; $actWeather[$varNames[$v]] = (1.0-$w)*$Tlast + $w*$Tnext; } #v break; } #fi $weatherLast = $weather; } #t if($debug){print_r($actWeather);} return $actWeather; } function mergeWeatherForecasts($today,$path="./"){ global $debug; if($debug){echo "<p><aj>mergeWeatherForecasts</aj>:</p>";} #Compose weather forecasts file names for the next days $month = substr($today,0,7); $wf[0] = $path.$month."/weather_".$today.".log"; $nday[0] = $today; for($d=1; $d<3; $d++){ $nday[$d] = date('Y-m-d', strtotime($today .' +'.$d.' day')); $month = substr($nday[$d],0,7); $wf[$d] = $path.$month."/weather_".$nday[$d].".log"; } #d #Read and merge data of next days to single data set $allWeather = array(); $t=-1; for($d=0; $d<count($wf); $d++){ $handle = fopen($wf[$d], "r"); if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { if($buffer[0]!=" #"){ $t++; $allWeather[$t] = $nday[$d]."T".$buffer; }elseif($buffer[0]==" #"){ $header = $buffer; } } #fi fclose($handle); } #fi } #d #Export merged weather data for plotting $fid = fopen("weather.dat","w"); fputs($fid,$header); for($t=0;$t<count($allWeather);$t++){ fputs($fid,$allWeather[$t]); } #t fclose($fid); if($debug){ print_r($wf); echo "<p>wrote weather.dat</p>"; echo count($allWeather)." lines of data<br>"; } $varNames = explode("\t",$header); $colNo = array(); for($i=0; $i<count($varNames); $i++){ $colNo[trim($varNames[$i])] = $i; } return $colNo; } /* testing $today = "2024-05-12"; mergeWeatherForecasts($today); */ ?>
python
php
Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.