mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 18:59:33 +00:00
93_DbRep: contrib 8.50.0
git-svn-id: https://svn.fhem.de/fhem/trunk@26323 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
4b4d3ed758
commit
ce2a377257
@ -9359,7 +9359,7 @@ sub _DbRep_rl_updateHour {
|
|||||||
return $err if ($err);
|
return $err if ($err);
|
||||||
}
|
}
|
||||||
|
|
||||||
my $params;
|
my ($params, $value);
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
my $k = 1;
|
my $k = 1;
|
||||||
my $th = _DbRep_rl_logThreshold ($c);
|
my $th = _DbRep_rl_logThreshold ($c);
|
||||||
@ -9387,78 +9387,42 @@ sub _DbRep_rl_updateHour {
|
|||||||
next if (!$hourHash->{$hourKey}->[0]);
|
next if (!$hourHash->{$hourKey}->[0]);
|
||||||
my ($updDate,$updHour) = $hourHash->{$hourKey}->[0] =~ /(.*\d+)\s(\d{2}):/;
|
my ($updDate,$updHour) = $hourHash->{$hourKey}->[0] =~ /(.*\d+)\s(\d{2}):/;
|
||||||
|
|
||||||
$paref->{updDate} = $updDate;
|
$paref->{updDate} = $updDate;
|
||||||
$paref->{updHour} = $updHour;
|
$paref->{updHour} = $updHour;
|
||||||
$paref->{timestamp} = $hourHash->{$hourKey}->[0];
|
$paref->{timestamp} = $hourHash->{$hourKey}->[0];
|
||||||
$paref->{device} = $hourHash->{$hourKey}->[1];
|
$paref->{device} = $hourHash->{$hourKey}->[1];
|
||||||
$paref->{reading} = $hourHash->{$hourKey}->[3];
|
$paref->{reading} = $hourHash->{$hourKey}->[3];
|
||||||
$paref->{oldvalue} = $hourHash->{$hourKey}->[4]->[0];
|
$paref->{oldvalue} = $hourHash->{$hourKey}->[4]->[0];
|
||||||
|
|
||||||
if ($mstr eq 'average') { # Berechnung Average
|
if (scalar @{$hourHash->{$hourKey}->[4]} > 1) { # wahr wenn reading hat mehrere Datensätze diese Stunde
|
||||||
if (scalar @{$hourHash->{$hourKey}->[4]} > 1) { # wahr wenn reading hat mehrere Datensätze diese Stunde
|
|
||||||
|
$i++;
|
||||||
$i++;
|
|
||||||
|
$paref->{hourHashKeyRef} = $hourHash->{$hourKey}->[4];
|
||||||
my $sum = 0;
|
|
||||||
|
if ($mstr eq 'average') { # Berechnung Average
|
||||||
for my $val (@{$hourHash->{$hourKey}->[4]}) {
|
$value = __DbRep_rl_calcAverageHourly ($paref);
|
||||||
$sum += $val;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $value = sprintf "%.${ndp}f", $sum / scalar @{$hourHash->{$hourKey}->[4]};
|
|
||||||
|
|
||||||
$paref->{logtxt} = "(hourly-$mstr) updating";
|
|
||||||
$paref->{newvalue} = $value;
|
|
||||||
|
|
||||||
$err = __DbRep_rl_updateHourDatabase ($paref);
|
|
||||||
|
|
||||||
if ($err) {
|
|
||||||
Log3 ($name, 2, "DbRep $name - ERROR - reduceLog $mstr failed for day $processingDay: $err");
|
|
||||||
$err = encode_base64($err, "");
|
|
||||||
|
|
||||||
DbRep_rollbackOnly ($name, $dbh);
|
|
||||||
return $err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
__DbRep_rl_onlyFillDayArray ($paref);
|
|
||||||
}
|
}
|
||||||
}
|
elsif ($mstr eq 'max') { # Berechnung Max
|
||||||
elsif ($mstr eq 'max') { # Berechnung Max
|
$value = __DbRep_rl_calcMaxHourly ($paref);
|
||||||
if (scalar @{$hourHash->{$hourKey}->[4]} > 1) {
|
}
|
||||||
|
|
||||||
$i++;
|
$paref->{logtxt} = "(hourly-$mstr) updating";
|
||||||
|
$paref->{newvalue} = $value;
|
||||||
my $max;
|
|
||||||
|
$err = __DbRep_rl_updateHourDatabase ($paref);
|
||||||
for my $val (@{$hourHash->{$hourKey}->[4]}) {
|
|
||||||
if (!defined $max) {
|
if ($err) {
|
||||||
$max = $val;
|
Log3 ($name, 2, "DbRep $name - ERROR - reduceLog $mstr failed for day $processingDay: $err");
|
||||||
}
|
$err = encode_base64($err, "");
|
||||||
else {
|
|
||||||
$max = $val if ($val > $max);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
my $value = sprintf "%.${ndp}f", $max;
|
DbRep_rollbackOnly ($name, $dbh);
|
||||||
|
return $err;
|
||||||
$paref->{logtxt} = "(hourly-$mstr) updating";
|
}
|
||||||
$paref->{newvalue} = $value;
|
}
|
||||||
|
else {
|
||||||
$err = __DbRep_rl_updateHourDatabase ($paref);
|
__DbRep_rl_onlyFillDayArray ($paref);
|
||||||
|
}
|
||||||
if ($err) {
|
|
||||||
Log3 ($name, 2, "DbRep $name - ERROR - reduceLog $mstr failed for day $processingDay: $err");
|
|
||||||
$err = encode_base64($err, "");
|
|
||||||
|
|
||||||
DbRep_rollbackOnly ($name, $dbh);
|
|
||||||
return $err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
__DbRep_rl_onlyFillDayArray ($paref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9470,6 +9434,51 @@ sub _DbRep_rl_updateHour {
|
|||||||
return $err;
|
return $err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
# reduceLog stündlichen average Wert berechnen
|
||||||
|
####################################################################################################
|
||||||
|
sub __DbRep_rl_calcAverageHourly {
|
||||||
|
my $paref = shift;
|
||||||
|
my $name = $paref->{name};
|
||||||
|
my $hourHashKeyRef = $paref->{hourHashKeyRef};
|
||||||
|
my $ndp = $paref->{ndp};
|
||||||
|
|
||||||
|
my $sum = 0;
|
||||||
|
|
||||||
|
for my $val (@{$hourHashKeyRef}) {
|
||||||
|
$sum += $val;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $value = sprintf "%.${ndp}f", $sum / scalar @{$hourHashKeyRef};
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
# reduceLog stündlichen Max Wert berechnen
|
||||||
|
####################################################################################################
|
||||||
|
sub __DbRep_rl_calcMaxHourly {
|
||||||
|
my $paref = shift;
|
||||||
|
my $name = $paref->{name};
|
||||||
|
my $hourHashKeyRef = $paref->{hourHashKeyRef};
|
||||||
|
my $ndp = $paref->{ndp};
|
||||||
|
|
||||||
|
my $max;
|
||||||
|
|
||||||
|
for my $val (@{$hourHashKeyRef}) {
|
||||||
|
if (!defined $max) {
|
||||||
|
$max = $val;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$max = $val if ($val > $max);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
my $value = sprintf "%.${ndp}f", $max;
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# reduceLog Stundenupdate Datenbank und
|
# reduceLog Stundenupdate Datenbank und
|
||||||
# füllen Tages Update Array
|
# füllen Tages Update Array
|
||||||
|
Loading…
Reference in New Issue
Block a user