Hamburger Hamburger

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

1/HvcLightControl.py
2/HvcHCSR04ultrasonic.py
3/HvcPV.py
4/HvcMotorDriver.py
5/HvcRollerShutter.py
6/manGenMqttMap.py
7/HvcReadSPI.py
8/HvcMqtt.py
9/HvcTables.py
10/HvcMain.py
11/HvcSetGPIO.py
12/HvcWifiRelay.py
13/HvcOperationMode.py
14/HvcControl.py
15/HvcRaw2phys.py
16/HvcWeather.py
17/HvcOneWire.py
18/makeDoc.py
19/HvcFronius.py
20/EnergyManager.py
21/HvcSendI2C.py

php

1/HV_colorMap.php
2/HV_Admin_Login.php
3/HV_readOperationState.php
4/HV_setParameters.php
5/HV_config.php
6/EM_handleJSON.php
7/index.php
8/readFilenames.php
9/HV_restart.php
10/HV_moveGate.php
11/HV_showLog.php
12/HV_RollerShutter.php
13/EM_editParameter.php
14/HV_serviceLog.php
15/HV_H2Olevel.php
16/HV_TempCal.php
17/HV_Fronius.php
18/EM_plot.php
19/readNamedData.php
20/HV_composeH2Oplot.php
21/HVdoc.php
22/HV_showWeatherForecast.php
23/HV_showHouse.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.