Heating and Ventilation Control
/EM_plot
Keine Erläuterungen gefunden.
<?php function plotRoom($room,$date,$path,$parameter,$relayDict){ $debug = FALSE; $Tmin = 10; $Tmax = 30; $fileT = $path.$date."_T.dat"; $filePhi = $path.$date."_phi.dat"; $fileP = $path.$date."_p.dat"; $fileR = $path.$date."_relay.dat"; #determine column for room $cmd = "head -1 ".$fileT; exec($cmd,$output); if ($debug){print_r($output);} $keys = explode("\t",$output[0]); for($k=0;$k<count($keys);$k++){ if($keys[$k]==$room){$col=$k+1;} } #identdfy correspondign relay $relayName = $relayDict[$room]; $cmd = "head -1 ".$fileR; exec($cmd,$output); if ($debug){print_r($output);} $keys = explode("\t",$output[1]); for($k=0;$k<count($keys);$k++){ if($keys[$k]==$relayName){$relCol=$k+1;} } #compose GnuPlot $plot = "set grid\n"; $plot.= "set datafile missing '-999.00'\n"; $plot.= "set xdata time\n"; $plot.= "set timefmt '%H:%M'\n"; $plot.= "set format x '%H'\n"; $plot.= "set xrange ['00:00':'24:00']\n"; $plot.= "set yrange [".$Tmin.":".$Tmax."]\n"; $plot.= "set y2range [0:110]\n"; $plot.= "set y2tics ('20' 20, '40' 40, '60' 60, '80' 80, '100' 100) textcolor rgb '#800080'\n"; $plot.= "set ylabel 'Temperatur'\n"; $plot.= "set title '".$room." ".$date."'\n"; $plot.= "set key bottom right\n"; $plot.= "set style line 1 lt 1 lc rgb '#ff0000' lw 2 pt 7 ps 1\n"; $plot.= "set style line 2 lt 1 lc rgb '#ff9900' lw 2 pt 7 ps 1\n"; $plot.= "set style line 3 lt 1 lc rgb '#ffff00' lw 2 pt 7 ps 1\n"; $plot.= "set style line 4 lt 1 lc rgb '#00ff00' lw 2 pt 7 ps 1\n"; $plot.= "set style line 5 lt 1 lc rgb '#0000ff' lw 2 pt 7 ps 1\n"; $plot.= "set style line 6 lt 1 lc rgb '#800080' lw 2 pt 7 ps 1\n"; $plot.= "set style line 7 lt 1 lc rgb '#c0c0c0' lw 2 pt 7 ps 1\n"; #hysteresis band in relative graph coordinates $borderDown = $parameter[$room]-$parameter['hysteresis']; $borderUp = $parameter[$room]+$parameter['hysteresis']; $plot.= "set object 1 rect from graph 0, first ".$borderDown." to graph 1, first ".$borderUp." back fc rgb '#fff6d5'\n"; $plot.= "set arrow from graph 0, first ".$parameter[$room]." to graph 1, first ".$parameter[$room]." nohead lc rgb '#ff9900'\n"; $plot.= "set term svg\n"; $plot.= "set output 'HVC/LogDir/log.svg'\n"; $plot.= "u=0.; v=0.\n"; $plot.= "plot '".$fileP."' u 1:($".$col."/10) w lp ls 7 axis x1y2 ti 'Luftdruck',\\\n"; $plot.= " '".$fileR."' u 1:(30*$".$relCol."+2) w steps axis x1y2 ls 5 ti 'Heizung',\\\n"; $plot.= " '".$fileR."' u 1:(30*$".$relCol."+2) w p axis x1y2 ls 5 notitle,\\\n"; $plot.= " '".$filePhi."' u 1:".$col." w lp ls 6 axis x1y2 ti 'Feuchte',\\\n"; $plot.= " '".$fileT."' u 1:".$col." w lp ls 1 ti 'Temperatur'\n"; $pid = fopen("HVC/log.gp","w"); fputs($pid,$plot); fclose($pid); #execute Gnuplot exec("gnuplot HVC/log.gp"); #display figure $html = "<div style='text-align:left;'>\n"; $html.= "<img src='HVC/LogDir/log.svg' alt='Logfile' />\n"; $html.= "</div>\n"; return $html; } function plotAll($type,$date,$path,$parameter,$relayDict){ $debug = False; if($type=="T"){ $file = $path.$date."_T.dat"; $myAxis = "axis x1y1"; $plotType = "w lp"; }else if($type=="phi"){ $file = $path.$date."_phi.dat"; $myAxis = "axis x1y1"; $plotType = "w lp"; }else if($type=="p"){ $file = $path.$date."_p.dat"; $myAxis = "axis x1y1"; $plotType = "w lp"; }else if($type=="relay"){ $file = $path.$date."_relay.dat"; $file2 = $path.$date."_T.dat"; $myAxis = "axis x1y1"; $plotType = "w steps"; } #determine columns $cmd = "head -1 ".$file; exec($cmd,$output); if ($debug){print_r($output);} $keys = explode("\t",$output[0]); $cols = array(); $sensor = array(); $i=-1; if($type=="relay"){ $cmd = "head -1 ".$file2; exec($cmd,$output); if ($debug){print_r($output[1]);} $sensNames = explode("\t",$output[1]); #add relais without sensor array_push($sensNames,"LC1"); $relayDict["LC1"]="LC1"; for($s=0;$s<count($sensNames);$s++){ $relayName = $relayDict[$sensNames[$s]]; for($k=0;$k<count($keys);$k++){ if($relayName == $keys[$k]){ $i++; $colNo[$i] = $k+1; $sensor[$i] = $relayName; } } } }else{ for($k=0;$k<count($keys);$k++){ $thisKey = $keys[$k]; #drop time column if($thisKey[0]!=" #"){ $i++; $colNo[$i] = $k+1; $sensor[$i] = $thisKey; } } } if ($debug){ echo "<p>colNo"; print_r($colNo); echo "<p>sensor"; print_r($sensor); } #compose GnuPlot $plot = "set grid\n"; $plot.= "set datafile missing '-999.00'\n"; $plot.= "set xdata time\n"; $plot.= "set timefmt '%H:%M'\n"; $plot.= "set format x '%H'\n"; $plot.= "set xrange ['00:00':'24:00']\n"; #$plot.= "set yrange [".$Tmin.":".$Tmax."]\n"; if($type=="relay"){ $plot.= "set yrange [-0.1:1.1]\n"; $plot.= "set ytics ('off' 0, 'on' 1) textcolor rgb '#800080'\n"; } $plot.= "set ylabel '".$type."'\n"; $plot.= "set title '".$type." ".$date."'\n"; #$plot.= "set key bottom right\n"; $plot.= "set key outside below horizontal\n"; $plot.= "set style line 1 lt 1 lc rgb '#ff0000' lw 2 pt 7 ps 1\n"; $plot.= "set style line 2 lt 1 lc rgb '#ff9900' lw 2 pt 7 ps 1\n"; $plot.= "set style line 3 lt 1 lc rgb '#ffff00' lw 2 pt 7 ps 1\n"; $plot.= "set style line 4 lt 1 lc rgb '#00ff00' lw 2 pt 7 ps 1\n"; $plot.= "set style line 5 lt 1 lc rgb '#0000ff' lw 2 pt 7 ps 1\n"; $plot.= "set style line 6 lt 1 lc rgb '#800080' lw 2 pt 7 ps 1\n"; $plot.= "set style line 7 lt 1 lc rgb '#c0c0c0' lw 2 pt 7 ps 1\n"; $plot.= "set style line 8 lt 1 lc rgb '#ff0066' lw 2 pt 7 ps 1\n"; $plot.= "set style line 9 lt 1 lc rgb '#00ffff' lw 2 pt 7 ps 1\n"; $plot.= "set style line 10 lt 1 lc rgb '#008080' lw 2 pt 7 ps 1\n"; $plot.= "set style line 11 lt 1 lc rgb '#000080' lw 2 pt 7 ps 1\n"; $plot.= "set style line 12 lt 1 lc rgb '#800080' lw 2 pt 7 ps 1\n"; $plot.= "set term svg\n"; $plot.= "set output 'HVC/LogDir/log.svg'\n"; $plot.= "u=0.; v=0.\n"; if($type=="relay"){ $offset = 0.05; }else{ $offset = 0.0; } $plot.= "plot '".$file."' u 1:($".$colNo[0]."+".$offset.") ".$plotType." ls 1 ".$myAxis." ti '".$sensor[0]."'"; for($c=1;$c<count($colNo);$c++){ $cc=$c+1; if($type=="relay"){ $offset = 0.05 - 0.01*$c; } $plot.= ",\\\n '".$file."' u 1:($".$colNo[$c]."+".$offset.") ".$plotType." ls ".$cc." ".$myAxis." ti '".$sensor[$c]."'"; } $pid = fopen("HVC/log.gp","w"); fputs($pid,$plot); fclose($pid); #execute Gnuplot exec("gnuplot HVC/log.gp"); #display figure $html = "<div style='text-align:left;'>\n"; $html.= "<img src='HVC/LogDir/log.svg' alt='Logfile' />\n"; $html.= "</div>\n"; return array($html,$sensor); } ?>
python
php
Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.