mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-07 23:09:26 +00:00
98_SVG.pm: plotmode=gnuplot optimizations (Forum #35129)
git-svn-id: https://svn.fhem.de/fhem/trunk@11687 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
d85efb607a
commit
440c8d61e0
@ -1038,49 +1038,41 @@ SVG_doShowLog($$$$;$)
|
|||||||
}
|
}
|
||||||
SVG_calcOffsets($d,$wl);
|
SVG_calcOffsets($d,$wl);
|
||||||
|
|
||||||
|
my ($f,$t)=($SVG_devs{$d}{from}, $SVG_devs{$d}{to});
|
||||||
|
$f = 0 if(!$f); # From the beginning of time...
|
||||||
|
$t = 9 if(!$t); # till the end
|
||||||
|
|
||||||
if($pm =~ m/gnuplot/) {
|
if($pm =~ m/gnuplot/) {
|
||||||
|
|
||||||
my $tmpfile = "/tmp/file.$$";
|
my $tmpfile = "/tmp/file.$$";
|
||||||
my $errfile = "/tmp/gnuplot.err";
|
my $errfile = "/tmp/gnuplot.err";
|
||||||
|
|
||||||
my $f;
|
|
||||||
my $t;
|
|
||||||
my $xrange;
|
my $xrange;
|
||||||
|
|
||||||
if(!$SVG_devs{$d}{from}) {
|
if(!$SVG_devs{$d}{from}) {
|
||||||
# Fix range, as we are without scroll
|
|
||||||
$f = 0; # From the beginning of time...
|
|
||||||
$t = 9; # till the end
|
|
||||||
$xrange = "\n"; #We don't have a range, but need the new line
|
$xrange = "\n"; #We don't have a range, but need the new line
|
||||||
} else {
|
} else {
|
||||||
# Read the data from the filelog
|
|
||||||
($f,$t)=($SVG_devs{$d}{from}, $SVG_devs{$d}{to});
|
|
||||||
$xrange = "set xrange [\"$f\":\"$t\"]\n";
|
$xrange = "set xrange [\"$f\":\"$t\"]\n";
|
||||||
}
|
}
|
||||||
|
my $da = SVG_getData($wl, $f, $t, $srcDesc, 0); # substcfg needs it(!)
|
||||||
|
|
||||||
|
my $tmpstring = "";
|
||||||
|
open(FH, ">$tmpfile");
|
||||||
|
for(my $dIdx=0; $dIdx<@{$da}; $dIdx++) {
|
||||||
|
if (${$da->[$dIdx]}) {
|
||||||
|
$tmpstring = ${$da->[$dIdx]};
|
||||||
|
$tmpstring =~ s/#.*/\n/g;
|
||||||
|
} else {
|
||||||
|
$tmpstring = "$f 0\n\n";
|
||||||
|
}
|
||||||
|
print FH "$tmpstring";
|
||||||
|
|
||||||
my $oll = $attr{global}{verbose};
|
|
||||||
$attr{global}{verbose} = 0; # Else the filenames will be Log'ged
|
|
||||||
my @path;
|
|
||||||
my $tmp = 0;
|
|
||||||
foreach my $src (@{$srcDesc->{order}}) {
|
|
||||||
my $s = $srcDesc->{src}{$src};
|
|
||||||
my $fname = ($src eq $defs{$d}{LOGDEVICE} ? $defs{$d}{LOGFILE}:"CURRENT");
|
|
||||||
my $cmd = "get $src $fname $tmpfile$tmp $f $t ".$s->{arg};
|
|
||||||
my @files = split(" ", FW_fC($cmd, 1));
|
|
||||||
push(@path, @files);
|
|
||||||
$tmp++;
|
|
||||||
}
|
}
|
||||||
$attr{global}{verbose} = $oll;
|
close(FH);
|
||||||
|
|
||||||
# replace the path with the temporary filenames of the filelog output
|
# put in the filename of the temporary data file into the plot file string
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
$plot =~ s/\".*?using 1:[^ ]+ /"\"$path[$i++]\" using 1:2 "/gse;
|
$plot =~ s/\".*?using 1:[^ ]+ /"\"$tmpfile\" i " . $i++ . " using 1:2 "/gse;
|
||||||
foreach my $p (@path) { # If the file is empty, write a 0 line
|
|
||||||
next if(!-z $p);
|
|
||||||
open(FH, ">$p");
|
|
||||||
print FH "$f 0\n";
|
|
||||||
close(FH);
|
|
||||||
}
|
|
||||||
|
|
||||||
my $gplot_script = SVG_substcfg(0, $wl, $cfg, $plot, $file, $tmpfile);
|
my $gplot_script = SVG_substcfg(0, $wl, $cfg, $plot, $file, $tmpfile);
|
||||||
|
|
||||||
@ -1088,26 +1080,23 @@ SVG_doShowLog($$$$;$)
|
|||||||
open(FH, "|gnuplot >> $errfile 2>&1");# feed it to gnuplot
|
open(FH, "|gnuplot >> $errfile 2>&1");# feed it to gnuplot
|
||||||
print FH $gplot_script, $xrange, $plot;
|
print FH $gplot_script, $xrange, $plot;
|
||||||
close(FH);
|
close(FH);
|
||||||
foreach my $p (@path) {
|
unlink($tmpfile);
|
||||||
unlink($p);
|
|
||||||
}
|
my $ext;
|
||||||
|
|
||||||
if($pm eq "gnuplot-scroll") {
|
if($pm eq "gnuplot-scroll") {
|
||||||
$FW_RETTYPE = "image/png";
|
$FW_RETTYPE = "image/png";
|
||||||
open(FH, "$tmpfile.png"); # read in the result and send it
|
$ext = "png";
|
||||||
binmode (FH); # necessary for Windows
|
|
||||||
FW_pO join("", <FH>);
|
|
||||||
close(FH);
|
|
||||||
unlink("$tmpfile.png");
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$FW_RETTYPE = "image/svg+xml";
|
$FW_RETTYPE = "image/svg+xml";
|
||||||
open(FH, "$tmpfile.svg"); # read in the result and send it
|
$ext = "svg";
|
||||||
binmode (FH); # necessary for Windows
|
|
||||||
FW_pO join("", <FH>);
|
|
||||||
close(FH);
|
|
||||||
unlink("$tmpfile.svg");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open(FH, "$tmpfile.$ext"); # read in the result and send it
|
||||||
|
binmode (FH); # necessary for Windows
|
||||||
|
FW_pO join("", <FH>);
|
||||||
|
close(FH);
|
||||||
|
unlink("$tmpfile.$ext");
|
||||||
|
|
||||||
} elsif($pm eq "SVG") {
|
} elsif($pm eq "SVG") {
|
||||||
my ($f,$t)=($SVG_devs{$d}{from}, $SVG_devs{$d}{to});
|
my ($f,$t)=($SVG_devs{$d}{from}, $SVG_devs{$d}{to});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user