Add a count to sensor summary info.

This commit is contained in:
Michael Stenta 2020-08-26 17:00:38 -04:00
parent f0bc6a8e6f
commit ac67a1f239
1 changed files with 4 additions and 0 deletions

View File

@ -512,6 +512,9 @@ function farm_sensor_listener_values_info($id) {
->condition('farm_sensor_data.id', $id)
->groupBy('farm_sensor_data.name');
// Select the total record count for each value name.
$query->addExpression('COUNT(farm_sensor_data.timestamp)', 'count');
// Select the max timestamp for each value name.
$query->addExpression('MAX(farm_sensor_data.timestamp)', 'last');
@ -524,6 +527,7 @@ function farm_sensor_listener_values_info($id) {
// Add each value's info keyed by value name.
foreach ($result as $row) {
$values[$row->name] = array(
'count' => $row->count,
'first' => $row->first,
'last' => $row->last,
);