Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(62) Show air quality alerts and 3-day forecast for selected zone #29

Merged
merged 39 commits into from
Oct 7, 2024

Conversation

edavey
Copy link
Collaborator

@edavey edavey commented Oct 3, 2024

In this PR we implement two stories which rely on data from CERC's "London-airTEXT" API

We've included guidance in the UV row, and will add guidance to the other rows as appropriate in future PRs.

3 day forecasts with guidance for UV

3-day-forecasts-w-uv-guidance

No air quality alerts to display

no_alerts

Air quality alerts for each of the 3 days forecast (guidance unexpanded)

alerts_unexpanded

Air quality alerts for each of the 3 days forecast (guidance expanded)

alerts_expanded

@edavey edavey force-pushed the 62-show-air-quality-alerts branch 2 times, most recently from 7ead96f to 0a06f37 Compare October 3, 2024 09:17
@edavey
Copy link
Collaborator Author

edavey commented Oct 3, 2024

@edavey
Copy link
Collaborator Author

edavey commented Oct 3, 2024

@patrickjfl patrickjfl force-pushed the 62-show-air-quality-alerts branch 2 times, most recently from 4098430 to e466283 Compare October 4, 2024 11:01
patrickjfl and others added 24 commits October 7, 2024 10:56
These are the forecast zones supported by the CERC API, which we will offer to the user on the forecast page.
We will use this library to make calls to the CERC API in our client.
To facilitate this, I have moved the sample forecast into the test fixtures, and added two new environment variables, CERC_API_HOST_URL and CERC_API_KEY.
We have agree that this method is rendering a single, three day forecast at a time, therefore it should be a show rather than an index method, and forecast should be singular in the path.
Users can now select a zone and fetch live data for that zone from the CERC API
This is so we can load styles more easily when debugging a
Capybara integration test which is saved to a local file
e.g. with `#save_and_open_page`.
This [mocking library][] will allow us to stub the HTTP response
from CERC which our `CercApiClient` receives.

We'll use it to set up scenarios for our integration tests.

[mocking library]:
https://github.com/bblimke/webmock
We have two scenarios:

1. "View air quality alerts": we see an alert with a
   different warning status for each of the 3 days included
   in the forecast

2. "See confirmation that there are current no air quality alert":
   We see that there are no alerts

We introduce three test helper modules:

1. a `Fixtures` module to build Forecasts for our tests

2. a `HttpStub` module to set WebMock stubs on HTTP traffic

3. an `AirQualitySteps` module to manage the implementation
   details for each "step" in the test. In our
   `view_air_quality_alerts_spec.rb` feature spec we
   ["include"][] this module in order to have access to its
   methods. This leaves the acceptance test
   clean and focused on describing the expected behaviour.

["include"]:
https://ruby-doc.org/docs/ruby-doc-bundle/ProgrammingRuby/book/classes.html#UC
Thanks to Prettier linter
One of our 2 acceptance tests now passes (albeit with a
naive implementation in the controller!)

```
scenario "See confirmation that there are current no air quality alert"
  given_an_air_pollution_prediction_for_today_w_low_status
  and_an_air_pollution_prediction_for_tomorrow_w_low_warning_status
  and_an_air_pollution_prediction_for_day_after_tomorrow_w_low_warning_status
  and_the_response_from_cercs_api_is_stubbed_accordingly

  when_i_look_at_the_forecasts
  then_i_see_that_there_are_no_current_air_quality_alerts
```
- stub environment variables
- use an inline JSON fixture for clarity
We implement a `ForecastSteps` module for our helper
methods.
Each row in the table now has a class describing the
information it carries:

- `air-pollution`
- `uv`
- `pollen`
- `temperature`

Each of the "value cells" now has a [`data-*` attribute][] of
`data-date` to identify which day's value it contains.

This will allow our integration tests to be clear and
maintainable.

[`data-*` attribute]:
https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
I couldn't for now figure out how to resolve these warnings.
I tried updating all gems to their latest versions. There
isn't a more recent Ruby version to try.

Come back to this later, maybe.

```

air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/date_time_parser.rb:837: warning: statement not reached
air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/date_time_parser.rb:691: warning: assigned but unused variable - testEof
air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32457: warning: statement not reached
air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32618: warning: statement not reached
air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32654: warning: statement not reached
air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32743: warning: statement not reached
air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32759: warning: statement not reached
air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32825: warning: statement not reached
air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32866: warning: statement not reached
air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32891: warning: statement not reached
air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:31987: warning: assigned but unused variable - testEof
air-text/vendor/bundle/ruby/3.3.0/gems/sassc-rails-2.1.2/lib/sassc/rails/functions.rb:7: warning: method redefined; discarding old asset_data_url
air-text/vendor/bundle/ruby/3.3.0/gems/sprockets-4.2.1/lib/sprockets/sass_processor.rb:274: warning: previous definition of asset_data_url was here
air-text/vendor/bundle/ruby/3.3.0/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb:7: warning: method redefined; discarding old initialize
air-text/vendor/bundle/ruby/3.3.0/gems/sprockets-4.2.1/lib/sprockets/sass_compressor.rb:39: warning: previous definition of initialize was here
air-text/vendor/bundle/ruby/3.3.0/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb:17: warning: method redefined; discarding old call
air-text/vendor/bundle/ruby/3.3.0/gems/sprockets-4.2.1/lib/sprockets/sass_compressor.rb:49: warning: previous definition of call was here
air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge/log_subscribers/base.rb:44: warning: method redefined; discarding old extract_status
air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge/log_subscribers/base.rb:41: warning: previous definition of extract_status was here
air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge.rb:82: warning: method redefined; discarding old ignore_tests
air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge.rb:28: warning: previous definition of ignore_tests was here
air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge.rb:82: warning: method redefined; discarding old ignore_tests
air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge.rb:28: warning: previous definition of ignore_tests was here
```
We take a representation of a Forecast from CERC's API and
build a list of our own Forecast entities.

For now our ForecastBuilder only uses the first zone
returned (i.e. only handles the scenario where we've asked
CERC's API for information on a particular zone). We will
likely develop this to handle all zones: that's what's
returned if we don't request a specific zone e.g.

```
curl "https://cerc.example.com/getforecast/all?numdays=3
```

For now we also leave out the rain and wind information as
we aren't sure how/if/where this is needed.
`Forecast#inspect` will return a string representation like:

```
"#<Forecast
  @obtained_at=2024-10-02 15:38:00 +0100
  @forecast_for=2024-10-02
  @zone=#<ForecastZone
    @id=29
    @name=Southwark
    @type=1>
  @air_pollution=#<AirPollutionPrediction
    @forecasted_at=2024-10-02 15:50:00 +0100
    @nitrogen_dioxide=1>
    @particulate_matter_10=1
    @particulate_matter_2_5=1
    @ozone=2
    @overall_score=2
    @overall_label=LOW>
  @UV=2
  @pollen=-999
  @temperature=#<TemperaturePrediction
    @min=10.0
    @max=16.6>>
```
We are going to build test fixtures for our own `Forecast`
entities as distinct from the JSON representations which we
receive from CERC's `/getforecast/all?` endpoint.
@edavey edavey marked this pull request as ready for review October 7, 2024 10:52
@edavey edavey changed the title WIP (62) show air quality alerts (62) Show air quality alerts and 3-day forecast for selected zone Oct 7, 2024
@edavey edavey merged commit e8d5c89 into develop Oct 7, 2024
2 checks passed
@edavey edavey deleted the 62-show-air-quality-alerts branch October 7, 2024 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants