3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Use the data stream entity name in name/value pairs.

This commit is contained in:
paul121 2021-07-08 13:51:22 -07:00 committed by Michael Stenta
parent 1a10fbf276
commit 93e8bd79bc
3 changed files with 9 additions and 6 deletions

View file

@ -48,6 +48,7 @@ trait DataStreamSqlStorage {
$result = $query->execute();
// Build an array of data.
$name = $stream->label();
$data = [];
foreach ($result as $row) {
@ -63,7 +64,7 @@ trait DataStreamSqlStorage {
// Create a data object for the sensor value.
$point = new \stdClass();
$point->timestamp = $row->timestamp;
$point->value = $value;
$point->{$name} = $value;
$data[] = $point;
}
@ -115,8 +116,8 @@ trait DataStreamSqlStorage {
// Iterate over the JSON properties.
foreach ($data as $key => $value) {
// If the key is "timestamp", skip to the next property in the JSON.
if ($key == 'timestamp') {
// If the key does not match the data stream name, skip it.
if ($key !== $stream->label()) {
continue;
}

View file

@ -145,10 +145,11 @@ class DataStreamApiTest extends DataStreamTestBase {
// Test data.
$timestamp = $this->startTime - 86400;
$test_data = ['timestamp' => $timestamp, 'value' => 200];
$name = $this->dataStream->label();
$test_data = ['timestamp' => $timestamp, $name => 200];
$test_point = new \stdClass();
$test_point->timestamp = $test_data['timestamp'];
$test_point->value = $test_data['value'];
$test_point->{$name} = 200;
// Make a request.
$request = Request::create($uri, 'POST', [], [], [], [], Json::encode($test_data));

View file

@ -58,11 +58,12 @@ trait DataStreamCreationTrait {
$data = [];
$name = $stream->label();
$value = 0;
for ($x = 0; $x < $count; $x++) {
$data[] = [
'timestamp' => $start_time,
'value' => $value,
$name => $value,
];
$start_time += 86400;
$value += 1;