From ba36e4921f56759b8881858fe37c3d5554f13481 Mon Sep 17 00:00:00 2001
From: Damian <>
Date: Mon, 13 Feb 2023 19:35:24 +0000
Subject: [PATCH] 98_DOIF.pm: back to revision 27202
git-svn-id: https://svn.fhem.de/fhem/trunk@27216 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/98_DOIF.pm | 184 ++++++++++++++++++-------------------------
1 file changed, 76 insertions(+), 108 deletions(-)
diff --git a/fhem/FHEM/98_DOIF.pm b/fhem/FHEM/98_DOIF.pm
index b78d433db..ff3a17ae4 100644
--- a/fhem/FHEM/98_DOIF.pm
+++ b/fhem/FHEM/98_DOIF.pm
@@ -18,6 +18,7 @@
##############################################
+
package main;
use strict;
use warnings;
@@ -1549,15 +1550,11 @@ sub setValue_collect
readingsSingleUpdate ($hash, "error", "${$collect}{output}, ".$@,1);
}
}
+ return if (!defined $r);
my ($seconds, $microseconds) = gettimeofday();
- if (defined $r) {
- $r = ($r =~ /(-?\d+(\.\d+)?)/ ? $1 : "N/A");
- } else {
- $r="N/A";
- }
-
+ $r = ($r =~ /(-?\d+(\.\d+)?)/ ? $1 : "N/A");
${$collect}{value}=$r;
${$collect}{time}=$seconds;
@@ -1568,56 +1565,48 @@ sub setValue_collect
my $va=${$collect}{values};
my $ta=${$collect}{times};
-
- my $seconds_per_slot=$hours*3600/$dim;
-
- # if (@{$ta} == $dim) {
- #if (defined ${$va}[$dim-1]) {
- # $last_slot=int (${$ta}[-1]/$seconds_per_slot);
- #}
- my $slot_nr=int ($seconds/$seconds_per_slot);
-
- if (!defined ${$collect}{last_slot}) {
- $last_slot=$slot_nr-1;
- } else {
- $last_slot=${$collect}{last_slot};
- }
-
- $diff_slots=$slot_nr-$last_slot;
- if ($diff_slots > 0) {
- $change=1;
- if ($diff_slots >= $dim) {
- ${$collect}{last_value}=${$collect}{value} if (defined ${$collect}{value});
- @{$va}=();
- @{$ta}=();
- ${$collect}{last}=undef;
- } else {
- my @rv=splice (@{$va},0,$diff_slots);
- my @rt=splice (@{$ta},0,$diff_slots);
- if ($diff_slots > 1 and !defined ${$va}[$dim-$diff_slots] and defined ${$collect}{last} and ${$va}[$dim-$diff_slots-1] != ${$collect}{last}) {
- ${$va}[$dim-$diff_slots]=${$collect}{last};
- ${$ta}[$dim-$diff_slots]=(int(${$ta}[$dim-$diff_slots-1]/$seconds_per_slot)+1)*$seconds_per_slot;
- }
- ${$collect}{last}=undef;
- for (my $i=@rv-1;$i>=0;$i--) {
- if (defined ($rv[$i])) {
- ${$collect}{last_value}=$rv[$i];
- last;
+ if ($r ne "N/A") {
+ my $seconds_per_slot=$hours*3600/$dim;
+
+ # if (@{$ta} == $dim) {
+ if (defined ${$va}[$dim-1]) {
+ $last_slot=int (${$ta}[-1]/$seconds_per_slot);
+ }
+ my $slot_nr=int ($seconds/$seconds_per_slot);
+ if (defined $last_slot) {
+ $diff_slots=$slot_nr-$last_slot;
+ if ($diff_slots > 0) {
+ if ($diff_slots >= $dim) {
+ ${$collect}{last_value}=${$collect}{value} if (defined ${$collect}{value});
+ @{$va}=();
+ @{$ta}=();
+ ${$collect}{last}=undef;
+ } else {
+ my @rv=splice (@{$va},0,$diff_slots);
+ my @rt=splice (@{$ta},0,$diff_slots);
+ if ($diff_slots > 1 and !defined ${$va}[$dim-$diff_slots] and defined ${$collect}{last} and ${$va}[$dim-$diff_slots-1] != ${$collect}{last}) {
+ ${$va}[$dim-$diff_slots]=${$collect}{last};
+ ${$ta}[$dim-$diff_slots]=(int(${$ta}[$dim-$diff_slots-1]/$seconds_per_slot)+1)*$seconds_per_slot;
+ }
+ ${$collect}{last}=undef;
+ for (my $i=@rv-1;$i>=0;$i--) {
+ if (defined ($rv[$i])) {
+ ${$collect}{last_value}=$rv[$i];
+ last;
+ }
+ }
}
}
}
- }
- if ($r ne "N/A") {
if (!defined ${$va}[$dim-1] or !defined ${$collect}{last_v} or (abs($r-${$collect}{last_v}) > abs(${$va}[$dim-1]-${$collect}{last_v}))) {
${$va}[$dim-1]=$r;
${$ta}[$dim-1]=$seconds;
+ $change=1;
} elsif (${$va}[$dim-1] != $r) {
${$collect}{last}=$r;
}
}
- ${$collect}{last_slot}=$slot_nr;
-
if (defined $change) {
DOIF_statistic_col ($collect)
}
@@ -1660,22 +1649,15 @@ sub DOIF_statistic_col
last;
}
}
- delete ${$collect}{max_value};
- delete ${$collect}{max_value_time};
- delete ${$collect}{max_value_slot};
- delete ${$collect}{min_value};
- delete ${$collect}{min_value_time};
- delete ${$collect}{min_value_slot};
+
+ ${$collect}{max_value}=$maxVal;
+ ${$collect}{max_value_time}=$maxValTime;
+ ${$collect}{max_value_slot}=$maxValSlot;
+
+ ${$collect}{min_value}=$minVal;
+ ${$collect}{min_value_time}=$minValTime;
+ ${$collect}{min_value_slot}=$minValSlot;
- if (defined $maxVal) {
- ${$collect}{max_value}=$maxVal;
- ${$collect}{max_value_time}=$maxValTime;
- ${$collect}{max_value_slot}=$maxValSlot;
-
- ${$collect}{min_value}=$minVal;
- ${$collect}{min_value_time}=$minValTime;
- ${$collect}{min_value_slot}=$minValSlot;
- }
if (defined ${$collect}{last_value}) {
if (${$collect}{last_value} > $maxVal) {
${$collect}{last_value}=$maxVal;
@@ -1733,13 +1715,6 @@ sub DOIF_statistic_bar
}
}
}
-
- delete ${$bar}{max_value};
- delete ${$bar}{max_value_slot};
- delete ${$bar}{min_value};
- delete ${$bar}{min_value_slot};
- delete ${$bar}{average_value};
-
if ($numb > 0) {
${$bar}{max_value}=$maxVal;
${$bar}{max_value_slot}=$maxValSlot;
@@ -1854,15 +1829,14 @@ sub setValue_bar
readingsSingleUpdate ($hash, "error", "${$bar}{output}, ".$@,1);
}
}
+ return if (!defined $r);
my ($seconds, $microseconds) = gettimeofday();
- my ($period1,$period2,$begin_period2)=DOIF_setPeriod($seconds,$period);
- if (defined $r) {
- $r = ($r =~ /(-?\d+(\.\d+)?)/ ? $1 : "N/A");
- } else {
- $r="N/A";
- }
+ $r = ($r =~ /(-?\d+(\.\d+)?)/ ? $1 : "N/A");
+ ${$bar}{value}=$r;
+
+ my ($period1,$period2,$begin_period2)=DOIF_setPeriod($seconds,$period);
if (defined $trigger) {
if ($r ne "N/A") {
@@ -1878,8 +1852,6 @@ sub setValue_bar
# }
}
}
-
-
my $va=${$bar}{values};
my $change="";
@@ -1896,15 +1868,8 @@ sub setValue_bar
}
$change=1;
}
-
- ${$bar}{last_period2}=$period2;
- ${$bar}{last_period1}=$period1;
- ${$bar}{begin_period2}=$begin_period2;
-
-
- ${$bar}{value}=$r;
- if (defined $trigger and $r ne "N/A") {
+ if (defined $trigger) {
if ($timeOffset == 0) {
${$va}[$period1]=${$bar}{value};
} else {
@@ -1913,6 +1878,10 @@ sub setValue_bar
$change=1;
}
+ ${$bar}{last_period2}=$period2;
+ ${$bar}{last_period1}=$period1;
+ ${$bar}{begin_period2}=$begin_period2;
+
if ($change or defined $statistic) {
DOIF_statistic_bar ($bar)
}
@@ -5033,7 +5002,7 @@ sub format_value {
my ($val,$min,$dec)=@_;
my $format;
my $value=$val;
- if (!defined $val or $val eq "" or $val eq "N/A") {
+ if (!defined $val or $val eq "") {
$val="N/A";
$format='%s';
$value=$min;
@@ -5141,8 +5110,6 @@ sub plot {
}
my ($format,$value);
($format,$value,$val)=format_value($val,$min,$dec);
-
- my $decform='%1.'.$dec.'f';
$minVal=$value if (!defined $minVal);
$maxVal=$value if (!defined $maxVal);
@@ -5244,7 +5211,7 @@ sub plot {
for (my $i=0;$i<=5;$i++) {
my $v=($maxPlot-$minPlot)*(1-$i*0.2)+$minPlot;
my ($color)= get_color($v,$min,$max,$minColor,$maxColor,$func);
- $out.= sprintf('%s',$anchor,$pos,$i*10+2,$noColor eq "1" ? "#CCCCCC":color($color,$lmm),"",sprintf($decform,$v));
+ $out.= sprintf('%s',$anchor,$pos,$i*10+2,$noColor eq "1" ? "#CCCCCC":color($color,$lmm),"",sprintf($format,$v));
}
}
@@ -5329,11 +5296,11 @@ sub plot {
$footer.= sprintf('%s',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", $unit);
if (defined $maxValSlot) {
$footer.= sprintf('Ø',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC");
- $footer.= sprintf('%s',$bwidth/2-15,$footerPos,color($averageValColor,$lmm),"",sprintf($decform,$averageVal));
+ $footer.= sprintf('%s',$bwidth/2-15,$footerPos,color($averageValColor,$lmm),"",sprintf($format,$averageVal));
$footer.= sprintf('▲%s',$bwidth/2-15,$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", $maxValTime) ;
- $footer.= sprintf('%s',$bwidth/2+42.5,$footerPos,color($maxValColor,$lmm),"",sprintf($decform,${$collect}{max_value}));
+ $footer.= sprintf('%s',$bwidth/2+42.5,$footerPos,color($maxValColor,$lmm),"",sprintf($format,${$collect}{max_value}));
$footer.= sprintf('▼%s',$bwidth/2+42.5,$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", $minValTime);
- $footer.= sprintf('%s', $bwidth+8,$footerPos,color($minValColor,$lmm),"",sprintf($decform,${$collect}{min_value}));
+ $footer.= sprintf('%s', $bwidth+8,$footerPos,color($minValColor,$lmm),"",sprintf($format,${$collect}{min_value}));
}
}
} else { # col
@@ -5382,25 +5349,26 @@ sub plot {
}
$out.=sprintf('',$yNull,$chart_dim,$yNull);
- if (defined $maxValSlot) {
- my ($x1,$y1)=($maxValSlot*$x_prop,(50-int((${$a}[$maxValSlot]*$m+$n)*10)/10)-2.3);
- $out.=sprintf('',$x1,$y1,$x1+2.4,$y1+4.3,$x1-2.4,$y1+4.3, defined $unitColor ? $unitColor:color($maxValColor,$ln));
- ($x1,$y1)=($minValSlot*$x_prop,(50-int((${$a}[$minValSlot]*$m+$n)*10)/10)+2.3);
- $out.=sprintf('',$x1,$y1,$x1+2.4,$y1-4.3,$x1-2.4,$y1-4.3, defined $unitColor ? $unitColor:color($minValColor,$ln));
- }
+ ##$out.=sprintf('',$maxValSlot*$x_prop,(50-int((${$a}[$maxValSlot]*$m+$n)*10)/10),defined $unitColor ? $unitColor:color($maxValColor,$ln)) if (defined $maxValSlot);
+ my ($x1,$y1)=($maxValSlot*$x_prop,(50-int((${$a}[$maxValSlot]*$m+$n)*10)/10)-2.3);
+ $out.=sprintf('',$x1,$y1,$x1+2.4,$y1+4.3,$x1-2.4,$y1+4.3, defined $unitColor ? $unitColor:color($maxValColor,$ln)) if (defined $maxValSlot);
+
+ ##$out.=sprintf(',',$minValSlot*$x_prop,(50-int((${$a}[$minValSlot]*$m+$n)*10)/10),defined $unitColor ? $unitColor:color($minValColor,$ln)) if (defined $minValSlot);
+ ($x1,$y1)=($minValSlot*$x_prop,(50-int((${$a}[$minValSlot]*$m+$n)*10)/10)+2.3);
+ $out.=sprintf('',$x1,$y1,$x1+2.4,$y1-4.3,$x1-2.4,$y1-4.3, defined $unitColor ? $unitColor:color($minValColor,$ln)) if (defined $minValSlot);
$out.=sprintf((''.$animate),$chart_dim,(50-int(($value*$m+$n)*10)/10),defined $unitColor ? $unitColor:color($currColor,$ln)) if ($val ne "N/A");
if ($footerPos) {
- $footer.= sprintf('%s',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", $unit);
if (defined $maxValTime) {
+ $footer.= sprintf('%s',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", $unit);
if ($hours > 168) {
$footer.= sprintf('▲%s',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", ::strftime("%d.%m %H:%M",localtime($maxValTime)));
} else {
$footer.= sprintf('▲%s',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", ::strftime("%a",localtime($maxValTime)));
$footer.= sprintf('%s',$footerPos,::strftime("%H:%M",localtime($maxValTime)));
}
- $footer.= sprintf('%s',$bwidth/2+25.5,$footerPos,color($maxValColor,$lmm),"",sprintf($decform,${$collect}{max_value}));
+ $footer.= sprintf('%s',$bwidth/2+25.5,$footerPos,color($maxValColor,$lmm),"",sprintf($format,${$collect}{max_value}));
}
if (defined $minValTime) {
if ($hours > 168) {
@@ -5410,7 +5378,7 @@ sub plot {
$footer.= sprintf('▼%s',$bwidth/2+25.5,$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", ::strftime("%a",localtime($minValTime)));
$footer.= sprintf('%s',$bwidth/2+46,$footerPos,::strftime("%H:%M",localtime($minValTime)));
}
- $footer.= sprintf('%s', $bwidth+8,$footerPos,color($minValColor,$lmm),"",sprintf($decform,${$collect}{min_value}));
+ $footer.= sprintf('%s', $bwidth+8,$footerPos,color($minValColor,$lmm),"",sprintf($format,${$collect}{min_value}));
}
}
} # col
@@ -5776,8 +5744,8 @@ sub card
my $maxVal;
for (my $i=0;$i< @value1;$i++) {
if (defined ($value1[$i]{dim})) {
- my $min=defined $value1[$i]{min_value} ? $value1[$i]{min_value} : $value1[$i]{value} ne "N/A" ? $value1[$i]{value} : $min;
- my $max=defined $value1[$i]{max_value} ? $value1[$i]{max_value} : $value1[$i]{value} ne "N/A" ? $value1[$i]{value} : $max;
+ my $min=defined $value1[$i]{min_value} ? $value1[$i]{min_value} : $value1[$i]{value};
+ my $max=defined $value1[$i]{max_value} ? $value1[$i]{max_value} : $value1[$i]{value};
$minVal=$min if (!defined $minVal or $min < $minVal);
$maxVal=$max if (!defined $maxVal or $max > $maxVal);
}
@@ -5785,7 +5753,7 @@ sub card
my $j=0;
for (my $i=0;$i<@value1;$i++) {
- if (defined $value1[$i]{dim}) {
+ if (defined ($value1[$i]{dim})) {
($outplot,$outfooter) = plot ($value1[$i],[$min,$minVal],[$max,$maxVal],$minColor,$maxColor,$dec,$func,$steps,$x_prop,$chart_dim, $noColor,$lmm,$ln,$lr,$plot,$bwidth,$noFooter eq "1" ? 0:84+$j*10,undef,-2.5,"end",(split(",",$unit1[$i]))[1],(split(",",$unit1[$i]))[0]);
$j++;
$out.=$outplot;
@@ -5866,15 +5834,15 @@ sub card
my $maxVal;
for (my $i=0;$i< @value1;$i++) {
if (defined ($value1[$i]{dim})) {
- my $min=defined $value1[$i]{min_value} ? $value1[$i]{min_value} : $value1[$i]{value} ne "N/A" ? $value1[$i]{value} : $min;
- my $max=defined $value1[$i]{max_value} ? $value1[$i]{max_value} : $value1[$i]{value} ne "N/A" ? $value1[$i]{value} : $max;
+ my $min=defined $value1[$i]{min_value} ? $value1[$i]{min_value} : $value1[$i]{value};
+ my $max=defined $value1[$i]{max_value} ? $value1[$i]{max_value} : $value1[$i]{value};
$minVal=$min if (!defined $minVal or $min < $minVal);
$maxVal=$max if (!defined $maxVal or $max > $maxVal);
}
}
my $j=0;
for (my $i=0;$i<@value1;$i++) {
- if (defined $value1[$i]{dim}) {
+ if (defined ($value1[$i]{dim})) {
($outplot,$outfooter) = plot ($value1[$i],[$min,$minVal],[$max,$maxVal],$minColor,$maxColor,$dec,$func,$steps,$x_prop,$chart_dim, $j == 0 ? $noColor:-1,$lmm,$ln,$lr,$plot,$bwidth,$noFooter eq "1" ? 0:84+$j*10,undef,-2.5,"end",(split(",",$unit1[$i]))[1],(split(",",$unit1[$i]))[0]);
$j++;
$out.=$outplot;
@@ -5886,8 +5854,8 @@ sub card
my $maxVal2;
for (my $i=0;$i< @value2;$i++) {
if (defined ($value2[$i]{dim})) {
- my $min=defined $value2[$i]{min_value} ? $value2[$i]{min_value} : $value2[$i]{value} ne "N/A" ? $value2[$i]{value} : $min;
- my $max=defined $value2[$i]{max_value} ? $value2[$i]{max_value} : $value2[$i]{value} ne "N/A" ? $value2[$i]{value} : $max;
+ my $min=defined $value2[$i]{min_value} ? $value2[$i]{min_value} : $value2[$i]{value};
+ my $max=defined $value2[$i]{max_value} ? $value2[$i]{max_value} : $value2[$i]{value};
$minVal2=$min if (!defined $minVal2 or $min < $minVal2);
$maxVal2=$max if (!defined $maxVal2 or $max > $maxVal2);
}
@@ -5895,7 +5863,7 @@ sub card
my $offset=@outfooter*10;
my $j=0;
for (my $i=0;$i<@value2;$i++) {
- if (defined $value2[$i]{dim}) {
+ if (defined ($value2[$i]{dim})) {
($outplot,$outfooter) = plot ($value2[$i],[$min2,$minVal2],[$max2,$maxVal2],$minColor2,$maxColor2,$dec2,$func2,$steps,$x_prop,$chart_dim, $j == 0 ? $noColor:-1,$lmm,$ln,$lr,$plot,$bwidth,$noFooter eq "1" ? 0:84+$offset+$j*10,undef,$chart_dim+3,"start",(split(",",$unit2[$i]))[1],(split(",",$unit2[$i]))[0]);
$j++;
$out.=$outplot;