From 01eb4db802421952c1be10c70ca017f3aec6c339 Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Sat, 19 Oct 2013 07:27:51 +0000
Subject: [PATCH] SVG: endPlotNow from ChrisD
git-svn-id: https://svn.fhem.de/fhem/trunk@4067 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/FHEM/01_FHEMWEB.pm | 19 ++++++++--
fhem/FHEM/98_SVG.pm | 81 +++++++++++++++++++++++++++--------------
3 files changed, 71 insertions(+), 30 deletions(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index 01970caee..8d71f60ba 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,6 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
- 2013-xx-xx (SVN)
+ - feature: endPlotNow attribute for SVG-Plots (ChrisD)
- feature: new module 51_BBB_BMP180.pm added (betateilchen)
- feature: readingsGroup: allow devStateIcon to be displayed
- feature: readingsGroup: allow multiple device readings in one line
diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm
index 07f591a59..ca0ce5194 100755
--- a/fhem/FHEM/01_FHEMWEB.pm
+++ b/fhem/FHEM/01_FHEMWEB.pm
@@ -114,7 +114,7 @@ FHEMWEB_Initialize($)
$hash->{ActivateInformFn} = "FW_ActivateInform";
$hash->{AttrList}=
"webname fwcompress:0,1 ".
- "plotmode:gnuplot,gnuplot-scroll,SVG plotsize endPlotToday:1,0 plotfork ".
+ "plotmode:gnuplot,gnuplot-scroll,SVG plotsize endPlotToday:1,0 endPlotNow:1,0 plotfork ".
"stylesheetPrefix touchpad:deprecated smallscreen:deprecated ".
"basicAuth basicAuthMsg hiddenroom hiddengroup HTTPS allowfrom CORS:0,1 ".
"refresh longpoll:0,1 longpollSVG:1,0 redirectCmds:0,1 reverseLogs:0,1 ".
@@ -1973,7 +1973,12 @@ FW_FlushInform($)
my $hash = $defs{$name};
return if(!$hash);
my $c = $hash->{CD};
- print $c $hash->{INFORMBUF};
+ #print $c $hash->{INFORMBUF};
+ if(defined($hash->{".WRITEBUFFER"})) {
+ $hash->{".WRITEBUFFER"} .= $hash->{INFORMBUF};
+ } else {
+ $hash->{".WRITEBUFFER"} = $hash->{INFORMBUF};
+ }
$hash->{INFORMBUF}="";
}
@@ -2392,11 +2397,19 @@ FW_ActivateInform()
endPlotToday
- If this FHEMWEB attribute ist set to 1, then week and month plots will
+ If this FHEMWEB attribute is set to 1, then week and month plots will
end today. Else the current week (starting at Sunday) or the current
month will be shown.
+
+ endPlotNow
+ If this FHEMWEB attribute is set to 1, then day and hour plots will
+ end at current time. Else the whole day, the 6 hour period starting at
+ 0, 6, 12 or 18 hour or the whole hour will be shown. This attribute
+ is not used if the SVG has the attribute startDate defined.
+
+
plotfork
If set, generate the logs in a parallel process. Note: do not use it
diff --git a/fhem/FHEM/98_SVG.pm b/fhem/FHEM/98_SVG.pm
index d2534bb5e..893a8a6b8 100755
--- a/fhem/FHEM/98_SVG.pm
+++ b/fhem/FHEM/98_SVG.pm
@@ -589,34 +589,61 @@ SVG_calcOffsets($$)
if($zoom eq "hour") {
- my $t = $now + $off*3600;
- my @l = localtime($t);
- $SVG_devs{$d}{from}
- = sprintf("%04d-%02d-%02d_%02d:00:00",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
- @l = localtime($t+3600);
- $SVG_devs{$d}{to}
- = sprintf("%04d-%02d-%02d_%02d:00:01",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
-
+ if(AttrVal($FW_wname, "endPlotNow", undef) && !$st) {
+ my $t = int(($now + $off*3600 - 3600)/300.0)*300 + 300;
+ my @l = localtime($t);
+ $SVG_devs{$d}{from} =
+ sprintf("%04d-%02d-%02d_%02d:%02d:00",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
+ @l = localtime($t+3600);
+ $SVG_devs{$d}{to} =
+ sprintf("%04d-%02d-%02d_%02d:%02d:01",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
+ } else {
+ my $t = $now + $off*3600;
+ my @l = localtime($t);
+ $SVG_devs{$d}{from}
+ = sprintf("%04d-%02d-%02d_%02d:00:00",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
+ @l = localtime($t+3600);
+ $SVG_devs{$d}{to}
+ = sprintf("%04d-%02d-%02d_%02d:00:01",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
+ }
} elsif($zoom eq "qday") {
- my $t = $now + $off*21600;
- my @l = localtime($t);
- $l[2] = int($l[2]/6)*6;
- $SVG_devs{$d}{from} =
- sprintf("%04d-%02d-%02d_%02d:00:00",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
- @l = localtime($t+21600);
- $l[2] = int($l[2]/6)*6;
- $SVG_devs{$d}{to} =
- sprintf("%04d-%02d-%02d_%02d:00:01",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
-
+ if(AttrVal($FW_wname, "endPlotNow", undef) && !$st) {
+ my $t = int(($now + $off*21600 - 21600)/300.0)*300 + 300;
+ my @l = localtime($t);
+ $SVG_devs{$d}{from} =
+ sprintf("%04d-%02d-%02d_%02d:%02d:00",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
+ @l = localtime($t+21600);
+ $SVG_devs{$d}{to} =
+ sprintf("%04d-%02d-%02d_%02d:%02d:01",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
+ } else {
+ my $t = $now + $off*21600;
+ my @l = localtime($t);
+ $l[2] = int($l[2]/6)*6;
+ $SVG_devs{$d}{from} =
+ sprintf("%04d-%02d-%02d_%02d:00:00",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
+ @l = localtime($t+21600);
+ $l[2] = int($l[2]/6)*6;
+ $SVG_devs{$d}{to} =
+ sprintf("%04d-%02d-%02d_%02d:00:01",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
+ }
} elsif($zoom eq "day") {
- my $t = $now + $off*86400;
- my @l = localtime($t);
- $SVG_devs{$d}{from} =
- sprintf("%04d-%02d-%02d_00:00:00",$l[5]+1900,$l[4]+1,$l[3]);
- @l = localtime($t+86400);
- $SVG_devs{$d}{to} =
- sprintf("%04d-%02d-%02d_00:00:01",$l[5]+1900,$l[4]+1,$l[3]);
-
+ if(AttrVal($FW_wname, "endPlotNow", undef) && !$st) {
+ my $t = int(($now + $off*86400 - 86400)/900.0)*900 + 900;
+ my @l = localtime($t);
+ $SVG_devs{$d}{from} =
+ sprintf("%04d-%02d-%02d_%02d:%02d:00",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
+ @l = localtime($t+86400);
+ $SVG_devs{$d}{to} =
+ sprintf("%04d-%02d-%02d_%02d:%02d:01",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
+ } else {
+ my $t = $now + $off*86400;
+ my @l = localtime($t);
+ $SVG_devs{$d}{from} =
+ sprintf("%04d-%02d-%02d_00:00:00",$l[5]+1900,$l[4]+1,$l[3]);
+ @l = localtime($t+86400);
+ $SVG_devs{$d}{to} =
+ sprintf("%04d-%02d-%02d_00:00:01",$l[5]+1900,$l[4]+1,$l[3]);
+ }
} elsif($zoom eq "week") {
my @l = localtime($now);
my $start = (AttrVal($FW_wname, "endPlotToday", undef) ? 6 : $l[6]);
@@ -1513,7 +1540,7 @@ SVG_pO($)
In plotmode gnuplot-scroll or SVG the given time-range will be used,
and no scrolling for this weblinks will be possible. Needed e.g. for
looking at last-years data without scrolling.
- If the value is one of day, week, month, year than set the zoom level
+ If the value is one of day, week, month, year then set the zoom level
for this weblink independently of the user specified zoom-level.
This is useful for pages with multiple plots: one of the plots is best
viewed in with the default (day) zoom, the other one with a week zoom.