mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-07 16:59:18 +00:00
93_DbRep: contrib Testversion
git-svn-id: https://svn.fhem.de/fhem/trunk@26787 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
722a73b57a
commit
40e41b5def
@ -1,5 +1,5 @@
|
||||
##########################################################################################################
|
||||
# $Id: 93_DbRep.pm 26413 2022-09-17 18:08:05Z DS_Starter $
|
||||
# $Id: 93_DbRep.pm 26650 2022-11-04 22:02:44Z DS_Starter $
|
||||
##########################################################################################################
|
||||
# 93_DbRep.pm
|
||||
#
|
||||
@ -57,6 +57,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
|
||||
|
||||
# Version History intern
|
||||
my %DbRep_vNotesIntern = (
|
||||
"8.50.4" => "04.11.2022 fix daylight saving bug in aggregation eq 'month' (_DbRep_collaggstr) ",
|
||||
"8.50.3" => "19.09.2022 reduce memory allocation of function DbRep_reduceLog ",
|
||||
"8.50.2" => "17.09.2022 release setter 'index' for device model 'Agent' ",
|
||||
"8.50.1" => "05.09.2022 DbRep_setLastCmd, change changeValue syntax, minor fixes ",
|
||||
@ -2844,19 +2845,26 @@ sub DbRep_createTimeArray {
|
||||
my $aggsec;
|
||||
if ($aggregation eq "minute") {
|
||||
$aggsec = 60;
|
||||
} elsif ($aggregation eq "hour") {
|
||||
}
|
||||
elsif ($aggregation eq "hour") {
|
||||
$aggsec = 3600;
|
||||
} elsif ($aggregation eq "day") {
|
||||
}
|
||||
elsif ($aggregation eq "day") {
|
||||
$aggsec = 86400;
|
||||
} elsif ($aggregation eq "week") {
|
||||
}
|
||||
elsif ($aggregation eq "week") {
|
||||
$aggsec = 604800;
|
||||
} elsif ($aggregation eq "month") {
|
||||
$aggsec = 2678400; # Initialwert, wird in _DbRep_collaggstr für jeden Monat berechnet
|
||||
} elsif ($aggregation eq "year") {
|
||||
$aggsec = 31536000; # Initialwert, wird in _DbRep_collaggstr für jedes Jahr berechnet
|
||||
} elsif ($aggregation eq "no") {
|
||||
}
|
||||
elsif ($aggregation eq "month") {
|
||||
$aggsec = 2678400; # Initialwert
|
||||
}
|
||||
elsif ($aggregation eq "year") {
|
||||
$aggsec = 31536000; # Initialwert
|
||||
}
|
||||
elsif ($aggregation eq "no") {
|
||||
$aggsec = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2880,7 +2888,12 @@ sub DbRep_createTimeArray {
|
||||
# Aufbau Timestampstring mit Zeitgrenzen entsprechend Aggregation
|
||||
while (!$ll) {
|
||||
# collect aggregation strings
|
||||
($runtime,$runtime_string,$runtime_string_first,$runtime_string_next,$ll) = _DbRep_collaggstr($hash,$runtime,$i,$runtime_string_next);
|
||||
($runtime,$runtime_string,$runtime_string_first,$runtime_string_next,$ll) = _DbRep_collaggstr( { hash => $hash,
|
||||
rtm => $runtime,
|
||||
i => $i,
|
||||
rsn => $runtime_string_next
|
||||
}
|
||||
);
|
||||
$ts .= $runtime_string."#".$runtime_string_first."#".$runtime_string_next."|";
|
||||
$i++;
|
||||
}
|
||||
@ -2895,7 +2908,12 @@ return ($epoch_seconds_begin,$epoch_seconds_end,$runtime_string_first,$runtime_s
|
||||
#
|
||||
####################################################################################################
|
||||
sub _DbRep_collaggstr {
|
||||
my ($hash,$runtime,$i,$runtime_string_next) = @_;
|
||||
my $paref = shift;
|
||||
my $hash = $paref->{hash};
|
||||
my $runtime = $paref->{rtm};
|
||||
my $i = $paref->{i};
|
||||
my $runtime_string_next = $paref->{rsn};
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $runtime_string; # Datum/Zeit im SQL-Format für Readingname Teilstring
|
||||
my $runtime_string_first; # Datum/Zeit Auswertungsbeginn im SQL-Format für SQL-Statement
|
||||
@ -2978,7 +2996,7 @@ sub _DbRep_collaggstr {
|
||||
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");
|
||||
Log3 ($name, 5, "DbRep $name - act year: $ry, act month: $rm, days in month: $dim");
|
||||
|
||||
$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)
|
||||
@ -2992,6 +3010,7 @@ sub _DbRep_collaggstr {
|
||||
|
||||
if ($ysstr == $yestr && $msstr == $mestr || $ry == $yestr && $rm == $mestr) {
|
||||
$runtime_string_first = strftime "%Y-%m-01", localtime($runtime) if($i>1);
|
||||
$runtime_string_first = strftime "%Y-%m-01", localtime($runtime);
|
||||
$runtime_string_next = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_end);
|
||||
$ll = 1;
|
||||
}
|
||||
@ -3008,11 +3027,9 @@ sub _DbRep_collaggstr {
|
||||
}
|
||||
}
|
||||
|
||||
# my ($yyyy1, $mm1, $dd1) = ($runtime_string_next =~ /(\d+)-(\d+)-(\d+)/);
|
||||
# $runtime = timelocal("00", "00", "00", "01", $mm1-1, $yyyy1-1900);
|
||||
|
||||
# neue Beginnzeit in Epoche-Sekunden
|
||||
$runtime = $runtime_orig+$aggsec;
|
||||
#$runtime = $runtime_orig + $aggsec; # ausgebaut 04.11.2022
|
||||
$runtime = $runtime + $aggsec;
|
||||
}
|
||||
|
||||
# Wochenaggregation
|
||||
@ -4234,7 +4251,7 @@ sub DbRep_diffval {
|
||||
my @ts = split("\\|", $ts); # Timestampstring to Array
|
||||
Log3 ($name, 5, "DbRep $name - Timestamp-Array: \n@ts");
|
||||
|
||||
if($dbmodel eq "MYSQL") {
|
||||
if($dbmodel eq "MYSQL2") {
|
||||
$selspec = "TIMESTAMP,VALUE, if(VALUE-\@V < 0 OR \@RB = 1 , \@diff:= 0, \@diff:= VALUE-\@V ) as DIFF, \@V:= VALUE as VALUEBEFORE, \@RB:= '0' as RBIT ";
|
||||
}
|
||||
else {
|
||||
@ -4253,7 +4270,7 @@ sub DbRep_diffval {
|
||||
my $runtime_string_next = $a[2];
|
||||
$runtime_string = encode_base64($runtime_string,"");
|
||||
|
||||
if($dbmodel eq "MYSQL") {
|
||||
if($dbmodel eq "MYSQL2") {
|
||||
$err = DbRep_dbhDo ($name, $dbh, "set \@V:= 0, \@diff:= 0, \@diffTotal:= 0, \@RB:= 1;"); # @\RB = Resetbit wenn neues Selektionsintervall beginnt
|
||||
return "$name|$err" if ($err);
|
||||
}
|
||||
@ -4268,7 +4285,7 @@ sub DbRep_diffval {
|
||||
($err, $sth) = DbRep_prepareExecuteQuery ($name, $dbh, $sql);
|
||||
return "$name|$err" if ($err);
|
||||
|
||||
if($dbmodel eq "MYSQL") {
|
||||
if($dbmodel eq "MYSQL2") {
|
||||
@array = map { $runtime_string." ".$_ -> [0]." ".$_ -> [1]." ".$_ -> [2]."\n" } @{ $sth->fetchall_arrayref() };
|
||||
}
|
||||
else {
|
||||
@ -12307,7 +12324,9 @@ return ($ftperr,$ftpmsg,@ftpfd);
|
||||
# Test auf Daylight saving time
|
||||
####################################################################################################
|
||||
sub DbRep_dsttest {
|
||||
my ($hash,$runtime,$aggsec) = @_;
|
||||
my $hash = shift;
|
||||
my $runtime = shift;
|
||||
my $aggsec = shift;
|
||||
my $name = $hash->{NAME};
|
||||
my $dstchange = 0;
|
||||
|
||||
@ -12316,14 +12335,15 @@ sub DbRep_dsttest {
|
||||
# ein Wechsel der daylight saving time vorliegt
|
||||
|
||||
my $dst = (localtime($runtime))[8]; # ermitteln daylight saving aktuelle runtime
|
||||
my $time_str = localtime($runtime+$aggsec); # textual time representation
|
||||
my $ostr = localtime ($runtime);
|
||||
my $nstr = localtime ($runtime + $aggsec); # textual time representation
|
||||
my $dst_new = (localtime($runtime + $aggsec))[8]; # ermitteln daylight saving nächste runtime
|
||||
|
||||
if ($dst != $dst_new) {
|
||||
$dstchange = 1;
|
||||
}
|
||||
|
||||
Log3 ($name, 5, "DbRep $name - Daylight savings changed: $dstchange (on $time_str)");
|
||||
Log3 ($name, 5, qq{DbRep $name - Daylight savings changed: $dstchange (from "$ostr" to "$nstr")});
|
||||
|
||||
return $dstchange;
|
||||
}
|
||||
@ -13077,12 +13097,12 @@ sub DbRep_setVersionInfo {
|
||||
if($modules{$type}{META}{x_prereqs_src} && !$hash->{HELPER}{MODMETAABSENT}) {
|
||||
# META-Daten sind vorhanden
|
||||
$modules{$type}{META}{version} = "v".$v; # Version aus META.json überschreiben, Anzeige mit {Dumper $modules{SMAPortal}{META}}
|
||||
if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 93_DbRep.pm 26413 2022-09-17 18:08:05Z DS_Starter $ im Kopf komplett! vorhanden )
|
||||
if($modules{$type}{META}{x_version}) { # {x_version} ( nur gesetzt wenn $Id: 93_DbRep.pm 26650 2022-11-04 22:02:44Z DS_Starter $ im Kopf komplett! vorhanden )
|
||||
$modules{$type}{META}{x_version} =~ s/1.1.1/$v/g;
|
||||
} else {
|
||||
$modules{$type}{META}{x_version} = $v;
|
||||
}
|
||||
return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 93_DbRep.pm 26413 2022-09-17 18:08:05Z DS_Starter $ im Kopf komplett! vorhanden )
|
||||
return $@ unless (FHEM::Meta::SetInternals($hash)); # FVERSION wird gesetzt ( nur gesetzt wenn $Id: 93_DbRep.pm 26650 2022-11-04 22:02:44Z DS_Starter $ im Kopf komplett! vorhanden )
|
||||
if(__PACKAGE__ eq "FHEM::$type" || __PACKAGE__ eq $type) {
|
||||
# es wird mit Packages gearbeitet -> Perl übliche Modulversion setzen
|
||||
# mit {<Modul>->VERSION()} im FHEMWEB kann Modulversion abgefragt werden
|
||||
|
Loading…
x
Reference in New Issue
Block a user