2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

93_DbRep: new aggregation type year

git-svn-id: https://svn.fhem.de/fhem/trunk@19105 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2019-04-03 18:59:27 +00:00
parent 00933f7ebb
commit 15f16826ff
2 changed files with 207 additions and 161 deletions

View File

@ -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 type year
- bugfix 73_AMADCommBridge: fix little bug
- bugfix: 70_BRAVIA: fix channel presets, fix use of ReadingsAge
- change: 93_DbRep: consideration of leap year/daylight saving time changed,

View File

@ -58,6 +58,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
# Version History intern
our %DbRep_vNotesIntern = (
"8.18.0" => "01.04.2019 new aggregation year ",
"8.17.2" => "28.03.2019 consideration of daylight saving time/leap year changed (func DbRep_corrRelTime) ",
"8.17.1" => "24.03.2019 edit Meta data, activate Meta.pm, prevent module from deactivation in case of unavailable Meta.pm ",
"8.17.0" => "20.03.2019 prepare for Meta.pm, new attribute \"sqlCmdVars\" ",
@ -145,6 +146,7 @@ our %DbRep_vNotesIntern = (
# Version History extern:
our %DbRep_vNotesExtern = (
"8.18.0" => "01.04.2019 New aggregation type \"year\" ",
"8.17.0" => "20.03.2019 With new attribute \"sqlCmdVars\" you are able to set SQL session variables or SQLite PRAGMA every time ".
"before running a SQL-statement with sqlCmd command.",
"8.16.0" => "17.03.2019 allow SQLite PRAGMAS leading an SQLIte SQL-Statement in sqlCmd ",
@ -220,12 +222,8 @@ our %DbRep_vNotesExtern = (
"4.13.4" => "09.05.2017 attribute sqlResultSingleFormat: mline sline table, attribute 'allowDeletion' is now also valid for sqlResult, sqlResultSingle and delete command is forced ",
"4.13.2" => "09.05.2017 sqlResult, sqlResultSingle are able to execute delete, insert, update commands error corrections ",
"4.12.0" => "31.03.2017 support of primary key for insert functions ",
"4.11.4" => "29.03.2017 bugfix timestamp in minValue, maxValue if VALUE contains more than one numeric value (like in sysmon) ",
"4.11.3" => "26.03.2017 usage of daylight saving time changed to avoid wrong selection when wintertime switch to summertime, minor bug fixes ",
"4.11.2" => "16.03.2017 bugfix in func dbmeta_DoParse (SQLITE_DB_FILENAME) ",
"4.11.0" => "18.02.2017 added [current|previous]_[month|week|day|hour]_begin and [current|previous]_[month|week|day|hour]_end as options of timestamp ",
"4.10.2" => "16.01.2017 bugfix uninitialized value \$renmode if RenameAgent ",
"4.10.1" => "30.11.2016 bugfix importFromFile format problem if UNIT-field wasn't set ",
"4.9.0" => "23.12.2016 function readingRename added ",
"4.8.6" => "17.12.2016 new bugfix group by-clause due to incompatible changes made in MyQL 5.7.5 (Forum #msg541103) ",
"4.8.5" => "16.12.2016 bugfix group by-clause due to Forum #msg540610 ",
@ -342,7 +340,7 @@ sub DbRep_Initialize($) {
"ftpUse:1,0 ".
"ftpUser ".
"ftpUseSSL:1,0 ".
"aggregation:hour,day,week,month,no ".
"aggregation:hour,day,week,month,year,no ".
"diffAccept ".
"limit ".
"optimizeTablesBeforeDump:1,0 ".
@ -2098,6 +2096,8 @@ sub DbRep_createTimeArray($$$) {
$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") {
$aggsec = 1;
} else {
@ -2169,6 +2169,50 @@ sub DbRep_collaggstr($$$$) {
$ll = 1;
}
# Jahresaggregation
if ($aggregation eq "year") {
$runtime_orig = $runtime;
# Hilfsrechnungen
my $rm = strftime "%m", localtime($runtime); # Monat des aktuell laufenden Startdatums d. SQL-Select
my $cy = strftime "%Y", localtime($runtime); # Jahr des aktuell laufenden Startdatums d. SQL-Select
# my $icly = DbRep_IsLeapYear($name,$cy);
# my $inly = DbRep_IsLeapYear($name,$cy+1); # ist kommendes Jahr ein Schaltjahr ?
my $yf = 365;
$yf = 366 if(DbRep_IsLeapYear($name,$cy)); # ist aktuelles Jahr ein Schaltjahr ?
Log3 ($name, 5, "DbRep $name - current year: $cy, endyear: $yestr");
$aggsec = $yf * 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", localtime($runtime); # für Readingname
if ($i==1) {
# nur im ersten Durchlauf
$runtime_string_first = strftime "%Y-%m-%d %H:%M:%S", localtime($runtime_orig);
}
if ($ysstr == $yestr || $cy == $yestr) {
$runtime_string_first = strftime "%Y-01-01", localtime($runtime) if($i>1);
$runtime_string_next = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_end);
$ll=1;
} else {
if(($runtime) > $epoch_seconds_end) {
$runtime_string_first = strftime "%Y-01-01", localtime($runtime);
$runtime_string_next = strftime "%Y-%m-%d %H:%M:%S", localtime($epoch_seconds_end);
$ll=1;
} else {
$runtime_string_first = strftime "%Y-01-01", localtime($runtime) if($i>1);
$runtime_string_next = strftime "%Y-01-01", localtime($runtime+($yf * 86400));
}
}
# neue Beginnzeit in Epoche-Sekunden
$runtime = $runtime_orig+$aggsec;
}
# Monatsaggregation
if ($aggregation eq "month") {
$runtime_orig = $runtime;
@ -2203,11 +2247,11 @@ sub DbRep_collaggstr($$$$) {
} else {
$runtime_string_first = strftime "%Y-%m-01", localtime($runtime) if($i>1);
$runtime_string_next = strftime "%Y-%m-01", localtime($runtime+($dim*86400));
}
}
}
}
my ($yyyy1, $mm1, $dd1) = ($runtime_string_next =~ /(\d+)-(\d+)-(\d+)/);
$runtime = timelocal("00", "00", "00", "01", $mm1-1, $yyyy1-1900);
# 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;
@ -2272,6 +2316,7 @@ sub DbRep_collaggstr($$$$) {
} else {
$runtime_string_next = strftime "%Y-%m-%d", localtime($runtime+$aggsec);
}
Log3 ($name, 5, "DbRep $name - runtime_string: $runtime_string, runtime_string_first: $runtime_string_first, runtime_string_next: $runtime_string_next");
# neue Beginnzeit in Epoche-Sekunden
@ -8732,7 +8777,7 @@ return ("$hh:$mm:$ss");
}
####################################################################################################
# Check ob Zeitgrenzen bzw. Aggregation gesetzt sind, evtl. übertseuern (je nach Funktion)
# Check ob Zeitgrenzen bzw. Aggregation gesetzt sind, evtl. überseuern (je nach Funktion)
# Return "1" wenn Bedingung erfüllt, sonst "0"
####################################################################################################
sub DbRep_checktimeaggr ($) {
@ -9032,7 +9077,7 @@ sub DbRep_corrRelTime($$$) {
(undef,undef,undef,undef,undef,undef,undef,undef,$disdst) = localtime(time-$tim);
$tim += ($disdst-$isdst)*3600 if($disdst != $isdst);
Log3($name, 4, "DbRep $name - startMonth: $mon endMonth: $dmon lastleapyear: $lly baseYear: $fyear destdaylight:$disdst isdaylight:$isdst");
Log3($name, 4, "DbRep $name - startMonth: $dmon endMonth: $mon lastleapyear: $lly baseYear: $fyear diffdaylight:$disdst isdaylight:$isdst");
return $tim;
}
@ -9053,6 +9098,7 @@ sub DbRep_IsLeapYear($$) {
$ily = 1;
}
Log3($name, 4, "DbRep $name - Year $year is leap year") if($ily);
return $ily;
}
@ -12006,10 +12052,10 @@ return $ret;
<ul><ul>
<a name="aggregation"></a>
<li><b>aggregation </b> - Aggregation of Device/Reading-selections. Possible is hour, day, week, month or "no".
<li><b>aggregation </b> - Aggregation of Device/Reading-selections. Possible values are hour, day, week, month, year and "no".
Delivers e.g. the count of database entries for a day (countEntries), Summation of
difference values of a reading (sumValue) and so on. Using aggregation "no" (default) an
aggregation don't happens but the output contaims all values of Device/Reading in the defined time period. </li> <br>
aggregation don't happens but the output contains all values of Device/Reading in the selected time period. </li> <br>
<a name="allowDeletion"></a>
<li><b>allowDeletion </b> - unlocks the delete-function </li> <br>
@ -14414,13 +14460,12 @@ return $ret;
<ul><ul>
<a name="aggregation"></a>
<li><b>aggregation </b> - Zusammenfassung der Device/Reading-Selektionen in Stunden,Tage,Kalenderwochen,Kalendermonaten
<li><b>aggregation </b> - Zusammenfassung der Device/Reading-Selektionen in Stunden, Tagen, Kalenderwochen, Kalendermonaten, Kalenderjahren
oder "no". <br>
Liefert z.B. die Anzahl der DB-Einträge am Tag (countEntries), Summierung von
Differenzwerten eines Readings (sumValue), usw. <br>
Mit Aggregation "no" (default) erfolgt keine Zusammenfassung in einem Zeitraum, sondern die
Ausgabe wird aus allen Werten einer Device/Reading-Kombination zwischen den definierten
Zeiträumen ermittelt. </li> <br>
Liefert z.B. die Anzahl der DB-Einträge am Tag (countEntries) oder die Summierung von
Differenzwerten eines Readings (sumValue) usw. <br>
Mit Aggregation "no" (default) wird das Ergebnis aus allen Werten einer Device/Reading-Kombination im
selektierten Zeitraum ermittelt. </li> <br>
<a name="allowDeletion"></a>
<li><b>allowDeletion </b> - schaltet die Löschfunktion des Moduls frei </li> <br>