2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 03:06:37 +00:00

93_DbRep: new attr numDecimalPlaces

git-svn-id: https://svn.fhem.de/fhem/trunk@25250 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2021-11-21 12:22:51 +00:00
parent fac8aae0a9
commit 3803d06af3
2 changed files with 144 additions and 108 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- feature: 93_DbRep: new attr numDecimalPlaces,
Forum:#/topic,53584.msg1178063.html#msg1178063
- change: 98_WeekdayTimer: CONDITION now is checked at each switching time - change: 98_WeekdayTimer: CONDITION now is checked at each switching time
- bugfix: 10_KNX: fix for dpt3, dpt10 and dpt19 (working days) - bugfix: 10_KNX: fix for dpt3, dpt10 and dpt19 (working days)
- bugfix: 88_HMCCU: Fixed some bugs - bugfix: 88_HMCCU: Fixed some bugs

View File

@ -57,6 +57,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# Version History intern # Version History intern
my %DbRep_vNotesIntern = ( my %DbRep_vNotesIntern = (
"8.44.0" => "21.11.2021 new attr numDecimalPlaces ",
"8.43.1" => "02.11.2021 fix SQL statement if devspec can't be resolved, Forum:https://forum.fhem.de/index.php/topic,53584.msg1184155.html#msg1184155 ", "8.43.1" => "02.11.2021 fix SQL statement if devspec can't be resolved, Forum:https://forum.fhem.de/index.php/topic,53584.msg1184155.html#msg1184155 ",
"8.43.0" => "22.09.2021 consider attr device, reading in sqlCmd, remove length limit of attr device, reading ", "8.43.0" => "22.09.2021 consider attr device, reading in sqlCmd, remove length limit of attr device, reading ",
"8.42.9" => "05.09.2021 minor fixes, change SQL for SQLite in deldoublets_DoParse ", "8.42.9" => "05.09.2021 minor fixes, change SQL for SQLite in deldoublets_DoParse ",
@ -309,10 +310,12 @@ my %DbRep_vHintsExt_de = (
"1" => "Hilfreiche Hinweise zu DbRep im <a href=\"https://wiki.fhem.de/wiki/DbRep_-_Reporting_und_Management_von_DbLog-Datenbankinhalten#Praxisbeispiele_.2F_Hinweise_und_L.C3.B6sungsans.C3.A4tze_f.C3.BCr_verschiedene_Aufgaben\">FHEM-Wiki</a>." "1" => "Hilfreiche Hinweise zu DbRep im <a href=\"https://wiki.fhem.de/wiki/DbRep_-_Reporting_und_Management_von_DbLog-Datenbankinhalten#Praxisbeispiele_.2F_Hinweise_und_L.C3.B6sungsans.C3.A4tze_f.C3.BCr_verschiedene_Aufgaben\">FHEM-Wiki</a>."
); );
# Standard Feldbreiten falls noch nicht getInitData ausgeführt
my %dbrep_col = ("DEVICE" => 64, # Variablendefinitionen
"READING" => 64, my %dbrep_col = ("DEVICE" => 64, "READING" => 64, ); # Standard Feldbreiten falls noch nicht getInitData ausgeführt
); my $defdecplaces = 4; # Nachkommastellen Standard
################################################################################### ###################################################################################
# DbRep_Initialize # DbRep_Initialize
@ -364,6 +367,7 @@ sub DbRep_Initialize {
"ftpUseSSL:1,0 ". "ftpUseSSL:1,0 ".
"diffAccept ". "diffAccept ".
"limit ". "limit ".
"numDecimalPlaces:0,1,2,3,4,5,6,7 ".
"optimizeTablesBeforeDump:1,0 ". "optimizeTablesBeforeDump:1,0 ".
"readingNameMap ". "readingNameMap ".
"readingPreventFromDel ". "readingPreventFromDel ".
@ -1585,7 +1589,6 @@ return;
################################################################################### ###################################################################################
sub DbRep_firstconnect { sub DbRep_firstconnect {
my $string = shift; my $string = shift;
my ($name,$opt,$prop,$fret) = split("\\|", $string); my ($name,$opt,$prop,$fret) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $to = AttrVal($name, "timeout", "86400"); my $to = AttrVal($name, "timeout", "86400");
@ -1634,7 +1637,7 @@ return;
# DatenDatenbankeigenschaften ermitteln # DatenDatenbankeigenschaften ermitteln
#################################################################################################### ####################################################################################################
sub DbRep_getInitData { sub DbRep_getInitData {
my ($string) = @_; my $string = shift;
my ($name,$opt,$prop,$fret) = split("\\|", $string); my ($name,$opt,$prop,$fret) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -1752,7 +1755,7 @@ return $ret;
# Auswertungsroutine DbRep_getInitData # Auswertungsroutine DbRep_getInitData
#################################################################################################### ####################################################################################################
sub DbRep_getInitDataDone { sub DbRep_getInitDataDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -3211,6 +3214,8 @@ sub averval_ParseDone {
my $irowdone = $a[6]; my $irowdone = $a[6];
my $gtsstr = $a[7] ? decode_base64($a[7]) : undef; my $gtsstr = $a[7] ? decode_base64($a[7]) : undef;
my $gtsreached = $a[8]; my $gtsreached = $a[8];
my $ndp = AttrVal($name, "numDecimalPlaces", $defdecplaces);
my $reading_runtime_string; my $reading_runtime_string;
my $erread; my $erread;
@ -3284,7 +3289,7 @@ sub averval_ParseDone {
ReadingsBulkUpdateValue ($hash, $reading_runtime_string, looks_like_number($c) ? sprintf("%.1f",$c) :$c); ReadingsBulkUpdateValue ($hash, $reading_runtime_string, looks_like_number($c) ? sprintf("%.1f",$c) :$c);
} }
else { else {
ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $c ? sprintf("%.4f",$c) : "-"); ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $c ? sprintf("%.${ndp}f", $c) : "-");
} }
} }
@ -3675,6 +3680,8 @@ sub maxval_ParseDone {
my ($rt,$brt) = split(",", $bt); my ($rt,$brt) = split(",", $bt);
my $err = $a[5] ? decode_base64($a[5]) : undef; my $err = $a[5] ? decode_base64($a[5]) : undef;
my $irowdone = $a[6]; my $irowdone = $a[6];
my $ndp = AttrVal($name, "numDecimalPlaces", $defdecplaces);
my $reading_runtime_string; my $reading_runtime_string;
my $erread; my $erread;
@ -3721,7 +3728,7 @@ sub maxval_ParseDone {
} }
my $rv = $k[1]; my $rv = $k[1];
ReadingsBulkUpdateValue ($hash, $reading_runtime_string, defined($rv)?sprintf("%.4f",$rv):"-"); ReadingsBulkUpdateValue ($hash, $reading_runtime_string, defined($rv) ? sprintf("%.${ndp}f",$rv) : "-");
} }
ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB|deleteOther/); ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB|deleteOther/);
@ -3928,6 +3935,8 @@ sub minval_ParseDone {
my ($rt,$brt) = split(",", $bt); my ($rt,$brt) = split(",", $bt);
my $err = $a[5] ? decode_base64($a[5]) : undef; my $err = $a[5] ? decode_base64($a[5]) : undef;
my $irowdone = $a[6]; my $irowdone = $a[6];
my $ndp = AttrVal($name, "numDecimalPlaces", $defdecplaces);
my $reading_runtime_string; my $reading_runtime_string;
my $erread; my $erread;
@ -3974,7 +3983,7 @@ sub minval_ParseDone {
} }
my $rv = $k[1]; my $rv = $k[1];
ReadingsBulkUpdateValue ($hash, $reading_runtime_string, defined($rv)?sprintf("%.4f",$rv):"-"); ReadingsBulkUpdateValue ($hash, $reading_runtime_string, defined($rv) ? sprintf("%.${ndp}f",$rv) : "-");
} }
ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB|deleteOther/); ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB|deleteOther/);
@ -4035,7 +4044,7 @@ sub diffval_DoParse {
my @row_array; my @row_array;
my @array; my @array;
foreach my $row (@ts) { for my $row (@ts) {
my @a = split("#", $row); my @a = split("#", $row);
my $runtime_string = $a[0]; my $runtime_string = $a[0];
my $runtime_string_first = $a[1]; my $runtime_string_first = $a[1];
@ -4137,7 +4146,7 @@ sub diffval_DoParse {
Log3 ($name, 5, "DbRep $name - data of row_array result assigned to fields:\n"); Log3 ($name, 5, "DbRep $name - data of row_array result assigned to fields:\n");
foreach my $row (@row_array) { for my $row (@row_array) {
my @a = split("[ \t][ \t]*", $row, 6); my @a = split("[ \t][ \t]*", $row, 6);
my $runtime_string = decode_base64($a[0]); my $runtime_string = decode_base64($a[0]);
$lastruntimestring = $runtime_string if ($i == 1); $lastruntimestring = $runtime_string if ($i == 1);
@ -4184,7 +4193,8 @@ sub diffval_DoParse {
$lval = $value; $lval = $value;
$rslval = $runtime_string; $rslval = $runtime_string;
} }
} else { }
else {
# neuer Zeitabschnitt beginnt, ersten Value-Wert erfassen und Übertragsdifferenz bilden # neuer Zeitabschnitt beginnt, ersten Value-Wert erfassen und Übertragsdifferenz bilden
$lastruntimestring = $runtime_string; $lastruntimestring = $runtime_string;
$i = 1; $i = 1;
@ -4206,7 +4216,7 @@ sub diffval_DoParse {
} }
Log3 ($name, 4, "DbRep $name - result of diffValue calculation before encoding:"); Log3 ($name, 4, "DbRep $name - result of diffValue calculation before encoding:");
foreach my $key (sort(keys(%rh))) { for my $key (sort(keys(%rh))) {
Log3 ($name, 4, "runtimestring Key: $key, value: ".$rh{$key}); Log3 ($name, 4, "runtimestring Key: $key, value: ".$rh{$key});
} }
@ -4272,9 +4282,11 @@ sub diffval_ParseDone {
my $ncpslist = decode_base64($a[6]); # Hash von Perioden die nicht kalkuliert werden konnten "no calc in period" my $ncpslist = decode_base64($a[6]); # Hash von Perioden die nicht kalkuliert werden konnten "no calc in period"
my $err = $a[7] ? decode_base64($a[7]) : undef; my $err = $a[7] ? decode_base64($a[7]) : undef;
my $irowdone = $a[8]; my $irowdone = $a[8];
my $reading_runtime_string; my $ndp = AttrVal($name, "numDecimalPlaces", $defdecplaces);
my $difflimit = AttrVal($name, "diffAccept", "20"); # legt fest, bis zu welchem Wert Differenzen akzeptoert werden (Ausreißer eliminieren)AttrVal($name, "diffAccept", "20"); my $difflimit = AttrVal($name, "diffAccept", "20"); # legt fest, bis zu welchem Wert Differenzen akzeptoert werden (Ausreißer eliminieren)AttrVal($name, "diffAccept", "20");
my $erread; my $erread;
my $reading_runtime_string;
Log3 ($name, 5, qq{DbRep $name - BlockingCall finished PID "$hash->{HELPER}{RUNNING_PID}{pid}"}); Log3 ($name, 5, qq{DbRep $name - BlockingCall finished PID "$hash->{HELPER}{RUNNING_PID}{pid}"});
@ -4333,7 +4345,7 @@ sub diffval_ParseDone {
} }
my $rv = $k[1]; my $rv = $k[1];
ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $rv?sprintf("%.4f",$rv):"-"); ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $rv ? sprintf("%.${ndp}f", $rv) : "-");
} }
@ -4434,6 +4446,7 @@ sub sumval_DoParse {
@rsn = split(" ",$runtime_string_next); @rsn = split(" ",$runtime_string_next);
$arrstr .= $runtime_string."#".$line[0]."#".$rsf[0]."|"; $arrstr .= $runtime_string."#".$line[0]."#".$rsf[0]."|";
} }
@wsf = split(" ",$runtime_string_first); @wsf = split(" ",$runtime_string_first);
@wsn = split(" ",$runtime_string_next); @wsn = split(" ",$runtime_string_next);
$wrstr .= $runtime_string."#".$line[0]."#".$wsf[0]."_".$wsf[1]."#".$wsn[0]."_".$wsn[1]."|"; # Kombi zum Rückschreiben in die DB $wrstr .= $runtime_string."#".$line[0]."#".$wsf[0]."_".$wsf[1]."#".$wsn[0]."_".$wsn[1]."|"; # Kombi zum Rückschreiben in die DB
@ -4482,6 +4495,7 @@ sub sumval_ParseDone {
my ($rt,$brt) = split(",", $bt); my ($rt,$brt) = split(",", $bt);
my $err = $a[5] ? decode_base64($a[5]) : undef; my $err = $a[5] ? decode_base64($a[5]) : undef;
my $irowdone = $a[6]; my $irowdone = $a[6];
my $ndp = AttrVal($name, "numDecimalPlaces", $defdecplaces);
my ($reading_runtime_string,$erread); my ($reading_runtime_string,$erread);
@ -4520,7 +4534,7 @@ sub sumval_ParseDone {
$reading_runtime_string = $rsf.$ds.$rds."SUM__".$runtime_string; $reading_runtime_string = $rsf.$ds.$rds."SUM__".$runtime_string;
} }
ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $c ne "" ? sprintf "%.4f", $c : "-"); ReadingsBulkUpdateValue ($hash, $reading_runtime_string, $c ne "" ? sprintf "%.${ndp}f", $c : "-");
} }
ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB/); ReadingsBulkUpdateValue ($hash, "db_lines_processed", $irowdone) if($hash->{LASTCMD} =~ /writeToDB/);
@ -4535,7 +4549,7 @@ return;
# nichtblockierendes DB delete # nichtblockierendes DB delete
#################################################################################################### ####################################################################################################
sub del_DoParse { sub del_DoParse {
my ($string) = @_; my $string = shift;
my ($name,$table,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my ($name,$table,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -4605,7 +4619,7 @@ sub del_DoParse {
# Auswertungsroutine DB delete # Auswertungsroutine DB delete
#################################################################################################### ####################################################################################################
sub del_ParseDone { sub del_ParseDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -4755,7 +4769,7 @@ sub insert_Push {
# Auswertungsroutine DB insert # Auswertungsroutine DB insert
#################################################################################################### ####################################################################################################
sub insert_Done { sub insert_Done {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -4802,7 +4816,7 @@ return;
# Current-Tabelle mit Device,Reading Kombinationen aus history auffüllen # Current-Tabelle mit Device,Reading Kombinationen aus history auffüllen
#################################################################################################### ####################################################################################################
sub currentfillup_Push { sub currentfillup_Push {
my ($string) = @_; my $string = shift;
my ($name,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my ($name,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -4864,7 +4878,8 @@ sub currentfillup_Push {
# SQL-Statement zusammenstellen # SQL-Statement zusammenstellen
if ($IsTimeSet || $IsAggrSet) { if ($IsTimeSet || $IsAggrSet) {
$sql = DbRep_createCommonSql($hash,$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon); $sql = DbRep_createCommonSql($hash,$selspec,$device,$reading,"'$runtime_string_first'","'$runtime_string_next'",$addon);
} else { }
else {
$sql = DbRep_createCommonSql($hash,$selspec,$device,$reading,undef,undef,$addon); $sql = DbRep_createCommonSql($hash,$selspec,$device,$reading,undef,undef,$addon);
} }
@ -4911,7 +4926,7 @@ sub currentfillup_Push {
# Auswertungsroutine Current-Tabelle auffüllen # Auswertungsroutine Current-Tabelle auffüllen
#################################################################################################### ####################################################################################################
sub currentfillup_Done { sub currentfillup_Done {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -4958,7 +4973,7 @@ return;
# nichtblockierendes DB deviceRename / readingRename # nichtblockierendes DB deviceRename / readingRename
#################################################################################################### ####################################################################################################
sub change_Push { sub change_Push {
my ($string) = @_; my $string = shift;
my ($name,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my ($name,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -5060,7 +5075,7 @@ sub change_Push {
# nichtblockierendes DB changeValue (Field VALUE) # nichtblockierendes DB changeValue (Field VALUE)
#################################################################################################### ####################################################################################################
sub changeval_Push { sub changeval_Push {
my ($string) = @_; my $string = shift;
my ($name,$device,$reading,$runtime_string_first,$runtime_string_next,$ts) = split("\\§", $string); my ($name,$device,$reading,$runtime_string_first,$runtime_string_next,$ts) = split("\\§", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -5239,7 +5254,7 @@ sub changeval_Push {
# Auswertungsroutine DB deviceRename/readingRename/changeValue # Auswertungsroutine DB deviceRename/readingRename/changeValue
#################################################################################################### ####################################################################################################
sub change_Done { sub change_Done {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -5307,7 +5322,7 @@ return;
# nichtblockierende DB-Abfrage fetchrows # nichtblockierende DB-Abfrage fetchrows
#################################################################################################### ####################################################################################################
sub fetchrows_DoParse { sub fetchrows_DoParse {
my ($string) = @_; my $string = shift;
my ($name,$table,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my ($name,$table,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -5338,7 +5353,8 @@ sub fetchrows_DoParse {
# SQL zusammenstellen für DB-Abfrage # SQL zusammenstellen für DB-Abfrage
if ($IsTimeSet) { if ($IsTimeSet) {
$sql = DbRep_createSelectSql($hash,$table,"DEVICE,READING,TIMESTAMP,VALUE,UNIT",$device,$reading,"'$runtime_string_first'","'$runtime_string_next'","ORDER BY TIMESTAMP $fetchroute LIMIT ".($limit+1)); $sql = DbRep_createSelectSql($hash,$table,"DEVICE,READING,TIMESTAMP,VALUE,UNIT",$device,$reading,"'$runtime_string_first'","'$runtime_string_next'","ORDER BY TIMESTAMP $fetchroute LIMIT ".($limit+1));
} else { }
else {
$sql = DbRep_createSelectSql($hash,$table,"DEVICE,READING,TIMESTAMP,VALUE,UNIT",$device,$reading,undef,undef,"ORDER BY TIMESTAMP $fetchroute LIMIT ".($limit+1)); $sql = DbRep_createSelectSql($hash,$table,"DEVICE,READING,TIMESTAMP,VALUE,UNIT",$device,$reading,undef,undef,"ORDER BY TIMESTAMP $fetchroute LIMIT ".($limit+1));
} }
@ -5392,7 +5408,7 @@ sub fetchrows_DoParse {
# Auswertungsroutine der nichtblockierenden DB-Abfrage fetchrows # Auswertungsroutine der nichtblockierenden DB-Abfrage fetchrows
#################################################################################################### ####################################################################################################
sub fetchrows_ParseDone { sub fetchrows_ParseDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $rowlist = decode_base64($a[1]); my $rowlist = decode_base64($a[1]);
@ -5509,7 +5525,7 @@ return;
# Doubletten finden und löschen # Doubletten finden und löschen
#################################################################################################### ####################################################################################################
sub deldoublets_DoParse { sub deldoublets_DoParse {
my ($string) = @_; my $string = shift;
my ($name,$opt,$device,$reading,$ts) = split("\\§", $string); my ($name,$opt,$device,$reading,$ts) = split("\\§", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -5682,7 +5698,7 @@ return "$name|$rowlist|$rt|0|$retn|$opt";
# sequentielle Doubletten löschen # sequentielle Doubletten löschen
#################################################################################################### ####################################################################################################
sub delseqdoubl_DoParse { sub delseqdoubl_DoParse {
my ($string) = @_; my $string = shift;
my ($name,$opt,$device,$reading,$ts) = split("\\§", $string); my ($name,$opt,$device,$reading,$ts) = split("\\§", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -5898,7 +5914,7 @@ return "$name|$rowlist|$rt|0|$retn|$opt";
# Auswertungsroutine delSeqDoublets / delDoublets # Auswertungsroutine delSeqDoublets / delDoublets
#################################################################################################### ####################################################################################################
sub delseqdoubl_ParseDone { sub delseqdoubl_ParseDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $rowlist = decode_base64($a[1]); my $rowlist = decode_base64($a[1]);
@ -5972,7 +5988,7 @@ return;
# nichtblockierende DB-Funktion expfile # nichtblockierende DB-Funktion expfile
#################################################################################################### ####################################################################################################
sub expfile_DoParse { sub expfile_DoParse {
my ($string) = @_; my $string = shift;
my ($name, $device, $reading, $rsf, $file, $ts) = split("\\§", $string); my ($name, $device, $reading, $rsf, $file, $ts) = split("\\§", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -6115,7 +6131,7 @@ sub expfile_DoParse {
# Auswertungsroutine der nichtblockierenden DB-Funktion expfile # Auswertungsroutine der nichtblockierenden DB-Funktion expfile
#################################################################################################### ####################################################################################################
sub expfile_ParseDone { sub expfile_ParseDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $nrows = $a[1]; my $nrows = $a[1];
@ -6164,7 +6180,7 @@ return;
# nichtblockierende DB-Funktion impfile # nichtblockierende DB-Funktion impfile
#################################################################################################### ####################################################################################################
sub impfile_Push { sub impfile_Push {
my ($string) = @_; my $string = shift;
my ($name, $rsf, $file) = split("\\|", $string); my ($name, $rsf, $file) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -6320,7 +6336,7 @@ sub impfile_Push {
# Auswertungsroutine der nichtblockierenden DB-Funktion impfile # Auswertungsroutine der nichtblockierenden DB-Funktion impfile
#################################################################################################### ####################################################################################################
sub impfile_PushDone { sub impfile_PushDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $irowdone = $a[1]; my $irowdone = $a[1];
@ -6366,7 +6382,7 @@ return;
# set logdbrep sqlCmd select count(*) from history # set logdbrep sqlCmd select count(*) from history
# set logdbrep sqlCmd select DEVICE,count(*) from history group by DEVICE HAVING count(*) > 10000 # set logdbrep sqlCmd select DEVICE,count(*) from history group by DEVICE HAVING count(*) > 10000
sub sqlCmd_DoParse { sub sqlCmd_DoParse {
my ($string) = @_; my $string = shift;
my ($name, $opt, $runtime_string_first, $runtime_string_next, $cmd) = split("\\|", $string); my ($name, $opt, $runtime_string_first, $runtime_string_next, $cmd) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -6585,7 +6601,7 @@ sub sqlCmd_DoParse {
# Auswertungsroutine der nichtblockierenden DB-Abfrage sqlCmd # Auswertungsroutine der nichtblockierenden DB-Abfrage sqlCmd
#################################################################################################### ####################################################################################################
sub sqlCmd_ParseDone { sub sqlCmd_ParseDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -6647,7 +6663,7 @@ sub sqlCmd_ParseDone {
my $res = "<html><table border=2 bordercolor='darkgreen' cellspacing=0>"; my $res = "<html><table border=2 bordercolor='darkgreen' cellspacing=0>";
my @rows = split( /§/, $rowstring ); my @rows = split( /§/, $rowstring );
my $row; my $row;
foreach $row ( @rows ) { for $row ( @rows ) {
$row =~ s/\|°escaped°\|/§/g; $row =~ s/\|°escaped°\|/§/g;
$row =~ s/$srs/\|/g if($srs !~ /\|/); $row =~ s/$srs/\|/g if($srs !~ /\|/);
$row =~ s/\|/<\/td><td style='padding-right:5px;padding-left:5px;text-align: right;'>/g; $row =~ s/\|/<\/td><td style='padding-right:5px;padding-left:5px;text-align: right;'>/g;
@ -6661,7 +6677,7 @@ sub sqlCmd_ParseDone {
my $res = "<html>"; my $res = "<html>";
my @rows = split( /§/, $rowstring ); my @rows = split( /§/, $rowstring );
my $row; my $row;
foreach $row ( @rows ) { for $row ( @rows ) {
$row =~ s/\|°escaped°\|/§/g; $row =~ s/\|°escaped°\|/§/g;
$res .= $row."<br>"; $res .= $row."<br>";
} }
@ -6675,7 +6691,7 @@ sub sqlCmd_ParseDone {
my $numd = ceil(log10($bigint)); my $numd = ceil(log10($bigint));
my $formatstr = sprintf('%%%d.%dd', $numd, $numd); my $formatstr = sprintf('%%%d.%dd', $numd, $numd);
my $i = 0; my $i = 0;
foreach my $row ( @rows ) { for my $row ( @rows ) {
$i++; $i++;
$row =~ s/\|°escaped°\|/§/g; $row =~ s/\|°escaped°\|/§/g;
my $fi = sprintf($formatstr, $i); my $fi = sprintf($formatstr, $i);
@ -6688,13 +6704,13 @@ sub sqlCmd_ParseDone {
my $numd = ceil(log10($bigint)); my $numd = ceil(log10($bigint));
my $formatstr = sprintf('%%%d.%dd', $numd, $numd); my $formatstr = sprintf('%%%d.%dd', $numd, $numd);
my $i = 0; my $i = 0;
foreach my $row ( @rows ) { for my $row ( @rows ) {
$i++; $i++;
$row =~ s/\|°escaped°\|/§/g; $row =~ s/\|°escaped°\|/§/g;
my $fi = sprintf($formatstr, $i); my $fi = sprintf($formatstr, $i);
$result{$fi} = $row; $result{$fi} = $row;
} }
my $json = toJSON(\%result); # at least fhem.pl 14348 2017-05-22 20:25:06Z my $json = toJSON(\%result); # need at least fhem.pl 14348 2017-05-22 20:25:06Z
ReadingsBulkUpdateValue ($hash, "SqlResult", $json); ReadingsBulkUpdateValue ($hash, "SqlResult", $json);
} }
@ -6708,7 +6724,7 @@ return;
# nichtblockierende DB-Abfrage get db Metadaten # nichtblockierende DB-Abfrage get db Metadaten
#################################################################################################### ####################################################################################################
sub dbmeta_DoParse { sub dbmeta_DoParse {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $name = $a[0]; my $name = $a[0];
my $hash = $defs{$name}; my $hash = $defs{$name};
@ -6917,7 +6933,7 @@ sub dbmeta_DoParse {
# Auswertungsroutine der nichtblockierenden DB-Abfrage get db Metadaten # Auswertungsroutine der nichtblockierenden DB-Abfrage get db Metadaten
#################################################################################################### ####################################################################################################
sub dbmeta_ParseDone { sub dbmeta_ParseDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -6974,7 +6990,7 @@ return;
# #
#################################################################################################### ####################################################################################################
sub DbRep_Index { sub DbRep_Index {
my ($string) = @_; my $string = shift;
my ($name,$cmdidx) = split("\\|", $string); my ($name,$cmdidx) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -7156,7 +7172,7 @@ return "$name|$ret|$rt|''";
# Auswertungsroutine Index Operation # Auswertungsroutine Index Operation
#################################################################################################### ####################################################################################################
sub DbRep_IndexDone { sub DbRep_IndexDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $name = $a[0]; my $name = $a[0];
my $hash = $defs{$name}; my $hash = $defs{$name};
@ -7404,7 +7420,7 @@ return "$name|$rt|''|$db_MB_start|$db_MB_end";
# Auswertungsroutine optimize tables # Auswertungsroutine optimize tables
#################################################################################################### ####################################################################################################
sub DbRep_OptimizeDone { sub DbRep_OptimizeDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $bt = $a[1]; my $bt = $a[1];
@ -8222,7 +8238,7 @@ return "$name|$rt|''|$dump_path$bfile|n.a.|n.a.|$fsize|$ftp|$bfd|$ffd";
# Auswertungsroutine der nicht blockierenden DB-Funktion Dump # Auswertungsroutine der nicht blockierenden DB-Funktion Dump
#################################################################################################### ####################################################################################################
sub DbRep_DumpDone { sub DbRep_DumpDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $bt = $a[1]; my $bt = $a[1];
@ -8345,7 +8361,7 @@ return "$name|$brt|0";
# Auswertungsroutine der nicht blockierenden DB-Funktion Dump # Auswertungsroutine der nicht blockierenden DB-Funktion Dump
#################################################################################################### ####################################################################################################
sub DbRep_RepairDone { sub DbRep_RepairDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $brt = $a[1]; my $brt = $a[1];
@ -8390,7 +8406,7 @@ return;
# Restore SQLite # Restore SQLite
#################################################################################################### ####################################################################################################
sub DbRep_sqliteRestore { sub DbRep_sqliteRestore {
my ($string) = @_; my $string = shift;
my ($name,$bfile) = split("\\|", $string); my ($name,$bfile) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -8468,7 +8484,7 @@ return "$name|$rt|''|$dump_path$bfile|n.a.";
# Restore MySQL (serverSide) # Restore MySQL (serverSide)
#################################################################################################### ####################################################################################################
sub mysql_RestoreServerSide { sub mysql_RestoreServerSide {
my ($string) = @_; my $string = shift;
my ($name, $bfile) = split("\\|", $string); my ($name, $bfile) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -8542,7 +8558,7 @@ return "$name|$rt|''|$dump_path_rem$bfile|n.a.";
# Restore MySQL (ClientSide) # Restore MySQL (ClientSide)
#################################################################################################### ####################################################################################################
sub mysql_RestoreClientSide { sub mysql_RestoreClientSide {
my ($string) = @_; my $string = shift;
my ($name, $bfile) = split("\\|", $string); my ($name, $bfile) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -8731,7 +8747,7 @@ return "$name|$rt|''|$dump_path$bfile|$nh|$nc";
# Auswertungsroutine Restore # Auswertungsroutine Restore
#################################################################################################### ####################################################################################################
sub DbRep_restoreDone { sub DbRep_restoreDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $bt = $a[1]; my $bt = $a[1];
@ -8773,7 +8789,7 @@ return;
# Übertragung Datensätze in weitere DB # Übertragung Datensätze in weitere DB
#################################################################################################### ####################################################################################################
sub DbRep_syncStandby { sub DbRep_syncStandby {
my ($string) = @_; my $string = shift;
my ($name,$device,$reading,$runtime_string_first,$runtime_string_next,$ts,$stbyname) = split("\\§", $string); my ($name,$device,$reading,$runtime_string_first,$runtime_string_next,$ts,$stbyname) = split("\\§", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $table = "history"; my $table = "history";
@ -8890,7 +8906,7 @@ sub DbRep_syncStandby {
# Auswertungsroutine Übertragung Datensätze in weitere DB # Auswertungsroutine Übertragung Datensätze in weitere DB
#################################################################################################### ####################################################################################################
sub DbRep_syncStandbyDone { sub DbRep_syncStandbyDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $hash = $defs{$a[0]}; my $hash = $defs{$a[0]};
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -8933,7 +8949,7 @@ return;
# $nts - reduce Logs neuer als: Attribut "timeDiffToNow" oder "timestamp_end" # $nts - reduce Logs neuer als: Attribut "timeDiffToNow" oder "timestamp_end"
#################################################################################################### ####################################################################################################
sub DbRep_reduceLog { sub DbRep_reduceLog {
my ($string) = @_; my $string = shift;
my ($name,$d,$r,$nts,$ots) = split("\\|", $string); my ($name,$d,$r,$nts,$ots) = split("\\|", $string);
my $hash = $defs{$name}; my $hash = $defs{$name};
my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}};
@ -9297,7 +9313,7 @@ return "$name|$ret|0|$brt";
# reduceLog non-blocking Rückkehrfunktion # reduceLog non-blocking Rückkehrfunktion
#################################################################################################### ####################################################################################################
sub DbRep_reduceLogDone { sub DbRep_reduceLogDone {
my ($string) = @_; my $string = shift;
my @a = split("\\|",$string); my @a = split("\\|",$string);
my $name = $a[0]; my $name = $a[0];
my $hash = $defs{$name}; my $hash = $defs{$name};
@ -9530,7 +9546,8 @@ sub DbRep_createCommonSql {
if(defined $valfilter) { if(defined $valfilter) {
if ($dbmodel eq "POSTGRESQL") { if ($dbmodel eq "POSTGRESQL") {
$vf = "VALUE ~ '$valfilter' AND "; $vf = "VALUE ~ '$valfilter' AND ";
} else { }
else {
$vf = "VALUE REGEXP '$valfilter' AND "; $vf = "VALUE REGEXP '$valfilter' AND ";
} }
} }
@ -9545,7 +9562,8 @@ sub DbRep_createCommonSql {
foreach(@dwc) { foreach(@dwc) {
if($i<$len) { if($i<$len) {
$sql .= "DEVICE LIKE '$_' OR "; $sql .= "DEVICE LIKE '$_' OR ";
} else { }
else {
$sql .= "DEVICE LIKE '$_' "; $sql .= "DEVICE LIKE '$_' ";
} }
$i++; $i++;
@ -9576,7 +9594,8 @@ sub DbRep_createCommonSql {
foreach(@rwc) { foreach(@rwc) {
if($i<$len) { if($i<$len) {
$sql .= "READING LIKE '$_' OR "; $sql .= "READING LIKE '$_' OR ";
} else { }
else {
$sql .= "READING LIKE '$_' "; $sql .= "READING LIKE '$_' ";
} }
$i++; $i++;
@ -9606,7 +9625,8 @@ sub DbRep_createCommonSql {
} else { } else {
if ($dbmodel eq "POSTGRESQL") { if ($dbmodel eq "POSTGRESQL") {
$sql .= "true "; $sql .= "true ";
} else { }
else {
$sql .= "1 "; $sql .= "1 ";
} }
} }
@ -11228,6 +11248,8 @@ sub DbRep_OutputWriteToDB {
my $unit = ""; my $unit = "";
my $wrt = 0; my $wrt = 0;
my $irowdone = 0; my $irowdone = 0;
my $ndp = AttrVal($name, "numDecimalPlaces", $defdecplaces);
my ($dbh,$sth_ih,$sth_uh,$sth_ic,$sth_uc,$err,$value,$date,$time,$hour,$minute,$ndate,$ntime,$rsf,$rsn,@row_array); my ($dbh,$sth_ih,$sth_uh,$sth_ic,$sth_uc,$err,$value,$date,$time,$hour,$minute,$ndate,$ntime,$rsf,$rsn,@row_array);
my ($timestamp,$year,$mon,$mday,$t1,$corr); my ($timestamp,$year,$mon,$mday,$t1,$corr);
@ -11250,7 +11272,7 @@ sub DbRep_OutputWriteToDB {
foreach my $row (@arr) { foreach my $row (@arr) {
my @a = split("#", $row); my @a = split("#", $row);
my $runtime_string = $a[0]; # Aggregations-Alias (nicht benötigt) my $runtime_string = $a[0]; # Aggregations-Alias (nicht benötigt)
$value = defined($a[1])?(looks_like_number($a[1])?sprintf("%.4f",$a[1]):undef):undef; # in Version 8.40.0 geändert $value = defined($a[1]) ? (looks_like_number($a[1]) ? sprintf("%.${ndp}f",$a[1]) : undef) : undef; # in Version 8.40.0 geändert
$rsf = $a[2]; # Runtime String first - Datum / Zeit für DB-Speicherung $rsf = $a[2]; # Runtime String first - Datum / Zeit für DB-Speicherung
($date,$time) = split("_",$rsf); ($date,$time) = split("_",$rsf);
$time =~ s/-/:/g if($time); $time =~ s/-/:/g if($time);
@ -11314,7 +11336,7 @@ sub DbRep_OutputWriteToDB {
my %rh = split("§", $wrstr); my %rh = split("§", $wrstr);
foreach my $key (sort(keys(%rh))) { foreach my $key (sort(keys(%rh))) {
my @k = split("\\|",$rh{$key}); my @k = split("\\|",$rh{$key});
$value = defined($k[1])?sprintf("%.4f",$k[1]):undef; $value = defined($k[1])?sprintf("%.${ndp}f",$k[1]):undef;
$rsf = $k[2]; # Datum / Zeit für DB-Speicherung $rsf = $k[2]; # Datum / Zeit für DB-Speicherung
($date,$time) = split("_",$rsf); ($date,$time) = split("_",$rsf);
@ -14291,6 +14313,12 @@ sub bdump {
avoids FHEMWEB from blocking. Please change the attribut according your requirements or change the avoids FHEMWEB from blocking. Please change the attribut according your requirements or change the
selection criteria (decrease evaluation period). </li> <br> selection criteria (decrease evaluation period). </li> <br>
<a name="numDecimalPlaces"></a>
<li><b>numDecimalPlaces </b> - Sets the number of decimal places for readings with numeric results. <br>
Excludes results from user-specific queries (sqlCmd). <br>
(default: 4)
</li> <br>
<a name="optimizeTablesBeforeDump"></a> <a name="optimizeTablesBeforeDump"></a>
<li><b>optimizeTablesBeforeDump </b> - if set to "1", the database tables will be optimized before executing the dump <li><b>optimizeTablesBeforeDump </b> - if set to "1", the database tables will be optimized before executing the dump
(default: 0). (default: 0).
@ -15205,7 +15233,7 @@ sub bdump {
<ul> <ul>
<table> <table>
<colgroup> <col width=5%> <col width=95%> </colgroup> <colgroup> <col width=5%> <col width=95%> </colgroup>
<tr><td> <b>allowDeletion</b> </td><td>: needs to be set to execute the delete option </td></tr> <tr><td> <b>allowDeletion</b> </td><td>: Freischaltung der Löschfunktion </td></tr>
<tr><td> <b>aggregation</b> </td><td>: Auswahl einer Aggregationsperiode </td></tr> <tr><td> <b>aggregation</b> </td><td>: Auswahl einer Aggregationsperiode </td></tr>
<tr><td> <b>device</b> </td><td>: einschließen oder ausschließen von Datensätzen die &lt;device&gt; enthalten </td></tr> <tr><td> <b>device</b> </td><td>: einschließen oder ausschließen von Datensätzen die &lt;device&gt; enthalten </td></tr>
<tr><td> <b>limit</b> </td><td>: begrenzt NUR die Anzahl der anzuzeigenden Datensätze </td></tr> <tr><td> <b>limit</b> </td><td>: begrenzt NUR die Anzahl der anzuzeigenden Datensätze </td></tr>
@ -16946,6 +16974,12 @@ sub bdump {
blockieren von FHEMWEB verhindern. Bei Bedarf entsprechend ändern bzw. die blockieren von FHEMWEB verhindern. Bei Bedarf entsprechend ändern bzw. die
Selektionskriterien (Zeitraum der Auswertung) anpassen. </li> <br> Selektionskriterien (Zeitraum der Auswertung) anpassen. </li> <br>
<a name="numDecimalPlaces"></a>
<li><b>numDecimalPlaces </b> - Legt die Anzahl der Nachkommastellen bei Readings mit numerischen Ergebnissen fest. <br>
Ausgenommen sind Ergebnisse aus userspezifischen Abfragen (sqlCmd). <br>
(default: 4)
</li> <br>
<a name="optimizeTablesBeforeDump"></a> <a name="optimizeTablesBeforeDump"></a>
<li><b>optimizeTablesBeforeDump </b> - wenn "1", wird vor dem Datenbankdump eine Tabellenoptimierung ausgeführt (default: 0). <li><b>optimizeTablesBeforeDump </b> - wenn "1", wird vor dem Datenbankdump eine Tabellenoptimierung ausgeführt (default: 0).
Dadurch verlängert sich die Laufzeit des Dump. <br><br> Dadurch verlängert sich die Laufzeit des Dump. <br><br>