Speed now optimized for weak hardware like the NLSU2. Improvement is more than 50 percent.

git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@104 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
martinhaas
2007-10-23 19:42:09 +00:00
parent 8139f33507
commit f34719bc26
11 changed files with 304 additions and 160 deletions

View File

@@ -22,25 +22,6 @@ setlocale (LC_ALL, 'de_DE.utf8');
$_SESSION["arraydata"] = array();
$im = ImageCreateTrueColor($imgmaxxfht,$imgmaxyfht);
$black = ImageColorAllocate($im, 0, 0, 0);
$bg1p = ImageColorAllocate($im, 110,148,183);
$bg2p = ImageColorAllocate($im, 175,198,219);
$bg3p = ImageColorAllocate($im, $fontcol_grap_R,$fontcol_grap_G,$fontcol_grap_B);
$white = ImageColorAllocate($im, 255, 255, 255);
$gray= ImageColorAllocate($im, 133, 133, 133);
#$lightgray= ImageColorAllocate($im, 200, 198, 222);
$red = ImageColorAllocate($im, 255, 0, 0);
$green = ImageColorAllocate($im, 0, 255, 0);
$yellow= ImageColorAllocate($im, 255, 255, 0);
$lightyellow= ImageColorAllocate($im, 255, 247,222 );
$orange= ImageColorAllocate($im, 255, 230, 25);
$actuatorcolor = ImageColorAllocate($im, $actR, $actG, $actB);
$desiredcolor = ImageColorAllocate($im, $desR, $desG, $desB);
ImageFill($im, 0, 0, $bg2p);
ImageRectangle($im, 0, 0, $imgmaxxfht-1, $imgmaxyfht-1, $white);
$array = file($file);
$oldmin=0; //only the data from every 10min
@@ -48,10 +29,11 @@ setlocale (LC_ALL, 'de_DE.utf8');
$actuator="00%";
$actuator_date="unknown";
$counter=count($array);
$arraydesired=array();
$arrayactuator=array();
#echo $counter; exit;
#Logrotate
if ((($logrotateFHTlines+200) < $counter) and ($logrotate == 'yes')) LogRotate($array,$file,$logrotateFHTlines);
@@ -77,7 +59,50 @@ setlocale (LC_ALL, 'de_DE.utf8');
}
}
$resultreverse = array_reverse($_SESSION["arraydata"]);
#if the expected graphic alreay exist then do not redraw the picture
$savefile=$AbsolutPath."/tmp/FHT.".$drawfht.".log.".$resultreverse[0][0].".png";
if (file_exists($savefile)) {
$im2 = @ImageCreateFromPNG($savefile);
header("Content-type: image/png");
imagePng($im2);
exit; # ;-)))
}
else #delete old pngs
{
$delfile=$AbsolutPath."/tmp/FHT.".$drawfht.".log.*.png";
foreach (glob($delfile) as $filename) {
unlink($filename);
}
}
$im = ImageCreateTrueColor($imgmaxxfht,$imgmaxyfht);
$black = ImageColorAllocate($im, 0, 0, 0);
$bg1p = ImageColorAllocate($im, 110,148,183);
$bg2p = ImageColorAllocate($im, 175,198,219);
$bg3p = ImageColorAllocate($im, $fontcol_grap_R,$fontcol_grap_G,$fontcol_grap_B);
$white = ImageColorAllocate($im, 255, 255, 255);
$gray= ImageColorAllocate($im, 133, 133, 133);
#$lightgray= ImageColorAllocate($im, 200, 198, 222);
$red = ImageColorAllocate($im, 255, 0, 0);
$green = ImageColorAllocate($im, 0, 255, 0);
$yellow= ImageColorAllocate($im, 255, 255, 0);
$lightyellow= ImageColorAllocate($im, 255, 247,222 );
$orange= ImageColorAllocate($im, 255, 230, 25);
$actuatorcolor = ImageColorAllocate($im, $actR, $actG, $actB);
$desiredcolor = ImageColorAllocate($im, $desR, $desG, $desB);
ImageFill($im, 0, 0, $bg2p);
ImageRectangle($im, 0, 0, $imgmaxxfht-1, $imgmaxyfht-1, $white);
$reversedesired = array_reverse($arraydesired);
$reverseactuator = array_reverse($arrayactuator);
$xold=$imgmaxxfht;
@@ -158,19 +183,13 @@ setlocale (LC_ALL, 'de_DE.utf8');
ImageTTFText ($im, $fontsize, 0, $imgmaxxfht-230-$XcorrectDate, 23, $txtcolor, $fontttf, $text);
#$text=$desired_date;
#ImageTTFText ($im, $fontsize, 0, $imgmaxxfht-127-$XcorrectDate, 23, $txtcolor, $fontttf, $text);
$text="Actuator: $actuator";
ImageTTFText ($im, $fontsize, 0, $imgmaxxfht-230-$XcorrectDate, 33, $txtcolor, $fontttf, $text);
#$text=$actuator_date;
#ImageTTFText ($im, $fontsize, 0, $imgmaxxfht-127-$XcorrectDate, 33, $txtcolor, $fontttf, $text);
$text=$resultreverse[0][0];
ImageTTFText ($im, $fontsize, 0, $imgmaxxfht-127, 13, $txtcolor, $fontttf, $text);
#ImageTTFText ($im, $fontsize, 0, $imgmaxxfht-127-$XcorrectDate, 13, $txtcolor, $fontttf, $text);
imagePng($im,$savefile);
header("Content-type: image/png");
imagePng($im);
@@ -195,4 +214,6 @@ function show_error($file,$drawfht,$imgmaxxfht,$imgmaxyfht)
exit;
}
?>

