From 3a0dbe629e2a578bd03026fff340b78fff77018f Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Thu, 23 Jul 2020 21:09:07 +0000 Subject: [PATCH] 93_DbRep: new aggregation value 'minute', some fixes git-svn-id: https://svn.fhem.de/fhem/trunk@22455 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/93_DbRep.pm | 527 ++++++++++++++++------------ fhem/contrib/DS_Starter/93_DbRep.pm | 74 ++-- 3 files changed, 343 insertions(+), 259 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index bcd7e7460..320228ee9 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # 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. + - feature: 93_DbRep: new aggregation value 'minute', some fixes - feature: 14_SD_UT.pm new model Westinghouse Bendan, NAVARIS touch light switch, Remote control BF-301 from Shenzhen BOFU Mechanic & Electronic Co diff --git a/fhem/FHEM/93_DbRep.pm b/fhem/FHEM/93_DbRep.pm index b9c422159..31402e032 100644 --- a/fhem/FHEM/93_DbRep.pm +++ b/fhem/FHEM/93_DbRep.pm @@ -53,11 +53,12 @@ use Time::Local; use Encode; use IO::Compress::Gzip qw(gzip $GzipError); use IO::Uncompress::Gunzip qw(gunzip $GunzipError); -# no if $] >= 5.018000, warnings => 'experimental'; no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Version History intern our %DbRep_vNotesIntern = ( + "8.40.4" => "23.07.2020 new aggregation value 'minute', some fixes ", + "8.40.3" => "22.07.2020 delete prototypes ", "8.40.2" => "27.06.2020 improve versionNotes 2 ", "8.40.1" => "18.05.2020 improve 'restore' setlist, revised comRef, fix compare timesettings for delEntries,reduceLog ", "8.40.0" => "30.03.2020 new attribute 'autoForward' ", @@ -317,7 +318,6 @@ our %DbRep_vHintsExt_de = ( ); # foreward declaration -sub DbRep_Main($$;$); sub DbLog_cutCol($$$$$$$); # DbLog-Funktion nutzen um Daten auf maximale Länge beschneiden # Standard Feldbreiten falls noch nicht getInitData ausgeführt @@ -328,7 +328,7 @@ my %dbrep_col = ("DEVICE" => 64, ################################################################################### # DbRep_Initialize ################################################################################### -sub DbRep_Initialize($) { +sub DbRep_Initialize { my ($hash) = @_; $hash->{DefFn} = "DbRep_Define"; $hash->{UndefFn} = "DbRep_Undef"; @@ -340,7 +340,8 @@ sub DbRep_Initialize($) { $hash->{AttrFn} = "DbRep_Attr"; $hash->{FW_deviceOverview} = 1; - $hash->{AttrList} = "disable:1,0 ". + $hash->{AttrList} = "aggregation:minute,hour,day,week,month,year,no ". + "disable:1,0 ". "reading ". "allowDeletion:1,0 ". "autoForward:textField-long ". @@ -372,7 +373,6 @@ sub DbRep_Initialize($) { "ftpUse:1,0 ". "ftpUser ". "ftpUseSSL:1,0 ". - "aggregation:hour,day,week,month,year,no ". "diffAccept ". "limit ". "optimizeTablesBeforeDump:1,0 ". @@ -423,7 +423,7 @@ return; ################################################################################### # DbRep_Define ################################################################################### -sub DbRep_Define($@) { +sub DbRep_Define { # define DbRep # ($hash) [1] [2] # @@ -470,9 +470,9 @@ return; } ################################################################################### -# DbRep_Set +# Set ################################################################################### -sub DbRep_Set($@) { +sub DbRep_Set { my ($hash, @a) = @_; return "\"set X\" needs at least an argument" if ( @a < 2 ); my $name = $a[0]; @@ -551,7 +551,7 @@ sub DbRep_Set($@) { if ($opt =~ /eraseReadings/) { $hash->{LASTCMD} = $prop?"$opt $prop":"$opt"; DbRep_delread($hash); # Readings löschen die nicht in der Ausnahmeliste (Attr readingPreventFromDel) stehen - return undef; + return; } if ($opt eq "dumpMySQL" && $hash->{ROLE} ne "Agent") { @@ -567,7 +567,7 @@ sub DbRep_Set($@) { } DbRep_beforeproc($hash, "dump"); DbRep_Main($hash,$opt,$prop); - return undef; + return; } if ($opt eq "dumpSQLite" && $hash->{ROLE} ne "Agent") { @@ -577,7 +577,7 @@ sub DbRep_Set($@) { Log3 ($name, 3, "DbRep $name - ################################################################"); DbRep_beforeproc($hash, "dump"); DbRep_Main($hash,$opt,$prop); - return undef; + return; } if ($opt eq "repairSQLite" && $hash->{ROLE} ne "Agent") { @@ -596,7 +596,7 @@ sub DbRep_Set($@) { DbRep_beforeproc($hash, "repair"); DbRep_Main($hash,$opt); - return undef; + return; } if ($opt =~ /restoreMySQL|restoreSQLite/ && $hash->{ROLE} ne "Agent") { @@ -606,7 +606,7 @@ sub DbRep_Set($@) { Log3 ($name, 3, "DbRep $name - ################################################################"); DbRep_beforeproc($hash, "restore"); DbRep_Main($hash,$opt,$prop); - return undef; + return; } if ($opt =~ /optimizeTables|vacuum/ && $hash->{ROLE} ne "Agent") { @@ -616,7 +616,7 @@ sub DbRep_Set($@) { Log3 ($name, 3, "DbRep $name - ################################################################"); DbRep_beforeproc($hash, "optimize"); DbRep_Main($hash,$opt); - return undef; + return; } if ($opt =~ m/delSeqDoublets|delDoublets/ && $hash->{ROLE} ne "Agent") { @@ -626,7 +626,7 @@ sub DbRep_Set($@) { } DbRep_beforeproc($hash, "delDoublets"); DbRep_Main($hash,$opt,$prop); - return undef; + return; } if ($opt =~ m/reduceLog/ && $hash->{ROLE} ne "Agent") { @@ -643,7 +643,7 @@ sub DbRep_Set($@) { Log3 ($name, 3, "DbRep $name - ################################################################"); DbRep_beforeproc($hash, "reduceLog"); DbRep_Main($hash,$opt); - return undef; + return; } } @@ -667,7 +667,7 @@ sub DbRep_Set($@) { BlockingKill($hash->{HELPER}{RUNNING_BACKUP_CLIENT}); Log3 ($name, 3, "DbRep $name -> running Dump has been canceled"); ReadingsSingleUpdateValue ($hash, "state", "Dump canceled", 1); - return undef; + return; } if ($opt eq "cancelRepair" && $hash->{ROLE} ne "Agent") { @@ -675,7 +675,7 @@ sub DbRep_Set($@) { BlockingKill($hash->{HELPER}{RUNNING_REPAIR}); Log3 ($name, 3, "DbRep $name -> running Repair has been canceled"); ReadingsSingleUpdateValue ($hash, "state", "Repair canceled", 1); - return undef; + return; } if ($opt eq "cancelRestore" && $hash->{ROLE} ne "Agent") { @@ -683,13 +683,13 @@ sub DbRep_Set($@) { BlockingKill($hash->{HELPER}{RUNNING_RESTORE}); Log3 ($name, 3, "DbRep $name -> running Restore has been canceled"); ReadingsSingleUpdateValue ($hash, "state", "Restore canceled", 1); - return undef; + return; } if ($opt =~ m/tableCurrentFillup/ && $hash->{ROLE} ne "Agent") { $hash->{LASTCMD} = $prop?"$opt $prop":"$opt"; DbRep_Main($hash,$opt); - return undef; + return; } if ($opt eq "index" && $hash->{ROLE} ne "Agent") { @@ -697,10 +697,11 @@ sub DbRep_Set($@) { Log3 ($name, 3, "DbRep $name - ################################################################"); Log3 ($name, 3, "DbRep $name - ### New Index operation ###"); Log3 ($name, 3, "DbRep $name - ################################################################"); - # Befehl vor Procedure ausführen - DbRep_beforeproc($hash, "index"); - DbRep_Main($hash,$opt,$prop); - return undef; + + # Befehl vor Procedure ausführen + DbRep_beforeproc ($hash, "index"); + DbRep_Main ($hash,$opt,$prop); + return; } if ($opt eq "adminCredentials" && $hash->{ROLE} ne "Agent") { @@ -937,9 +938,9 @@ return; } ################################################################################### -# DbRep_Get +# Get ################################################################################### -sub DbRep_Get($@) { +sub DbRep_Get { my ($hash, @a) = @_; return "\"get X\" needs at least an argument" if ( @a < 2 ); my $name = $a[0]; @@ -1128,9 +1129,9 @@ return; } ################################################################################### -# DbRep_Attr +# Attr ################################################################################### -sub DbRep_Attr($$$$) { +sub DbRep_Attr { my ($cmd,$name,$aName,$aVal) = @_; my $hash = $defs{$name}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -1414,14 +1415,15 @@ sub DbRep_Attr($$$$) { return "Length of \"$aName\" is too big. Maximum length for database type $dbmodel is $mlen" if(length($aVal) > $mlen); } } - } -return undef; + } + +return; } ################################################################################### -# DbRep_Notify Eventverarbeitung +# Eventverarbeitung ################################################################################### -sub DbRep_Notify($$) { +sub DbRep_Notify { # Es werden nur die Events von Geräten verarbeitet die im Hash $hash->{NOTIFYDEV} gelistet sind (wenn definiert). # Dadurch kann die Menge der Events verringert werden. In sub DbRep_Define angeben. # Beispiele: @@ -1493,7 +1495,7 @@ return; ################################################################################### # DbRep_Undef ################################################################################### -sub DbRep_Undef($$) { +sub DbRep_Undef { my ($hash, $arg) = @_; RemoveInternalTimer($hash); @@ -1510,7 +1512,7 @@ sub DbRep_Undef($$) { DbRep_delread($hash,1); -return undef; +return; } ################################################################################### @@ -1523,7 +1525,7 @@ return undef; # FHEM-Prozess, als auch dauerhafte Daten bspw. im physikalischen # Gerät zu löschen die mit dieser Gerätedefinition zu tun haben. ################################################################################### -sub DbRep_Delete($$) { +sub DbRep_Delete { my ($hash, $arg) = @_; my $name = $hash->{NAME}; @@ -1531,13 +1533,13 @@ sub DbRep_Delete($$) { my $index = $hash->{TYPE}."_".$name."_adminCredentials"; setKeyValue($index, undef); -return undef; +return; } ################################################################################### # DbRep_Shutdown ################################################################################### -sub DbRep_Shutdown($) { +sub DbRep_Shutdown { my ($hash) = @_; my $dbh = $hash->{DBH}; @@ -1545,14 +1547,14 @@ sub DbRep_Shutdown($) { DbRep_delread($hash,1); RemoveInternalTimer($hash); -return undef; +return; } ################################################################################### # First Init DB Connect # Verbindung zur DB aufbauen und Datenbankeigenschaften ermitteln ################################################################################### -sub DbRep_firstconnect(@) { +sub DbRep_firstconnect { my ($string) = @_; my ($name,$opt,$prop,$fret) = split("\\|", $string); my $hash = $defs{$name}; @@ -1592,7 +1594,7 @@ return; #################################################################################################### # DatenDatenbankeigenschaften ermitteln #################################################################################################### -sub DbRep_getInitData($) { +sub DbRep_getInitData { my ($string) = @_; my ($name,$opt,$prop,$fret) = split("\\|", $string); my $hash = $defs{$name}; @@ -1699,7 +1701,7 @@ return "$name|$mints|$rt|0|$opt|$prop|$fret|$idxstate|$grants"; #################################################################################################### # Auswertungsroutine DbRep_getInitData #################################################################################################### -sub DbRep_getInitDataDone($) { +sub DbRep_getInitDataDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -1748,7 +1750,7 @@ return &$fret($hash,$opt,$prop); #################################################################################################### # Abbruchroutine DbRep_getInitData #################################################################################################### -sub DbRep_getInitDataAborted(@) { +sub DbRep_getInitDataAborted { my ($hash,$cause) = @_; my $name = $hash->{NAME}; @@ -1768,7 +1770,7 @@ return; ###################################################################################### # Connect zur Datenbank herstellen ###################################################################################### -sub DbRep_dbConnect($$) { +sub DbRep_dbConnect { my ($name,$uac) = @_; my $hash = $defs{$name}; my $dbconn = $defs{$defs{$name}->{HELPER}{DBLOGDEVICE}}->{dbconn}; @@ -1814,7 +1816,7 @@ return ($err,$dbh); ################################################################################################################ # Hauptroutine ################################################################################################################ -sub DbRep_Main($$;$) { +sub DbRep_Main { my ($hash,$opt,$prop) = @_; my $name = $hash->{NAME}; my $to = AttrVal($name, "timeout", "86400"); @@ -1945,12 +1947,13 @@ sub DbRep_Main($$;$) { ($epoch_seconds_begin,$epoch_seconds_end,$runtime_string_first,$runtime_string_next,$ts) = DbRep_createTimeArray($hash,$aggregation,$opt); } else { Log3 ($name, 4, "DbRep $name - Timestamp begin human readable: not set") if($opt !~ /tableCurrentPurge/); - Log3 ($name, 4, "DbRep $name - Timestamp end human readable: not set") if($opt !~ /tableCurrentPurge/); + Log3 ($name, 4, "DbRep $name - Timestamp end human readable: not set") if($opt !~ /tableCurrentPurge/); } - Log3 ($name, 4, "DbRep $name - Aggregation: $aggregation") if($opt !~ /tableCurrentPurge|tableCurrentFillup|fetchrows|insert|reduceLog|delEntries/); + Log3 ($name, 4, "DbRep $name - Aggregation: $aggregation") if($opt !~ /tableCurrentPurge|tableCurrentFillup|fetchrows|insert|reduceLog|delEntries|^sql/x); - ##### Funktionsaufrufe ##### + ##### Funktionsaufrufe ##### + ############################# if ($opt eq "sumValue") { $hash->{HELPER}{RUNNING_PID} = BlockingCall("sumval_DoParse", "$name§$device§$reading§$prop§$ts", "sumval_ParseDone", $to, "DbRep_ParseAborted", $hash); @@ -2106,13 +2109,14 @@ sub DbRep_Main($$;$) { } $hash->{HELPER}{RUNNING_PID}{loglevel} = 5 if($hash->{HELPER}{RUNNING_PID}); # Forum #77057 + return; } ################################################################################################################ # Create zentrales Timsstamp-Array ################################################################################################################ -sub DbRep_createTimeArray($$$) { +sub DbRep_createTimeArray { my ($hash,$aggregation,$opt) = @_; my $name = $hash->{NAME}; @@ -2432,10 +2436,10 @@ sub DbRep_createTimeArray($$$) { my $testr = strftime "%H:%M:%S", localtime($epoch_seconds_end); # für Berechnung Tagesverschieber / Stundenverschieber my $dsstr = strftime "%Y-%m-%d", localtime($runtime); # für Berechnung Tagesverschieber / Stundenverschieber my $destr = strftime "%Y-%m-%d", localtime($epoch_seconds_end); # für Berechnung Tagesverschieber / Stundenverschieber - my $msstr = strftime "%m", localtime($runtime); # Startmonat für Berechnung Monatsverschieber - my $mestr = strftime "%m", localtime($epoch_seconds_end); # Endemonat für Berechnung Monatsverschieber - my $ysstr = strftime "%Y", localtime($runtime); # Startjahr für Berechnung Monatsverschieber - my $yestr = strftime "%Y", localtime($epoch_seconds_end); # Endejahr für Berechnung Monatsverschieber + my $msstr = strftime "%m", localtime($runtime); # Startmonat für Berechnung Monatsverschieber + my $mestr = strftime "%m", localtime($epoch_seconds_end); # Endemonat für Berechnung Monatsverschieber + my $ysstr = strftime "%Y", localtime($runtime); # Startjahr für Berechnung Monatsverschieber + my $yestr = strftime "%Y", localtime($epoch_seconds_end); # Endejahr für Berechnung Monatsverschieber my $wd = strftime "%a", localtime($runtime); # Wochentag des aktuellen Startdatum/Zeit my $wdadd = 604800 if($wd eq "Mo"); # wenn Start am "Mo" dann nächste Grenze +7 Tage @@ -2449,7 +2453,9 @@ sub DbRep_createTimeArray($$$) { Log3 ($name, 5, "DbRep $name - weekday start for selection: $wd -> wdadd: $wdadd") if($wdadd); my $aggsec; - if ($aggregation eq "hour") { + if ($aggregation eq "minute") { + $aggsec = 60; + } elsif ($aggregation eq "hour") { $aggsec = 3600; } elsif ($aggregation eq "day") { $aggsec = 86400; @@ -2494,9 +2500,12 @@ return ($epoch_seconds_begin,$epoch_seconds_end,$runtime_string_first,$runtime_s } #################################################################################################### +# # Zusammenstellung Aggregationszeiträume +# $runtime = Beginnzeit in Epochesekunden +# #################################################################################################### -sub DbRep_collaggstr($$$$) { +sub DbRep_collaggstr { my ($hash,$runtime,$i,$runtime_string_next) = @_; my $name = $hash->{NAME}; my $runtime_string; # Datum/Zeit im SQL-Format für Readingname Teilstring @@ -2579,9 +2588,10 @@ sub DbRep_collaggstr($$$$) { my $rm = strftime "%m", localtime($runtime); # Monat des aktuell laufenden Startdatums d. SQL-Select my $ry = strftime "%Y", localtime($runtime); # Jahr des aktuell laufenden Startdatums d. SQL-Select my $dim = $rm-2?30+($rm*3%7<4):28+!($ry%4||$ry%400*!($ry%100)); # Anzahl Tage des aktuell laufenden Monats - Log3 ($name, 5, "DbRep $name - act year: $ry, act month: $rm, days in month: $dim, endyear: $yestr, endmonth: $mestr"); - $aggsec = $dim * 86400; + Log3 ($name, 5, "DbRep $name - act year: $ry, act month: $rm, days in month: $dim, endyear: $yestr, endmonth: $mestr"); + + $aggsec = $dim * 86400; $runtime = $runtime+3600 if(DbRep_dsttest($hash,$runtime,$aggsec) && (strftime "%m", localtime($runtime)) > 6); # Korrektur Winterzeitumstellung (Uhr wurde 1 Stunde zurück gestellt) $runtime_string = strftime "%Y-%m", localtime($runtime); # für Readingname @@ -2631,9 +2641,9 @@ sub DbRep_collaggstr($$$$) { # Korrektur $runtime_orig für Berechnung neue Beginnzeit für nächsten Durchlauf my ($yyyy1, $mm1, $dd1) = ($runtime_string_first =~ /(\d+)-(\d+)-(\d+)/); - $runtime = timelocal("00", "00", "00", $dd1, $mm1-1, $yyyy1-1900); - $runtime = $runtime+3600 if(DbRep_dsttest($hash,$runtime,$aggsec) && (strftime "%m", localtime($runtime)) > 6); # Korrektur Winterzeitumstellung (Uhr wurde 1 Stunde zurück gestellt) - $runtime = $runtime+$wdadd; + $runtime = timelocal("00", "00", "00", $dd1, $mm1-1, $yyyy1-1900); + $runtime = $runtime+3600 if(DbRep_dsttest($hash,$runtime,$aggsec) && (strftime "%m", localtime($runtime)) > 6); # Korrektur Winterzeitumstellung (Uhr wurde 1 Stunde zurück gestellt) + $runtime = $runtime+$wdadd; $runtime_orig = $runtime-$aggsec; # die Woche Beginn ist gleich der Woche vom Ende Auswertung @@ -2646,7 +2656,7 @@ sub DbRep_collaggstr($$$$) { } else { # weitere Durchläufe if(($runtime+$aggsec) > $epoch_seconds_end) { - $runtime_string_first = strftime "%Y-%m-%d", localtime($runtime_orig); + $runtime_string_first = strftime "%Y-%m-%d", localtime($runtime_orig); $runtime_string_next = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_end); $ll=1; } else { @@ -2661,13 +2671,13 @@ sub DbRep_collaggstr($$$$) { # Tagesaggregation if ($aggregation eq "day") { - $runtime_string = strftime "%Y-%m-%d", localtime($runtime); # für Readingname + $runtime_string = strftime "%Y-%m-%d", localtime($runtime); # für Readingname $runtime_string_first = strftime "%Y-%m-%d %H:%M:%S", localtime($runtime) if($i==1); - $runtime_string_first = strftime "%Y-%m-%d", localtime($runtime) if($i>1); - $runtime = $runtime+3600 if(DbRep_dsttest($hash,$runtime,$aggsec) && (strftime "%m", localtime($runtime)) > 6); # Korrektur Winterzeitumstellung (Uhr wurde 1 Stunde zurück gestellt) + $runtime_string_first = strftime "%Y-%m-%d", localtime($runtime) if($i>1); + $runtime = $runtime+3600 if(DbRep_dsttest($hash,$runtime,$aggsec) && (strftime "%m", localtime($runtime)) > 6); # Korrektur Winterzeitumstellung (Uhr wurde 1 Stunde zurück gestellt) if((($tsstr gt $testr) ? $runtime : ($runtime+$aggsec)) > $epoch_seconds_end) { - $runtime_string_first = strftime "%Y-%m-%d", localtime($runtime); + $runtime_string_first = strftime "%Y-%m-%d", localtime($runtime); $runtime_string_first = strftime "%Y-%m-%d %H:%M:%S", localtime($runtime) if( $dsstr eq $destr); $runtime_string_next = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_end); $ll=1; @@ -2683,20 +2693,20 @@ sub DbRep_collaggstr($$$$) { # Stundenaggregation if ($aggregation eq "hour") { - $runtime_string = strftime "%Y-%m-%d_%H", localtime($runtime); # für Readingname + $runtime_string = strftime "%Y-%m-%d_%H", localtime($runtime); # für Readingname $runtime_string_first = strftime "%Y-%m-%d %H:%M:%S", localtime($runtime) if($i==1); - $runtime = $runtime+3600 if(DbRep_dsttest($hash,$runtime,$aggsec) && (strftime "%m", localtime($runtime)) > 6); # Korrektur Winterzeitumstellung (Uhr wurde 1 Stunde zurück gestellt) - $runtime_string_first = strftime "%Y-%m-%d %H", localtime($runtime) if($i>1); + $runtime = $runtime+3600 if(DbRep_dsttest($hash,$runtime,$aggsec) && (strftime "%m", localtime($runtime)) > 6); # Korrektur Winterzeitumstellung (Uhr wurde 1 Stunde zurück gestellt) + $runtime_string_first = strftime "%Y-%m-%d %H", localtime($runtime) if($i>1); - my @a = split (":",$tsstr); - my $hs = $a[0]; + my @a = split (":",$tsstr); + my $hs = $a[0]; my $msstr = $a[1].":".$a[2]; - @a = split (":",$testr); - my $he = $a[0]; + @a = split (":",$testr); + my $he = $a[0]; my $mestr = $a[1].":".$a[2]; if((($msstr gt $mestr) ? $runtime : ($runtime+$aggsec)) > $epoch_seconds_end) { - $runtime_string_first = strftime "%Y-%m-%d %H", localtime($runtime); + $runtime_string_first = strftime "%Y-%m-%d %H", localtime($runtime); $runtime_string_first = strftime "%Y-%m-%d %H:%M:%S", localtime($runtime) if( $dsstr eq $destr && $hs eq $he); $runtime_string_next = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_end); $ll=1; @@ -2707,6 +2717,33 @@ sub DbRep_collaggstr($$$$) { # neue Beginnzeit in Epoche-Sekunden $runtime = $runtime+$aggsec; } + + # Minutenaggregation + if ($aggregation eq "minute") { + $runtime_string = strftime "%Y-%m-%d_%H_%M", localtime($runtime); # für Readingname + $runtime_string_first = strftime "%Y-%m-%d %H:%M:%S", localtime($runtime) if($i==1); + $runtime = $runtime+60 if(DbRep_dsttest($hash,$runtime,$aggsec) && (strftime "%m", localtime($runtime)) > 6); # Korrektur Winterzeitumstellung (Uhr wurde 1 Stunde zurück gestellt) + $runtime_string_first = strftime "%Y-%m-%d %H:%M", localtime($runtime) if($i>1); + + my @a = split (":",$tsstr); + my $ms = $a[1]; + my $ssstr = $a[2]; + @a = split (":",$testr); + my $me = $a[1]; + my $sestr = $a[2]; + + if((($ssstr gt $sestr) ? $runtime : ($runtime+$aggsec)) > $epoch_seconds_end) { + $runtime_string_first = strftime "%Y-%m-%d %H:%M", localtime($runtime); + # $runtime_string_first = strftime "%Y-%m-%d %H:%M", localtime($runtime) if( $dsstr eq $destr && $ms eq $me); + $runtime_string_next = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_end); + $ll=1; + } else { + $runtime_string_next = strftime "%Y-%m-%d %H:%M", localtime($runtime+$aggsec); + } + + # neue Beginnzeit in Epoche-Sekunden + $runtime = $runtime+$aggsec; + } return ($runtime,$runtime_string,$runtime_string_first,$runtime_string_next,$ll); } @@ -2714,7 +2751,7 @@ return ($runtime,$runtime_string,$runtime_string_first,$runtime_string_next,$ll) #################################################################################################### # nichtblockierende DB-Abfrage averageValue #################################################################################################### -sub averval_DoParse($) { +sub averval_DoParse { my ($string) = @_; my ($name,$device,$reading,$prop,$ts) = split("\\§", $string); my $hash = $defs{$name}; @@ -2809,10 +2846,15 @@ sub averval_DoParse($) { Log3 ($name, 5, "DbRep $name - SQL result: $line[0]") if($line[0]); - if(AttrVal($name, "aggregation", "") eq "hour") { + my $aval = (DbRep_checktimeaggr($hash))[2]; + if($aval eq "hour") { @rsf = split(/[ :]/,$runtime_string_first); @rsn = split(/[ :]/,$runtime_string_next); $arrstr .= $runtime_string."#".$line[0]."#".$rsf[0]."_".$rsf[1]."|"; + } elsif ($aval eq "minute") { + @rsf = split(/[ :]/,$runtime_string_first); + @rsn = split(/[ :]/,$runtime_string_next); + $arrstr .= $runtime_string."#".$line[0]."#".$rsf[0]."_".$rsf[1]."-".$rsf[2]."|"; } else { @rsf = split(" ",$runtime_string_first); @rsn = split(" ",$runtime_string_next); @@ -2870,10 +2912,15 @@ sub averval_DoParse($) { $sum = qq{insufficient values - execute get $name versionNotes 2 for further information}; } - if(AttrVal($name, "aggregation", "") eq "hour") { + my $aval = (DbRep_checktimeaggr($hash))[2]; + if($aval eq "hour") { @rsf = split(/[ :]/,$runtime_string_first); @rsn = split(/[ :]/,$runtime_string_next); $arrstr .= $runtime_string."#".$sum."#".$rsf[0]."_".$rsf[1]."|"; + } elsif ($aval eq "minute") { + @rsf = split(/[ :]/,$runtime_string_first); + @rsn = split(/[ :]/,$runtime_string_next); + $arrstr .= $runtime_string."#".$sum."#".$rsf[0]."_".$rsf[1]."-".$rsf[2]."|"; } else { @rsf = split(" ",$runtime_string_first); @rsn = split(" ",$runtime_string_next); @@ -2881,7 +2928,7 @@ sub averval_DoParse($) { } @wsf = split(" ",$runtime_string_first); @wsn = split(" ",$runtime_string_next); - $wrstr .= $runtime_string."#".$sum."#".$rsf[0]."_".$rsf[1]."#".$rsn[0]."_".$rsn[1]."|"; # Kombi zum Rückschreiben in die DB + $wrstr .= $runtime_string."#".$sum."#".$wsf[0]."_".$wsf[1]."#".$wsn[0]."_".$wsn[1]."|"; # Kombi zum Rückschreiben in die DB } elsif ($acf eq "avgTimeWeightMean") { # zeitgewichteten Mittelwert berechnen @@ -2959,10 +3006,16 @@ sub averval_DoParse($) { Log3 ($name, 5, "DbRep $name - time sum: $tsum, delta time: $dt, value: $val1, twm: ".$val1*($dt/$tsum)); } } - if(AttrVal($name, "aggregation", "") eq "hour") { + + my $aval = (DbRep_checktimeaggr($hash))[2]; + if($aval eq "hour") { @rsf = split(/[ :]/,$runtime_string_first); @rsn = split(/[ :]/,$runtime_string_next); $arrstr .= $runtime_string."#".$sum."#".$rsf[0]."_".$rsf[1]."|"; + } elsif ($aval eq "minute") { + @rsf = split(/[ :]/,$runtime_string_first); + @rsn = split(/[ :]/,$runtime_string_next); + $arrstr .= $runtime_string."#".$sum."#".$rsf[0]."_".$rsf[1]."-".$rsf[2]."|"; } else { @rsf = split(" ",$runtime_string_first); @rsn = split(" ",$runtime_string_next); @@ -2970,7 +3023,7 @@ sub averval_DoParse($) { } @wsf = split(" ",$runtime_string_first); @wsn = split(" ",$runtime_string_next); - $wrstr .= $runtime_string."#".$sum."#".$rsf[0]."_".$rsf[1]."#".$rsn[0]."_".$rsn[1]."|"; # Kombi zum Rückschreiben in die DB + $wrstr .= $runtime_string."#".$sum."#".$wsf[0]."_".$wsf[1]."#".$wsn[0]."_".$wsn[1]."|"; # Kombi zum Rückschreiben in die DB } } @@ -3007,7 +3060,7 @@ sub averval_DoParse($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Abfrage averageValue #################################################################################################### -sub averval_ParseDone($) { +sub averval_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -3082,7 +3135,7 @@ return; #################################################################################################### # nichtblockierende DB-Abfrage count #################################################################################################### -sub count_DoParse($) { +sub count_DoParse { my ($string) = @_; my ($name,$table,$device,$reading,$ts) = split("\\§", $string); my $hash = $defs{$name}; @@ -3197,7 +3250,7 @@ sub count_DoParse($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Abfrage count #################################################################################################### -sub count_ParseDone($) { +sub count_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -3261,7 +3314,7 @@ return; #################################################################################################### # nichtblockierende DB-Abfrage maxValue #################################################################################################### -sub maxval_DoParse($) { +sub maxval_DoParse { my ($string) = @_; my ($name,$device,$reading,$prop,$ts) = split("\\§", $string); my $hash = $defs{$name}; @@ -3326,9 +3379,13 @@ sub maxval_DoParse($) { my @array = map { $runtime_string." ".$_->[0]." ".$_->[1]."!_ESC_!".$runtime_string_first."|".$runtime_string_next } @{ $sth->fetchall_arrayref() }; if(!@array) { - if(AttrVal($name, "aggregation", "") eq "hour") { + my $aval = AttrVal($name, "aggregation", ""); + if($aval eq "hour") { my @rsf = split(/[ :]/,$runtime_string_first); @array = ($runtime_string." "."0"." ".$rsf[0]."_".$rsf[1]."!_ESC_!".$runtime_string_first."|".$runtime_string_next); + } elsif($aval eq "minute") { + my @rsf = split(/[ :]/,$runtime_string_first); + @array = ($runtime_string." "."0"." ".$rsf[0]."_".$rsf[1]."-".$rsf[2]."!_ESC_!".$runtime_string_first."|".$runtime_string_next); } else { my @rsf = split(" ",$runtime_string_first); @array = ($runtime_string." "."0"." ".$rsf[0]."!_ESC_!".$runtime_string_first."|".$runtime_string_next); @@ -3437,7 +3494,7 @@ sub maxval_DoParse($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Abfrage maxValue #################################################################################################### -sub maxval_ParseDone($) { +sub maxval_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -3505,7 +3562,7 @@ return; #################################################################################################### # nichtblockierende DB-Abfrage minValue #################################################################################################### -sub minval_DoParse($) { +sub minval_DoParse { my ($string) = @_; my ($name,$device,$reading,$prop,$ts) = split("\\§", $string); my $hash = $defs{$name}; @@ -3570,9 +3627,13 @@ sub minval_DoParse($) { my @array = map { $runtime_string." ".$_->[0]." ".$_->[1]."!_ESC_!".$runtime_string_first."|".$runtime_string_next } @{ $sth->fetchall_arrayref() }; if(!@array) { - if(AttrVal($name, "aggregation", "") eq "hour") { + my $aval = AttrVal($name, "aggregation", ""); + if($aval eq "hour") { my @rsf = split(/[ :]/,$runtime_string_first); @array = ($runtime_string." "."0"." ".$rsf[0]."_".$rsf[1]."!_ESC_!".$runtime_string_first."|".$runtime_string_next); + } elsif($aval eq "minute") { + my @rsf = split(/[ :]/,$runtime_string_first); + @array = ($runtime_string." "."0"." ".$rsf[0]."_".$rsf[1]."-".$rsf[2]."!_ESC_!".$runtime_string_first."|".$runtime_string_next); } else { my @rsf = split(" ",$runtime_string_first); @array = ($runtime_string." "."0"." ".$rsf[0]."!_ESC_!".$runtime_string_first."|".$runtime_string_next); @@ -3681,7 +3742,7 @@ sub minval_DoParse($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Abfrage minValue #################################################################################################### -sub minval_ParseDone($) { +sub minval_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -3749,7 +3810,7 @@ return; #################################################################################################### # nichtblockierende DB-Abfrage diffValue #################################################################################################### -sub diffval_DoParse($) { +sub diffval_DoParse { my ($string) = @_; my ($name,$device,$reading,$prop,$ts) = split("\\§", $string); my $hash = $defs{$name}; @@ -3858,9 +3919,13 @@ sub diffval_DoParse($) { } if(!@array) { - if(AttrVal($name, "aggregation", "") eq "hour") { + my $aval = AttrVal($name, "aggregation", ""); + if($aval eq "hour") { my @rsf = split(/[ :]/,$runtime_string_first); @array = ($runtime_string." ".$rsf[0]."_".$rsf[1]."\n"); + } elsif($aval eq "minute") { + my @rsf = split(/[ :]/,$runtime_string_first); + @array = ($runtime_string." ".$rsf[0]."_".$rsf[1]."-".$rsf[2]."\n"); } else { my @rsf = split(" ",$runtime_string_first); @array = ($runtime_string." ".$rsf[0]."\n"); @@ -4013,7 +4078,7 @@ sub diffval_DoParse($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Abfrage diffValue #################################################################################################### -sub diffval_ParseDone($) { +sub diffval_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -4103,7 +4168,7 @@ return; #################################################################################################### # nichtblockierende DB-Abfrage sumValue #################################################################################################### -sub sumval_DoParse($) { +sub sumval_DoParse { my ($string) = @_; my ($name,$device,$reading,$prop,$ts) = split("\\§", $string); my $hash = $defs{$name}; @@ -4226,7 +4291,7 @@ sub sumval_DoParse($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Abfrage sumValue #################################################################################################### -sub sumval_ParseDone($) { +sub sumval_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -4289,7 +4354,7 @@ return; #################################################################################################### # nichtblockierendes DB delete #################################################################################################### -sub del_DoParse($) { +sub del_DoParse { my ($string) = @_; my ($name,$table,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my $hash = $defs{$name}; @@ -4359,7 +4424,7 @@ sub del_DoParse($) { #################################################################################################### # Auswertungsroutine DB delete #################################################################################################### -sub del_ParseDone($) { +sub del_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -4416,7 +4481,7 @@ return; #################################################################################################### # nichtblockierendes DB insert #################################################################################################### -sub insert_Push($) { +sub insert_Push { my ($name) = @_; my $hash = $defs{$name}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -4504,7 +4569,7 @@ sub insert_Push($) { #################################################################################################### # Auswertungsroutine DB insert #################################################################################################### -sub insert_Done($) { +sub insert_Done { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -4549,7 +4614,7 @@ return; #################################################################################################### # Current-Tabelle mit Device,Reading Kombinationen aus history auffüllen #################################################################################################### -sub currentfillup_Push($) { +sub currentfillup_Push { my ($string) = @_; my ($name,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my $hash = $defs{$name}; @@ -4658,7 +4723,7 @@ sub currentfillup_Push($) { #################################################################################################### # Auswertungsroutine Current-Tabelle auffüllen #################################################################################################### -sub currentfillup_Done($) { +sub currentfillup_Done { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -4703,7 +4768,7 @@ return; #################################################################################################### # nichtblockierendes DB deviceRename / readingRename #################################################################################################### -sub change_Push($) { +sub change_Push { my ($string) = @_; my ($name,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my $hash = $defs{$name}; @@ -4805,7 +4870,7 @@ sub change_Push($) { #################################################################################################### # nichtblockierendes DB changeValue (Field VALUE) #################################################################################################### -sub changeval_Push($) { +sub changeval_Push { my ($string) = @_; my ($name,$device,$reading,$runtime_string_first,$runtime_string_next,$ts) = split("\\§", $string); my $hash = $defs{$name}; @@ -4984,7 +5049,7 @@ sub changeval_Push($) { #################################################################################################### # Auswertungsroutine DB deviceRename/readingRename/changeValue #################################################################################################### -sub change_Done($) { +sub change_Done { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -5050,7 +5115,7 @@ return; #################################################################################################### # nichtblockierende DB-Abfrage fetchrows #################################################################################################### -sub fetchrows_DoParse($) { +sub fetchrows_DoParse { my ($string) = @_; my ($name,$table,$device,$reading,$runtime_string_first,$runtime_string_next) = split("\\|", $string); my $hash = $defs{$name}; @@ -5135,7 +5200,7 @@ sub fetchrows_DoParse($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Abfrage fetchrows #################################################################################################### -sub fetchrows_ParseDone($) { +sub fetchrows_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -5250,7 +5315,7 @@ return; #################################################################################################### # Doubletten finden und löschen #################################################################################################### -sub deldoublets_DoParse($) { +sub deldoublets_DoParse { my ($string) = @_; my ($name,$opt,$device,$reading,$ts) = split("\\§", $string); my $hash = $defs{$name}; @@ -5413,7 +5478,7 @@ return "$name|$rowlist|$rt|0|$retn|$opt"; #################################################################################################### # sequentielle Doubletten löschen #################################################################################################### -sub delseqdoubl_DoParse($) { +sub delseqdoubl_DoParse { my ($string) = @_; my ($name,$opt,$device,$reading,$ts) = split("\\§", $string); my $hash = $defs{$name}; @@ -5623,7 +5688,7 @@ return "$name|$rowlist|$rt|0|$retn|$opt"; #################################################################################################### # Auswertungsroutine delSeqDoublets / delDoublets #################################################################################################### -sub delseqdoubl_ParseDone($) { +sub delseqdoubl_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -5695,7 +5760,7 @@ return; #################################################################################################### # nichtblockierende DB-Funktion expfile #################################################################################################### -sub expfile_DoParse($) { +sub expfile_DoParse { my ($string) = @_; my ($name, $device, $reading, $rsf, $file, $ts) = split("\\§", $string); my $hash = $defs{$name}; @@ -5838,7 +5903,7 @@ sub expfile_DoParse($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Funktion expfile #################################################################################################### -sub expfile_ParseDone($) { +sub expfile_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -5884,7 +5949,7 @@ return; #################################################################################################### # nichtblockierende DB-Funktion impfile #################################################################################################### -sub impfile_Push($) { +sub impfile_Push { my ($string) = @_; my ($name, $rsf, $file) = split("\\|", $string); my $hash = $defs{$name}; @@ -6040,7 +6105,7 @@ sub impfile_Push($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Funktion impfile #################################################################################################### -sub impfile_PushDone($) { +sub impfile_PushDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -6084,7 +6149,7 @@ return; #################################################################################################### # set logdbrep sqlCmd select count(*) from history # set logdbrep sqlCmd select DEVICE,count(*) from history group by DEVICE HAVING count(*) > 10000 -sub sqlCmd_DoParse($) { +sub sqlCmd_DoParse { my ($string) = @_; my ($name, $opt, $runtime_string_first, $runtime_string_next, $cmd) = split("\\|", $string); my $hash = $defs{$name}; @@ -6252,7 +6317,7 @@ sub sqlCmd_DoParse($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Abfrage sqlCmd #################################################################################################### -sub sqlCmd_ParseDone($) { +sub sqlCmd_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -6373,7 +6438,7 @@ return; #################################################################################################### # nichtblockierende DB-Abfrage get db Metadaten #################################################################################################### -sub dbmeta_DoParse($) { +sub dbmeta_DoParse { my ($string) = @_; my @a = split("\\|",$string); my $name = $a[0]; @@ -6579,7 +6644,7 @@ sub dbmeta_DoParse($) { #################################################################################################### # Auswertungsroutine der nichtblockierenden DB-Abfrage get db Metadaten #################################################################################################### -sub dbmeta_ParseDone($) { +sub dbmeta_ParseDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -6634,7 +6699,7 @@ return; # drop_Report_Idx # #################################################################################################### -sub DbRep_Index($) { +sub DbRep_Index { my ($string) = @_; my ($name,$cmdidx) = split("\\|", $string); my $hash = $defs{$name}; @@ -6816,7 +6881,7 @@ return "$name|$ret|$rt|''"; #################################################################################################### # Auswertungsroutine Index Operation #################################################################################################### -sub DbRep_IndexDone($) { +sub DbRep_IndexDone { my ($string) = @_; my @a = split("\\|",$string); my $name = $a[0]; @@ -6854,7 +6919,7 @@ return; #################################################################################################### # Abbruchroutine Index operation #################################################################################################### -sub DbRep_IndexAborted(@) { +sub DbRep_IndexAborted { my ($hash,$cause) = @_; my $name = $hash->{NAME}; my $dbh = $hash->{DBH}; @@ -6881,7 +6946,7 @@ return; #################################################################################################### # optimize Tables alle Datenbanken #################################################################################################### -sub DbRep_optimizeTables($) { +sub DbRep_optimizeTables { my ($name) = @_; my $hash = $defs{$name}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -7064,7 +7129,7 @@ return "$name|$rt|''|$db_MB_start|$db_MB_end"; #################################################################################################### # Auswertungsroutine optimize tables #################################################################################################### -sub DbRep_OptimizeDone($) { +sub DbRep_OptimizeDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -7108,7 +7173,7 @@ return; #################################################################################################### # nicht blockierende Dump-Routine für MySQL (clientSide) #################################################################################################### -sub mysql_DoDumpClientSide($) { +sub mysql_DoDumpClientSide { my ($name) = @_; my $hash = $defs{$name}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -7582,7 +7647,7 @@ return "$name|$rt|''|$dump_path$backupfile|$drc|$drh|$fsize|$ftp|$bfd|$ffd"; #################################################################################################### # nicht blockierende Dump-Routine für MySQL (serverSide) #################################################################################################### -sub mysql_DoDumpServerSide($) { +sub mysql_DoDumpServerSide { my ($name) = @_; my $hash = $defs{$name}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -7757,7 +7822,7 @@ return "$name|$rt|''|$dump_path_rem$bfile|n.a.|$drh|$fsize|$ftp|$bfd|$ffd"; #################################################################################################### # Dump-Routine SQLite #################################################################################################### -sub DbRep_sqliteDoDump($) { +sub DbRep_sqliteDoDump { my ($name) = @_; my $hash = $defs{$name}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -7881,7 +7946,7 @@ return "$name|$rt|''|$dump_path$bfile|n.a.|n.a.|$fsize|$ftp|$bfd|$ffd"; #################################################################################################### # Auswertungsroutine der nicht blockierenden DB-Funktion Dump #################################################################################################### -sub DbRep_DumpDone($) { +sub DbRep_DumpDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -7937,7 +8002,7 @@ return; #################################################################################################### # Dump-Routine SQLite #################################################################################################### -sub DbRep_sqliteRepair($) { +sub DbRep_sqliteRepair { my ($name) = @_; my $hash = $defs{$name}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -8004,7 +8069,7 @@ return "$name|$brt|0"; #################################################################################################### # Auswertungsroutine der nicht blockierenden DB-Funktion Dump #################################################################################################### -sub DbRep_RepairDone($) { +sub DbRep_RepairDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -8049,7 +8114,7 @@ return; #################################################################################################### # Restore SQLite #################################################################################################### -sub DbRep_sqliteRestore ($) { +sub DbRep_sqliteRestore { my ($string) = @_; my ($name,$bfile) = split("\\|", $string); my $hash = $defs{$name}; @@ -8127,7 +8192,7 @@ return "$name|$rt|''|$dump_path$bfile|n.a."; #################################################################################################### # Restore MySQL (serverSide) #################################################################################################### -sub mysql_RestoreServerSide($) { +sub mysql_RestoreServerSide { my ($string) = @_; my ($name, $bfile) = split("\\|", $string); my $hash = $defs{$name}; @@ -8201,7 +8266,7 @@ return "$name|$rt|''|$dump_path_rem$bfile|n.a."; #################################################################################################### # Restore MySQL (ClientSide) #################################################################################################### -sub mysql_RestoreClientSide($) { +sub mysql_RestoreClientSide { my ($string) = @_; my ($name, $bfile) = split("\\|", $string); my $hash = $defs{$name}; @@ -8390,7 +8455,7 @@ return "$name|$rt|''|$dump_path$bfile|$nh|$nc"; #################################################################################################### # Auswertungsroutine Restore #################################################################################################### -sub DbRep_restoreDone($) { +sub DbRep_restoreDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -8432,7 +8497,7 @@ return; #################################################################################################### # Übertragung Datensätze in weitere DB #################################################################################################### -sub DbRep_syncStandby($) { +sub DbRep_syncStandby { my ($string) = @_; my ($name,$device,$reading,$runtime_string_first,$runtime_string_next,$ts,$stbyname) = split("\\§", $string); my $hash = $defs{$name}; @@ -8549,7 +8614,7 @@ sub DbRep_syncStandby($) { #################################################################################################### # Auswertungsroutine Übertragung Datensätze in weitere DB #################################################################################################### -sub DbRep_syncStandbyDone($) { +sub DbRep_syncStandbyDone { my ($string) = @_; my @a = split("\\|",$string); my $hash = $defs{$a[0]}; @@ -8590,7 +8655,7 @@ return; # $ots - reduce Logs älter als: Attribut "timeOlderThan" oder "timestamp_begin" # $nts - reduce Logs neuer als: Attribut "timeDiffToNow" oder "timestamp_end" #################################################################################################### -sub DbRep_reduceLog($) { +sub DbRep_reduceLog { my ($string) = @_; my ($name,$d,$r,$nts,$ots) = split("\\|", $string); my $hash = $defs{$name}; @@ -8954,7 +9019,7 @@ return "$name|$ret|0|$brt"; #################################################################################################### # reduceLog non-blocking Rückkehrfunktion #################################################################################################### -sub DbRep_reduceLogDone($) { +sub DbRep_reduceLogDone { my ($string) = @_; my @a = split("\\|",$string); my $name = $a[0]; @@ -8997,7 +9062,7 @@ return; #################################################################################################### # Abbruchroutine Timeout reduceLog #################################################################################################### -sub DbRep_reduceLogAborted(@) { +sub DbRep_reduceLogAborted { my ($hash,$cause) = @_; my $name = $hash->{NAME}; my $dbh = $hash->{DBH}; @@ -9025,7 +9090,7 @@ return; #################################################################################################### # Abbruchroutine Timeout Restore #################################################################################################### -sub DbRep_restoreAborted(@) { +sub DbRep_restoreAborted { my ($hash,$cause) = @_; my $name = $hash->{NAME}; my $dbh = $hash->{DBH}; @@ -9053,7 +9118,7 @@ return; #################################################################################################### # Abbruchroutine Timeout DB-Abfrage #################################################################################################### -sub DbRep_ParseAborted(@) { +sub DbRep_ParseAborted { my ($hash,$cause) = @_; my $name = $hash->{NAME}; my $dbh = $hash->{DBH}; @@ -9081,7 +9146,7 @@ return; #################################################################################################### # Abbruchroutine Timeout DB-Dump #################################################################################################### -sub DbRep_DumpAborted(@) { +sub DbRep_DumpAborted { my ($hash,$cause) = @_; my $name = $hash->{NAME}; my $dbh = $hash->{DBH}; @@ -9110,7 +9175,7 @@ return; #################################################################################################### # Abbruchroutine Timeout DB-Abfrage #################################################################################################### -sub DbRep_OptimizeAborted(@) { +sub DbRep_OptimizeAborted { my ($hash,$cause) = @_; my $name = $hash->{NAME}; my $dbh = $hash->{DBH}; @@ -9137,7 +9202,7 @@ return; #################################################################################################### # Abbruchroutine Repair SQlite #################################################################################################### -sub DbRep_RepairAborted(@) { +sub DbRep_RepairAborted { my ($hash,$cause) = @_; my $name = $hash->{NAME}; my $dbh = $hash->{DBH}; @@ -9166,7 +9231,7 @@ return; #################################################################################################### # SQL-Statement zusammenstellen Common #################################################################################################### -sub DbRep_createCommonSql ($$$$$$$) { +sub DbRep_createCommonSql { my ($hash,$selspec,$device,$reading,$tf,$tn,$addon) = @_; my $name = $hash->{NAME}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -9272,7 +9337,7 @@ return $sql; #################################################################################################### # SQL-Statement zusammenstellen für DB-Abfrage Select #################################################################################################### -sub DbRep_createSelectSql($$$$$$$$) { +sub DbRep_createSelectSql { my ($hash,$table,$selspec,$device,$reading,$tf,$tn,$addon) = @_; my $name = $hash->{NAME}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -9378,7 +9443,7 @@ return $sql; #################################################################################################### # SQL-Statement zusammenstellen für Löschvorgänge #################################################################################################### -sub DbRep_createDeleteSql($$$$$$$) { +sub DbRep_createDeleteSql { my ($hash,$table,$device,$reading,$tf,$tn,$addon) = @_; my $name = $hash->{NAME}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -9488,7 +9553,7 @@ return $sql; #################################################################################################### # Ableiten von Device, Reading-Spezifikationen #################################################################################################### -sub DbRep_specsForSql($$$) { +sub DbRep_specsForSql { my ($hash,$device,$reading) = @_; my $name = $hash->{NAME}; my (@idvspcs,@edvspcs,@idvs,@edvs,@idvswc,@edvswc,@residevs,@residevswc); @@ -9663,7 +9728,7 @@ return ($idevs,$idevswc,$idanz,$irdgs,$iranz,$irdswc,$edevs,$edevswc,$edanz,$erd #################################################################################################### # Leerzeichen am Anfang / Ende eines strings entfernen #################################################################################################### -sub DbRep_trim ($) { +sub DbRep_trim { my $str = shift; $str =~ s/^\s+|\s+$//g; return ($str); @@ -9672,7 +9737,7 @@ return ($str); #################################################################################################### # Sekunden in Format hh:mm:ss umwandeln #################################################################################################### -sub DbRep_sec2hms ($) { +sub DbRep_sec2hms { my $s = shift; my $hms; @@ -9687,8 +9752,8 @@ return ("$hh:$mm:$ss"); # Check ob Zeitgrenzen bzw. Aggregation gesetzt sind, evtl. überseuern (je nach Funktion) # Return "1" wenn Bedingung erfüllt, sonst "0" #################################################################################################### -sub DbRep_checktimeaggr ($) { - my ($hash) = @_; +sub DbRep_checktimeaggr { + my $hash = shift // return; my $name = $hash->{NAME}; my $IsTimeSet = 0; my $IsAggrSet = 0; @@ -9716,14 +9781,14 @@ sub DbRep_checktimeaggr ($) { $IsAggrSet = 1; } if($hash->{LASTCMD} =~ /delSeqDoublets|delDoublets/) { - $aggregation = ($aggregation eq "no")?"day":$aggregation; # wenn Aggregation "no", für delSeqDoublets immer "day" setzen + $aggregation = ($aggregation eq "no") ? "day" : $aggregation; # wenn Aggregation "no", für delSeqDoublets immer "day" setzen $IsAggrSet = 1; } if($hash->{LASTCMD} =~ /averageValue/ && AttrVal($name,"averageCalcForm","avgArithmeticMean") eq "avgDailyMeanGWS") { - $aggregation = "day"; # für Tagesmittelwertberechnung des deutschen Wetterdienstes immer "day" + $aggregation = "day"; # für Tagesmittelwertberechnung des deutschen Wetterdienstes immer "day" $IsAggrSet = 1; } - if($hash->{LASTCMD} =~ /delEntries|fetchrows|deviceRename|readingRename|tableCurrentFillup|reduceLog|\breadingsDifferenceByTimeDelta\b/) { + if($hash->{LASTCMD} =~ /^sql|delEntries|fetchrows|deviceRename|readingRename|tableCurrentFillup|reduceLog|\breadingsDifferenceByTimeDelta\b/) { $IsAggrSet = 0; $aggregation = "no"; } @@ -9740,7 +9805,7 @@ sub DbRep_checktimeaggr ($) { } } if($hash->{LASTCMD} =~ /syncStandby/ ) { - if($aggregation !~ /day|hour|week/) { + if($aggregation !~ /minute|hour|day|week/) { $aggregation = "day"; $IsAggrSet = 1; } @@ -9752,7 +9817,7 @@ return ($IsTimeSet,$IsAggrSet,$aggregation); #################################################################################################### # ReadingsSingleUpdate für Reading, Value, Event #################################################################################################### -sub ReadingsSingleUpdateValue ($$$$) { +sub ReadingsSingleUpdateValue { my ($hash,$reading,$val,$ev) = @_; my $name = $hash->{NAME}; @@ -9767,7 +9832,7 @@ return; # Readingsbulkupdate für Reading, Value # readingsBeginUpdate und readingsEndUpdate muss vor/nach Funktionsaufruf gesetzt werden #################################################################################################### -sub ReadingsBulkUpdateValue ($$$) { +sub ReadingsBulkUpdateValue { my ($hash,$reading,$val) = @_; my $name = $hash->{NAME}; @@ -9782,7 +9847,7 @@ return; # Readingsbulkupdate für processing_time, state # readingsBeginUpdate und readingsEndUpdate muss vor/nach Funktionsaufruf gesetzt werden #################################################################################################### -sub ReadingsBulkUpdateTimeState ($$$$) { +sub ReadingsBulkUpdateTimeState { my ($hash,$brt,$rt,$sval) = @_; my $name = $hash->{NAME}; @@ -9811,7 +9876,7 @@ return; # .... # } #################################################################################################### -sub DbRep_autoForward ($$$) { +sub DbRep_autoForward { my ($name,$reading,$value) = @_; my $hash = $defs{$name}; my $av = AttrVal($name, "autoForward", ""); @@ -9869,7 +9934,7 @@ return; #################################################################################################### # Anzeige von laufenden Blocking Prozessen #################################################################################################### -sub DbRep_getblockinginfo ($) { +sub DbRep_getblockinginfo { my ($hash) = @_; my $name = $hash->{NAME}; @@ -9926,7 +9991,7 @@ return; # # liefert die Attribute timeOlderThan, timeDiffToNow als Sekunden normiert zurück #################################################################################################### -sub DbRep_normRelTime($) { +sub DbRep_normRelTime { my ($hash) = @_; my $name = $hash->{NAME}; my $tdtn = AttrVal($name, "timeDiffToNow", undef); @@ -10026,7 +10091,7 @@ return ($toth,$tdtn,$fdopt); #################################################################################################### # Korrektur Schaltjahr und Sommer/Winterzeit bei relativen Zeitangaben #################################################################################################### -sub DbRep_corrRelTime($$$) { +sub DbRep_corrRelTime { my ($name,$tim,$tdtn) = @_; my $hash = $defs{$name}; @@ -10097,7 +10162,7 @@ return $tim; # - es ist durch 400 teilbar, dann ist es ein schaltjahr # #################################################################################################### -sub DbRep_IsLeapYear($$) { +sub DbRep_IsLeapYear { my ($name,$year) = @_; my $ily = 0; if ($year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0) { # $year modulo 4 -> muß 0 sein @@ -10111,7 +10176,7 @@ return $ily; ############################################################################### # Zeichencodierung für Fileexport filtern ############################################################################### -sub DbRep_charfilter($) { +sub DbRep_charfilter { my ($txt) = @_; # nur erwünschte Zeichen, Filtern von Steuerzeichen @@ -10126,7 +10191,7 @@ return($txt); ################################################################################### # Befehl vor Procedure ausführen ################################################################################### -sub DbRep_beforeproc ($$) { +sub DbRep_beforeproc { my ($hash, $txt) = @_; my $name = $hash->{NAME}; @@ -10149,7 +10214,7 @@ return; ################################################################################### # Befehl nach Procedure ausführen ################################################################################### -sub DbRep_afterproc ($$) { +sub DbRep_afterproc { my ($hash, $txt) = @_; my $name = $hash->{NAME}; my $erread; @@ -10174,7 +10239,7 @@ return $erread; # timestamp_begin, timestamp_end bei Einsatz datetime-Picker entsprechend # den Anforderungen formatieren ############################################################################################## -sub DbRep_formatpicker ($) { +sub DbRep_formatpicker { my ($str) = @_; if ($str =~ /^(\d{4})-(\d{2})-(\d{2})_(\d{2}):(\d{2})$/) { # Anpassung für datetime-Picker Widget @@ -10194,7 +10259,7 @@ return $str; # # Aufruf der mit $name,$reading,$value #################################################################################################### -sub DbRep_userexit ($$$) { +sub DbRep_userexit { my ($name,$reading,$value) = @_; my $hash = $defs{$name}; @@ -10220,7 +10285,7 @@ return; #################################################################################################### # delete Readings before new operation #################################################################################################### -sub DbRep_delread($;$$) { +sub DbRep_delread { # Readings löschen die nicht in der Ausnahmeliste (Attr readingPreventFromDel) stehen my ($hash,$shutdown) = @_; my $name = $hash->{NAME}; @@ -10272,7 +10337,7 @@ return undef; #################################################################################################### # erstellen neues SQL-File für Dumproutine #################################################################################################### -sub DbRep_NewDumpFilename ($$$$$){ +sub DbRep_NewDumpFilename { my ($sql_text,$dump_path,$dbname,$time_stamp,$character_set) = @_; my $part = ""; my $sql_file = $dump_path.$dbname."_".$time_stamp.$part.".sql"; @@ -10295,7 +10360,7 @@ return ($sql_text,$first_insert,$sql_file,$backupfile,undef); #################################################################################################### # Schreiben DB-Dumps in SQL-File #################################################################################################### -sub DbRep_WriteToDumpFile ($$) { +sub DbRep_WriteToDumpFile { my ($inh,$sql_file) = @_; my $filesize; my $err = 0; @@ -10322,7 +10387,7 @@ return ($filesize,undef); #################################################################################################### # Filesize (Byte) umwandeln in KB bzw. MB #################################################################################################### -sub DbRep_byteOutput ($) { +sub DbRep_byteOutput { my $bytes = shift; return if(!defined($bytes)); @@ -10340,7 +10405,7 @@ return $ret; # Username / Paßwort speichern # $cre = "adminCredentials" -> Credentials für Datenbank root-Zugriff ###################################################################################### -sub DbRep_setcredentials ($$@) { +sub DbRep_setcredentials { my ($hash, $cre, @credentials) = @_; my $name = $hash->{NAME}; my ($success, $credstr, $index, $retcode,$username,$passwd); @@ -10372,7 +10437,7 @@ return ($success); # Username / Paßwort abrufen # $cre = "adminCredentials" -> Credentials für Datenbank root-Zugriff ###################################################################################### -sub DbRep_getcredentials ($$) { +sub DbRep_getcredentials { my ($hash, $cre) = @_; my $name = $hash->{NAME}; my ($success, $username, $passwd, $index, $retcode, $credstr); @@ -10411,7 +10476,7 @@ return ($success, $username, $passwd); #################################################################################################### # Schreibroutine in DbRep Keyvalue-File #################################################################################################### -sub DbRep_setCmdFile($$$) { +sub DbRep_setCmdFile { my ($key,$value,$hash) = @_; my $fName = $attr{global}{modpath}."/FHEM/FhemUtils/cacheDbRep"; @@ -10441,7 +10506,7 @@ return FileWrite($param, @new); #################################################################################################### # anlegen Keyvalue-File für DbRep wenn nicht vorhanden #################################################################################################### -sub DbRep_createCmdFile ($) { +sub DbRep_createCmdFile { my ($hash) = @_; my $fName = $attr{global}{modpath}."/FHEM/FhemUtils/cacheDbRep"; @@ -10460,7 +10525,7 @@ return FileWrite($param, @new); #################################################################################################### # Leseroutine aus DbRep Keyvalue-File #################################################################################################### -sub DbRep_getCmdFile($) { +sub DbRep_getCmdFile { my ($key) = @_; my $fName = $attr{global}{modpath}."/FHEM/FhemUtils/cacheDbRep"; my $param = { @@ -10479,7 +10544,7 @@ return (undef, undef); #################################################################################################### # Tabellenoptimierung MySQL #################################################################################################### -sub DbRep_mysqlOptimizeTables ($$@) { +sub DbRep_mysqlOptimizeTables { my ($hash,$dbh,@tablenames) = @_; my $name = $hash->{NAME}; my $dbname = $hash->{DATABASE}; @@ -10549,7 +10614,7 @@ return (undef,$db_MB_start,$db_MB_end); #################################################################################################### # Dump-Files im dumpDirLocal löschen bis auf die letzten "n" #################################################################################################### -sub DbRep_deldumpfiles ($$) { +sub DbRep_deldumpfiles { my ($hash,$bfile) = @_; my $name = $hash->{NAME}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -10598,7 +10663,7 @@ return @fd; #################################################################################################### # Dumpfile komprimieren #################################################################################################### -sub DbRep_dumpCompress ($$) { +sub DbRep_dumpCompress { my ($hash,$bfile) = @_; my $name = $hash->{NAME}; my $dump_path_def = $attr{global}{modpath}."/log/"; @@ -10625,7 +10690,7 @@ return (undef,$bfile.".gzip"); #################################################################################################### # Dumpfile dekomprimieren #################################################################################################### -sub DbRep_dumpUnCompress ($$) { +sub DbRep_dumpUnCompress { my ($hash,$bfile) = @_; my $name = $hash->{NAME}; my $dump_path_def = $attr{global}{modpath}."/log/"; @@ -10659,7 +10724,7 @@ return (undef,$outfile); #################################################################################################### # erzeugtes Dump-File aus dumpDirLocal zum FTP-Server übertragen #################################################################################################### -sub DbRep_sendftp ($$) { +sub DbRep_sendftp { my ($hash,$bfile) = @_; my $name = $hash->{NAME}; my $dump_path_def = $attr{global}{modpath}."/log/"; @@ -10784,7 +10849,7 @@ return ($ftperr,$ftpmsg,@ftpfd); #################################################################################################### # Test auf Daylight saving time #################################################################################################### -sub DbRep_dsttest ($$$) { +sub DbRep_dsttest { my ($hash,$runtime,$aggsec) = @_; my $name = $hash->{NAME}; my $dstchange = 0; @@ -10812,10 +10877,10 @@ return $dstchange; # Rückgabe eines ncp-hash (no calc in period) mit den Perioden für die keine Differenz berechnet # werden konnte weil nur ein Datensatz in der Periode zur Verfügung stand #################################################################################################### -sub DbRep_calcount ($$) { +sub DbRep_calcount { my ($hash,$ch) = @_; my $name = $hash->{NAME}; - my %ncp = (); + my %ncp = (); Log3 ($name, 4, "DbRep $name - count of values used for calc:"); foreach my $key (sort(keys%{$ch})) { @@ -10831,7 +10896,7 @@ return \%ncp; #################################################################################################### # Funktionsergebnisse in Datenbank schreiben #################################################################################################### -sub DbRep_OutputWriteToDB($$$$$) { +sub DbRep_OutputWriteToDB { my ($name,$device,$reading,$wrstr,$optxt) = @_; my $hash = $defs{$name}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -10850,8 +10915,8 @@ sub DbRep_OutputWriteToDB($$$$$) { my $unit = ""; my $wrt = 0; my $irowdone = 0; - my ($dbh,$sth_ih,$sth_uh,$sth_ic,$sth_uc,$err,$timestamp,$value,$date,$time,$hour,$ndate,$ntime,$rsf,$rsn,$aggr,@row_array); - my ($year,$mon,$mday,$t1,$corr); + 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); if(!$dbloghash->{HELPER}{COLSET}) { $err = "No result of \"$hash->{LASTCMD}\" to database written. Cause: column width in \"$hash->{DEF}\" isn't set"; @@ -10859,7 +10924,8 @@ sub DbRep_OutputWriteToDB($$$$$) { } no warnings 'uninitialized'; - (undef,undef,$aggr) = DbRep_checktimeaggr($hash); + + my $aggr = (DbRep_checktimeaggr($hash))[2]; $reading = $optxt."_".$aggr."_".AttrVal($name, "readingNameMap", $reading); $type = $defs{$device}{TYPE} if($defs{$device}); # $type vom Device ableiten @@ -10887,10 +10953,19 @@ sub DbRep_OutputWriteToDB($$$$$) { $t1 = fhemTimeLocal(59, 59, 23, $mday, $mon-1, $year-1900)-$corr; ($ndate,undef) = split(" ",FmtDateTime($t1)); - } elsif ($aggr =~ /hour/) { - $hour = (split(":", $time))[0]; - $time = "$hour:00:01" if($time !~ /^(\d{2}):(\d{2}):(\d{2})$/ || $hash->{LASTCMD} =~ /\bwriteToDB(Single)*?\b/); # https://forum.fhem.de/index.php/topic,105787.msg1013920.html#msg1013920 - $ntime = "$hour:59:59" if($ntime !~ /^(\d{2}):(\d{2}):(\d{2})$/ || $hash->{LASTCMD} =~ /\bwriteToDB(Single)*?\b/); + } elsif ($aggr =~ /minute|hour/) { + ($hour,$minute) = split ":", $time; + + if($aggr eq "minute") { + $time = "$hour:$minute:01" if($time !~ /^(\d{2}):(\d{2}):(\d{2})$/ || $hash->{LASTCMD} =~ /\bwriteToDB(Single)*?\b/); # https://forum.fhem.de/index.php/topic,105787.msg1013920.html#msg1013920 + $ntime = "$hour:$minute:59" if($ntime !~ /^(\d{2}):(\d{2}):(\d{2})$/ || $hash->{LASTCMD} =~ /\bwriteToDB(Single)*?\b/); + } + + if($aggr eq "hour") { + $time = "$hour:00:01" if($time !~ /^(\d{2}):(\d{2}):(\d{2})$/ || $hash->{LASTCMD} =~ /\bwriteToDB(Single)*?\b/); # https://forum.fhem.de/index.php/topic,105787.msg1013920.html#msg1013920 + $ntime = "$hour:59:59" if($ntime !~ /^(\d{2}):(\d{2}):(\d{2})$/ || $hash->{LASTCMD} =~ /\bwriteToDB(Single)*?\b/); + } + if ($ntime eq "23:59:59") { ($year,$mon,$mday) = split("-", $ndate); $t1 = fhemTimeLocal(59, 59, 23, $mday, $mon-1, $year-1900)-86400; @@ -10931,12 +11006,14 @@ sub DbRep_OutputWriteToDB($$$$$) { ($date,$time) = split("_",$rsf); $time =~ s/-/:/g if($time); - + if($time !~ /^(\d{2}):(\d{2}):(\d{2})$/) { if($aggr =~ /no|day|week|month/) { $time = "23:59:58"; } elsif ($aggr =~ /hour/) { $time = "$time:59:58"; + } elsif ($aggr =~ /minute/) { + $time = "$time:58"; } } if ($value) { @@ -10961,7 +11038,7 @@ sub DbRep_OutputWriteToDB($$$$$) { if (!$supk) { ($usepkh,$usepkc,$pkh,$pkc) = DbRep_checkUsePK($hash,$dbloghash,$dbh); } else { - Log3 $hash->{NAME}, 5, "DbRep $name -> Primary Key usage suppressed by attribute noSupportPK in DbLog \"$dblogname\""; + Log3 ($hash->{NAME}, 5, "DbRep $name -> Primary Key usage suppressed by attribute noSupportPK in DbLog \"$dblogname\""); } if (lc($DbLogType) =~ m(history)) { @@ -11026,8 +11103,10 @@ sub DbRep_OutputWriteToDB($$$$$) { if (lc($DbLogType) =~ m(history) ) { my $rv_uh = $dbh->do("UPDATE history SET TIMESTAMP=\"$timestamp\", DEVICE=\"$device\", READING=\"$reading\", TYPE=\"$type\", EVENT=\"$event\", VALUE=\"$value\", UNIT=\"$unit\" WHERE TIMESTAMP=\"$timestamp\" AND DEVICE=\"$device\" AND READING=\"$reading\""); $uhs += $rv_uh if($rv_uh); - Log3 $hash->{NAME}, 4, "DbRep $name - UPDATE history: $row, RESULT: $rv_uh"; - if ($rv_uh == 0) { + + Log3 ($hash->{NAME}, 4, "DbRep $name - UPDATE history: $row, RESULT: $rv_uh"); + + if ($rv_uh == 0) { my $rv_ih = $sth_ih->execute($timestamp,$device,$type,$event,$reading,$value,$unit); $ihs += $rv_ih if($rv_ih); Log3 $hash->{NAME}, 4, "DbRep $name - INSERT history: $row, RESULT: $rv_ih"; @@ -11055,8 +11134,8 @@ sub DbRep_OutputWriteToDB($$$$$) { $dbh->disconnect; - Log3 $hash->{NAME}, 3, "DbRep $name - number of lines updated in \"$dblogname\": $uhs"; - Log3 $hash->{NAME}, 3, "DbRep $name - number of lines inserted into \"$dblogname\": $ihs"; + Log3 ($hash->{NAME}, 3, "DbRep $name - number of lines updated in \"$dblogname\": $uhs"); + Log3 ($hash->{NAME}, 3, "DbRep $name - number of lines inserted into \"$dblogname\": $ihs"); $irowdone = $ihs + $uhs; # SQL-Laufzeit ermitteln @@ -11074,7 +11153,7 @@ return ($wrt,$irowdone,$err); # $runtime_string."|".$max_value."|".$row_max_time."|".$runtime_string_first."|".$runtime_string_next # ####################################################################################################### -sub DbRep_deleteOtherFromDB($$$$) { +sub DbRep_deleteOtherFromDB { my ($name,$device,$reading,$rows) = @_; my $hash = $defs{$name}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -11092,7 +11171,7 @@ sub DbRep_deleteOtherFromDB($$$$) { foreach my $key (sort(keys(%rh))) { # Inhalt $rh{$key} -> $runtime_string."|".$max_value."|".$row_max_time."|".$runtime_string_first."|".$runtime_string_next my @k = split("\\|",$rh{$key}); - $value = defined($k[1])?$k[1]:undef; + $value = $k[1] // undef; $row_extreme_time = $k[2]; $runtime_string_first = $k[3]; $runtime_string_next = $k[4]; @@ -11171,7 +11250,7 @@ return ($wrt,$irowdone,$err); # $histupd = 1 wenn history update, $histupd = 0 nur history insert # #################################################################################################### -sub DbRep_WriteToDB($$$@) { +sub DbRep_WriteToDB { my ($name,$dbh,$dbloghash,$histupd,@row_array) = @_; my $hash = $defs{$name}; my $dblogname = $dbloghash->{NAME}; @@ -11318,7 +11397,7 @@ return ($wrt,$irowdone,$err); ################################################################ # check ob primary key genutzt wird ################################################################ -sub DbRep_checkUsePK ($$$){ +sub DbRep_checkUsePK { my ($hash,$dbloghash,$dbh) = @_; my $name = $hash->{NAME}; my $dbconn = $dbloghash->{dbconn}; @@ -11344,7 +11423,7 @@ return ($upkh,$upkc,$pkh,$pkc); ################################################################ # extrahiert aus dem übergebenen Wert nur die Zahl ################################################################ -sub DbRep_numval ($){ +sub DbRep_numval { my ($val) = @_; return undef if(!defined($val)); $val = ($val =~ /(-?\d+(\.\d+)?)/ ? $1 : ""); @@ -11355,7 +11434,7 @@ return $val; #################################################################################################### # löscht einen Wert vom $hash des Hauptprozesses aus einem BlockingCall heraus #################################################################################################### -sub DbRep_delHashValFromBlocking($$;$) { +sub DbRep_delHashValFromBlocking { my ($name,$v1,$v2) = @_; my $hash = $defs{$name}; @@ -11373,7 +11452,7 @@ return 1; # Schwartzian Transform and the GRT transform # Übergabe: "asc | desc", ################################################################ -sub DbRep_sortVersion (@){ +sub DbRep_sortVersion { my ($sseq,@versions) = @_; my @sorted = map {$_->[0]} @@ -11395,7 +11474,7 @@ return @sorted; # Versionierungen des Moduls setzen # Die Verwendung von Meta.pm und Packages wird berücksichtigt ################################################################ -sub DbRep_setVersionInfo($) { +sub DbRep_setVersionInfo { my ($hash) = @_; my $name = $hash->{NAME}; @@ -11430,7 +11509,7 @@ return; # blockierende DB-Abfrage # liefert Ergebnis sofort zurück, setzt keine Readings #################################################################################################### -sub DbRep_dbValue($$) { +sub DbRep_dbValue { my ($name,$cmd) = @_; my $hash = $defs{$name}; my $dbloghash = $defs{$hash->{HELPER}{DBLOGDEVICE}}; @@ -11549,7 +11628,7 @@ return ($ret); # Aufruf als Funktion: DbReadingsVal("","",","") # Aufruf als FHEM-Cmd: DbReadingsVal #################################################################################################### -sub CommandDbReadingsVal($$) { +sub CommandDbReadingsVal { my ($cl, $param) = @_; my @a = split("[ \t][ \t]*", $param); @@ -11626,7 +11705,7 @@ return $ret; #################################################################################################### # Browser Refresh nach DB-Abfrage #################################################################################################### -sub browser_refresh($) { +sub browser_refresh { my ($hash) = @_; RemoveInternalTimer($hash, "browser_refresh"); {FW_directNotify("#FHEMWEB:WEB", "location.reload('true')", "")}; @@ -11637,7 +11716,7 @@ return; ################################################################################### # Associated Devices setzen ################################################################################### -sub DbRep_modAssociatedWith ($$$) { +sub DbRep_modAssociatedWith { my ($hash,$cmd,$awdev) = @_; my $name = $hash->{NAME}; my (@naw,@edvs,@edvspcs,$edevswc); @@ -11690,7 +11769,7 @@ return; #################################################################################################### # Test-Sub zu Testzwecken #################################################################################################### -sub testexit ($) { +sub testexit { my ($hash) = @_; my $name = $hash->{NAME}; @@ -11933,8 +12012,8 @@ return;
    - - + +
    writeToDB : writes one value each with the time stamps 00:00:01 and 23:59:59 within the respective evaluation period
    writeToDBSingle : writes only one value with the time stamp 23:59:59 at the end of an evaluation period
    writeToDB : writes one value each with the time stamps XX:XX:01 and XX:XX:59 within the respective evaluation period
    writeToDBSingle : writes only one value with the time stamp XX:XX:59 at the end of an evaluation period
    writeToDBInTime : writes a value at the beginning and end of the time limits of an evaluation period
