Giter VIP home page Giter VIP logo

Comments (8)

BNNorman avatar BNNorman commented on June 25, 2024 1

from air-quality-web.

sbrl avatar sbrl commented on June 25, 2024

Thanks for opening a new issue about this. Sorry I didn't reply, I've been busy (both with PhD work, and sorting out the disclaimer on here).

I'll take a look into this.

Edit: Do you have that as a curl command? That would be much easier for me to test with

from air-quality-web.

sbrl avatar sbrl commented on June 25, 2024

For my own reference the above can be represented with curl like so:

curl 'http://[::1]:40482/api.php?action=list-devices-near&count=5' --data "latitude=53.750" --data "longitude=-0.395" | jq .

from air-quality-web.

sbrl avatar sbrl commented on June 25, 2024

With some investigation, it would seem that the SQL query is at fault...... somehow. Here's the SQL query for that api call:

SELECT
devices.device_id AS id,
devices.device_name AS name,
devices.device_latitude AS latitude,
devices.device_longitude AS longitude,
ST_DISTANCE_SPHERE(POINT(53.750, -0.395), devices.lat_lon) AS distance_calc, devices.last_seen AS last_seen
FROM devices
JOIN readings ON readings.device_id = devices.device_id
WHERE devices.lat_lon IS NOT NULL
ORDER BY ST_DISTANCE_SPHERE(POINT(53.750, -0.395), devices.lat_lon)
LIMIT 5;

I'm somewhat baffled as to what it's suddenly generating duplicates. Thoughts?

/cc @BNNorman

from air-quality-web.

BNNorman avatar BNNorman commented on June 25, 2024

duplicates normally arise if you don't use a right join

from air-quality-web.

bsimmo avatar bsimmo commented on June 25, 2024

I know it once worked, we/you altered it.
I then asked for last seen and the commit a678a89a was made.
I cannot remember if I tested if that worked, or if that brought in the last problem (server error), that was then fixed.

Just checking you are using the current beta server as the fix was never release to the live server. At least for normal users.

as for time, same problem here. reporting things between everything else when I drop in and have a go at using it :-)

from air-quality-web.

sbrl avatar sbrl commented on June 25, 2024

Ah, I see @BNNorman. If I change the query to this though:

SELECT
devices.device_id AS id,
devices.device_name AS name,
devices.device_latitude AS latitude,
devices.device_longitude AS longitude,
ST_DISTANCE_SPHERE(POINT(53.750, -0.395), devices.lat_lon) AS distance_calc, devices.last_seen AS last_seen
FROM devices
RIGHT JOIN readings ON readings.device_id = devices.device_id
WHERE devices.lat_lon IS NOT NULL
ORDER BY ST_DISTANCE_SPHERE(POINT(53.750, -0.395), devices.lat_lon)
LIMIT 5;

...I still get the same result:

+----+----------------+-------------+-------------+-------------------+---------------------+
| id | name           | latitude    | longitude   | distance_calc     | last_seen           |
+----+----------------+-------------+-------------+-------------------+---------------------+
| 36 | CHASW-24AD43-1 | 53.75642593 | -0.36844245 | 1886.588853560329 | 2020-05-01 22:09:46 |
| 36 | CHASW-24AD43-1 | 53.75642593 | -0.36844245 | 1886.588853560329 | 2020-05-01 22:09:46 |
| 36 | CHASW-24AD43-1 | 53.75642593 | -0.36844245 | 1886.588853560329 | 2020-05-01 22:09:46 |
| 36 | CHASW-24AD43-1 | 53.75642593 | -0.36844245 | 1886.588853560329 | 2020-05-01 22:09:46 |
| 36 | CHASW-24AD43-1 | 53.75642593 | -0.36844245 | 1886.588853560329 | 2020-05-01 22:09:46 |
+----+----------------+-------------+-------------+-------------------+---------------------+

...even though I'm specifying a right join explicitly.

@bsimmo: This is using a local development server that's running the latest from the dev branch.

Hrm. You're saying that this is a regression and it worked before? Thanks for that commit id - that;s really helpful for narrowing down what's gone wrong. I'm pretty sure the problematic change is in a678a89#diff-de7016366166fa0b532d03d624168e27R151-R176.

Thinking about it, I'm not even sure why we're joining there in the first place, since it would appear that the only time the readings table is referenced is in the join itself. If I do this instead:

SELECT
devices.device_id AS id,
devices.device_name AS name,
devices.device_latitude AS latitude,
devices.device_longitude AS longitude,
ST_DISTANCE_SPHERE(POINT(53.750, -0.395), devices.lat_lon) AS distance_calc, devices.last_seen AS last_seen
FROM devices
WHERE devices.lat_lon IS NOT NULL
ORDER BY ST_DISTANCE_SPHERE(POINT(53.750, -0.395), devices.lat_lon)
LIMIT 5;

...then I correctly get this:

+----+------------------+-------------+-------------+--------------------+---------------------+
| id | name             | latitude    | longitude   | distance_calc      | last_seen           |
+----+------------------+-------------+-------------+--------------------+---------------------+
| 36 | CHASW-24AD43-1   | 53.75642593 | -0.36844245 |  1886.588853560329 | 2020-05-01 22:15:46 |
| 32 | CHASW-56AB6D-1   |   53.767262 |   -0.403431 | 1997.8605170536607 | 2020-05-01 06:00:56 |
| 51 | CL-AW15CH6N      |  53.7432075 |  -0.3586957 | 2503.8574249443122 | 2020-03-12 23:00:00 |
| 35 | CHASR-6F3BD82C-1 |    53.75776 |   -0.436268 |  2847.053372632466 | 2020-05-01 22:17:15 |
| 48 | HCCSENSOR03      |   53.739378 | -0.34838408 | 3285.0856113502487 | 2020-05-01 22:16:51 |
+----+------------------+-------------+-------------+--------------------+---------------------+

...does this look right to everyone? Have I missed something? I can't remember what I was thinking at the time, and the commit message doesn't give anything away. I feel like I'm missing something.

If this altered SQL query looks ok, I'll go ahead and patch the SQL query by removing the JOIN altogether.

from air-quality-web.

sbrl avatar sbrl commented on June 25, 2024

Fixed - at least for me. Should land in beta in ~20 mins

from air-quality-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.