2007-10-13 16:36:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################# Creates graphics vor pgm3
|
|
|
|
|
|
|
|
|
|
|
|
################
|
|
|
|
|
|
|
|
include "../config.php";
|
|
|
|
include "functions.php";
|
|
|
|
|
|
|
|
|
|
|
|
$userdefnr=$_GET['userdefnr'];
|
|
|
|
|
|
|
|
$room=$userdef[$userdefnr]['room'];
|
|
|
|
|
|
|
|
$file= $userdef[$userdefnr]['logpath'];
|
|
|
|
$drawuserdef=$userdef[$userdefnr]['name'];
|
|
|
|
$imgmaxxuserdef=$userdef[$userdefnr]['imagemax'];
|
|
|
|
$imgmaxyuserdef=$userdef[$userdefnr]['imagemay'];
|
|
|
|
$SemanticLong=$userdef[$userdefnr]['semlong'];
|
|
|
|
$SemanticShort=$userdef[$userdefnr]['semshort'];
|
2007-10-14 14:20:25 +00:00
|
|
|
$valuefield=$userdef[$userdefnr]['valuefield'];
|
2007-10-13 16:36:00 +00:00
|
|
|
$type='UserDef '.$userdefnr;
|
2007-10-16 21:01:34 +00:00
|
|
|
$logrotateUSERDEFlines=$userdef[$userdefnr]['logrotatelines'];
|
|
|
|
$maxcountUSERDEF=$userdef[$userdefnr]['maxcount'];
|
|
|
|
$XcorrectMainTextUSERDEF=$userdef[$userdefnr]['XcorrectMainText'];
|
|
|
|
$gnuplottype=$userdef[$userdefnr]['gnuplottype'];
|
2007-10-13 16:36:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (! file_exists($file)) show_error($file,$drawuserdef,$imgmaxxuserdef,$imgmaxyuserdef,$type,$userdefnr);
|
|
|
|
|
2007-10-23 19:42:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
## do we really need a new graphic??
|
|
|
|
$execorder=$tailpath.' -1 '.$file;
|
|
|
|
exec($execorder,$tail1);
|
|
|
|
$parts = explode(" ", $tail1[0]);
|
2007-10-13 16:36:00 +00:00
|
|
|
|
2007-10-24 08:32:55 +00:00
|
|
|
|
|
|
|
$today= date("d");
|
2007-10-23 19:42:09 +00:00
|
|
|
$savefile=$AbsolutPath."/tmp/USERDEF.".$drawuserdef.".log.".$parts[0].".png";
|
2007-10-24 08:32:55 +00:00
|
|
|
$fmtime=date ("d", filemtime($savefile)); #at least one new graphic per day (gnuplot)
|
|
|
|
if ((file_exists($savefile)) and ($fmtime == $today)) {
|
2007-10-13 16:36:00 +00:00
|
|
|
|
2007-10-23 19:42:09 +00:00
|
|
|
$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();
|
|
|
|
|
2007-10-13 16:36:00 +00:00
|
|
|
|
|
|
|
$array = file($file);
|
|
|
|
$oldmin=0; //only the data from every 10min
|
|
|
|
$oldhour=0; //only the data from every 10min
|
|
|
|
$mintemp=100;
|
|
|
|
$maxtemp=-100;
|
|
|
|
$counter=count($array);
|
|
|
|
|
|
|
|
#Logrotate
|
|
|
|
if ((($logrotateUSERDEFlines+100) < $counter) and ($logrotate == 'yes')) LogRotate($array,$file,$logrotateUSERDEFlines);
|
|
|
|
|
|
|
|
#print_r($array[1]);
|
|
|
|
#print_r($array[1][12]); exit;
|
|
|
|
###########################################################################
|
|
|
|
|
|
|
|
for ($x = 0; $x < $counter; $x++)
|
|
|
|
{
|
2007-10-14 14:20:25 +00:00
|
|
|
list ($date,$f2,$f3,$f4,$f5,$f6,$f7,$f8,$f9,$f10) = preg_split("/[\s,]+/", $array[$x]);
|
2007-10-13 16:36:00 +00:00
|
|
|
if ((($array[$x][14] != $oldmin) or ($array[$x][12] != $oldhour) or ($x==$counter-1))
|
|
|
|
and ( $date !="NEWLOGS"))
|
|
|
|
{
|
2007-10-14 14:20:25 +00:00
|
|
|
|
|
|
|
switch ($valuefield):
|
2007-10-16 21:01:34 +00:00
|
|
|
Case 1: $value=$date;break;
|
2007-10-14 14:20:25 +00:00
|
|
|
Case 2: $value=$f2;break;
|
|
|
|
Case 3: $value=$f3;break;
|
|
|
|
Case 4: $value=$f4;break;
|
|
|
|
Case 5: $value=$f5;break;
|
|
|
|
Case 6: $value=$f6;break;
|
|
|
|
Case 7: $value=$f7;break;
|
|
|
|
Case 8: $value=$f8;break;
|
|
|
|
Case 9: $value=$f9;break;
|
|
|
|
Case 10: $value=$f10;break;
|
|
|
|
endswitch;
|
2007-10-13 16:36:00 +00:00
|
|
|
$oldmin=$array[$x][14];
|
|
|
|
$oldhour=$array[$x][12];
|
2007-10-14 14:20:25 +00:00
|
|
|
array_push( $_SESSION["arraydata"],array($date,$value));
|
|
|
|
$temp=$value;
|
2007-10-13 16:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-16 21:01:34 +00:00
|
|
|
|
2007-10-13 16:36:00 +00:00
|
|
|
|
2007-10-23 19:42:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
# 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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-13 16:36:00 +00:00
|
|
|
$xold=$imgmaxxuserdef;
|
2007-10-23 19:42:09 +00:00
|
|
|
$resultreverse = array_reverse($_SESSION["arraydata"]);
|
2007-10-13 16:36:00 +00:00
|
|
|
|
|
|
|
if ( $imgmaxxuserdef > count ($resultreverse) )
|
|
|
|
{ $_SESSION["maxdata"] = count ($resultreverse); }
|
|
|
|
else
|
|
|
|
{ $_SESSION["maxdata"] = $imgmaxxuserdef; };
|
|
|
|
|
|
|
|
###################
|
|
|
|
### min/max
|
2007-10-14 14:20:25 +00:00
|
|
|
$mintemp=1000;
|
|
|
|
$maxtemp=-1000;
|
2007-10-13 16:36:00 +00:00
|
|
|
for ($x = 0; $x <= $_SESSION["maxdata"]; $x++)
|
|
|
|
{
|
|
|
|
if ( $resultreverse[$x][1] > $maxtemp ) $maxtemp=$resultreverse[$x][1];
|
2007-10-14 14:20:25 +00:00
|
|
|
if ( ($resultreverse[$x][1] < $mintemp) and ($resultreverse[$x][1]>-1000) ) $mintemp=$resultreverse[$x][1];
|
2007-10-13 16:36:00 +00:00
|
|
|
}
|
|
|
|
$tempdiff=$maxtemp-$mintemp;
|
|
|
|
if ($tempdiff==0) $tempdiff=1;
|
|
|
|
$fac=$imgmaxyuserdef/$tempdiff;
|
|
|
|
$yold=round($imgmaxyuserdef-(($resultreverse[0][1]-$mintemp)*$fac));
|
|
|
|
###################
|
|
|
|
|
|
|
|
|
|
|
|
if ($maxcountUSERDEF < $_SESSION["maxdata"]) {$anzlines=$maxcountUSERDEF;} else {$anzlines= $_SESSION["maxdata"];}
|
2007-10-16 21:01:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
if ($gnuplottype=='piri' or $gnuplottype=='fs20')
|
|
|
|
{
|
|
|
|
$datumtomorrow= mktime (0,0,0,date("m") ,date("d")+1,date("Y"));
|
|
|
|
$xrange1= date ("Y-m-d",$datumtomorrow);
|
|
|
|
$datumyesterday= mktime (0,0,0,date("m") ,date("d")-5,date("Y"));
|
|
|
|
$xrange2= date ("Y-m-d",$datumyesterday);
|
|
|
|
$xrange="set xrange ['$xrange2':'$xrange1']";
|
2007-10-23 19:42:09 +00:00
|
|
|
$gnuplotfile=$AbsolutPath."/tmp/".$drawuserdef;
|
|
|
|
$gnuplotpng=$drawuserdef.".sm.png";
|
2007-10-16 21:01:34 +00:00
|
|
|
|
|
|
|
$messageA=<<<EOD
|
2007-10-23 19:42:09 +00:00
|
|
|
set output '$AbsolutPath/tmp/$gnuplotpng'
|
2007-10-16 21:01:34 +00:00
|
|
|
set terminal png
|
|
|
|
set xdata time
|
|
|
|
set timefmt '%Y-%m-%d_%H:%M:%S'
|
|
|
|
set noytics
|
|
|
|
unset label
|
|
|
|
$xrange
|
|
|
|
set grid
|
|
|
|
set yrange [-0.3:1.3]
|
|
|
|
set size 0.8,0.15
|
|
|
|
set format x ''
|
|
|
|
|
|
|
|
EOD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch ($gnuplottype):
|
|
|
|
Case 'piri':
|
|
|
|
$messageB=<<<EOD
|
|
|
|
plot "< awk '{print $1, 1; }' $file "\
|
|
|
|
using 1:2 title '' with impulses
|
|
|
|
EOD;
|
|
|
|
break;
|
|
|
|
Case 'fs20':
|
2007-10-18 08:42:19 +00:00
|
|
|
$actdate= date("Y-m-d_H:i:s");
|
|
|
|
$newlastline=$actdate." ".$f2." ".$f3." ".$f4." ".$f5." ".$f6;
|
|
|
|
array_push( $array ,$newlastline);
|
|
|
|
$filename=substr($file,strrpos($file, '/')+1);
|
2007-10-23 19:42:09 +00:00
|
|
|
$filename=$AbsolutPath.'/tmp/'.$filename.'.tmp';
|
2007-10-18 08:42:19 +00:00
|
|
|
$f1=fopen("$filename","w");
|
|
|
|
for ($x = 0; $x <= count($array); $x++)
|
|
|
|
{
|
|
|
|
fputs($f1,$array[$x]);
|
|
|
|
}
|
|
|
|
fputs($f1,"\n");
|
|
|
|
fclose($f1);
|
|
|
|
|
|
|
|
|
2007-10-16 21:01:34 +00:00
|
|
|
$messageB=<<<EOD
|
|
|
|
plot "< awk '{print $1, $3==\"on\"? 1 : $3==\"dimup\"? 0.8 : $3==\"dimdown\"? 0.2 : $3==\"off\"? 0 : 0.5;}' \
|
2007-10-18 08:42:19 +00:00
|
|
|
$filename" using 1:2 title '' with steps
|
2007-10-16 21:01:34 +00:00
|
|
|
|
|
|
|
EOD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-10-13 16:36:00 +00:00
|
|
|
for ($x = 0; $x < $anzlines; $x++)
|
|
|
|
|
|
|
|
{
|
|
|
|
$parts = explode("_", $resultreverse[$x][0]);
|
|
|
|
if ( ($parts[0] != $olddate) )
|
|
|
|
{
|
|
|
|
$olddate=$parts[0];
|
|
|
|
ImageLine($im, $imgmaxxuserdef-$x, 0,$imgmaxxuserdef-$x , $imgmaxyuserdef, $bg1p);
|
|
|
|
}
|
|
|
|
$y = round($imgmaxyuserdef-(($resultreverse[$x][1]-$mintemp)*$fac));
|
|
|
|
ImageLine($im, $imgmaxxuserdef-$x, $y, $xold, $yold, $red);
|
|
|
|
$xold=$imgmaxxuserdef-$x;
|
|
|
|
$yold=$y;
|
|
|
|
};
|
2007-10-16 21:01:34 +00:00
|
|
|
ImageLine($im, $imgmaxxuserdef-$x, 0,$imgmaxxuserdef-$x , $imgmaxyuserdef, $yellow);
|
|
|
|
break;
|
|
|
|
endswitch;
|
|
|
|
|
|
|
|
|
|
|
|
if ($gnuplottype=='piri' or $gnuplottype=='fs20')
|
|
|
|
{
|
|
|
|
$message=$messageA.$messageB;
|
2007-10-23 19:42:09 +00:00
|
|
|
$f1=fopen("$AbsolutPath/tmp/$drawuserdef","w+");
|
2007-10-16 21:01:34 +00:00
|
|
|
fputs($f1,$message);
|
|
|
|
fclose($f1);
|
2007-10-23 19:42:09 +00:00
|
|
|
# exit;
|
|
|
|
exec("$gnuplot $AbsolutPath/tmp/$drawuserdef",$output);
|
2007-10-16 21:01:34 +00:00
|
|
|
|
|
|
|
$w = imagesx($im);
|
|
|
|
$h = imagesy($im);
|
2007-10-13 16:36:00 +00:00
|
|
|
|
2007-10-23 19:42:09 +00:00
|
|
|
$im2 = imagecreatefrompng("$AbsolutPath/tmp/$gnuplotpng");
|
2007-10-16 21:01:34 +00:00
|
|
|
$w2 = imagesx($im2);
|
|
|
|
$h2 = imagesy($im2);
|
|
|
|
ImageCopy($im,$im2,150,0,0,10,$w2-10,$h2);
|
|
|
|
}
|
2007-10-13 16:36:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-16 21:01:34 +00:00
|
|
|
ImageLine($im, $imgmaxxuserdef-$maxcountUSERDEF, 0,$imgmaxxuserdef-$maxcountUSERDEF , $imgmaxyuserdef, $white);
|
|
|
|
$tempTEMP=$temp;
|
|
|
|
|
2007-10-13 16:36:00 +00:00
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
$text=$SemanticLong;
|
|
|
|
$fontsize=7;
|
|
|
|
$txtcolor=$bg3p;
|
|
|
|
ImageTTFText ($im, $fontsize, 0, 3, 10, $txtcolor, $fontttf, $text);
|
|
|
|
$txtcolor=$bg3p;
|
|
|
|
$fontsize=9;
|
|
|
|
$text=$tempTEMP." ".$SemanticShort;
|
|
|
|
$tvalue=$tempTEMP;
|
|
|
|
ImageTTFText ($im, $fontsize, 0, 90-$XcorrectMainTextUSERDEF, 37, $txtcolor, $fontttfb, $text);
|
|
|
|
|
|
|
|
$txtcolor=$bg3p;
|
|
|
|
$fontsize=7;
|
|
|
|
$text="min= $mintemp max= $maxtemp";
|
|
|
|
ImageTTFText ($im, $fontsize, 0, 67-$XcorrectMainTextUSERDEF, 49, $txtcolor, $fontttf, $text);
|
|
|
|
$text=$resultreverse[0][0];
|
|
|
|
ImageTTFText ($im, $fontsize, 0, $imgmaxxuserdef-127, 13, $txtcolor, $fontttf, $text);
|
|
|
|
#############################################################################
|
|
|
|
## general
|
|
|
|
$txtcolor=$bg3p;
|
|
|
|
$fontsize=9;
|
|
|
|
$text= $drawuserdef;
|
|
|
|
ImageTTFText ($im, 8, 0,90-$XcorrectMainTextUSERDEF, 22, $txtcolor, $fontttfb, $text);
|
|
|
|
$fontsize=7;
|
|
|
|
$text=$txtroom.$room;
|
|
|
|
ImageTTFText ($im, $fontsize, 0, 3, $imgmaxyuserdef-7, $txtcolor, $fontttf, $text);
|
|
|
|
$text=$type;
|
|
|
|
ImageTTFText ($im, $fontsize, 0, 5, $imgmaxyuserdef-17, $txtcolor, $fontttf, $text);
|
|
|
|
|
|
|
|
|
|
|
|
#############################################################################
|
|
|
|
#ok. let's draw
|
|
|
|
|
2007-10-23 19:42:09 +00:00
|
|
|
imagePng($im,$savefile);
|
2007-10-13 16:36:00 +00:00
|
|
|
header("Content-type: image/png");
|
|
|
|
imagePng($im);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###############################################################
|
|
|
|
## first start: shows the required logfiles
|
|
|
|
function show_error($file,$drawuserdef,$imgmaxx,$imgmaxy,$type,$section)
|
|
|
|
{
|
|
|
|
$im = ImageCreateTrueColor($imgmaxx,$imgmaxy);
|
|
|
|
$black = ImageColorAllocate($im, 0, 0, 0);
|
|
|
|
$bg2p = ImageColorAllocate($im, 175,198,219);
|
|
|
|
$white = ImageColorAllocate($im, 255, 255, 255);
|
|
|
|
$red = ImageColorAllocate($im, 255, 0, 0);
|
|
|
|
|
|
|
|
ImageFill($im, 0, 0, $bg2p);
|
|
|
|
ImageRectangle($im, 0, 0, $imgmaxx-1, $imgmaxy-1, $white);
|
|
|
|
|
|
|
|
include "../config.php";
|
|
|
|
$bg3p = ImageColorAllocate($im, $fontcol_grap_R,$fontcol_grap_G,$fontcol_grap_B);
|
|
|
|
$text="There is a new supported $type-Device but no Logfile $file";
|
|
|
|
$fontsize=9;
|
|
|
|
$txtcolor=$bg3p;
|
|
|
|
ImageTTFText ($im, $fontsize, 0, 5, 17, $txtcolor, $fontttf, $text);
|
|
|
|
$text="Please check the userdef[$section] of <pgm3>/config.php and refresh your browser";
|
|
|
|
ImageTTFText ($im, $fontsize, 0, 5, 45, $txtcolor, $fontttf, $text);
|
|
|
|
|
|
|
|
header("Content-type: image/png");
|
|
|
|
imagePng($im);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
###############################################################
|
|
|
|
|
|
|
|
?>
|