Commit Graph

170 Commits

Author SHA1 Message Date
Paul van Tilburg 4576f8d90a
More textual improvements 2022-03-11 16:35:38 +01:00
Paul van Tilburg 66bd02ea57
Also document the map API endpoint
Because, why not?
2022-03-11 16:18:04 +01:00
Paul van Tilburg 80fd9525c4
Fix missing endpoint in example URLs; tweak text a bit 2022-03-11 16:09:14 +01:00
Paul van Tilburg 32964cea21
Add basic top-level tests
This starts to address #14 but didn't turn into a full MR yet.

* Use crates `assert_float_eq` and `assert_matches` for extra assertions
* Split off a function to build a Rocket `rocket()` that can be used
  in the tests
2022-03-11 16:03:56 +01:00
Paul van Tilburg 738409c3a8
Fix bound check using constant value
It should use the actual count instead!
2022-03-07 19:19:14 +01:00
Paul van Tilburg 65a4420191
Bump dependency; cargo update
Bump the dependency on `cached` to 0.32.0 (fixes documentation)
2022-02-26 09:36:15 +01:00
Paul van Tilburg dc90f57422 Document API response; fix typo 2022-02-25 15:43:15 +01:00
Paul van Tilburg 512f170804 Bump dependencies; cargo update
* Bump the dependency on `image` to 0.24.1 (PNG bugfix)
* Bump the dependency on `cached` to 0.31.0 (I/O caching support?)
2022-02-25 15:26:44 +01:00
Paul van Tilburg 8b1dee96e0 Merge pull request 'Implement PAQI metric' (#16) from 15-implement-paqi into main
Reviewed-on: #16
2022-02-24 20:43:34 +01:00
Paul van Tilburg d33b5f1dbb
Hook up the combined metric in the forecast 2022-02-24 20:40:35 +01:00
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 9cd4be160c Update description; add authors and repository fields 2022-02-21 21:05:50 +01:00
Paul van Tilburg 9e9955fb58 Add Debian packaging via cargo-deb
* Add the required metadata to `Cargo.toml`
* Add a systemd unit file
* Use `Rocket.toml.example` as the default configuration
2022-02-21 20:55:00 +01:00
Paul van Tilburg 4db8e4ac03 Add Rocket.toml example file; fix syntax
Also ignore a local `Rocket.toml`; it can be used for development
without comitting it.
2022-02-21 20:54:32 +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 a5ca1f02ff Merge pull request 'Implment the pollen and UV index metrics' (#13) from 4-implement-pollen-uvi into main
Reviewed-on: #13
2022-02-19 15:42:57 +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 ac9576defa Merge pull request 'Implement Mercator projection' (#10) from 9-implement-mercator-projection into main
Reviewed-on: #10
2022-02-18 23:04:08 +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 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