2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

93_DbRep: V7.19.0, attribute "valueFilter" to filter datasets in fetchrows

git-svn-id: https://svn.fhem.de/fhem/trunk@17202 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2018-08-25 10:55:42 +00:00
parent 56d4382da8
commit ae342f6c77
2 changed files with 43 additions and 5 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- feature: 93_DbRep: V7.19.0, attribute "valueFilter" to filter datasets in
fetchrows
- feature: 49_SSCam: V7.0.0, compatibility to SVS 8.2.0 - feature: 49_SSCam: V7.0.0, compatibility to SVS 8.2.0
- feature: 93_Log2Syslog: V4.8.5, new Syslog-Server Mode and some other - feature: 93_Log2Syslog: V4.8.5, new Syslog-Server Mode and some other
improvements, version is moved from contrib improvements, version is moved from contrib

View File

@ -37,6 +37,7 @@
########################################################################################################################### ###########################################################################################################################
# Versions History: # Versions History:
# #
# 7.19.0 25.08.2018 attribute "valueFilter" to filter datasets in fetchrows
# 7.18.2 02.08.2018 fix in fetchrow function (forum:#89886), fix highlighting # 7.18.2 02.08.2018 fix in fetchrow function (forum:#89886), fix highlighting
# 7.18.1 03.06.2018 commandref revised # 7.18.1 03.06.2018 commandref revised
# 7.18.0 02.06.2018 possible use of y:(\d) for timeDiffToNow, timeOlderThan , minor fixes of timeOlderThan # 7.18.0 02.06.2018 possible use of y:(\d) for timeDiffToNow, timeOlderThan , minor fixes of timeOlderThan
@ -343,7 +344,7 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
sub DbRep_Main($$;$); sub DbRep_Main($$;$);
sub DbLog_cutCol($$$$$$$); # DbLog-Funktion nutzen um Daten auf maximale Länge beschneiden sub DbLog_cutCol($$$$$$$); # DbLog-Funktion nutzen um Daten auf maximale Länge beschneiden
my $DbRepVersion = "7.18.2"; my $DbRepVersion = "7.19.0";
my %dbrep_col = ("DEVICE" => 64, my %dbrep_col = ("DEVICE" => 64,
"TYPE" => 64, "TYPE" => 64,
@ -418,8 +419,14 @@ sub DbRep_Initialize($) {
"timeOlderThan ". "timeOlderThan ".
"timeout ". "timeout ".
"userExitFn ". "userExitFn ".
"valueFilter ".
$readingFnAttributes; $readingFnAttributes;
# Umbenennen von existierenden Attrbuten
# $hash->{AttrRenameMap} = { "reading" => "readingFilter",
# "device" => "deviceFilter",
# };
return undef; return undef;
} }
@ -1077,9 +1084,15 @@ sub DbRep_Attr($$$$) {
} }
if ($cmd eq "set") { if ($cmd eq "set") {
if ($aName =~ /valueFilter/) {
eval { "Hallo" =~ m/$aVal/ };
return "Bad regexp: $@" if($@);
}
if ($aName =~ /seqDoubletsVariance/) { if ($aName =~ /seqDoubletsVariance/) {
unless (looks_like_number($aVal)) { return " The Value of $aName is not valid. Only figures are allowed !";} unless (looks_like_number($aVal)) { return " The Value of $aName is not valid. Only figures are allowed !";}
} }
if ($aName eq "timeYearPeriod") { if ($aName eq "timeYearPeriod") {
# 06-01 02-28 # 06-01 02-28
unless ($aVal =~ /^(\d{2})-(\d{2}) (\d{2})-(\d{2})$/ ) unless ($aVal =~ /^(\d{2})-(\d{2}) (\d{2})-(\d{2})$/ )
@ -4464,6 +4477,7 @@ sub fetchrows_DoParse($) {
my $limit = AttrVal($name, "limit", 1000); my $limit = AttrVal($name, "limit", 1000);
my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0; my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0;
my $fetchroute = AttrVal($name, "fetchRoute", "descent"); my $fetchroute = AttrVal($name, "fetchRoute", "descent");
my $valfilter = AttrVal($name, "valueFilter", undef); # nur Anzeige von Datensätzen die "valueFilter" enthalten
$fetchroute = ($fetchroute eq "descent")?"DESC":"ASC"; $fetchroute = ($fetchroute eq "descent")?"DESC":"ASC";
my ($err,$dbh,$sth,$sql,$rowlist,$nrows); my ($err,$dbh,$sth,$sql,$rowlist,$nrows);
@ -4506,6 +4520,16 @@ sub fetchrows_DoParse($) {
no warnings 'uninitialized'; no warnings 'uninitialized';
my @row_array = map { $_->[0]."_ESC_".$_->[1]."_ESC_".($_->[2] =~ s/ /_ESC_/r)."_ESC_".$_->[3]."_ESC_".$_->[4]."\n" } @{$sth->fetchall_arrayref()}; my @row_array = map { $_->[0]."_ESC_".$_->[1]."_ESC_".($_->[2] =~ s/ /_ESC_/r)."_ESC_".$_->[3]."_ESC_".$_->[4]."\n" } @{$sth->fetchall_arrayref()};
# eventuell gesetzten Datensatz-Filter anwenden
if($valfilter) {
my @fiarr;
foreach my $row (@row_array) {
next if($row !~ /$valfilter/);
push @fiarr,$row;
}
@row_array = @fiarr;
}
use warnings; use warnings;
$nrows = $#row_array+1; # Anzahl der Ergebniselemente $nrows = $#row_array+1; # Anzahl der Ergebniselemente
pop @row_array if($nrows>$limit); # das zuviel selektierte Element wegpoppen wenn Limit überschritten pop @row_array if($nrows>$limit); # das zuviel selektierte Element wegpoppen wenn Limit überschritten
@ -4552,7 +4576,6 @@ sub fetchrows_ParseDone($) {
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
my @i;
my @row; my @row;
my $reading_runtime_string; my $reading_runtime_string;
@ -9746,6 +9769,7 @@ return;
<tr><td> <b>device</b> </td><td>: select only datasets which are contain &lt;device&gt; </td></tr> <tr><td> <b>device</b> </td><td>: select only datasets which are contain &lt;device&gt; </td></tr>
<tr><td> <b>reading</b> </td><td>: select only datasets which are contain &lt;reading&gt; </td></tr> <tr><td> <b>reading</b> </td><td>: select only datasets which are contain &lt;reading&gt; </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> <b>valueFilter</b> </td><td>: filter datasets of database field "VALUE" by a regular expression </td></tr>
</table> </table>
</ul> </ul>
<br> <br>
@ -10748,7 +10772,12 @@ sub bdump {
</li> </li>
<br><br> <br><br>
</ul></ul></ul> <li><b>valueFilter </b> - Regular expression to filter datasets within particular functions. The regex is
applied to the whole selected dataset (inclusive Device, Reading and so on).
Please compare to explanations of relevant set-commands. </li> <br>
</ul>
</ul></ul>
<a name="DbRepReadings"></a> <a name="DbRepReadings"></a>
<b>Readings</b> <b>Readings</b>
@ -11545,6 +11574,7 @@ sub bdump {
<tr><td> <b>device</b> </td><td>: Selektion nur von Datensätzen die &lt;device&gt; enthalten </td></tr> <tr><td> <b>device</b> </td><td>: Selektion nur von Datensätzen die &lt;device&gt; enthalten </td></tr>
<tr><td> <b>reading</b> </td><td>: Selektion nur von Datensätzen die &lt;reading&gt; enthalten </td></tr> <tr><td> <b>reading</b> </td><td>: Selektion nur von Datensätzen die &lt;reading&gt; 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> <b>valueFilter</b> </td><td>: filtert Datensätze des Datenbankfeldes "VALUE" mit einem regulären Ausdruck </td></tr>
</table> </table>
</ul> </ul>
<br> <br>
@ -12562,7 +12592,13 @@ sub bdump {
</ul> </ul>
</li> </li>
<br><br> <br>
<br>
<li><b>valueFilter </b> - Regulärer Ausdruck zur Filterung von Datensätzen innerhalb bestimmter Funktionen. Der
Regex auf den gesamten selektierten Datensatz (inkl. Device, Reading usw.) angewendet.
Bitte vergleichen sie die Erläuterungen zu den entsprechenden Set-Kommandos. </li> <br>
</ul></ul> </ul></ul>
</ul> </ul>