Commit Graph

103 Commits

Author SHA1 Message Date
Paul van Tilburg 95f30751c6
Add the combined provider 2022-02-24 20:40:07 +01:00
Paul van Tilburg 1ae6c896dd
Make item/sample fields available to the crate 2022-02-24 20:23:33 +01:00
Paul van Tilburg d0ace275ec
Filter out items that are older than 1h before now
Luchtmeetnet seems to yield some results that are in the past some
times?
2022-02-24 20:21:55 +01:00
Paul van Tilburg a78c55332f Refactor the API for the maps module
* Move the function `draw_position` to the maps module and split it up
* Replace and refactor `pollen_at` and `uvi_at` methods on `Maps`
  by `pollen_mark` and `uvi_mark`
* Drop the `pollen_project` and `uvi_project` methods on `Maps`,
  just call the `project` helper method directly
* Add `map_at` and `mark` helper methods that handle maps slicing
  and drawing
* Rename `pollen_sample` and `uvi_sample` methods on `Maps` to their
  plural forms
* Also, rename the map handlers to `map_address` and `map_geo`
2022-02-22 12:49:42 +01:00
Paul van Tilburg 84a434268f
Add README.md and LICENSE file (closes: #6)
Also link the files from the crate and include `README.md` as main crate
documentation.
2022-02-21 17:48:28 +01:00
Paul van Tilburg 7432fb3cd3 Fix Buienradar timestamp madness (closes: #3)
* Use the `Europe::Amsterdam` time zone from `chrono_tz` to determine
  what date/time it is in that time zone
* Parse timestamps in the rain text API relative to this date/time
* Add the `fix_items_day_boundary` function to fix up stuff if
  the series of timestamps in the rain text cross the day boundary
2022-02-20 17:39:49 +01:00
Paul van Tilburg 17d5daeabc Use chrono (UTC) timestamps for maps (closes: #12)
* Adapt `retrieve_image` to also return a timestamp based on the
  CDN's last modified time; adapt other methods accordingly
* For the maps module, use `chrono::Utc` instead of
  `tokio::time::Instant` and use `chrono::Duration` instead of
  `tokio::time::Duration`
* Pass the maps timestamp to the `sample` function so it can use
  that timestamp as base
2022-02-19 16:45:37 +01:00
Paul van Tilburg 46531a76bd Add retrieval of pollen and UVI metrics for Buienradar provider 2022-02-19 15:33:00 +01:00
Paul van Tilburg 5dc51b4c02 Implement map sampling using a map key
* Define the map key for Buienradar as `MAP_KEY` (colors used on
  Buienradar maps)
* Define a `MapkeyHistogram` type and add the `map_key_historgram()`
  function to construct one
* Define the sample size to look for pixels around the sampling
  coordinate
* Introduce a separata `sample` function that returns the samples
  for a map and the provided coordinates and starting timestamp
* Implement `Maps::pollen_sample` and Maps::uvi_sample`
2022-02-19 15:32:55 +01:00
Paul van Tilburg eb9951dbce Distinguish between a map and maps
* A map is a view into the image of concatenated maps
* Ensure that projection only happens on the first map
* Make `project` generic over all generic image views
2022-02-19 15:08:05 +01:00
Paul van Tilburg 0df30b695f Split off precipitation get code
This is necessary so that the Buienradar provider can support more
metrics using the maps.
2022-02-19 09:41:11 +01:00
Paul van Tilburg 7c24f73937 Add an extra map handler for showing lat/lon
* Split of the positioning and drawing code to the `draw_position`
  helper method
* Move the positioning and drawing code to a Tokia task
2022-02-18 23:18:50 +01:00
Paul van Tilburg a03573d20d Allow dead code for not-yet-implemented methods (for now) 2022-02-18 23:04:49 +01:00
Paul van Tilburg 7895b5afc9 Hook up the map projection in the map debug handler
Also change how the resulting coordinate is marked on the map
(2 line guides instead of a square).
2022-02-18 23:00:58 +01:00
Paul van Tilburg 4b80121187 Implement map projection using reference points
* Use the Mercator projection to get the image coordinates
* Fix errors in the reference points
* Tweak documentation
2022-02-18 22:59:21 +01:00
Paul van Tilburg 7d1a1a1c0d Add helper methods that calculate lat/lon in radians 2022-02-18 22:58:39 +01:00
Paul van Tilburg 6b62cc7797 Add some unimplemented API for map project and sampling
* Add map reference point constants `*_MAP_REF_POINTS `that can be used
  for map projections
* Add (unimplemented )`*_project` and `*_sample` methods to the `Maps`
  implementation
* Add `PollenSample` and `UviSample` structs
* Make `Position::new` const
2022-02-18 21:25:06 +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 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
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