From e86b0b4f97fcc21d0831ee4b865b953503c79ea9 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 26 Jun 2019 21:02:17 +0100 Subject: [PATCH] Upgrade ST_DISTANCE() to ST_DISTANCE_SPHERE(), but there's a permissions issue. --- Changelog.md | 3 +++ logic/Repositories/MariaDBDeviceRepository.php | 4 ++-- version | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index b84caec..fa14375 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,9 @@ This is the changelog for the air quality web interface and its associated HTTP - `[Code]` refers to internal changes to the code that have no direct impact on the web interface or the HTTP API, but are significant enough to warrant note. - `[Docs]` refers to changes to the [documentation](https://aq.connectedhumber.org/__nightdocs/00-Welcome.html). +## v0.12-dev + - [API] Improve accuracy of `distance_calc` for the `list-devices-near` action by using _Haversine's Formula_. + ## 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! - For users of the HTTP API, said queries are `fetch-data` and `device-data`. diff --git a/logic/Repositories/MariaDBDeviceRepository.php b/logic/Repositories/MariaDBDeviceRepository.php index 793c651..8331f78 100644 --- a/logic/Repositories/MariaDBDeviceRepository.php +++ b/logic/Repositories/MariaDBDeviceRepository.php @@ -125,10 +125,10 @@ class MariaDBDeviceRepository implements IDeviceRepository { {$s("table_name")}.{$s("column_device_name")} AS name, {$s("table_name")}.{$s("column_lat")} AS latitude, {$s("table_name")}.{$s("column_long")} AS longitude, - ST_DISTANCE(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 FROM {$s("table_name")} WHERE {$s("table_name")}.{$s("column_point")} IS NOT NULL - ORDER BY ST_DISTANCE(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;", [ "latitude" => $lat, "longitude" => $long, diff --git a/version b/version index 4f7638f..b39c2f2 100644 --- a/version +++ b/version @@ -1 +1 @@ -v0.11.1 +v0.12-dev