View File

@@ -11,6 +11,35 @@ include "../config.php";
$datefs20=$_GET['datefs20'];
$room=$_GET['room'];
## do we really need a new graphic??
#$execorder=$tailpath.' -1 '.$file;
#exec($execorder,$tail1);
#$parts = explode(" ", $tail1[0]);
#$date=$parts[0];
$savefile=$AbsolutPath."/tmp/FS20.".$drawfs20.".log.".$datefs20.".png";
if (file_exists($savefile)) {
$im2 = @ImageCreateFromPNG($savefile);
header("Content-type: image/png");
imagePng($im2);
exit; # ;-)))
}
else #delete old pngs
{
$delfile=$AbsolutPath."/tmp/FS20.".$drawfs20.".log.*.png";
foreach (glob($delfile) as $filename) {
unlink($filename);
}
}
$im = ImageCreateTrueColor($imgmaxxfs20,$imgmaxyfs20);
$black = ImageColorAllocate($im, 0, 0, 0);
$bg1p = ImageColorAllocate($im, 110,148,183);
@@ -86,6 +115,7 @@ include "../config.php";
if ($room != '') {ImageTTFText ($im, 7, 0, 5, 26, $txtcolor, $fontttf, $txtroom.$room);};
imagePng($im,$savefile);
header("Content-type: image/png");
imagePng($im);
?>

View File

