- viac senzorov, oprava chyb ked nevracia hodnotu controller

This commit is contained in:
2022-10-29 10:20:24 +02:00
parent 5e521583af
commit ce144bcd58
7 changed files with 4113 additions and 4205 deletions

View File

@@ -32,13 +32,15 @@ class MeasurementController extends Controller
if ($enddate == NULL || $enddate == '') $enddate = "now()";
else $enddate = sprintf("'%s'",Carbon::parse($enddate)->toDateTimeString());
$q = sprintf("select time,value from %s_value where host='%s' and type='%s' and time >= %s and time <= %s",$model,$host,$type,$startdate,$enddate);
$q = sprintf("select time,mean(value) as v from %s_value where host='%s' and type='%s' and time >= %s and time <= %s group by time(%s) fill(linear)",$model,$host,$type,$startdate,$enddate,'5m');
\Debugbar::info($q);
$result = \InfluxDB::query($q);
$points = $result->getPoints();
$a = [];
foreach ($points as $p) {
$a[] = [ Carbon::createFromFormat("Y-m-d\TH:i:s.u+",$p["time"],'UTC'), $p["value"]];
if (!isset($p["v"])) continue;
$a[] = [ $p["time"], $p["v"]];
// $a[] = [ Carbon::createFromFormat("Y-m-d\TH:i:s.u+",$p["time"],'UTC'), $p["v"]];
}
return response()->json($a);