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

Commits on Oct 7, 2024

  1. Add list of zones as static json

    These are the forecast zones supported by the CERC API, which we will offer to the user on the forecast page.
    patrickjfl authored and edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    d8eda46 View commit details
    Browse the repository at this point in the history
  2. Add HTTParty gem

    We will use this library to make calls to the CERC API in our client.
    patrickjfl authored and edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    310a07e View commit details
    Browse the repository at this point in the history
  3. Add client for fetching forecast data from CERC API

    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.
    patrickjfl authored and edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    e9844da View commit details
    Browse the repository at this point in the history
  4. Move from forecasts#index -> forecasts#show method

    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.
    patrickjfl authored and edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    b26164a View commit details
    Browse the repository at this point in the history
  5. Update forecast page with live data and zone form

    Users can now select a zone and fetch live data for that zone from the CERC API
    patrickjfl authored and edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    49380f5 View commit details
    Browse the repository at this point in the history
  6. Turn off fingerprinting of assets in test env

    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`.
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    2f959a6 View commit details
    Browse the repository at this point in the history
  7. Add WebMock gem to stub CERC API

    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
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    e951d8d View commit details
    Browse the repository at this point in the history
  8. Describe 'View Air Quality Alerts' journey in int. test

    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
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    ba5eabf View commit details
    Browse the repository at this point in the history
  9. Fix indentation on forecasts view

    Thanks to Prettier linter
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    cfeb99f View commit details
    Browse the repository at this point in the history
  10. Confirm 'No air quality alerts' when 0 alerts found

    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
    ```
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    2c64f82 View commit details
    Browse the repository at this point in the history
  11. Fix up controller spec

    - stub environment variables
    - use an inline JSON fixture for clarity
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    dd53af8 View commit details
    Browse the repository at this point in the history
  12. Stub CERC API for 'View forecasts' test

    We implement a `ForecastSteps` module for our helper
    methods.
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    0bfcaaf View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    ef2b0a7 View commit details
    Browse the repository at this point in the history
  14. Add markup to aid semantics and testability

    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
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    2a7d2e8 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    00c5aa6 View commit details
    Browse the repository at this point in the history
  16. Turn off deprecation warning in Rspec

    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
    ```
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    9b3c4c9 View commit details
    Browse the repository at this point in the history
  17. Implement a ForecastFactory to build Forecast entities from CERC's API

    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.
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    f4dded0 View commit details
    Browse the repository at this point in the history
  18. Add #inspect methods to forecast classes to aid debugging

    `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>>
    ```
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    90946ba View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    da08d6c View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    48885e9 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    cec5ae8 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    cd38e0b View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    f0b43a1 View commit details
    Browse the repository at this point in the history
  24. Move CERC API forecast fixtures into own namespace

    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 committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    49e7576 View commit details
    Browse the repository at this point in the history
  25. Ask forecast for #alerts

    We will implement these alerts properly in coming commits.
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    24108e2 View commit details
    Browse the repository at this point in the history
  26. Add factories to create test fixtures for domain forecasts

    We need a way to build our `Forecast` domain entities (and
    their `AirPollutionPrediction`, `TemperaturePrediction`,
    `ForecastZone` component entities).
    
    We use [FactoryBot][] to help.
    
    [FactoryBot]:
    https://github.com/thoughtbot/factory_bot
    edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    539da60 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    628a046 View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    11c42a7 View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    cc7b917 View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    deb404e View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    b850e03 View commit details
    Browse the repository at this point in the history
  32. Create UV prediction model

    The DAQI scale is from 1 to 10:
    
      1-3 = Low
      4-6 = Moderate
      7-9 = High
      10 = Very high
    patrickjfl authored and edavey committed Oct 7, 2024
    Configuration menu
    Copy the full SHA
    cd831ba View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    54e56dd View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    d860cc7 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    e164907 View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    9b013e0 View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    7a691e3 View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    b50a88d View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    dcc4815 View commit details
    Browse the repository at this point in the history