2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-27 04:35:34 +00:00

DbLog (contrib):

added Attribute: DbLogType to setup: 
  - "Current": log into current table
  - "History": log into history table
  - "Current/History" log into both tables (default)

Added support for (thanks to Roedert):
  - dummy
  - FHT8v


git-svn-id: https://svn.fhem.de/fhem/trunk@2975 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
tobiasfaust 2013-03-24 11:46:28 +00:00
parent f46406a2a5
commit 910e838c6e

View File

@ -30,7 +30,7 @@ DbLog_Initialize($)
$hash->{NotifyFn} = "DbLog_Log";
$hash->{GetFn} = "DbLog_Get";
$hash->{AttrFn} = "DbLog_Attr";
$hash->{AttrList} = "disable:0,1 loglevel:0,5";
$hash->{AttrList} = "disable:0,1 loglevel:0,5 DbLogType:Current,History,Current/History";
}
@ -250,6 +250,23 @@ DbLog_ParseEvent($$)
if($reading =~ m(^pressure_trend)) { $unit= ""; }
}
# FHT8V
elsif($type eq "FHT8V") {
if($reading =~ m(valve)) {
@parts= split(/ /,$event);
$reading= $parts[0];
$value= $parts[1];
$unit= "%";
}
}
# DUMMY
elsif($type eq "DUMMY") {
$reading= "data";
$value= $event;
$unit= "";
}
@result= ($reading,$value,$unit);
return @result;
}
@ -299,9 +316,15 @@ DbLog_Log($$)
my $is= "(TIMESTAMP, DEVICE, TYPE, EVENT, READING, VALUE, UNIT) VALUES " .
"('$ts', '$n', '$t', '$s', '$reading', '$value', '$unit')";
my $DbLogType = AttrVal($log->{NAME}, "DbLogType", "Current/History");
if ($DbLogType =~ m(History) ) {
DbLog_ExecSQL($log, "INSERT INTO history" . $is);
}
if ($DbLogType =~ m(Current) ) {
DbLog_ExecSQL($log, "DELETE FROM current WHERE (DEVICE='$n') AND (READING='$reading')");
DbLog_ExecSQL($log, "INSERT INTO current" . $is);
}
@ -396,6 +419,25 @@ DbLog_Connect($)
Log 3, "Connection to db $dbconn established";
$hash->{DBH}= $dbh;
if ($hash->{DBMODEL} eq "SQLITE") {
$dbh->do("PRAGMA temp_store=MEMORY");
$dbh->do("PRAGMA synchronous=NORMAL");
$dbh->do("PRAGMA journal_mode=WAL");
$dbh->do("CREATE TEMP TABLE IF NOT EXISTS current (TIMESTAMP TIMESTAMP, DEVICE varchar(32), TYPE varchar(32), EVENT varchar(512), READING varchar(32), VALUE varchar(32), UNIT varchar(32))");
$dbh->do("CREATE TABLE IF NOT EXISTS history (TIMESTAMP TIMESTAMP, DEVICE varchar(32), TYPE varchar(32), EVENT varchar(512), READING varchar(32), VALUE varchar(32), UNIT varchar(32))");
$dbh->do("CREATE INDEX IF NOT EXISTS Search_Idx ON `history` (DEVICE, READING, TIMESTAMP)");
}
# creating an own connection for the webfrontend, saved as DBHF in Hash
# this makes sure that the connection doesnt get lost due to other modules
my $dbhf = DBI->connect_cached("dbi:$dbconn", $dbuser, $dbpassword);
if(!$dbhf) {
Log 2, "Can't connect to $dbconn: $DBI::errstr";
return 0;
}
Log 3, "Connection to db $dbconn established";
$hash->{DBHF}= $dbhf;
return 1;
}
@ -469,6 +511,9 @@ DbLog_Get($@)
if($outf eq "INT") {
$outf = "-";
$internal = 1;
} elsif (uc($outf) eq "WEBCHART") {
# redirect the get request to the chartQuery function
return chartQuery($hash, @_);
}
my @readings = ();
@ -556,6 +601,8 @@ DbLog_Get($@)
FROM history
WHERE 1=1
AND $sqlspec{reading_clause} = ('".$readings[$i]->[0]."|".$readings[$i]->[1]."')
AND DEVICE = '".$readings[$i]->[0]."'
AND READING = '".$readings[$i]->[1]."'
AND TIMESTAMP > $sqlspec{from_timestamp}
AND TIMESTAMP < $sqlspec{to_timestamp}
ORDER BY TIMESTAMP";
@ -582,7 +629,7 @@ DbLog_Get($@)
my $val = $sql_value;
eval("$readings[$i]->[4]");
$sql_value = $val;
if($@) {Log 3, "DbLog: Fehler in der übergebenen Funktion: <".$readings[$i]->[4].">, Fehler: $@";}
if($@) {Log 3, "DbLog: Error in inline function: <".$readings[$i]->[4].">, Fehler: $@";}
$out_tstamp = $sql_timestamp;
$writeout=1;
}
@ -595,7 +642,7 @@ DbLog_Get($@)
$writeout=1;
} elsif ($readings[$i]->[3] && $readings[$i]->[3] =~ m/^int(\d+).*/o) {
#?bernehme den Dezimalwert mit den angegebenen Stellen an Nachkommastellen
bernehme den Dezimalwert mit den angegebenen Stellen an Nachkommastellen
$out_value = $1 if($sql_value =~ m/^([-\.\d]+).*/o);
$out_tstamp = $sql_timestamp;
$writeout=1;
@ -711,6 +758,273 @@ DbLog_Get($@)
}
return $retval;
}
################################################################
#
# Charting Specific functions start here
#
################################################################
################################################################
#
# Error handling, returns a JSON String
#
################################################################
sub jsonError($) {
my $errormsg = $_[0];
my $json = '{"success": "false", "msg":"'.$errormsg.'"}';
return $json;
}
################################################################
#
# Prepare the SQL String
#
################################################################
sub prepareSql(@_) {
my ($hash, @a) = @_;
my $starttime = $_[5];
$starttime =~ s/_/ /;
my $endtime = $_[6];
$endtime =~ s/_/ /;
my $device = $_[7];
my $userquery = $_[8];
my $xaxis = $_[9];
my $yaxis = $_[10];
my $savename = $_[11];
my $jsonChartConfig = $_[12];
my $pagingstart = $_[13];
my $paginglimit = $_[14];
my $dbmodel = $hash->{DBMODEL};
my ($sql, $jsonstring, $countsql, $hourstats, $daystats, $weekstats, $monthstats, $yearstats);
if ($dbmodel eq "POSTGRESQL") {
### POSTGRESQL Queries for Statistics ###
### hour:
$hourstats = "SELECT to_char(timestamp, 'YYYY-MM-DD HH24:00:00') AS TIMESTAMP, SUM(VALUE::float) AS SUM, ";
$hourstats .= "AVG(VALUE::float) AS AVG, MIN(VALUE::float) AS MIN, MAX(VALUE::float) AS MAX, ";
$hourstats .= "COUNT(VALUE) AS COUNT FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' ";
$hourstats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY 1 ORDER BY 1;";
### day:
$daystats = "SELECT to_char(timestamp, 'YYYY-MM-DD 00:00:00') AS TIMESTAMP, SUM(VALUE::float) AS SUM, ";
$daystats .= "AVG(VALUE::float) AS AVG, MIN(VALUE::float) AS MIN, MAX(VALUE::float) AS MAX, ";
$daystats .= "COUNT(VALUE) AS COUNT FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' ";
$daystats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY 1 ORDER BY 1;";
### week:
$weekstats = "SELECT date_trunc('week',timestamp) AS TIMESTAMP, SUM(VALUE::float) AS SUM, ";
$weekstats .= "AVG(VALUE::float) AS AVG, MIN(VALUE::float) AS MIN, MAX(VALUE::float) AS MAX, ";
$weekstats .= "COUNT(VALUE) AS COUNT FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' ";
$weekstats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY 1 ORDER BY 1;";
### month:
$monthstats = "SELECT to_char(timestamp, 'YYYY-MM-01 00:00:00') AS TIMESTAMP, SUM(VALUE::float) AS SUM, ";
$monthstats .= "AVG(VALUE::float) AS AVG, MIN(VALUE::float) AS MIN, MAX(VALUE::float) AS MAX, ";
$monthstats .= "COUNT(VALUE) AS COUNT FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' ";
$monthstats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY 1 ORDER BY 1;";
### year:
$yearstats = "SELECT to_char(timestamp, 'YYYY-01-01 00:00:00') AS TIMESTAMP, SUM(VALUE::float) AS SUM, ";
$yearstats .= "AVG(VALUE::float) AS AVG, MIN(VALUE::float) AS MIN, MAX(VALUE::float) AS MAX, ";
$yearstats .= "COUNT(VALUE) AS COUNT FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' ";
$yearstats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY 1 ORDER BY 1;";
} elsif ($dbmodel eq "MYSQL") {
### MYSQL Queries for Statistics ###
### hour:
$hourstats = "SELECT date_format(timestamp, '%Y-%m-%d %H:00:00') AS TIMESTAMP, SUM(CAST(VALUE AS DECIMAL(12,4))) AS SUM, ";
$hourstats .= "AVG(CAST(VALUE AS DECIMAL(12,4))) AS AVG, MIN(CAST(VALUE AS DECIMAL(12,4))) AS MIN, ";
$hourstats .= "MAX(CAST(VALUE AS DECIMAL(12,4))) AS MAX, COUNT(VALUE) AS COUNT FROM history WHERE READING = '$yaxis' ";
$hourstats .= "AND DEVICE = '$device' AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY 1 ORDER BY 1;";
### day:
$daystats = "SELECT date_format(timestamp, '%Y-%m-%d 00:00:00') AS TIMESTAMP, SUM(CAST(VALUE AS DECIMAL(12,4))) AS SUM, ";
$daystats .= "AVG(CAST(VALUE AS DECIMAL(12,4))) AS AVG, MIN(CAST(VALUE AS DECIMAL(12,4))) AS MIN, ";
$daystats .= "MAX(CAST(VALUE AS DECIMAL(12,4))) AS MAX, COUNT(VALUE) AS COUNT FROM history WHERE READING = '$yaxis' ";
$daystats .= "AND DEVICE = '$device' AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY 1 ORDER BY 1;";
### week:
$weekstats = "SELECT date_format(timestamp, '%Y-%m-%d 00:00:00') AS TIMESTAMP, SUM(CAST(VALUE AS DECIMAL(12,4))) AS SUM, ";
$weekstats .= "AVG(CAST(VALUE AS DECIMAL(12,4))) AS AVG, MIN(CAST(VALUE AS DECIMAL(12,4))) AS MIN, ";
$weekstats .= "MAX(CAST(VALUE AS DECIMAL(12,4))) AS MAX, COUNT(VALUE) AS COUNT FROM history WHERE READING = '$yaxis' ";
$weekstats .= "AND DEVICE = '$device' AND TIMESTAMP Between '$starttime' AND '$endtime' ";
$weekstats .= "GROUP BY date_format(timestamp, '%Y-%u 00:00:00') ORDER BY 1;";
### month:
$monthstats = "SELECT date_format(timestamp, '%Y-%m-01 00:00:00') AS TIMESTAMP, SUM(CAST(VALUE AS DECIMAL(12,4))) AS SUM, ";
$monthstats .= "AVG(CAST(VALUE AS DECIMAL(12,4))) AS AVG, MIN(CAST(VALUE AS DECIMAL(12,4))) AS MIN, ";
$monthstats .= "MAX(CAST(VALUE AS DECIMAL(12,4))) AS MAX, COUNT(VALUE) AS COUNT FROM history WHERE READING = '$yaxis' ";
$monthstats .= "AND DEVICE = '$device' AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY 1 ORDER BY 1;";
### year:
$yearstats = "SELECT date_format(timestamp, '%Y-01-01 00:00:00') AS TIMESTAMP, SUM(CAST(VALUE AS DECIMAL(12,4))) AS SUM, ";
$yearstats .= "AVG(CAST(VALUE AS DECIMAL(12,4))) AS AVG, MIN(CAST(VALUE AS DECIMAL(12,4))) AS MIN, ";
$yearstats .= "MAX(CAST(VALUE AS DECIMAL(12,4))) AS MAX, COUNT(VALUE) AS COUNT FROM history WHERE READING = '$yaxis' ";
$yearstats .= "AND DEVICE = '$device' AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY 1 ORDER BY 1;";
} elsif ($hash->{DBMODEL} eq "SQLITE") {
### SQLITE Queries for Statistics ###
### hour:
$hourstats = "SELECT TIMESTAMP, SUM(CAST(VALUE AS FLOAT)) AS SUM, AVG(CAST(VALUE AS FLOAT)) AS AVG, ";
$hourstats .= "MIN(CAST(VALUE AS FLOAT)) AS MIN, MAX(CAST(VALUE AS FLOAT)) AS MAX, COUNT(VALUE) AS COUNT ";
$hourstats .= "FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' ";
$hourstats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY strftime('%Y-%m-%d %H:00:00', TIMESTAMP);";
### day:
$daystats = "SELECT TIMESTAMP, SUM(CAST(VALUE AS FLOAT)) AS SUM, AVG(CAST(VALUE AS FLOAT)) AS AVG, ";
$daystats .= "MIN(CAST(VALUE AS FLOAT)) AS MIN, MAX(CAST(VALUE AS FLOAT)) AS MAX, COUNT(VALUE) AS COUNT ";
$daystats .= "FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' ";
$daystats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY strftime('%Y-%m-%d 00:00:00', TIMESTAMP);";
### week:
$weekstats = "SELECT TIMESTAMP, SUM(CAST(VALUE AS FLOAT)) AS SUM, AVG(CAST(VALUE AS FLOAT)) AS AVG, ";
$weekstats .= "MIN(CAST(VALUE AS FLOAT)) AS MIN, MAX(CAST(VALUE AS FLOAT)) AS MAX, COUNT(VALUE) AS COUNT ";
$weekstats .= "FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' ";
$weekstats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY strftime('%Y-%W 00:00:00', TIMESTAMP);";
### month:
$monthstats = "SELECT TIMESTAMP, SUM(CAST(VALUE AS FLOAT)) AS SUM, AVG(CAST(VALUE AS FLOAT)) AS AVG, ";
$monthstats .= "MIN(CAST(VALUE AS FLOAT)) AS MIN, MAX(CAST(VALUE AS FLOAT)) AS MAX, COUNT(VALUE) AS COUNT ";
$monthstats .= "FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' ";
$monthstats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY strftime('%Y-%m 00:00:00', TIMESTAMP);";
### year:
$yearstats = "SELECT TIMESTAMP, SUM(CAST(VALUE AS FLOAT)) AS SUM, AVG(CAST(VALUE AS FLOAT)) AS AVG, ";
$yearstats .= "MIN(CAST(VALUE AS FLOAT)) AS MIN, MAX(CAST(VALUE AS FLOAT)) AS MAX, COUNT(VALUE) AS COUNT ";
$yearstats .= "FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' ";
$yearstats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY strftime('%Y 00:00:00', TIMESTAMP);";
} else {
$sql = "errordb";
}
if($userquery eq "getreadings") {
$sql = "SELECT distinct(reading) FROM history WHERE device = '".$device."'";
} elsif($userquery eq "getdevices") {
$sql = "SELECT distinct(device) FROM history";
} elsif($userquery eq "timerange") {
$sql = "SELECT ".$xaxis.", VALUE FROM history WHERE READING = '$yaxis' AND DEVICE = '$device' AND TIMESTAMP Between '$starttime' AND '$endtime';";
} elsif($userquery eq "hourstats") {
$sql = $hourstats;
} elsif($userquery eq "daystats") {
$sql = $daystats;
} elsif($userquery eq "weekstats") {
$sql = $weekstats;
} elsif($userquery eq "monthstats") {
$sql = $monthstats;
} elsif($userquery eq "yearstats") {
$sql = $yearstats;
} elsif($userquery eq "savechart") {
$sql = "INSERT INTO frontend (TYPE, NAME, VALUE) VALUES ('savedchart', '$savename', '$jsonChartConfig')";
} elsif($userquery eq "deletechart") {
$sql = "DELETE FROM frontend WHERE TYPE = 'savedchart' AND ID = '".$savename."'";
} elsif($userquery eq "getcharts") {
$sql = "SELECT * FROM frontend WHERE TYPE = 'savedchart'";
} elsif($userquery eq "getTableData") {
$countsql = "SELECT count(*) FROM history";
$sql = "SELECT * FROM history LIMIT ".$paginglimit." OFFSET ".$pagingstart;
return ($sql, $countsql);
} else {
$sql = "error";
}
return $sql;
}
################################################################
#
# Do the query
#
################################################################
sub chartQuery($@) {
my ($sql, $countsql) = prepareSql(@_);
if ($sql eq "error") {
return jsonError("Could not setup SQL String. Maybe the Database is busy, please try again!");
} elsif ($sql eq "errordb") {
return jsonError("The Database Type is not supported!");
}
my ($hash, @a) = @_;
my $dbhf= $hash->{DBHF};
my $totalcount;
if (defined $countsql && $countsql ne "") {
my $query_handle = $dbhf->prepare($countsql)
or return jsonError("Could not prepare statement: " . $dbhf->errstr . ", SQL was: " .$countsql);
$query_handle->execute()
or return jsonError("Could not execute statement: " . $query_handle->errstr);
my @data = $query_handle->fetchrow_array();
$totalcount = join(", ", @data);
}
# prepare the query
my $query_handle = $dbhf->prepare($sql)
or return jsonError("Could not prepare statement: " . $dbhf->errstr . ", SQL was: " .$sql);
# execute the query
$query_handle->execute()
or return jsonError("Could not execute statement: " . $query_handle->errstr);
my $columns = $query_handle->{'NAME'};
my $columncnt;
# When columns are empty but execution was successful, we have done a successful INSERT, UPDATE or DELETE
if($columns) {
$columncnt = scalar @$columns;
} else {
return '{"success": "true", "msg":"All ok"}';
}
my $i = 0;
my $jsonstring = '{"data":[';
while ( my @data = $query_handle->fetchrow_array()) {
if($i == 0) {
$jsonstring .= '{';
} else {
$jsonstring .= ',{';
}
for ($i = 0; $i < $columncnt; $i++) {
$jsonstring .= '"';
$jsonstring .= uc($query_handle->{NAME}->[$i]);
$jsonstring .= '":';
if (defined $data[$i]) {
my $fragment = substr($data[$i],0,1);
if ($fragment eq "{") {
$jsonstring .= $data[$i];
} else {
$jsonstring .= '"'.$data[$i].'"';
}
} else {
$jsonstring .= '""'
}
if($i != ($columncnt -1)) {
$jsonstring .= ',';
}
}
$jsonstring .= '}';
}
$jsonstring .= ']';
if (defined $totalcount && $totalcount ne "") {
$jsonstring .= ',"totalCount": '.$totalcount.'}';
} else {
$jsonstring .= '}';
}
return $jsonstring;
}
################################################################
@ -726,6 +1040,7 @@ DbLog_Get($@)
=pod
=begin html
<a name="DbLog"></a>
<h3>DbLog</h3>
<ul>
@ -865,12 +1180,83 @@ DbLog_Get($@)
</ul>
<br><br>
</ul>
<b>Get</b> when used for webcharts
<ul>
<code>get &lt;name&gt; &lt;infile&gt; &lt;outfile&gt; &lt;from&gt;
&lt;to&gt; &lt;device&gt; &lt;querytype&gt; &lt;xaxis&gt; &lt;yaxis&gt; &lt;savename&gt; </code>
<br><br>
Query the Database to retrieve JSON-Formatted Data, which is used by the charting frontend.
<br>
<ul>
<li>&lt;name&gt;<br>
The name of the defined DbLog, like it is given in fhem.cfg.</li>
<li>&lt;in&gt;<br>
A dummy parameter for FileLog compatibility. Always set to <code>-</code></li>
<li>&lt;out&gt;<br>
A dummy parameter for FileLog compatibility. Set it to <code>webchart</code>
to use the charting related get function.
</li>
<li>&lt;from&gt; / &lt;to&gt;<br>
Used to select the data. Please use the following timeformat:<br>
<ul><code>YYYY-MM-DD_HH24:MI:SS</code></ul></li>
<li>&lt;device&gt;<br>
A string which represents the device to query.</li>
<li>&lt;querytype&gt;<br>
A string which represents the method the query should use. Actually supported values are: <br>
<code>getreadings</code> to retrieve the possible readings for a given device<br>
<code>getdevices</code> to retrieve all available devices<br>
<code>timerange</code> to retrieve charting data, which requires a given xaxis, yaxis, device, to and from<br>
<code>savechart</code> to save a chart configuration in the database. Requires a given xaxis, yaxis, device, to and from, and a 'savename' used to save the chart<br>
<code>deletechart</code> to delete a saved chart. Requires a given id which was set on save of the chart<br>
<code>getcharts</code> to get a list of all saved charts.<br>
<code>getTableData</code> to get jsonformatted data from the database. Uses paging Parameters like start and limit.<br>
<code>hourstats</code> to get statistics for a given value (yaxis) for an hour.<br>
<code>daystats</code> to get statistics for a given value (yaxis) for a day.<br>
<code>weekstats</code> to get statistics for a given value (yaxis) for a week.<br>
<code>monthstats</code> to get statistics for a given value (yaxis) for a month.<br>
<code>yearstats</code> to get statistics for a given value (yaxis) for a year.<br>
</li>
<li>&lt;xaxis&gt;<br>
A string which represents the xaxis</li>
<li>&lt;yaxis&gt;<br>
A string which represents the yaxis</li>
<li>&lt;savename&gt;<br>
A string which represents the name a chart will be saved with</li>
<li>&lt;chartconfig&gt;<br>
A jsonstring which represents the chart to save</li>
<li>&lt;pagingstart&gt;<br>
An integer used to determine the start for the sql used for query 'getTableData'</li>
<li>&lt;paginglimit&gt;<br>
An integer used to set the limit for the sql used for query 'getTableData'</li>
</ul>
<br><br>
Examples:
<ul>
<li><code>get logdb - webchart "" "" "" getcharts</code><br>
Retrieves all saved charts from the Database</li>
<li><code>get logdb - webchart "" "" "" getdevices</code><br>
Retrieves all available devices from the Database</li>
<li><code>get logdb - webchart "" "" ESA2000_LED_011e getreadings</code><br>
Retrieves all available Readings for a given device from the Database</li>
<li><code>get logdb - webchart 2013-02-11_00:00:00 2013-02-12_00:00:00 ESA2000_LED_011e timerange TIMESTAMP day_kwh</code><br>
Retrieves charting data, which requires a given xaxis, yaxis, device, to and from<br>
Will ouput a JSON like this: <code>[{'TIMESTAMP':'2013-02-11 00:10:10','VALUE':'0.22431388090756'},{'TIMESTAMP'.....}]</code></li>
<li><code>get logdb - webchart 2013-02-11_00:00:00 2013-02-12_00:00:00 ESA2000_LED_011e savechart TIMESTAMP day_kwh tageskwh</code><br>
Will save a chart in the database with the given name and the chart configuration parameters</li>
<li><code>get logdb - webchart "" "" "" deletechart "" "" 7</code><br>
Will delete a chart from the database with the given id</li>
</ul>
<br><br>
</ul>
<a name="DbLogattr"></a>
<b>Attributes</b> <ul>N/A</ul><br>
</ul>
=end html
=end html
=begin html_DE
<a name="DbLog"></a>
<h3>DbLog</h3>
<ul>
@ -1027,9 +1413,82 @@ DbLog_Get($@)
</ul>
<br><br>
</ul>
<b>Get</b> für die Nutzung von webcharts
<ul>
<code>get &lt;name&gt; &lt;infile&gt; &lt;outfile&gt; &lt;from&gt;
&lt;to&gt; &lt;device&gt; &lt;querytype&gt; &lt;xaxis&gt; &lt;yaxis&gt; &lt;savename&gt; </code>
<br><br>
Liest Daten aus der Datenbank aus und gibt diese in JSON formatiert aus. Wird für das Charting Frontend genutzt
<br>
<ul>
<li>&lt;name&gt;<br>
Der Name des definierten DbLogs, so wie er in der fhem.cfg angegeben wurde.</li>
<li>&lt;in&gt;<br>
Ein Dummy Parameter um eine Kompatibilität zum Filelog herzustellen.
Dieser Parameter ist immer auf <code>-</code> zu setzen.</li>
<li>&lt;out&gt;<br>
Ein Dummy Parameter um eine Kompatibilität zum Filelog herzustellen.
Dieser Parameter ist auf <code>webchart</code> zu setzen um die Charting Get Funktion zu nutzen.
</li>
<li>&lt;from&gt; / &lt;to&gt;<br>
Wird benutzt um den Zeitraum der Daten einzugrenzen. Es ist das folgende
Zeitformat zu benutzen:<br>
<ul><code>YYYY-MM-DD_HH24:MI:SS</code></ul></li>
<li>&lt;device&gt;<br>
Ein String, der das abzufragende Device darstellt.</li>
<li>&lt;querytype&gt;<br>
Ein String, der die zu verwendende Abfragemethode darstellt. Zur Zeit unterstützte Werte sind: <br>
<code>getreadings</code> um für ein bestimmtes device alle Readings zu erhalten<br>
<code>getdevices</code> um alle verfügbaren devices zu erhalten<br>
<code>timerange</code> um Chart-Daten abzufragen. Es werden die Parameter 'xaxis', 'yaxis', 'device', 'to' und 'from' benötigt<br>
<code>savechart</code> um einen Chart unter Angabe eines 'savename' und seiner zugehörigen Konfiguration abzuspeichern<br>
<code>deletechart</code> um einen zuvor gespeicherten Chart unter Angabe einer id zu löschen<br>
<code>getcharts</code> um eine Liste aller gespeicherten Charts zu bekommen.<br>
<code>getTableData</code> um Daten aus der Datenbank abzufragen und in einer Tabelle darzustellen. Benötigt paging Parameter wie start und limit.<br>
<code>hourstats</code> um Statistiken für einen Wert (yaxis) für eine Stunde abzufragen.<br>
<code>daystats</code> um Statistiken für einen Wert (yaxis) für einen Tag abzufragen.<br>
<code>weekstats</code> um Statistiken für einen Wert (yaxis) für eine Woche abzufragen.<br>
<code>monthstats</code> um Statistiken für einen Wert (yaxis) für einen Monat abzufragen.<br>
<code>yearstats</code> um Statistiken für einen Wert (yaxis) für ein Jahr abzufragen.<br>
</li>
<li>&lt;xaxis&gt;<br>
Ein String, der die X-Achse repräsentiert</li>
<li>&lt;yaxis&gt;<br>
Ein String, der die Y-Achse repräsentiert</li>
<li>&lt;savename&gt;<br>
Ein String, unter dem ein Chart in der Datenbank gespeichert werden soll</li>
<li>&lt;chartconfig&gt;<br>
Ein jsonstring der den zu speichernden Chart repräsentiert</li>
<li>&lt;pagingstart&gt;<br>
Ein Integer um den Startwert für die Abfrage 'getTableData' festzulegen</li>
<li>&lt;paginglimit&gt;<br>
Ein Integer um den Limitwert für die Abfrage 'getTableData' festzulegen</li>
</ul>
<br><br>
Beispiele:
<ul>
<li><code>get logdb - webchart "" "" "" getcharts</code><br>
Liefert alle gespeicherten Charts aus der Datenbank</li>
<li><code>get logdb - webchart "" "" "" getdevices</code><br>
Liefert alle verfügbaren Devices aus der Datenbank</li>
<li><code>get logdb - webchart "" "" ESA2000_LED_011e getreadings</code><br>
Liefert alle verfügbaren Readings aus der Datenbank unter Angabe eines Gerätes</li>
<li><code>get logdb - webchart 2013-02-11_00:00:00 2013-02-12_00:00:00 ESA2000_LED_011e timerange TIMESTAMP day_kwh</code><br>
Liefert Chart-Daten, die auf folgenden Parametern basieren: 'xaxis', 'yaxis', 'device', 'to' und 'from'<br>
Die Ausgabe erfolgt als JSON, z.B.: <code>[{'TIMESTAMP':'2013-02-11 00:10:10','VALUE':'0.22431388090756'},{'TIMESTAMP'.....}]</code></li>
<li><code>get logdb - webchart 2013-02-11_00:00:00 2013-02-12_00:00:00 ESA2000_LED_011e savechart TIMESTAMP day_kwh tageskwh</code><br>
Speichert einen Chart unter Angabe eines 'savename' und seiner zugehörigen Konfiguration</li>
<li><code>get logdb - webchart "" "" "" deletechart "" "" 7</code><br>
Löscht einen zuvor gespeicherten Chart unter Angabe einer id</li>
</ul>
<br><br>
</ul>
<a name="DbLogattr"></a>
<b>Attributes</b> <ul>N/A</ul><br>
</ul>
=end html_DE
=cut