mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +00:00
93_DbRep: new attribute fetchValueFn to change displayed values of database field VALUE got by fetchrows command
git-svn-id: https://svn.fhem.de/fhem/trunk@20048 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a09ca54e88
commit
49fa4ce71d
@ -1,5 +1,7 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- feature: 93_DbRep: new attribute fetchValueFn to change displayed values of
|
||||||
|
database field VALUE got by fetchrows command
|
||||||
- feature: 93_DbLog: new attribute dbSchema to add database schema to tables
|
- feature: 93_DbLog: new attribute dbSchema to add database schema to tables
|
||||||
Forum: #102679
|
Forum: #102679
|
||||||
- feature: 76_SMAInverter: V2.13.0, attr target-serial/target-susyid are set
|
- feature: 76_SMAInverter: V2.13.0, attr target-serial/target-susyid are set
|
||||||
|
@ -58,6 +58,8 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
|
|||||||
|
|
||||||
# Version History intern
|
# Version History intern
|
||||||
our %DbRep_vNotesIntern = (
|
our %DbRep_vNotesIntern = (
|
||||||
|
"8.22.0" => "23.08.2019 new attr fetchValueFn. When fetching the database content, manipulate the VALUE-field before create reading ",
|
||||||
|
"8.21.2" => "14.08.2019 commandRef revised ",
|
||||||
"8.21.1" => "31.05.2019 syncStandby considers executeBeforeProc, commandRef revised ",
|
"8.21.1" => "31.05.2019 syncStandby considers executeBeforeProc, commandRef revised ",
|
||||||
"8.21.0" => "28.04.2019 implement FHEM command \"dbReadingsVal\" ",
|
"8.21.0" => "28.04.2019 implement FHEM command \"dbReadingsVal\" ",
|
||||||
"8.20.1" => "28.04.2019 set index verbose changed, check index \"Report_Idx\" in getInitData ",
|
"8.20.1" => "28.04.2019 set index verbose changed, check index \"Report_Idx\" in getInitData ",
|
||||||
@ -153,6 +155,8 @@ our %DbRep_vNotesIntern = (
|
|||||||
|
|
||||||
# Version History extern:
|
# Version History extern:
|
||||||
our %DbRep_vNotesExtern = (
|
our %DbRep_vNotesExtern = (
|
||||||
|
"8.22.0" => "23.08.2019 A new attribute \"fetchValueFn\" is provided. When fetching the database content, you are able to manipulate ".
|
||||||
|
"the value displayed from the VALUE database field before create the appropriate reading. ",
|
||||||
"8.21.0" => "28.04.2019 FHEM command \"dbReadingsVal\" implemented.",
|
"8.21.0" => "28.04.2019 FHEM command \"dbReadingsVal\" implemented.",
|
||||||
"8.20.0" => "27.04.2019 With the new set \"index\" command it is now possible to list and (re)create the indexes which are ".
|
"8.20.0" => "27.04.2019 With the new set \"index\" command it is now possible to list and (re)create the indexes which are ".
|
||||||
"needed for DbLog and/or DbRep operation.",
|
"needed for DbLog and/or DbRep operation.",
|
||||||
@ -340,6 +344,7 @@ sub DbRep_Initialize($) {
|
|||||||
"fastStart:1,0 ".
|
"fastStart:1,0 ".
|
||||||
"fetchRoute:ascent,descent ".
|
"fetchRoute:ascent,descent ".
|
||||||
"fetchMarkDuplicates:red,blue,brown,green,orange ".
|
"fetchMarkDuplicates:red,blue,brown,green,orange ".
|
||||||
|
"fetchValueFn:textField-long ".
|
||||||
"ftpDebug:1,0 ".
|
"ftpDebug:1,0 ".
|
||||||
"ftpDir ".
|
"ftpDir ".
|
||||||
"ftpDumpFilesKeep:1,2,3,4,5,6,7,8,9,10 ".
|
"ftpDumpFilesKeep:1,2,3,4,5,6,7,8,9,10 ".
|
||||||
@ -1143,6 +1148,21 @@ sub DbRep_Attr($$$$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($aName eq "fetchValueFn") {
|
||||||
|
if($cmd eq "set") {
|
||||||
|
my $VALUE = "Hello";
|
||||||
|
# Funktion aus Attr validieren
|
||||||
|
if( $aVal =~ m/^\s*(\{.*\})\s*$/s ) {
|
||||||
|
$aVal = $1;
|
||||||
|
} else {
|
||||||
|
$aVal = "";
|
||||||
|
}
|
||||||
|
return "Your function does not match the form \"{<function>}\"" if(!$aVal);
|
||||||
|
eval $aVal;
|
||||||
|
return "Bad function: $@" if($@);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($aName eq "sqlCmdHistoryLength") {
|
if ($aName eq "sqlCmdHistoryLength") {
|
||||||
if($cmd eq "set") {
|
if($cmd eq "set") {
|
||||||
$do = ($aVal) ? 1 : 0;
|
$do = ($aVal) ? 1 : 0;
|
||||||
@ -4874,6 +4894,7 @@ sub fetchrows_ParseDone($) {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $reading = AttrVal($name, "reading", undef);
|
my $reading = AttrVal($name, "reading", undef);
|
||||||
my $limit = AttrVal($name, "limit", 1000);
|
my $limit = AttrVal($name, "limit", 1000);
|
||||||
|
my $fvfn = AttrVal($name, "fetchValueFn", undef);
|
||||||
my $color = "<html><span style=\"color: #".AttrVal($name, "fetchMarkDuplicates", "000000").";\">"; # Highlighting doppelter DB-Einträge
|
my $color = "<html><span style=\"color: #".AttrVal($name, "fetchMarkDuplicates", "000000").";\">"; # Highlighting doppelter DB-Einträge
|
||||||
$color =~ s/#// if($color =~ /red|blue|brown|green|orange/);
|
$color =~ s/#// if($color =~ /red|blue|brown|green|orange/);
|
||||||
my $ecolor = "</span></html>"; # Ende Highlighting
|
my $ecolor = "</span></html>"; # Ende Highlighting
|
||||||
@ -4946,6 +4967,19 @@ sub fetchrows_ParseDone($) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($fvfn) {
|
||||||
|
my $VALUE = $val;
|
||||||
|
if( $fvfn =~ m/^\s*(\{.*\})\s*$/s ) {
|
||||||
|
$fvfn = $1;
|
||||||
|
} else {
|
||||||
|
$fvfn = "";
|
||||||
|
}
|
||||||
|
if ($fvfn) {
|
||||||
|
eval $fvfn;
|
||||||
|
$val = $VALUE if(!$@);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ReadingsBulkUpdateValue($hash, $reading_runtime_string, $val);
|
ReadingsBulkUpdateValue($hash, $reading_runtime_string, $val);
|
||||||
}
|
}
|
||||||
my $sfx = AttrVal("global", "language", "EN");
|
my $sfx = AttrVal("global", "language", "EN");
|
||||||
@ -9543,13 +9577,11 @@ sub DbRep_delread($;$$) {
|
|||||||
# Highlighted Readings löschen und save statefile wegen Inkompatibilitär beim Restart
|
# Highlighted Readings löschen und save statefile wegen Inkompatibilitär beim Restart
|
||||||
if($key =~ /<html><span/) {
|
if($key =~ /<html><span/) {
|
||||||
$do = 1;
|
$do = 1;
|
||||||
# delete($defs{$name}{READINGS}{$key});
|
|
||||||
readingsDelete($hash,$key);
|
readingsDelete($hash,$key);
|
||||||
}
|
}
|
||||||
# Reading löschen wenn Featuelevel > 5.9 und zu lang nach der neuen Festlegung
|
# Reading löschen wenn Featuelevel > 5.9 und zu lang nach der neuen Festlegung
|
||||||
if($do == 0 && $featurelevel > 5.9 && !goodReadingName($key)) {
|
if($do == 0 && $featurelevel > 5.9 && !goodReadingName($key)) {
|
||||||
$do = 1;
|
$do = 1;
|
||||||
# delete($defs{$name}{READINGS}{$key});
|
|
||||||
readingsDelete($hash,$key);
|
readingsDelete($hash,$key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -11624,7 +11656,8 @@ return;
|
|||||||
Every reading of result is composed of the dataset timestring , an index, the device name
|
Every reading of result is composed of the dataset timestring , an index, the device name
|
||||||
and the reading name.
|
and the reading name.
|
||||||
The function has the capability to reconize multiple occuring datasets (doublets).
|
The function has the capability to reconize multiple occuring datasets (doublets).
|
||||||
Such doublets are marked by an index > 1. <br>
|
Such doublets are marked by an index > 1. Optional a Unique-Index is appended if
|
||||||
|
datasets with identical timestamp, device and reading but different value are existing. <br>
|
||||||
Doublets can be highlighted in terms of color by setting attribut e"fetchMarkDuplicates". <br><br>
|
Doublets can be highlighted in terms of color by setting attribut e"fetchMarkDuplicates". <br><br>
|
||||||
|
|
||||||
<b>Note:</b> <br>
|
<b>Note:</b> <br>
|
||||||
@ -11644,8 +11677,8 @@ return;
|
|||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<b>Example:</b> <br>
|
<b>Example:</b> <br>
|
||||||
2017-10-22_03-04-43__1__SMA_Energymeter__Bezug_WirkP_Kosten_Diff <br>
|
2017-10-22_03-04-43__1__SMA_Energymeter__Bezug_WirkP_Kosten_Diff__[1] <br>
|
||||||
# <date>_<time>__<index>__<device>__<reading>
|
# <date>_<time>__<index>__<device>__<reading>__[Unique-Index]
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@ -11654,10 +11687,11 @@ return;
|
|||||||
<ul>
|
<ul>
|
||||||
<table>
|
<table>
|
||||||
<colgroup> <col width=5%> <col width=95%> </colgroup>
|
<colgroup> <col width=5%> <col width=95%> </colgroup>
|
||||||
<tr><td> <b>fetchRoute</b> </td><td>: direction of selection read in database </td></tr>
|
|
||||||
<tr><td> <b>limit</b> </td><td>: limits the number of datasets to select and display </td></tr>
|
|
||||||
<tr><td> <b>fetchMarkDuplicates</b> </td><td>: Highlighting of found doublets </td></tr>
|
|
||||||
<tr><td> <b>device</b> </td><td>: include or exclude <device> from selection </td></tr>
|
<tr><td> <b>device</b> </td><td>: include or exclude <device> from selection </td></tr>
|
||||||
|
<tr><td> <b>fetchRoute</b> </td><td>: direction of selection read in database </td></tr>
|
||||||
|
<tr><td> <b>fetchMarkDuplicates</b> </td><td>: Highlighting of found doublets </td></tr>
|
||||||
|
<tr><td> <b>fetchValueFn</b> </td><td>: the displayed value of the VALUE database field can be changed by a function before the reading is created </td></tr>
|
||||||
|
<tr><td> <b>limit</b> </td><td>: limits the number of datasets to select and display </td></tr>
|
||||||
<tr><td> <b>reading</b> </td><td>: include or exclude <reading> from selection </td></tr>
|
<tr><td> <b>reading</b> </td><td>: include or exclude <reading> from selection </td></tr>
|
||||||
<tr><td> <b>time.*</b> </td><td>: A number of attributes to limit selection by time </td></tr>
|
<tr><td> <b>time.*</b> </td><td>: A number of attributes to limit selection by time </td></tr>
|
||||||
<tr><td style="vertical-align:top"> <b>valueFilter</b> <td>: an additional REGEXP to control the record selection. The REGEXP is applied to the database field 'VALUE'. </td></tr>
|
<tr><td style="vertical-align:top"> <b>valueFilter</b> <td>: an additional REGEXP to control the record selection. The REGEXP is applied to the database field 'VALUE'. </td></tr>
|
||||||
@ -11674,7 +11708,7 @@ return;
|
|||||||
</li> <br>
|
</li> <br>
|
||||||
|
|
||||||
<li><b> index <Option> </b>
|
<li><b> index <Option> </b>
|
||||||
- Reports the existing indexes in the database or creates the needed indexes.
|
- Reports the existing indexes in the database or creates the index which is needed.
|
||||||
If the index is already created, it will be renewed (dropped and new created) <br><br>
|
If the index is already created, it will be renewed (dropped and new created) <br><br>
|
||||||
|
|
||||||
The possible options are: <br><br>
|
The possible options are: <br><br>
|
||||||
@ -11691,6 +11725,9 @@ return;
|
|||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
<b>Note:</b> <br>
|
||||||
|
The used database user needs the ALTER and INDEX privilege. <br>
|
||||||
|
|
||||||
</li> <br>
|
</li> <br>
|
||||||
|
|
||||||
<li><b> insert </b> - use it to insert data ito table "history" manually. Input values for Date, Time and Value are mandatory. The database fields for Type and Event will be filled in with "manual" automatically and the values of Device, Reading will be get from set <a href="#DbRepattr">attributes</a>. <br><br>
|
<li><b> insert </b> - use it to insert data ito table "history" manually. Input values for Date, Time and Value are mandatory. The database fields for Type and Event will be filled in with "manual" automatically and the values of Device, Reading will be get from set <a href="#DbRepattr">attributes</a>. <br><br>
|
||||||
@ -12680,6 +12717,21 @@ sub bdump {
|
|||||||
|
|
||||||
</li> <br><br>
|
</li> <br><br>
|
||||||
|
|
||||||
|
<a name="fetchValueFn"></a>
|
||||||
|
<li><b>fetchValueFn </b> - When fetching the database content, you are able to manipulate the value fetched from the
|
||||||
|
VALUE database field before create the appropriate reading. You have to insert a Perl
|
||||||
|
function which is enclosed in {} .<br>
|
||||||
|
The value of the database field VALUE is provided in variable $VALUE. <br><br>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<b>Example:</b> <br>
|
||||||
|
attr <name> fetchValueFn { $VALUE =~ s/^.*Used:\s(.*)\sMB,.*/$1." MB"/e } <br>
|
||||||
|
|
||||||
|
# From a long line a specific pattern is extracted and will be displayed als VALUE instead
|
||||||
|
the whole line
|
||||||
|
</ul>
|
||||||
|
</li> <br><br>
|
||||||
|
|
||||||
<a name="ftpUse"></a>
|
<a name="ftpUse"></a>
|
||||||
<li><b>ftpUse </b> - FTP Transfer after dump will be switched on (without SSL encoding). The created
|
<li><b>ftpUse </b> - FTP Transfer after dump will be switched on (without SSL encoding). The created
|
||||||
database backup file will be transfered non-blocking to the FTP-Server (Attribut "ftpServer").
|
database backup file will be transfered non-blocking to the FTP-Server (Attribut "ftpServer").
|
||||||
@ -14037,10 +14089,12 @@ sub bdump {
|
|||||||
Die Leserichtung in der Datenbank kann durch das <a href="#DbRepattr">Attribut</a>
|
Die Leserichtung in der Datenbank kann durch das <a href="#DbRepattr">Attribut</a>
|
||||||
"fetchRoute" bestimmt werden. <br><br>
|
"fetchRoute" bestimmt werden. <br><br>
|
||||||
|
|
||||||
Jedes Ergebnisreading setzt sich aus dem Timestring des Datensatzes, einem Index, dem Device
|
Jedes Ergebnisreading setzt sich aus dem Timestring des Datensatzes, einem Dubletten-Index,
|
||||||
und dem Reading zusammen.
|
dem Device und dem Reading zusammen.
|
||||||
Die Funktion fetchrows ist in der Lage, mehrfach vorkommende Datensätze (Dubletten) zu erkennen.
|
Die Funktion fetchrows ist in der Lage, mehrfach vorkommende Datensätze (Dubletten) zu erkennen.
|
||||||
Solche Dubletten sind mit einem Index > 1 gekennzeichnet. <br>
|
Solche Dubletten sind mit einem Dubletten-Index > 1 gekennzeichnet. Optional wird noch ein
|
||||||
|
Unique-Index angehängt, wenn Datensätze mit identischem Timestamp, Device und Reading aber
|
||||||
|
unterschiedlichem Value vorhanden sind. <br>
|
||||||
Dubletten können mit dem Attribut "fetchMarkDuplicates" farblich hervorgehoben werden. <br><br>
|
Dubletten können mit dem Attribut "fetchMarkDuplicates" farblich hervorgehoben werden. <br><br>
|
||||||
|
|
||||||
<b>Hinweis:</b> <br>
|
<b>Hinweis:</b> <br>
|
||||||
@ -14062,8 +14116,8 @@ sub bdump {
|
|||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<b>Beispiel:</b> <br>
|
<b>Beispiel:</b> <br>
|
||||||
2017-10-22_03-04-43__1__SMA_Energymeter__Bezug_WirkP_Kosten_Diff <br>
|
2017-10-22_03-04-43__1__SMA_Energymeter__Bezug_WirkP_Kosten_Diff__[1] <br>
|
||||||
# <Datum>_<Zeit>__<Index>__<Device>__<Reading>
|
# <Datum>_<Zeit>__<Dubletten-Index>__<Device>__<Reading>__[Unique-Index]
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@ -14073,10 +14127,11 @@ sub bdump {
|
|||||||
<ul>
|
<ul>
|
||||||
<table>
|
<table>
|
||||||
<colgroup> <col width=5%> <col width=95%> </colgroup>
|
<colgroup> <col width=5%> <col width=95%> </colgroup>
|
||||||
<tr><td> <b>fetchRoute</b> </td><td>: Leserichtung der Selektion innerhalb der Datenbank </td></tr>
|
|
||||||
<tr><td> <b>limit</b> </td><td>: begrenzt die Anzahl zu selektierenden bzw. anzuzeigenden Datensätze </td></tr>
|
|
||||||
<tr><td> <b>fetchMarkDuplicates</b> </td><td>: Hervorhebung von gefundenen Dubletten </td></tr>
|
|
||||||
<tr><td> <b>device</b> </td><td>: einschließen oder ausschließen von Datensätzen die <device> enthalten </td></tr>
|
<tr><td> <b>device</b> </td><td>: einschließen oder ausschließen von Datensätzen die <device> enthalten </td></tr>
|
||||||
|
<tr><td> <b>fetchRoute</b> </td><td>: Leserichtung der Selektion innerhalb der Datenbank </td></tr>
|
||||||
|
<tr><td> <b>fetchMarkDuplicates</b> </td><td>: Hervorhebung von gefundenen Dubletten </td></tr>
|
||||||
|
<tr><td> <b>fetchValueFn</b> </td><td>: der angezeigte Wert des VALUE Datenbankfeldes kann mit einer Funktion vor der Readingerstellung geändert werden </td></tr>
|
||||||
|
<tr><td> <b>limit</b> </td><td>: begrenzt die Anzahl zu selektierenden bzw. anzuzeigenden Datensätze </td></tr>
|
||||||
<tr><td> <b>reading</b> </td><td>: einschließen oder ausschließen von Datensätzen die <reading> enthalten </td></tr>
|
<tr><td> <b>reading</b> </td><td>: einschließen oder ausschließen von Datensätzen die <reading> enthalten </td></tr>
|
||||||
<tr><td> <b>time.*</b> </td><td>: eine Reihe von Attributen zur Zeitabgrenzung </td></tr>
|
<tr><td> <b>time.*</b> </td><td>: eine Reihe von Attributen zur Zeitabgrenzung </td></tr>
|
||||||
<tr><td style="vertical-align:top"> <b>valueFilter</b> <td>: filtert die anzuzeigenden Datensätze mit einem regulären Ausdruck (Datenbank spezifischer REGEXP). Der REGEXP wird auf Werte des Datenbankfeldes 'VALUE' angewendet. </td></tr>
|
<tr><td style="vertical-align:top"> <b>valueFilter</b> <td>: filtert die anzuzeigenden Datensätze mit einem regulären Ausdruck (Datenbank spezifischer REGEXP). Der REGEXP wird auf Werte des Datenbankfeldes 'VALUE' angewendet. </td></tr>
|
||||||
@ -14112,6 +14167,9 @@ sub bdump {
|
|||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
<b>Hinweis:</b> <br>
|
||||||
|
Der verwendete Datenbank-Nutzer benötigt das ALTER und INDEX Privileg. <br>
|
||||||
|
|
||||||
</li> <br>
|
</li> <br>
|
||||||
|
|
||||||
<li><b> insert </b> - Manuelles Einfügen eines Datensatzes in die Tabelle "history". Obligatorisch sind Eingabewerte für Datum, Zeit und Value.
|
<li><b> insert </b> - Manuelles Einfügen eines Datensatzes in die Tabelle "history". Obligatorisch sind Eingabewerte für Datum, Zeit und Value.
|
||||||
@ -15118,6 +15176,21 @@ sub bdump {
|
|||||||
|
|
||||||
</li> <br><br>
|
</li> <br><br>
|
||||||
|
|
||||||
|
<a name="fetchValueFn"></a>
|
||||||
|
<li><b>fetchValueFn </b> - Der angezeigte Wert des Datenbankfeldes VALUE kann vor der Erstellung des entsprechenden
|
||||||
|
Readings geändert werden. Das Attribut muss eine Perl Funktion eingeschlossen in {}
|
||||||
|
enthalten. <br>
|
||||||
|
Der Wert des Datenbankfeldes VALUE wird in der Variable $VALUE zur Verfügung gestellt. <br><br>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<b>Beispiel:</b> <br>
|
||||||
|
attr <name> fetchValueFn { $VALUE =~ s/^.*Used:\s(.*)\sMB,.*/$1." MB"/e } <br>
|
||||||
|
|
||||||
|
# Von einer langen Ausgabe wird ein spezifisches Zeichenmuster extrahiert und als VALUE
|
||||||
|
anstatt der gesamten Zeile im Reading angezeigt.
|
||||||
|
</ul>
|
||||||
|
</li> <br><br>
|
||||||
|
|
||||||
<a name="ftpUse"></a>
|
<a name="ftpUse"></a>
|
||||||
<li><b>ftpUse </b> - FTP Transfer nach einem Dump wird eingeschaltet (ohne SSL Verschlüsselung). Das erzeugte
|
<li><b>ftpUse </b> - FTP Transfer nach einem Dump wird eingeschaltet (ohne SSL Verschlüsselung). Das erzeugte
|
||||||
Datenbank Backupfile wird non-blocking zum angegebenen FTP-Server (Attribut "ftpServer")
|
Datenbank Backupfile wird non-blocking zum angegebenen FTP-Server (Attribut "ftpServer")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user