@@ -71,7 +71,7 @@ break;
$gplotmain="
set ylabel 'Temperature (Celsius)'
set y2label 'Humidity (%)'
plot '$logfile' using 1:4 axes x1y1 title 'Temperature' with lines lw 3,\
plot '$logfile' using 1:4 axes x1y1 title 'Temperature' with lines lw 2,\
'$logfile' using 1:6 axes x1y2 title 'Rel. Humidity (%)' with lines
";
break;
@@ -89,7 +89,7 @@ EOD;
$gplotmain="
set ylabel 'Temperature (Celsius)'
set y2label 'Humidity (%)'
plot '$logfile' using 1:4 axes x1y1 title 'Temperature' with lines lw 3,\
plot '$logfile' using 1:4 axes x1y1 title 'Temperature' with lines lw 2,\
'$logfile' using 1:6 axes x1y2 title 'Rel. Humidity (%)' with lines
";
break;
@@ -118,7 +118,7 @@ EOD;
$gplotmaintmp = <<<EOD
plot "< awk '/measured/{print $1, $4}' $logfile"\
using 1:2 axes x1y1 title 'Measured temperature' with lines lw 3,\
using 1:2 axes x1y1 title 'Measured temperature' with lines lw 2,\
"< awk '/actuator/{print $1, $4+0}' $logfile"\
using 1:2 axes x1y2 title 'Actuator (%)' with steps lw 1,\
"< awk '/desired/{print $1, $4}' $logfile"\
@@ -128,7 +128,7 @@ EOD;
$gplotmainonlymeasured = <<<EOD
plot "< awk '/measured/{print $1, $4}' $logfile"\
using 1:2 axes x1y1 title 'Measured temperature' with lines lw 3
using 1:2 axes x1y1 title 'Measured temperature' with lines lw 2
EOD;
$gplotmain=$gplotmain.$gplotmaintmp;
$gplotmain2=$gplotmain2.$gplotmainonlymeasured;
@@ -137,7 +137,7 @@ EOD;
Case HMS100T: ############################################
$gplotmain="
set ylabel 'Temperature (Celsius)'
plot '$logfile' using 1:4 axes x1y1 title 'Temperature' with lines lw 3
plot '$logfile' using 1:4 axes x1y1 title 'Temperature' with lines lw 2
";
break;
@@ -147,7 +147,7 @@ $gplotmain=<<<EOD
set size 1,0.5
set noytics
set noy2tics
plot "$logfile" using 1:$valuefield axes x1y1 title '$SemanticLong' with lines lw 3
plot "$logfile" using 1:$valuefield axes x1y1 title '$SemanticLong' with lines lw 2
EOD;
break;
Case piri: ############################################
@@ -160,7 +160,7 @@ set yrange [-1.2:2.2]
plot "< awk '{print $1, 1; }' $logfile "\
using 1:2 title '$drawuserdef' with impulses
plot "$logfile" using 1:$valuefield axes x1y1 title '$SemanticLong' with lines lw 3
plot "$logfile" using 1:$valuefield axes x1y1 title '$SemanticLong' with lines lw 2
EOD;
break;
@@ -176,7 +176,7 @@ EOD;
endswitch;
$message=$OUT1.$gplothdr.$gplotmain;
$f1=fopen("tmp/gnu1","w");
$f1=fopen("tmp/gnu1","w+");
fputs($f1,$message);
fclose($f1);
exec("$gnuplot tmp/gnu1",$output);

View File

