specialDeltaPeriodHours

git-svn-id: https://svn.fhem.de/fhem/trunk@6024 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
tpoitzsch 2014-06-01 12:02:44 +00:00
parent c3e6b71809
commit 78fc9a9b3f

View File

@ -101,6 +101,7 @@ statistics_Initialize($)
."minAvgMaxReadings " ."minAvgMaxReadings "
."periodChangePreset " ."periodChangePreset "
."singularReadings " ."singularReadings "
."specialDeltaPeriodHours "
.$readingFnAttributes; .$readingFnAttributes;
} }
@ -242,8 +243,6 @@ statistics_Notify($$)
Log3 $name,5,"$name: Notification of '".$dev->{NAME}."' received but for my own readings only."; Log3 $name,5,"$name: Notification of '".$dev->{NAME}."' received but for my own readings only.";
} }
WriteStatefile();
return; return;
} }
@ -333,6 +332,8 @@ statistics_DoStatisticsAll($$)
statistics_DoStatistics($hash, $defs{$devName}, $periodSwitch); statistics_DoStatistics($hash, $defs{$devName}, $periodSwitch);
} }
} }
if ($periodSwitch != 0 ) { WriteStatefile(); }
} }
@ -381,8 +382,8 @@ statistics_DoStatistics($$$)
next if not exists ($dev->{READINGS}{$readingName}); next if not exists ($dev->{READINGS}{$readingName});
$statisticDone = 1; $statisticDone = 1;
if ($$f[1] == 1) { statistics_doStatisticMinMax ($hash, $dev, $readingName, $$f[2], $periodSwitch);} if ($$f[1] == 1) { statistics_doStatisticMinMax ($hash, $dev, $readingName, $$f[2], $periodSwitch);}
if ($$f[1] == 2) { statistics_doStatisticDelta ($hash, $dev, $readingName, $$f[2], $periodSwitch);} if ($$f[1] == 2) { statistics_doStatisticDelta ($hash, $dev, $readingName, $$f[2], $periodSwitch );}
if ($$f[1] == 3) { statistics_doStatisticDuration ($hash, $dev, $readingName, $periodSwitch);} if ($$f[1] == 3) { statistics_doStatisticDuration ($hash, $dev, $readingName, $periodSwitch ); }
} }
my @specialReadings = split /,/, AttrVal($hashName, "deltaReadings", ""); my @specialReadings = split /,/, AttrVal($hashName, "deltaReadings", "");
@ -677,9 +678,37 @@ statistics_doStatisticDelta ($$$$$)
statistics_storeSingularReadings ($name,$singularReadings,$dev,$statReadingName,$readingName,"Delta","Year",$statValue,$last[7],$periodSwitch == 4 || $periodSwitch == -4); statistics_storeSingularReadings ($name,$singularReadings,$dev,$statReadingName,$readingName,"Delta","Year",$statValue,$last[7],$periodSwitch == 4 || $periodSwitch == -4);
} }
if ($periodSwitch>=1) { statistics_doStatisticSpecialPeriod ( $hash, $dev, $readingName, $decPlaces, $stat[1] ); }
return ; return ;
} }
# Calculates deltas for period of several hours
sub ########################################
statistics_doStatisticSpecialPeriod ($$$$$)
{
my ($hash, $dev, $readingName, $decPlaces, $value) = @_;
my $name = $hash->{NAME};
my $result;
my $specialPeriod = AttrVal($name, "specialDeltaPeriodHours", 0);
return if $specialPeriod ==0;
my $statReadingName = $hash->{PREFIX} . ucfirst($readingName) . "SpecialPeriod";
my $hiddenReadingName = ".".$dev->{NAME} . ":" . $readingName . "SpecialPeriod";
my @hidden = split / /, ($value . " " . $hash->{READINGS}{$hiddenReadingName}{VAL}); # Internal values
if ( exists($hidden[$specialPeriod]) ) { delete $hidden[$specialPeriod]; }
foreach my $val (@hidden) { $result += $val; }
$result = sprintf "%.".$decPlaces."f", $result;
if ($#hidden != $specialPeriod) { $result .= " (".($#hidden+1)."_hours)"; }
readingsBulkUpdate($dev, $statReadingName, $result, 1);
$result = join( " ", @hidden );
readingsSingleUpdate($hash, $hiddenReadingName, $result, 0);
}
# Calculates single Duration Values and informs about end of day and month # Calculates single Duration Values and informs about end of day and month
sub ######################################## sub ########################################
statistics_doStatisticDuration ($$$$) statistics_doStatisticDuration ($$$$)
@ -723,7 +752,7 @@ statistics_doStatisticDurationSingle ($$$$$$)
# Show since-Value # Show since-Value
$hidden{"showDate:"} = 1; $hidden{"showDate:"} = 1;
$saveLast = 0; $saveLast = 0;
# $stat[7] = strftime ("%Y-%m-%d_%H:%M:%S",localtime() ); $hidden{"(since:"} = strftime ("%Y-%m-%d_%H:%M:%S)",localtime() );
} else { } else {
# Do calculations if hidden reading exists # Do calculations if hidden reading exists
%hidden = split / /, $hash->{READINGS}{$hiddenReadingName}{VAL}; # Internal values %hidden = split / /, $hash->{READINGS}{$hiddenReadingName}{VAL}; # Internal values
@ -739,26 +768,26 @@ statistics_doStatisticDurationSingle ($$$$$$)
# Prepare new current reading, delete hidden reading if it is used again # Prepare new current reading, delete hidden reading if it is used again
$result = ""; $result = "";
while (my ($key, $duration) = each(%hidden)){ while (my ($key, $duration) = each(%hidden)){
if ($key !~ /lastState:|lastTime:|showDate:/) { if ($key !~ /lastState:|lastTime:|showDate:|since:/) {
if ($result ne "") {$result .= " ";} if ($result ne "") {$result .= " ";}
$result .= "$key ".statistics_FormatDuration($duration); $result .= "$key ".statistics_FormatDuration($duration);
if ($saveLast) { delete $hidden{$key}; } if ($saveLast) { delete $hidden{$key}; }
} }
} }
if ($result eq "") {$result = "$state: 0";} if ($result eq "") {$result = "$state: 0";}
# if ($hidden[9] == 1) { $result .= " (since: $stat[7] )"; } if ($hidden{"showDate:"} == 1) { $result .= " (since: ".$hidden{"(since:"}; }
# Store current reading as last reading, Reset current reading # Store current reading as last reading, Reset current reading
if ($saveLast) { if ($saveLast) {
readingsBulkUpdate($dev, $statReadingName . "Last", $result, 1); readingsBulkUpdate($dev, $statReadingName . "Last", $result, 1);
Log3 $name, 5, "Set '".$statReadingName . "Last'='$result'"; Log3 $name, 5, "Set '".$statReadingName . "Last = $result'";
$result = "$state: 00:00:00"; $result = "$state: 00:00:00";
$hidden{"showDate:"} = 0; $hidden{"showDate:"} = 0;
} }
# Store current reading # Store current reading
readingsBulkUpdate($dev, $statReadingName, $result, 0); readingsBulkUpdate($dev, $statReadingName, $result, 0);
Log3 $name, 5, "Set '$statReadingName'='$result'"; Log3 $name, 5, "Set '$statReadingName = $result'";
# Store single readings # Store single readings
my $singularReadings = AttrVal($name, "singularReadings", ""); my $singularReadings = AttrVal($name, "singularReadings", "");
@ -922,6 +951,10 @@ statistics_FormatDuration($)
z.B. <code>Wettersensor:rain:Delta:(Hour|Day))|(FritzDect:(current|power):(Avg|Max|Delta):(Hour|Day)</code> z.B. <code>Wettersensor:rain:Delta:(Hour|Day))|(FritzDect:(current|power):(Avg|Max|Delta):(Hour|Day)</code>
<br> <br>
</li><br> </li><br>
<li><code>specialDeltaPeriodHours &lt;Hours&gt;</code>
<br>
Adds for readings of delta statistics a singular reading for the given period of hours (e.g. for the rain of the last 72 hours)
</li><br>
</ul> </ul>
</ul> </ul>
@ -994,7 +1027,7 @@ statistics_FormatDuration($)
<li><code>excludedReadings &lt;Ger&auml;tenameRegExp:Ger&auml;tewertRegExp&gt;</code> <li><code>excludedReadings &lt;Ger&auml;tenameRegExp:Ger&auml;tewertRegExp&gt;</code>
<br> <br>
regul&auml;rer Ausdruck der Ger&auml;tewerte die nicht ausgewertet werden sollen. regul&auml;rer Ausdruck der Ger&auml;tewerte die nicht ausgewertet werden sollen.
z.B. "FritzDect:current|Sensor_.*:humidity" z.B. "<code>FritzDect:current|Sensor_.*:humidity</code>"
<br> <br>
</li><br> </li><br>
<li><code>minAvgMaxReadings &lt;Ger&auml;tewerte&gt;</code> <li><code>minAvgMaxReadings &lt;Ger&auml;tewerte&gt;</code>
@ -1008,16 +1041,19 @@ statistics_FormatDuration($)
Erlaubt die korrekte zeitliche Zuordnung in Plots, kann je nach Systemauslastung verringert oder vergr&ouml;&szlig;ert werden Erlaubt die korrekte zeitliche Zuordnung in Plots, kann je nach Systemauslastung verringert oder vergr&ouml;&szlig;ert werden
<br> <br>
</li><br> </li><br>
<li><code>singularReadings &lt;Ger&auml;tenameRegExp:Ger&auml;tewertRegExp&gt;:Statistiktypen:ZeitPeriode</code> <li><code>singularReadings &lt;Ger&auml;teNameRegExp:Ger&auml;teWertRegExp:StatistikTypen:ZeitPeriode&gt;</code>
<ul> <ul>
<li>Statistiktypen: Min|Avg|Max|Delta</li> <li>StatistikTypen: Min|Avg|Max|Delta|Duration</li>
<li>ZeitPeriode: Hour|Day|Month|Year</li> <li>ZeitPeriode: Hour|Day|Month|Year</li>
</ul> </ul>
Regul&auml;rer Ausdruck statistischer Werte, die nicht nur in zusammengefassten sondern auch als einzelne Werte gespeichert werden sollen. Regul&auml;rer Ausdruck statistischer Werte, die nicht nur in zusammengefassten sondern auch als einzelne Werte gespeichert werden sollen.
Erleichtert die Erzeugung von Plots. Erleichtert die Erzeugung von Plots.
<br> <br>
z.B. <code>Wettersensor:rain:Delta:(Hour|Day))|FritzDect:power:Delta:Day</code> z.B. <code>Wettersensor:rain:Delta:(Hour|Day))|FritzDect:power:Delta:Day</code>
</li><br>
<li><code>specialDeltaPeriodHours &lt;Stunden&gt;</code>
<br> <br>
F&uuml;gt den Delta-Statistiken einen singul&auml;ren Ger&auml;tewert f&uuml;r die angegebenen Stunden hinzu (z.b. f&uuml;r den Regen in den letzten 72 Stunden)
</li><br> </li><br>
<li><a href="#readingFnAttributes">readingFnAttributes</a> <li><a href="#readingFnAttributes">readingFnAttributes</a>
</li><br> </li><br>