openaq / openaq-api-v2

OpenAQ API
https://api.openaq.org
39 stars 9 forks source link

Request to average endpoint times out #326

Open MauriceHeinze opened 5 months ago

MauriceHeinze commented 5 months ago

Hello,

We're facing issues using the average endpoint. The locations endpoint we use to get the closest station near by works fine, but as soon as we try to get the average values for the first location it fails.

Error in requests.get: 408 Client Error: Request Time-out for url: https://api.openaq.org/v2/averages?temporal=year&date_to=2024-01-25&date_from=2023-01-25&locations_id=3197&spatial=location

Thanks in advance for looking into it.

Best, Maurice

russbiggs commented 5 months ago

Hi Maurice, Thanks for reporting this. I can't replicate the timeout right now but this is common. The 408 timeout usually means the request is too complex or requesting too much data. In the case of this location it is only reporting PM10, so not too complex.

One confusing point is you are requesting yearly averages starting and ending from January 25. This returns a "yearly" average for 2023 from 01-25 until 12-31 and a "yearly" average for 2024 from 01-01 until 01-25. This latter is not a yearly average and is adding extra work for the query which may be slowing it down. This is a shortcoming of this endpoint that it allows this. I would recommend trying something like:

https://api.openaq.org/v2/averages?temporal=year&date_to=2024-01-01&date_from=2023-01-01&locations_id=3197&spatial=location

Which will appropriately get you the full average from 2023.

We are working on a new endpoint that will hopefully be more clear for yearly averaging.

@caparker do you have any other thoughts on this?

MauriceHeinze commented 5 months ago

Thanks for the quick response, Russ!

russbiggs commented 5 months ago

@MauriceHeinze do the adjusted date_from and date_to values meet with your intended query? or were you intentionally trying to get the cross-year average 2023-01-25 to 2024-01-25?