Add last_seen to list_devices_near

This commit is contained in:
Starbeamrainbowlabs 2019-08-14 13:00:30 +01:00
parent 4e5a451cde
commit a678a89b95
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 10 additions and 1 deletions

View file

@ -10,6 +10,7 @@ This is the changelog for the air quality web interface and its associated HTTP
## v0.13-dev ## v0.13-dev
- Round dates before making API requests to improve caching potential - Round dates before making API requests to improve caching potential
- [@Mr-Pepp](https://github.com/Mr-Pepp): Improve initial on-boarding tour - [@Mr-Pepp](https://github.com/Mr-Pepp): Improve initial on-boarding tour
- Added `last_seen` to `list-devices-near` (#36)
## v0.12 ## v0.12
- Added loading animation while the map is loading - Added loading animation while the map is loading

View file

@ -148,14 +148,22 @@ class MariaDBDeviceRepository implements IDeviceRepository {
public function get_near_location(float $lat, float $long, int $count) { public function get_near_location(float $lat, float $long, int $count) {
$s = $this->get_static; $s = $this->get_static;
$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")}";
$result = $this->database->query( $result = $this->database->query(
"SELECT "SELECT
{$s("table_name")}.{$s("column_device_id")} AS id, {$s("table_name")}.{$s("column_device_id")} AS id,
{$s("table_name")}.{$s("column_device_name")} AS name, {$s("table_name")}.{$s("column_device_name")} AS name,
{$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,
ST_DISTANCE_SPHERE(POINT(:latitude, :longitude), {$s("table_name")}.{$s("column_point")}) AS distance_calc ST_DISTANCE_SPHERE(POINT(:latitude, :longitude), {$s("table_name")}.{$s("column_point")}) AS distance_calc,
MAX($data_repo_col_datetime) AS last_seen
FROM {$s("table_name")} FROM {$s("table_name")}
JOIN $data_repo_table_meta ON
$data_repo_col_device_id = {$s("table_name")}.{$s("column_device_id")}
WHERE {$s("table_name")}.{$s("column_point")} IS NOT NULL WHERE {$s("table_name")}.{$s("column_point")} IS NOT NULL
ORDER BY ST_DISTANCE_SPHERE(POINT(:latitude_again, :longitude_again), {$s("table_name")}.{$s("column_point")}) ORDER BY ST_DISTANCE_SPHERE(POINT(:latitude_again, :longitude_again), {$s("table_name")}.{$s("column_point")})
LIMIT :count;", [ LIMIT :count;", [