mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-25 09:55:38 +00:00
93_DbLog: contrib 5.8.0
git-svn-id: https://svn.fhem.de/fhem/trunk@27148 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
70d41557cd
commit
0ee801a5ff
@ -6053,13 +6053,13 @@ sub _DbLog_createQuerySql {
|
||||
my $current = $hash->{HELPER}{TC};
|
||||
|
||||
if ($opt eq 'dataRetrieval') {
|
||||
$querytype = $a[1] // qq();
|
||||
$device = $a[2] // qq();
|
||||
$reading = $a[3] // qq();
|
||||
$starttime = $a[4] // qq();
|
||||
$endtime = $a[5] // qq();
|
||||
$offset = $a[6] // qq();
|
||||
$limit = $a[7] // qq();
|
||||
$querytype = $a[1];
|
||||
$device = $a[2];
|
||||
$reading = $a[3];
|
||||
$starttime = $a[4];
|
||||
$endtime = $a[5];
|
||||
$offset = $a[6];
|
||||
$limit = $a[7];
|
||||
$xaxis = 'TIMESTAMP';
|
||||
|
||||
if ($querytype eq 'last') {
|
||||
@ -6067,11 +6067,14 @@ sub _DbLog_createQuerySql {
|
||||
}
|
||||
}
|
||||
|
||||
$starttime =~ s/_/ /;
|
||||
$endtime =~ s/_/ /;
|
||||
$starttime =~ s/_/ / if($starttime);
|
||||
$endtime =~ s/_/ / if($endtime);
|
||||
|
||||
my ($sql, $jsonstring, $countsql, $hourstats, $daystats, $weekstats, $monthstats, $yearstats);
|
||||
my ($sql, $jsonstring, $countsql);
|
||||
|
||||
my ($hourstats, $daystats, $weekstats, $monthstats, $yearstats) = ('error', 'error', 'error', 'error', 'error');
|
||||
|
||||
if ($device && $reading && $starttime && $endtime) {
|
||||
if ($dbmodel eq "POSTGRESQL") {
|
||||
### POSTGRESQL Queries for Statistics ###
|
||||
### hour:
|
||||
@ -6168,24 +6171,30 @@ sub _DbLog_createQuerySql {
|
||||
$yearstats .= "MIN(CAST(VALUE AS FLOAT)) AS MIN, MAX(CAST(VALUE AS FLOAT)) AS MAX, COUNT(VALUE) AS COUNT ";
|
||||
$yearstats .= "FROM $history WHERE READING = '$reading' AND DEVICE = '$device' ";
|
||||
$yearstats .= "AND TIMESTAMP Between '$starttime' AND '$endtime' GROUP BY strftime('%Y 00:00:00', TIMESTAMP);";
|
||||
|
||||
}
|
||||
else {
|
||||
$sql = "errordb";
|
||||
}
|
||||
}
|
||||
|
||||
if($querytype eq 'getreadings') {
|
||||
$sql = 'error';
|
||||
|
||||
if ($querytype eq 'getdevices') {
|
||||
$sql = "SELECT distinct(device) FROM $history";
|
||||
}
|
||||
elsif($querytype eq 'getreadings') {
|
||||
if ($device) {
|
||||
$sql = "SELECT distinct(reading) FROM $history WHERE device = '$device'";
|
||||
}
|
||||
elsif ($querytype eq 'getdevices') {
|
||||
$sql = "SELECT distinct(device) FROM $history";
|
||||
}
|
||||
elsif ($querytype eq 'last') {
|
||||
$sql = "SELECT TIMESTAMP, DEVICE, TYPE, EVENT, READING, VALUE, UNIT from $history ORDER BY TIMESTAMP DESC LIMIT $limit";
|
||||
}
|
||||
elsif ($querytype eq 'timerange') {
|
||||
if ($device && $reading && $starttime && $endtime) {
|
||||
$sql = "SELECT ".$xaxis.", VALUE FROM $history WHERE READING = '$reading' AND DEVICE = '$device' AND TIMESTAMP Between '$starttime' AND '$endtime' ORDER BY TIMESTAMP;";
|
||||
}
|
||||
}
|
||||
elsif ($querytype eq 'hourstats') {
|
||||
$sql = $hourstats;
|
||||
}
|
||||
@ -6252,9 +6261,6 @@ sub _DbLog_createQuerySql {
|
||||
|
||||
return ($sql, $countsql);
|
||||
}
|
||||
else {
|
||||
$sql = "error";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user