Commit Graph

41 Commits

Author SHA1 Message Date
Admar Schoonen a369dabdfa Oops! Fixed the build 2022-02-18 20:15:48 +01:00
Admar Schoonen fd0725be5c Extend positions with getters to retrieve lat/lon in radians 2022-02-18 20:09:34 +01:00
Admar Schoonen 5cd2b56176 It ain't fugly if it works, right? 2022-02-18 19:51:26 +01:00
Paul van Tilburg f1a303edc0
Use address instead of position for map debug handler 2022-02-17 22:25:13 +01:00
Paul van Tilburg 4920ab4abd
Drop Weerplaza precipitation maps (closes: #8) 2022-02-17 21:47:01 +01:00
Paul van Tilburg f67f3dfe82
Only update the cache if retrieval yielded maps
* Add `is_*_stale` methods to the `MapRefresh` trait
* Only update the maps of a type if `retrieve_image` yielded something
  or if the maps are stale
* Also only then bump the timestamp for the map type

This means if there is nothing in the cache, it will retry each refresh
to get something because the timestamp is not bumped until there is
something. Once there are maps, it will only update it and bump the
timestamp if there is an image, that or, it has become stale and it
can be set to `None` and we end up in the initial state.
2022-02-17 21:38:41 +01:00
Paul van Tilburg 8d2717b392
Provide not the first map but an instant-relative map
This calculates which offset to use in the maps series with respect to
the instant of caching. It assumes the first map is current for the
instant it was retrieved.

* Rename `*_first` to `*_at` methods
* For convenience, change the types of `*_MAP_COUNT` to `u32`
* Introduce `*_MAP_INTERVAL` constants to indicate the number of
  seconds each map in the series applies to
* Return `None` if the provided instant is too far in the future
2022-02-17 21:38:16 +01:00
Paul van Tilburg 7061842bd3
Sort Cargo.toml 2022-02-16 22:20:20 +01:00
Paul van Tilburg 88b24a83ff
Move blocking image load to separate task 2022-02-16 22:02:32 +01:00
Paul van Tilburg f4a12dacdb Add a debug handler for marking a position on a map
The map that is used depends on the selected metric.
2022-02-15 17:06:32 +01:00
Paul van Tilburg 9531114eec Add methods to get the first map of each type
Also introduce constants for the number of maps included in a single
`DynamicImage`.
2022-02-15 17:04:04 +01:00
Paul van Tilburg 3a48f234e9 Introduce the Position struct; add position module
* Use `Position` everywhere instead of latitude/longitude float values
* Implement `Partial`, `Eq` and `Hash` for `Position` so it can
  part of a cache key
* Drop the `cache_key` helper function
* Rename the `address_position` function to `resolve_address`
* Add methods on `Position` for formatting latitude/longitude with
  a given precision (used for URL parameters in providers)
2022-02-15 14:15:59 +01:00
Paul van Tilburg b2f63db6b4 Mention open issues in documentation; tweak docs 2022-02-15 14:15:21 +01:00
Paul van Tilburg c76e2315b5 Split off forecast stuff to a separate module 2022-02-15 13:14:01 +01:00
Paul van Tilburg 0c5367f87f
Document caching; increase Luchtmeetnet caching to 30min 2022-02-14 21:40:07 +01:00
Paul van Tilburg 79981314d3
Make output messages more consistent 2022-02-14 21:13:35 +01:00
Paul van Tilburg 8d19dbb517
Implement caching for provider get requests (closes: #2)
* Also cache address geocoding requests to OSM Nomatim!
* Use the `cached` crate for an easy implementation
* Add the `cache_key` helper function to deal with floats being annoying
* Cache Buienradar get request for 5 minutes (per position/metric)
* Cache Luchtmeetnet get request for 5 minutes (per position/metric)
* Note the `Item` structs need to implement `Clone` now because
  the cache will own them and Rocket will want a copy too
2022-02-14 21:06:31 +01:00
Paul van Tilburg 927cb0ad92
Fix geocoded address having latitude/longitude swapped 2022-02-14 21:04:31 +01:00
Paul van Tilburg c231447ce9
Be pedantic with constant number notation 😉 2022-02-13 21:31:12 +01:00
Paul van Tilburg 859288a329
Increase the refresh intervals; improve documentation 2022-02-13 21:24:26 +01:00
Paul van Tilburg 309c79d83c
Disable retrieving precipitation maps for now (see #8) 2022-02-13 21:23:48 +01:00
Paul van Tilburg 576bcc6640
Fix UV index maps base URL
The typo was introduced in commit d432bb4.
2022-02-13 16:55:21 +01:00
Paul van Tilburg f6b26c9659
Fix expect message 2022-02-13 16:55:03 +01:00
Paul van Tilburg 79dac18655
Parse Buienradar as CSV file using serde
* Add the `csv` crate as a dependency
* Use the `Row` struct as intermediate object
* Turn the `parse_value` function into the `convert_value` function that
  cannot fail
2022-02-13 16:46:02 +01:00
Paul van Tilburg 4232263a45
Hook up the Buienradar provider metric in the forecast
Also, sync up the Luchtmeetnet provider documentation a bit.
2022-02-13 15:39:09 +01:00
Paul van Tilburg 6279d379ab
Add the Buienradar provider 2022-02-13 15:38:17 +01:00
Paul van Tilburg d432bb4cd6
Use URL objects instead of formatted strings
Use `request::Url` for this, so we don't have to depend on the `url`
crate ourselves.

Also, make the URL constants more uniform.
2022-02-13 13:10:12 +01:00
Paul van Tilburg 66abc9c4db
Hook up the Luchtmeetnet provider metrics in the forecast 2022-02-13 12:46:42 +01:00
Paul van Tilburg 59c177d508
Add the Luchtmeetnet provider
Also introduce the providers module.
2022-02-13 12:45:27 +01:00
Paul van Tilburg cbd686bd60
Small documentation improvements 2022-02-13 11:22:22 +01:00
Paul van Tilburg cf77dbb5e7
Refactor maps cache to hold lock as short as possible
This makes the response time way more snappy when the maps thread
is updating its cache.

* Move the `MapsHandle` type to the `maps` module
* SWitch to using the standard library mutex
* Split refresh methods into retrieval methods that don't need the lock
  and check timestamp & update methods that only need it shortly
* Introduce the `MapsRefresh` trait and implement it for `MapsHandle`
* Reorder some methods for clarity
* Small documentation fixes
2022-02-13 11:22:02 +01:00
Paul van Tilburg 9b9b1a5f77
Refactor so that no static is necessary for the maps cache
* Replace the lazy `once_cell` by a maps handle type
* Use Rocket's managed state to manage a handle
* Ensure that the handlers have access to it
* Pass another handle to the maps updater loop
* Try to keep the lock as short as possible

Still, long downloads block the lock. Add a FIXME to refactor this
so the lock is only taken when updating the maps fields.
2022-02-12 21:35:58 +01:00
Paul van Tilburg 72fe9577bd
Implement retrieving and caching maps 2022-02-12 21:08:13 +01:00
Paul van Tilburg d058ab4448
Set up a global maps (cache) object 2022-02-12 17:20:36 +01:00
Paul van Tilburg b5dae45868
Create maps cache and run its task next to Rocket 2022-02-12 17:12:06 +01:00
Paul van Tilburg 6b24c4f6e7
Move blocking geocding forward resolving to a separate thread 2022-02-12 17:12:01 +01:00
Paul van Tilburg ae2d2c1c56 Merge pull request 'Clarify that PAQI is the combination of pollen and air quality index' (#1) from admar/sinoptik:clarify-PAQI into main
Reviewed-on: paul/sinoptik#1
2022-02-12 17:10:45 +01:00
Admar Schoonen 85d5d34a65 Clarify that PAQI is the combination of pollen and air quality index 2022-02-12 16:18:30 +01:00
Paul van Tilburg 7b496887c2
Properly implement all metrics expansion 2022-02-12 15:03:02 +01:00
Paul van Tilburg ebf1b0618b
Number forecast output per metric (for now)
Also don't include a `null` value in the JSON if it is not enabled.
2022-02-12 15:03:02 +01:00
Paul van Tilburg 0b5e980f04
Initial import into Git 2022-02-12 15:03:00 +01:00