@@ -22,6 +22,34 @@ $supported_HMS= array('HMS100T','HMS100TF','HMS100WD','HMS100MG','HMS100TFK','HM
$file="$logpath/$drawhms.log";
if (! in_array($type,$supported_HMS)) show_error_type($imgmaxxhms,$imgmaxyhms,$type);
if (! file_exists($file)) show_error($file,$drawhms,$imgmaxxhms,$imgmaxyhms,$type);
## do we really need a new graphic??
$execorder=$tailpath.' -1 '.$file;
exec($execorder,$tail1);
$parts = explode(" ", $tail1[0]);
$date=$parts[0];
$savefile=$AbsolutPath."/tmp/HMS.".$drawhms.".log.".$parts[0].".png";
if (file_exists($savefile)) {
#echo "exists: $savefile"; exit;
$im2 = @ImageCreateFromPNG($savefile);
header("Content-type: image/png");
imagePng($im2);
exit; # ;-)))
}
else #delete old pngs
{
#echo "not exist: $savefile"; exit;
$delfile=$AbsolutPath."/tmp/HMS.".$drawhms.".log.*.png";
foreach (glob($delfile) as $filename) {
unlink($filename);
}
}
$_SESSION["arraydata"] = array();
@@ -282,6 +310,7 @@ if ( $type == "HMS100WD" or $type == "HMS100MG" or $type == "HMS100W"
#ok. let's draw
imagePng($im,$savefile);
header("Content-type: image/png");
imagePng($im);
@@ -337,6 +366,7 @@ function show_error($file,$drawhms,$imgmaxx,$imgmaxy,$type)
}
ImageTTFText ($im, $fontsize, 0, 5, 45, $txtcolor, $fontttf, $text);
imagePng($im,$savefile);
header("Content-type: image/png");
imagePng($im);
exit;
@@ -365,6 +395,7 @@ function show_error_type($imgmaxx,$imgmaxy,$type)
ImageFill($im, 0, 0, $bg2p);
ImageRectangle($im, 0, 0, $imgmaxx-1, $imgmaxy-1, $white);
imagePng($im,$savefile);
header("Content-type: image/png");
imagePng($im);
exit;

View File

@@ -13,11 +13,36 @@ $drawks=$_GET['drawks'];
$room=$_GET['room'];
$avgday=$_GET['avgday'];
$avgmonth=$_GET['avgmonth'];
#$drawks="ks300";
$file="$logpath/$drawks.log";
if (! file_exists($file)) show_error($file,$drawks,$imgmaxxks,$imgmaxyks);
## do we really need a new graphic??
$execorder=$tailpath.' -1 '.$file;
exec($execorder,$tail1);
$parts = explode(" ", $tail1[0]);
$savefile=$AbsolutPath."/tmp/KS.".$drawks.".log.".$parts[0].".png";
if (file_exists($savefile)) {
$im2 = @ImageCreateFromPNG($savefile);
header("Content-type: image/png");
imagePng($im2);
exit; # ;-)))
}
else #delete old pngs
{
#echo "not exist: $savefile"; exit;
$delfile=$AbsolutPath."/tmp/KS.".$drawks.".log.*.png";
foreach (glob($delfile) as $filename) {
unlink($filename);
}
}
$arraydata = array();
$im = ImageCreateTrueColor($imgmaxxks,$imgmaxyks);
@@ -405,6 +430,7 @@ ImageCopy ($imall,$imw,0,$imgmaxyks*2,0,0,$imgmaxxks,$imgmaxyks);
ImageCopy ($imall,$imr,0,$imgmaxyks*3,0,0,$imgmaxxks,$imgmaxyks);
imagePng($imall,$savefile);
header("Content-type: image/png");
imagePng($imall);

View File

@@ -32,23 +32,36 @@ include "functions.php";
if (! file_exists($file)) show_error($file,$drawuserdef,$imgmaxxuserdef,$imgmaxyuserdef,$type,$userdefnr);
## do we really need a new graphic??
$execorder=$tailpath.' -1 '.$file;
exec($execorder,$tail1);
$parts = explode(" ", $tail1[0]);
$savefile=$AbsolutPath."/tmp/USERDEF.".$drawuserdef.".log.".$parts[0].".png";
if (file_exists($savefile)) {
$im2 = @ImageCreateFromPNG($savefile);
header("Content-type: image/png");
imagePng($im2);
exit; # ;-)))
}
else #delete old pngs
{
$delfile=$AbsolutPath."/tmp/USERDEF.".$drawuserdef.".log.*.png";
foreach (glob($delfile) as $filename) {
unlink($filename);
}
}
$_SESSION["arraydata"] = array();
$im = ImageCreateTrueColor($imgmaxxuserdef,$imgmaxyuserdef);
$black = ImageColorAllocate($im, 0, 0, 0);
$bg1p = ImageColorAllocate($im, 110,148,183);
$bg2p = ImageColorAllocate($im, 175,198,219);
$bg3p = ImageColorAllocate($im, $fontcol_grap_R,$fontcol_grap_G,$fontcol_grap_B);
$white = ImageColorAllocate($im, 255, 255, 255);
$gray= ImageColorAllocate($im, 133, 133, 133);
$red = ImageColorAllocate($im, 255, 0, 0);
$green = ImageColorAllocate($im, 0, 255, 0);
$yellow= ImageColorAllocate($im, 255, 255, 0);
$orange= ImageColorAllocate($im, 255, 230, 25);
ImageFill($im, 0, 0, $bg2p);
ImageRectangle($im, 0, 0, $imgmaxxuserdef-1, $imgmaxyuserdef-1, $white);
$array = file($file);
$oldmin=0; //only the data from every 10min
@@ -92,8 +105,30 @@ include "functions.php";
}
$resultreverse = array_reverse($_SESSION["arraydata"]);
# Start Graphic
$im = ImageCreateTrueColor($imgmaxxuserdef,$imgmaxyuserdef);
$black = ImageColorAllocate($im, 0, 0, 0);
$bg1p = ImageColorAllocate($im, 110,148,183);
$bg2p = ImageColorAllocate($im, 175,198,219);
$bg3p = ImageColorAllocate($im, $fontcol_grap_R,$fontcol_grap_G,$fontcol_grap_B);
$white = ImageColorAllocate($im, 255, 255, 255);
$gray= ImageColorAllocate($im, 133, 133, 133);
$red = ImageColorAllocate($im, 255, 0, 0);
$green = ImageColorAllocate($im, 0, 255, 0);
$yellow= ImageColorAllocate($im, 255, 255, 0);
$orange= ImageColorAllocate($im, 255, 230, 25);
ImageFill($im, 0, 0, $bg2p);
ImageRectangle($im, 0, 0, $imgmaxxuserdef-1, $imgmaxyuserdef-1, $white);
$xold=$imgmaxxuserdef;
$resultreverse = array_reverse($_SESSION["arraydata"]);
if ( $imgmaxxuserdef > count ($resultreverse) )
{ $_SESSION["maxdata"] = count ($resultreverse); }
@@ -126,12 +161,11 @@ if ($gnuplottype=='piri' or $gnuplottype=='fs20')
$datumyesterday= mktime (0,0,0,date("m") ,date("d")-5,date("Y"));
$xrange2= date ("Y-m-d",$datumyesterday);
$xrange="set xrange ['$xrange2':'$xrange1']";
$gnuplotfile="../tmp/".$drawuserdef;
#$gnuplotpng="../tmp/".$drawuserdef.".png";
$gnuplotpng=$drawuserdef.".png";
$gnuplotfile=$AbsolutPath."/tmp/".$drawuserdef;
$gnuplotpng=$drawuserdef.".sm.png";
$messageA=<<<EOD
set output '$gnuplotpng'
set output '$AbsolutPath/tmp/$gnuplotpng'
set terminal png
set xdata time
set timefmt '%Y-%m-%d_%H:%M:%S'
@@ -159,7 +193,7 @@ EOD;
$newlastline=$actdate." ".$f2." ".$f3." ".$f4." ".$f5." ".$f6;
array_push( $array ,$newlastline);
$filename=substr($file,strrpos($file, '/')+1);
$filename='../tmp/'.$filename.'.tmp';
$filename=$AbsolutPath.'/tmp/'.$filename.'.tmp';
$f1=fopen("$filename","w");
for ($x = 0; $x <= count($array); $x++)
{
@@ -199,15 +233,16 @@ endswitch;
if ($gnuplottype=='piri' or $gnuplottype=='fs20')
{
$message=$messageA.$messageB;
$f1=fopen("$gnuplotfile","w");
$f1=fopen("$AbsolutPath/tmp/$drawuserdef","w+");
fputs($f1,$message);
fclose($f1);
exec("$gnuplot $gnuplotfile",$output);
# exit;
exec("$gnuplot $AbsolutPath/tmp/$drawuserdef",$output);
$w = imagesx($im);
$h = imagesy($im);
$im2 = imagecreatefrompng("$gnuplotpng");
$im2 = imagecreatefrompng("$AbsolutPath/tmp/$gnuplotpng");
$w2 = imagesx($im2);
$h2 = imagesy($im2);
ImageCopy($im,$im2,150,0,0,10,$w2-10,$h2);
@@ -253,6 +288,7 @@ if ($gnuplottype=='piri' or $gnuplottype=='fs20')
#############################################################################
#ok. let's draw
imagePng($im,$savefile);
header("Content-type: image/png");
imagePng($im);