2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

Min and Max by Erwin (MH)

git-svn-id: https://svn.fhem.de/fhem/trunk@1723 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2012-07-14 15:55:41 +00:00
parent 0368cc536c
commit 7b071d7305

View File

@ -60,6 +60,7 @@ average_Notify($$)
# Filtering # Filtering
next if(!defined($s)); next if(!defined($s));
my ($evName, $val) = split(" ", $s, 2); # resets $1 my ($evName, $val) = split(" ", $s, 2); # resets $1
# Log 1,"mytestavg pre-filter: ".$devName.$evName." s=".$s;
next if($devName !~ m/^$re$/ && "$devName:$s" !~ m/^$re$/ || $s =~ m/_avg_/); next if($devName !~ m/^$re$/ && "$devName:$s" !~ m/^$re$/ || $s =~ m/_avg_/);
if(defined($1)) { if(defined($1)) {
my $reArg = $1; my $reArg = $1;
@ -68,6 +69,8 @@ average_Notify($$)
next if(!defined($val) || $val !~ m/^(-?\d+\.?\d*)/); next if(!defined($val) || $val !~ m/^(-?\d+\.?\d*)/);
$val = $1; $val = $1;
# Log 1,"mytestavg pst-filter: ".$devName.$evName." val=".$val;
################ ################
# Avg computing # Avg computing
$evName =~ s/[^A-Za-z_-].*//; $evName =~ s/[^A-Za-z_-].*//;
@ -83,14 +86,29 @@ average_Notify($$)
my $cumName = "${evName}_cum_" . ($idx ? "month" : "day"); my $cumName = "${evName}_cum_" . ($idx ? "month" : "day");
my $avgName = "${evName}_avg_" . ($idx ? "month" : "day"); my $avgName = "${evName}_avg_" . ($idx ? "month" : "day");
my $minName = "${evName}_min_" . ($idx ? "month" : "day"); ##MH
my $maxName = "${evName}_max_" . ($idx ? "month" : "day"); ##MH
if(!$r->{$cumName}) { if(!$r->{$cumName}) {
$r->{$cumName}{VAL} = $secNow*$val; $r->{$cumName}{VAL} = $secNow*$val;
$r->{$avgName}{VAL} = $val; $r->{$avgName}{VAL} = $val;
$r->{$maxName}{VAL} = $val; ##MH
$r->{$minName}{VAL} = $val; ##MH
$r->{$cumName}{TIME} = $r->{$avgName}{TIME} = $tn; $r->{$cumName}{TIME} = $r->{$avgName}{TIME} = $tn;
next; next;
} }
##MH take care of existing average definitions - just add this one..
if(!$r->{$maxName}) {
$r->{$maxName}{VAL} = $val;
$r->{$maxName}{TIME} = $tn;
}
##MH take care of existing average definitions - just add this one..
if(!$r->{$minName}) {
$r->{$minName}{VAL} = $val;
$r->{$minName}{TIME} = $tn;
}
my @dLast = split("[ :-]", $r->{$cumName}{TIME}); my @dLast = split("[ :-]", $r->{$cumName}{TIME});
my $secLast = 3600*$dLast[3] + 60*$dLast[4] + $dLast[5]; my $secLast = 3600*$dLast[3] + 60*$dLast[4] + $dLast[5];
$secLast += $dLast[2]*86400 if($idx); $secLast += $dLast[2]*86400 if($idx);
@ -100,11 +118,29 @@ average_Notify($$)
my $cum = $r->{$cumName}{VAL} + ($secNow-$secLast) * $val; my $cum = $r->{$cumName}{VAL} + ($secNow-$secLast) * $val;
$r->{$cumName}{VAL} = $cum; $r->{$cumName}{VAL} = $cum;
$r->{$avgName}{VAL} = sprintf("%0.1f", $cum/$secNow); $r->{$avgName}{VAL} = sprintf("%0.1f", $cum/$secNow);
##MH change only if current value bigger than maxvalue
if($r->{$maxName}{VAL} < $val) {
$r->{$maxName}{VAL} = sprintf("%0.1f", $val); ##MH
$r->{$maxName}{TIME} = $tn; ##MH
}
##MH change only if current value smaller than minvalue
if($r->{$minName}{VAL} > $val) {
$r->{$minName}{VAL} = sprintf("%0.1f", $val); ##MH
$r->{$minName}{TIME} = $tn; ##MH
}
} else { } else {
$dev->{CHANGED}[$myIdx++] = "$avgName: ".$r->{$avgName}{VAL}; $dev->{CHANGED}[$myIdx++] = "$avgName: ".$r->{$avgName}{VAL};
$dev->{CHANGED}[$myIdx++] = "$maxName: ".$r->{$maxName}{VAL}; ##MH
$dev->{CHANGED}[$myIdx++] = "$minName: ".$r->{$minName}{VAL}; ##MH
$r->{$cumName}{VAL} = $secNow*$val; $r->{$cumName}{VAL} = $secNow*$val;
$r->{$avgName}{VAL} = $val; $r->{$avgName}{VAL} = $val;
##MH set to current value
$r->{$maxName}{VAL} = sprintf("%0.1f", $val); ##MH
$r->{$maxName}{TIME} = $tn; ##MH
$r->{$minName}{VAL} = sprintf("%0.1f", $val); ##MH
$r->{$minName}{TIME} = $tn; ##MH
} }
$r->{$cumName}{TIME} = $r->{$avgName}{TIME} = $tn; $r->{$cumName}{TIME} = $r->{$avgName}{TIME} = $tn;
} }
@ -113,3 +149,4 @@ average_Notify($$)
} }
1; 1;