@@ -13017,8 +13096,8 @@ return; If the session variable or PRAGMA has to be set every time before executing a SQL statement, the attribute 'sqlCmdVars' can be set.
If the attribute 'timestamp_begin' respectively 'timestamp_end' - is assumed in the statement, it is possible to use placeholder "§timestamp_begin§" respectively - "§timestamp_end§" on suitable place.

+ is assumed in the statement, it is possible to use placeholder §timestamp_begin§ respectively + §timestamp_end§ on suitable place.

If you want update a dataset, you have to add "TIMESTAMP=TIMESTAMP" to the update-statement to avoid changing the original timestamp.

@@ -13169,8 +13248,8 @@ return;
    - - + +
    writeToDB : writes one value each with the time stamps 00:00:01 and 23:59:59 within the respective evaluation period
    writeToDBSingle : writes only one value with the time stamp 23:59:59 at the end of an evaluation period
    writeToDB : writes one value each with the time stamps XX:XX:01 and XX:XX:59 within the respective evaluation period
    writeToDBSingle : writes only one value with the time stamp XX:XX:59 at the end of an evaluation period
    writeToDBInTime : writes a value at the beginning and end of the time limits of an evaluation period
@@ -14498,8 +14577,8 @@ sub bdump {
    - - + +
    writeToDB : schreibt jeweils einen Wert mit den Zeitstempeln 00:00:01 und 23:59:59 innerhalb der jeweiligen Auswertungsperiode
    writeToDBSingle : schreibt nur einen Wert mit dem Zeitstempel 23:59:59 am Ende einer Auswertungsperiode
    writeToDB : schreibt jeweils einen Wert mit den Zeitstempeln XX:XX:01 und XX:XX:59 innerhalb der jeweiligen Auswertungsperiode
    writeToDBSingle : schreibt nur einen Wert mit dem Zeitstempel XX:XX:59 am Ende einer Auswertungsperiode
    writeToDBInTime : schreibt jeweils einen Wert am Anfang und am Ende der Zeitgrenzen einer Auswertungsperiode
@@ -15597,19 +15676,19 @@ sub bdump {
  • sqlCmd - führt ein beliebiges benutzerspezifisches Kommando aus.
    - Enthält dieses Kommando eine Delete-Operation, muss zur Sicherheit das - Attribut "allowDeletion" gesetzt sein.
    + Enthält dieses Kommando eine Delete-Operation, muss zur Sicherheit das Attribut + allowDeletion gesetzt sein.
    Bei der Ausführung dieses Kommandos werden keine Einschränkungen durch gesetzte Attribute "device", "reading", "time.*" bzw. "aggregation" berücksichtigt.
    Dieses Kommando akzeptiert ebenfalls das Setzen von SQL Session Variablen wie z.B. "SET @open:=NULL, @closed:=NULL;" oder die Verwendung von SQLite PRAGMA vor der Ausführung des SQL-Statements. Soll die Session Variable oder das PRAGMA vor jeder Ausführung eines SQL Statements - gesetzt werden, kann dafür das Attribut "sqlCmdVars" + gesetzt werden, kann dafür das Attribut sqlCmdVars verwendet werden.
    - Sollen die im Modul gesetzten Attribute "timestamp_begin" bzw. - "timestamp_end" im Statement berücksichtigt werden, können die Platzhalter - "§timestamp_begin§" bzw. "§timestamp_end§" dafür verwendet werden.

    + Sollen die im Modul gesetzten Attribute timestamp_begin bzw. + timestamp_end im Statement berücksichtigt werden, können die Platzhalter + §timestamp_begin§ bzw. §timestamp_end§ dafür verwendet werden.

    Soll ein Datensatz upgedated werden, ist dem Statement "TIMESTAMP=TIMESTAMP" hinzuzufügen um eine Änderung des originalen Timestamps zu verhindern.

    @@ -15764,8 +15843,8 @@ sub bdump {
      - - + +
      writeToDB : schreibt jeweils einen Wert mit den Zeitstempeln 00:00:01 und 23:59:59 innerhalb der jeweiligen Auswertungsperiode
      writeToDBSingle : schreibt nur einen Wert mit dem Zeitstempel 23:59:59 am Ende einer Auswertungsperiode
      writeToDB : schreibt jeweils einen Wert mit den Zeitstempeln XX:XX:01 und XX:XX:59 innerhalb der jeweiligen Auswertungsperiode
      writeToDBSingle : schreibt nur einen Wert mit dem Zeitstempel XX:XX:59 am Ende einer Auswertungsperiode
      writeToDBInTime : schreibt jeweils einen Wert am Anfang und am Ende der Zeitgrenzen einer Auswertungsperiode
    diff --git a/fhem/contrib/DS_Starter/93_DbRep.pm b/fhem/contrib/DS_Starter/93_DbRep.pm index 45a75f5b4..bde14fd8f 100644 --- a/fhem/contrib/DS_Starter/93_DbRep.pm +++ b/fhem/contrib/DS_Starter/93_DbRep.pm @@ -57,7 +57,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch'; # Version History intern our %DbRep_vNotesIntern = ( - "8.40.4" => "22.07.2020 new aggregation value 'minute' ", + "8.40.4" => "23.07.2020 new aggregation value 'minute', some fixes ", "8.40.3" => "22.07.2020 delete prototypes ", "8.40.2" => "27.06.2020 improve versionNotes 2 ", "8.40.1" => "18.05.2020 improve 'restore' setlist, revised comRef, fix compare timesettings for delEntries,reduceLog ", @@ -551,7 +551,7 @@ sub DbRep_Set { if ($opt =~ /eraseReadings/) { $hash->{LASTCMD} = $prop?"$opt $prop":"$opt"; DbRep_delread($hash); # Readings löschen die nicht in der Ausnahmeliste (Attr readingPreventFromDel) stehen - return undef; + return; } if ($opt eq "dumpMySQL" && $hash->{ROLE} ne "Agent") { @@ -567,7 +567,7 @@ sub DbRep_Set { } DbRep_beforeproc($hash, "dump"); DbRep_Main($hash,$opt,$prop); - return undef; + return; } if ($opt eq "dumpSQLite" && $hash->{ROLE} ne "Agent") { @@ -577,7 +577,7 @@ sub DbRep_Set { Log3 ($name, 3, "DbRep $name - ################################################################"); DbRep_beforeproc($hash, "dump"); DbRep_Main($hash,$opt,$prop); - return undef; + return; } if ($opt eq "repairSQLite" && $hash->{ROLE} ne "Agent") { @@ -596,7 +596,7 @@ sub DbRep_Set { DbRep_beforeproc($hash, "repair"); DbRep_Main($hash,$opt); - return undef; + return; } if ($opt =~ /restoreMySQL|restoreSQLite/ && $hash->{ROLE} ne "Agent") { @@ -606,7 +606,7 @@ sub DbRep_Set { Log3 ($name, 3, "DbRep $name - ################################################################"); DbRep_beforeproc($hash, "restore"); DbRep_Main($hash,$opt,$prop); - return undef; + return; } if ($opt =~ /optimizeTables|vacuum/ && $hash->{ROLE} ne "Agent") { @@ -616,7 +616,7 @@ sub DbRep_Set { Log3 ($name, 3, "DbRep $name - ################################################################"); DbRep_beforeproc($hash, "optimize"); DbRep_Main($hash,$opt); - return undef; + return; } if ($opt =~ m/delSeqDoublets|delDoublets/ && $hash->{ROLE} ne "Agent") { @@ -626,7 +626,7 @@ sub DbRep_Set { } DbRep_beforeproc($hash, "delDoublets"); DbRep_Main($hash,$opt,$prop); - return undef; + return; } if ($opt =~ m/reduceLog/ && $hash->{ROLE} ne "Agent") { @@ -643,7 +643,7 @@ sub DbRep_Set { Log3 ($name, 3, "DbRep $name - ################################################################"); DbRep_beforeproc($hash, "reduceLog"); DbRep_Main($hash,$opt); - return undef; + return; } } @@ -667,7 +667,7 @@ sub DbRep_Set { BlockingKill($hash->{HELPER}{RUNNING_BACKUP_CLIENT}); Log3 ($name, 3, "DbRep $name -> running Dump has been canceled"); ReadingsSingleUpdateValue ($hash, "state", "Dump canceled", 1); - return undef; + return; } if ($opt eq "cancelRepair" && $hash->{ROLE} ne "Agent") { @@ -675,7 +675,7 @@ sub DbRep_Set { BlockingKill($hash->{HELPER}{RUNNING_REPAIR}); Log3 ($name, 3, "DbRep $name -> running Repair has been canceled"); ReadingsSingleUpdateValue ($hash, "state", "Repair canceled", 1); - return undef; + return; } if ($opt eq "cancelRestore" && $hash->{ROLE} ne "Agent") { @@ -683,13 +683,13 @@ sub DbRep_Set { BlockingKill($hash->{HELPER}{RUNNING_RESTORE}); Log3 ($name, 3, "DbRep $name -> running Restore has been canceled"); ReadingsSingleUpdateValue ($hash, "state", "Restore canceled", 1); - return undef; + return; } if ($opt =~ m/tableCurrentFillup/ && $hash->{ROLE} ne "Agent") { $hash->{LASTCMD} = $prop?"$opt $prop":"$opt"; DbRep_Main($hash,$opt); - return undef; + return; } if ($opt eq "index" && $hash->{ROLE} ne "Agent") { @@ -697,10 +697,11 @@ sub DbRep_Set { Log3 ($name, 3, "DbRep $name - ################################################################"); Log3 ($name, 3, "DbRep $name - ### New Index operation ###"); Log3 ($name, 3, "DbRep $name - ################################################################"); - # Befehl vor Procedure ausführen - DbRep_beforeproc($hash, "index"); - DbRep_Main($hash,$opt,$prop); - return undef; + + # Befehl vor Procedure ausführen + DbRep_beforeproc ($hash, "index"); + DbRep_Main ($hash,$opt,$prop); + return; } if ($opt eq "adminCredentials" && $hash->{ROLE} ne "Agent") { @@ -1414,8 +1415,9 @@ sub DbRep_Attr { return "Length of \"$aName\" is too big. Maximum length for database type $dbmodel is $mlen" if(length($aVal) > $mlen); } } - } -return undef; + } + +return; } ################################################################################### @@ -1510,7 +1512,7 @@ sub DbRep_Undef { DbRep_delread($hash,1); -return undef; +return; } ################################################################################### @@ -1531,7 +1533,7 @@ sub DbRep_Delete { my $index = $hash->{TYPE}."_".$name."_adminCredentials"; setKeyValue($index, undef); -return undef; +return; } ################################################################################### @@ -1545,7 +1547,7 @@ sub DbRep_Shutdown { DbRep_delread($hash,1); RemoveInternalTimer($hash); -return undef; +return; } ################################################################################### @@ -1945,12 +1947,13 @@ sub DbRep_Main { ($epoch_seconds_begin,$epoch_seconds_end,$runtime_string_first,$runtime_string_next,$ts) = DbRep_createTimeArray($hash,$aggregation,$opt); } else { Log3 ($name, 4, "DbRep $name - Timestamp begin human readable: not set") if($opt !~ /tableCurrentPurge/); - Log3 ($name, 4, "DbRep $name - Timestamp end human readable: not set") if($opt !~ /tableCurrentPurge/); + Log3 ($name, 4, "DbRep $name - Timestamp end human readable: not set") if($opt !~ /tableCurrentPurge/); } - Log3 ($name, 4, "DbRep $name - Aggregation: $aggregation") if($opt !~ /tableCurrentPurge|tableCurrentFillup|fetchrows|insert|reduceLog|delEntries/); + Log3 ($name, 4, "DbRep $name - Aggregation: $aggregation") if($opt !~ /tableCurrentPurge|tableCurrentFillup|fetchrows|insert|reduceLog|delEntries|^sql/x); - ##### Funktionsaufrufe ##### + ##### Funktionsaufrufe ##### + ############################# if ($opt eq "sumValue") { $hash->{HELPER}{RUNNING_PID} = BlockingCall("sumval_DoParse", "$name§$device§$reading§$prop§$ts", "sumval_ParseDone", $to, "DbRep_ParseAborted", $hash); @@ -2106,6 +2109,7 @@ sub DbRep_Main { } $hash->{HELPER}{RUNNING_PID}{loglevel} = 5 if($hash->{HELPER}{RUNNING_PID}); # Forum #77057 + return; } @@ -9781,10 +9785,10 @@ sub DbRep_checktimeaggr { $IsAggrSet = 1; } if($hash->{LASTCMD} =~ /averageValue/ && AttrVal($name,"averageCalcForm","avgArithmeticMean") eq "avgDailyMeanGWS") { - $aggregation = "day"; # für Tagesmittelwertberechnung des deutschen Wetterdienstes immer "day" + $aggregation = "day"; # für Tagesmittelwertberechnung des deutschen Wetterdienstes immer "day" $IsAggrSet = 1; } - if($hash->{LASTCMD} =~ /delEntries|fetchrows|deviceRename|readingRename|tableCurrentFillup|reduceLog|\breadingsDifferenceByTimeDelta\b/) { + if($hash->{LASTCMD} =~ /^sql|delEntries|fetchrows|deviceRename|readingRename|tableCurrentFillup|reduceLog|\breadingsDifferenceByTimeDelta\b/) { $IsAggrSet = 0; $aggregation = "no"; } @@ -13092,8 +13096,8 @@ return; If the session variable or PRAGMA has to be set every time before executing a SQL statement, the attribute 'sqlCmdVars' can be set.
    If the attribute 'timestamp_begin' respectively 'timestamp_end' - is assumed in the statement, it is possible to use placeholder "§timestamp_begin§" respectively - "§timestamp_end§" on suitable place.

    + is assumed in the statement, it is possible to use placeholder §timestamp_begin§ respectively + §timestamp_end§ on suitable place.

    If you want update a dataset, you have to add "TIMESTAMP=TIMESTAMP" to the update-statement to avoid changing the original timestamp.

    @@ -15672,19 +15676,19 @@ sub bdump {

  • sqlCmd - führt ein beliebiges benutzerspezifisches Kommando aus.
    - Enthält dieses Kommando eine Delete-Operation, muss zur Sicherheit das - Attribut "allowDeletion" gesetzt sein.
    + Enthält dieses Kommando eine Delete-Operation, muss zur Sicherheit das Attribut + allowDeletion gesetzt sein.
    Bei der Ausführung dieses Kommandos werden keine Einschränkungen durch gesetzte Attribute "device", "reading", "time.*" bzw. "aggregation" berücksichtigt.
    Dieses Kommando akzeptiert ebenfalls das Setzen von SQL Session Variablen wie z.B. "SET @open:=NULL, @closed:=NULL;" oder die Verwendung von SQLite PRAGMA vor der Ausführung des SQL-Statements. Soll die Session Variable oder das PRAGMA vor jeder Ausführung eines SQL Statements - gesetzt werden, kann dafür das Attribut "sqlCmdVars" + gesetzt werden, kann dafür das Attribut sqlCmdVars verwendet werden.
    - Sollen die im Modul gesetzten Attribute "timestamp_begin" bzw. - "timestamp_end" im Statement berücksichtigt werden, können die Platzhalter - "§timestamp_begin§" bzw. "§timestamp_end§" dafür verwendet werden.

    + Sollen die im Modul gesetzten Attribute timestamp_begin bzw. + timestamp_end im Statement berücksichtigt werden, können die Platzhalter + §timestamp_begin§ bzw. §timestamp_end§ dafür verwendet werden.

    Soll ein Datensatz upgedated werden, ist dem Statement "TIMESTAMP=TIMESTAMP" hinzuzufügen um eine Änderung des originalen Timestamps zu verhindern.