mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-21 01:46:08 +00:00
statistics: Duration + Count
git-svn-id: https://svn.fhem.de/fhem/trunk@7320 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
387501ad89
commit
1a701d3953
@ -528,11 +528,13 @@ FRITZBOX_Readout_Run($)
|
|||||||
push @readoutArray, ["", "ctlmgr_ctl r telcfg settings/RefreshDiversity" ];
|
push @readoutArray, ["", "ctlmgr_ctl r telcfg settings/RefreshDiversity" ];
|
||||||
push @readoutArray, ["", "ctlmgr_ctl r telcfg settings/Diversity/count" ];
|
push @readoutArray, ["", "ctlmgr_ctl r telcfg settings/Diversity/count" ];
|
||||||
|
|
||||||
# Box model and firmware
|
# Box model and firmware
|
||||||
push @readoutArray, [ "box_model", 'echo $CONFIG_PRODUKT_NAME' ];
|
push @readoutArray, [ "box_model", 'echo $CONFIG_PRODUKT_NAME' ];
|
||||||
push @readoutArray, [ "box_fwVersion", "ctlmgr_ctl r logic status/nspver" ];
|
push @readoutArray, [ "box_fwVersion", "ctlmgr_ctl r logic status/nspver" ];
|
||||||
push @readoutArray, [ "box_fwUpdate", "ctlmgr_ctl r updatecheck status/update_available_hint" ];
|
push @readoutArray, [ "box_fwUpdate", "ctlmgr_ctl r updatecheck status/update_available_hint" ];
|
||||||
|
push @readoutArray, [ "box_tr069", "ctlmgr_ctl r tr069 settings/enabled", "onoff" ];
|
||||||
|
|
||||||
|
# Execute commands
|
||||||
$resultArray = FRITZBOX_Readout_Query( $hash, \@readoutArray, \@readoutReadings);
|
$resultArray = FRITZBOX_Readout_Query( $hash, \@readoutArray, \@readoutReadings);
|
||||||
|
|
||||||
my $dectCount = $resultArray->[1];
|
my $dectCount = $resultArray->[1];
|
||||||
@ -1974,6 +1976,7 @@ sub FRITZBOX_fritztris($)
|
|||||||
<li><b>box_guestWlanRemain</b> - Remaining time until the guest WLAN is switched off</li>
|
<li><b>box_guestWlanRemain</b> - Remaining time until the guest WLAN is switched off</li>
|
||||||
<li><b>box_model</b> - Fritz!Box model</li>
|
<li><b>box_model</b> - Fritz!Box model</li>
|
||||||
<li><b>box_moh</b> - music-on-hold setting</li>
|
<li><b>box_moh</b> - music-on-hold setting</li>
|
||||||
|
<li><b>box_tr069</b> - provider remote access TR069 (safety issue!)</li>
|
||||||
<li><b>box_wlan_2.4GHz</b> - Current state of the 2.4 GHz WLAN</li>
|
<li><b>box_wlan_2.4GHz</b> - Current state of the 2.4 GHz WLAN</li>
|
||||||
<li><b>box_wlan_5GHz</b> - Current state of the 5 GHz WLAN</li>
|
<li><b>box_wlan_5GHz</b> - Current state of the 5 GHz WLAN</li>
|
||||||
|
|
||||||
@ -2215,6 +2218,7 @@ sub FRITZBOX_fritztris($)
|
|||||||
<li><b>box_guestWlanRemain</b> - Verbleibende Zeit bis zum Ausschalten des Gäste-WLAN</li>
|
<li><b>box_guestWlanRemain</b> - Verbleibende Zeit bis zum Ausschalten des Gäste-WLAN</li>
|
||||||
<li><b>box_model</b> - Fritz!Box-Modell</li>
|
<li><b>box_model</b> - Fritz!Box-Modell</li>
|
||||||
<li><b>box_moh</b> - Wartemusik-Einstellung</li>
|
<li><b>box_moh</b> - Wartemusik-Einstellung</li>
|
||||||
|
<li><b>box_tr069</b> - Provider-Fernwartung TR069 (sicherheitsrelevant!)</li>
|
||||||
<li><b>box_wlan_2.4GHz</b> - Aktueller Status des 2.4-GHz-WLAN</li>
|
<li><b>box_wlan_2.4GHz</b> - Aktueller Status des 2.4-GHz-WLAN</li>
|
||||||
<li><b>box_wlan_5GHz</b> - Aktueller Status des 5-GHz-WLAN</li>
|
<li><b>box_wlan_5GHz</b> - Aktueller Status des 5-GHz-WLAN</li>
|
||||||
|
|
||||||
|
@ -861,48 +861,60 @@ sub statistics_doStatisticDurationSingle ($$$$$$)
|
|||||||
my $hiddenReadingName = ".".$dev->{NAME}.":".$readingName.$period;
|
my $hiddenReadingName = ".".$dev->{NAME}.":".$readingName.$period;
|
||||||
my $name=$hash->{NAME};
|
my $name=$hash->{NAME};
|
||||||
my $devName = $dev->{NAME};
|
my $devName = $dev->{NAME};
|
||||||
|
$state =~ s/ /_/g;
|
||||||
|
|
||||||
my $statReadingName = $hash->{PREFIX};
|
my $statReadingName = $hash->{PREFIX};
|
||||||
$statReadingName .= ucfirst($readingName).$period;
|
$statReadingName .= ucfirst($readingName).$period;
|
||||||
my %hidden;
|
my %hidden;
|
||||||
my $firstRun = not exists($hash->{READINGS}{$hiddenReadingName});
|
my $firstRun = not exists($hash->{READINGS}{$hiddenReadingName});
|
||||||
my $lastState = $state;
|
my $lastState;
|
||||||
my $statValue = "00:00:00";
|
my $statValue;
|
||||||
|
my $statCount;
|
||||||
|
|
||||||
if ( $firstRun ) {
|
if ( $firstRun ) {
|
||||||
# Show since-Value
|
# Show since-Value
|
||||||
$hidden{"showDate:"} = 1;
|
$hidden{"showDate:"} = 1;
|
||||||
$saveLast = 0;
|
$saveLast = 0;
|
||||||
|
$lastState = $state;
|
||||||
|
$statValue = "00:00:00";
|
||||||
|
$statCount = 1;
|
||||||
$hidden{"(since:"} = strftime ("%Y-%m-%d_%H:%M:%S)",localtime() );
|
$hidden{"(since:"} = strftime ("%Y-%m-%d_%H:%M:%S)",localtime() );
|
||||||
|
$hidden{$state} = 0;
|
||||||
|
$hidden{$state."_Count"} = 1;
|
||||||
} 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
|
||||||
$lastState = $hidden{"lastState:"};
|
$lastState = $hidden{"lastState:"};
|
||||||
my $timeDiff = int(gettimeofday())-$hidden{"lastTime:"};
|
my $timeDiff = int(gettimeofday())-$hidden{"lastTime:"};
|
||||||
$hidden{$lastState.":"} += $timeDiff;
|
$hidden{$lastState.":"} += $timeDiff;
|
||||||
|
$hidden{$state."_Count:"}++
|
||||||
|
if $state ne $lastState;
|
||||||
|
$statCount = $hidden{$state."_Count:"};
|
||||||
$statValue = statistics_FormatDuration ($hidden{$lastState.":"});
|
$statValue = statistics_FormatDuration ($hidden{$lastState.":"});
|
||||||
}
|
}
|
||||||
$hidden{"lastState:"} = $state;
|
$hidden{"lastState:"} = $state;
|
||||||
$hidden{"lastTime:"} = int(gettimeofday());
|
$hidden{"lastTime:"} = int(gettimeofday());
|
||||||
|
|
||||||
|
|
||||||
# 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)){
|
foreach my $key (sort keys %hidden)
|
||||||
if ($key !~ /lastState:|lastTime:|showDate:|since:/) {
|
{
|
||||||
if ($result ne "") {$result .= " ";}
|
if ($key !~ /^(lastState|lastTime|showDate|\(since):$/) {
|
||||||
$result .= "$key ".statistics_FormatDuration($duration);
|
$result .= " " if $result;
|
||||||
|
$result .= "$key ".statistics_FormatDuration($hidden{$key})
|
||||||
|
if $key !~ /_Count:$/;
|
||||||
|
$result .= "$key ".$hidden{$key}
|
||||||
|
if $key =~ /_Count:$/;
|
||||||
if ($saveLast) { delete $hidden{$key}; }
|
if ($saveLast) { delete $hidden{$key}; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($result eq "") {$result = "$state: 0";}
|
|
||||||
if ($hidden{"showDate:"} == 1) { $result .= " (since: ".$hidden{"(since:"}; }
|
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);
|
||||||
statistics_Log $hash, 5, "Set '".$statReadingName . "Last = $result'";
|
statistics_Log $hash, 5, "Set '".$statReadingName . "Last = $result'";
|
||||||
$result = "$state: 00:00:00";
|
$result = "$state: 00:00:00 ".$state."_Count: 1";
|
||||||
$hidden{"showDate:"} = 0;
|
$hidden{"showDate:"} = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -913,14 +925,17 @@ sub statistics_doStatisticDurationSingle ($$$$$$)
|
|||||||
# Store single readings
|
# Store single readings
|
||||||
my $singularReadings = AttrVal($name, "singularReadings", "");
|
my $singularReadings = AttrVal($name, "singularReadings", "");
|
||||||
if ($singularReadings ne "") {
|
if ($singularReadings ne "") {
|
||||||
# statistics_storeSingularReadings $hashName,$singularReadings,$dev,$statReadingName,$readingName,$statType,$period,$statValue,$value,$saveLast
|
# statistics_storeSingularReadings for Duration
|
||||||
|
# $hashName,$singularReadings,$dev,$statReadingName,$readingName,$statType,$period,$statValue,$value,$saveLast
|
||||||
statistics_storeSingularReadings ($name,$singularReadings,$dev,$statReadingName,$readingName,ucfirst($lastState),$period,$statValue,0,$saveLast);
|
statistics_storeSingularReadings ($name,$singularReadings,$dev,$statReadingName,$readingName,ucfirst($lastState),$period,$statValue,0,$saveLast);
|
||||||
|
# statistics_storeSingularReadings for Count
|
||||||
|
statistics_storeSingularReadings ($name,$singularReadings,$dev,$statReadingName."_Count",$readingName,ucfirst($lastState)."_Count",$period,$statCount,0,$saveLast);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Store hidden reading
|
# Store hidden reading
|
||||||
$result = "";
|
$result = "";
|
||||||
while (my ($key, $duration) = each(%hidden)){
|
while (my ($key, $duration) = each(%hidden)){
|
||||||
if ($result ne "") {$result .= " ";}
|
$result .= " " if $result;
|
||||||
$result .= "$key $duration";
|
$result .= "$key $duration";
|
||||||
}
|
}
|
||||||
readingsSingleUpdate($hash, $hiddenReadingName, $result, 0);
|
readingsSingleUpdate($hash, $hiddenReadingName, $result, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user