Add last_seen to device-info. For 36

This commit is contained in:
Starbeamrainbowlabs 2019-06-30 17:33:44 +01:00
parent 5efaab3f67
commit d5df81eed1
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 15 additions and 6 deletions

View file

@ -7,7 +7,7 @@ This is the changelog for the air quality web interface and its associated HTTP
## v0.12-dev ## v0.12-dev
- [API] Improve accuracy of `distance_calc` for the `list-devices-near` action by using _Haversine's Formula_. - [API] Improve accuracy of `distance_calc` for the `list-devices-near` action by using _Haversine's Formula_.
- [API] Added new `last_seen` property to the `list-devices` action. - [API] Added new `last_seen` property to the `list-devices` and `device-info` actions.
## v0.11.1 - 22nd June 2019 ## v0.11.1 - 22nd June 2019
- Drastically improve the performance of the backend SQL queries that power the heatmap and device graphs by over 35x in some cases! - Drastically improve the performance of the backend SQL queries that power the heatmap and device graphs by over 35x in some cases!

View file

@ -74,10 +74,10 @@ class MariaDBDeviceRepository implements IDeviceRepository {
$s = $this->get_static; $s = $this->get_static;
$o = $this->get_static_extra; $o = $this->get_static_extra;
$data_repo_name = MariaDBMeasurementDataRepository::class; $data_repo_class = MariaDBMeasurementDataRepository::class;
$data_repo_table_meta = $o($data_repo_name, "table_name_metadata"); $data_repo_table_meta = $o($data_repo_class, "table_name_metadata");
$data_repo_col_datetime = "$data_repo_table_meta.{$o($data_repo_name, "column_metadata_datetime")}"; $data_repo_col_datetime = "$data_repo_table_meta.{$o($data_repo_class, "column_metadata_datetime")}";
$data_repo_col_device_id = "$data_repo_table_meta.{$o($data_repo_name, "column_metadata_device_id")}"; $data_repo_col_device_id = "$data_repo_table_meta.{$o($data_repo_class, "column_metadata_device_id")}";
$sql = "SELECT $sql = "SELECT
{$s("table_name")}.{$s("column_device_id")} AS id, {$s("table_name")}.{$s("column_device_id")} AS id,
@ -104,6 +104,12 @@ class MariaDBDeviceRepository implements IDeviceRepository {
public function get_device_info_ext($device_id) { public function get_device_info_ext($device_id) {
$s = $this->get_static; $s = $this->get_static;
$o = $this->get_static_extra;
$data_repo_class = MariaDBMeasurementDataRepository::class;
$data_repo_table_meta = $o($data_repo_class, "table_name_metadata");
$data_repo_col_datetime = "$data_repo_table_meta.{$o($data_repo_class, "column_metadata_datetime")}";
$data_repo_col_device_id = "$data_repo_table_meta.{$o($data_repo_class, "column_metadata_device_id")}";
$query_result = $this->database->query( $query_result = $this->database->query(
"SELECT "SELECT
@ -112,10 +118,13 @@ class MariaDBDeviceRepository implements IDeviceRepository {
{$s("table_name")}.{$s("column_lat")} AS latitude, {$s("table_name")}.{$s("column_lat")} AS latitude,
{$s("table_name")}.{$s("column_long")} AS longitude, {$s("table_name")}.{$s("column_long")} AS longitude,
{$s("table_name")}.{$s("column_altitude")} AS altitude, {$s("table_name")}.{$s("column_altitude")} AS altitude,
{$s("table_name_type")}.* {$s("table_name_type")}.*,
MAX($data_repo_col_datetime) AS last_seen
FROM {$s("table_name")} FROM {$s("table_name")}
JOIN {$s("table_name_type")} ON JOIN {$s("table_name_type")} ON
{$s("table_name")}.{$s("column_device_type")} = {$s("table_name_type")}.{$s("column_type_id")} {$s("table_name")}.{$s("column_device_type")} = {$s("table_name_type")}.{$s("column_type_id")}
JOIN $data_repo_table_meta ON
$data_repo_col_device_id = {$s("table_name")}.{$s("column_device_id")}
WHERE {$s("table_name")}.{$s("column_device_id")} = :device_id;", [ WHERE {$s("table_name")}.{$s("column_device_id")} = :device_id;", [
"device_id" => $device_id "device_id" => $device_id
] ]