rainviewer-api-example icon indicating copy to clipboard operation
rainviewer-api-example copied to clipboard

Time stamp "latest"

Open woheller69 opened this issue 1 year ago • 8 comments

It seems instead of loading the json every time it is possible to insert "latest" as a time stamp. What exactly do I get in this case? I want it for a widget and this would reduce the nimber of internet requests.

woheller69 avatar Dec 14 '24 10:12 woheller69

@woheller69 This repository is a basic example of how to use our API. The code itself is far from perfect, so yes, any modifications are welcome.

However, regarding the "latest" keyword for tiles, I wouldn't recommend using it due to caching issues. The browser might not request the tile and instead return the "latest" tile from the local cache, which may no longer be the most up-to-date version.

luckyalvy avatar Dec 31 '24 15:12 luckyalvy

I found a different way which works well so far. https://github.com/woheller69/omweather/commit/e2369e45597148cbc574b5a04dd378fabced0ff8

I am calculating the timestamps instead of downloading them for the widget.

woheller69 avatar Dec 31 '24 16:12 woheller69

Regarding what might seem like the most obvious solution for optimization, I strongly advise against implementing it. There are two main reasons for this:

  1. New tiles typically become available about 40 seconds after a 10-minute step (e.g., 10:10, 10:20, etc.) - however, this is not always consistent. The availability depends on many internal factors, and it could take anywhere from 20 seconds to 2 minutes to generate a new map. In some cases, a new frame might not be generated at all.
  2. In the coming year, we plan to transition from using timestamps to using hashes for accessing radar frames. To ensure your app version remains compatible for an extended period, it's better to utilize the weather-maps.json file now.

luckyalvy avatar Dec 31 '24 16:12 luckyalvy

Well, that is bad... In a widget several internet calls do not work well. It takes too much time. I had it implemented before. The device goes back to sleep an the widget is not updated at all quite often.

Is there an issue with caching for "latest" on your side or just on the client side? There I can make sure it ignores the cache. It would be great to have a simple approach with just one internet call for the most recent radar frame.

woheller69 avatar Dec 31 '24 16:12 woheller69

I would then use "latest" and calculate its timestamp, which of course may be wrong by 10min. Or will "latest" also be "disabled"? With Android volley it seemed to work. I can do: request.setShouldCache(false)

woheller69 avatar Dec 31 '24 16:12 woheller69

have you thought a bit more about this? It would be great to have an offically supported way to access at least the "latest" radar frames immediately without the need of downloading the json file.

woheller69 avatar Feb 10 '25 12:02 woheller69

have you thought a bit more about this? It would be great to have an offically supported way to access at least the "latest" radar frames immediately without the need of downloading the json file.

Unfortunately, this is not possible. All the possible scenarios on how to do that involve 302 redirects, which are almost equal to querying and processing a JSON file.

luckyalvy avatar Feb 17 '25 01:02 luckyalvy

I guess the hashes are derived from time via a one-way-function. Can you provide a table with the hashes in advance? E.g. in another file weather-maps-24h.json which has time and path for the next 24h? Then I could download this table once a day when I am getting close to the end of the list. Instead of calculating the path of the most recent frame I could look it up in this table. Of course this table would not need to hold paths for paid nowcast data.

 "radar": {
    "24h": [
      {
        "time": 1609401600,
        "path": "/v2/radar/6b3c5a659cf4"
      },
      {
        "time": 1609402200,
        "path": "/v2/radar/dd3474d83b20"
      }
    ]
  },

Or just let me know the one-way-function ;-)

woheller69 avatar Feb 17 '25 05:02 woheller69