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

Google Floods Part 1: Adding backend + creating Gauge Points; COUNTRY=cambodia #1328

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

lowriech
Copy link
Collaborator

@lowriech lowriech commented Aug 8, 2024

Description

This fulfills step 1 of 3 for #1317 (see plan).

In this PR, we're fetching flood status by gauge from Google's Floods API for the entire country (10-100 gauges per country). We're displaying these gauges as points on Prism. They're color coded by flood status and provide additional insight when clicked.

This PR also adds support to provide a popup title in the layer config. Because these gauges are typically located on rivers that server as the boundary between two regions, using the region title for the pop up doesn't make much sense. Instead, we're adding an approach that allows one to use formatted feature properties as the title.

Forecasts for each gauge are added here: #1330

How to test the feature:

  • Open the Mozambique deployment
  • Enable the Google Flood layer

Checklist - did you ...

Test your changes with

  • REACT_APP_COUNTRY=rbd yarn start
  • REACT_APP_COUNTRY=cambodia yarn start
  • REACT_APP_COUNTRY=mozambique yarn start
  • Add / update necessary tests?
  • Add / update outdated documentation?

Screenshot/video of feature:

Screenshot 2024-08-12 at 2 03 31 PM Screenshot 2024-08-12 at 2 30 24 PM

@lowriech lowriech marked this pull request as draft August 8, 2024 22:11
Copy link

github-actions bot commented Aug 8, 2024

Build succeeded and deployed at https://prism-1328.surge.sh
(hash 6d33543 deployed at 2024-10-31T19:46:19)

api/app/main.py Outdated
@@ -412,3 +413,10 @@ def post_raster_geotiff(raster_geotiff: RasterGeotiffModel):
return JSONResponse(
content={"download_url": presigned_download_url}, status_code=200
)


@app.get("/google-floods-gauges")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're gonna add a bunch of integrations, it will be worthwile to think about a standardized approach and common architecture. And maybe expose them through a sub endpoint of the API to keep things cleaner. wdyt @lowriech ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good question, @ericboucher. Do you see other APIs we're already leveraging fitting into this integration category (kobo, hdc stats, others)? Or are you thinking just for new integrations?

I'm wary of premature abstraction and trying to determine if I think now is the right time to align on this standardized approach.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like low-hanging fruit to abstract once we decide on a pattern. So yes, agree we should think about it, but not sure about the velocity of adding entirely new providers. Would vote to wait until we see more pattern around this.

"title": "Google Flood Gauges",
"type": "point_data",
"hex_display": false,
"data": "http://0.0.0.0:80/google-floods/gauges/?region_code=MZ",
Copy link
Collaborator

@gislawill gislawill Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: need a better development set up

Set to a relative path, make sure we're using DEFAULT_API_URL for these requests

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericboucher have you all deployed the prism-api out in surge-like deployments before for testing?

@gislawill gislawill changed the title Adding Google Floods Backend Adding Google Floods Backend + Creating a Gauge Points Aug 12, 2024
@gislawill
Copy link
Collaborator

@lowriech and @ericboucher, there are a couple outstanding issues (noted in the PR description) but this ready for initial review

@gislawill gislawill changed the title Adding Google Floods Backend + Creating a Gauge Points Adding Google Floods Backend + Creating a Gauge Points; COUNTRY=mozambique Aug 12, 2024
Comment on lines +172 to +177
if (
itemProps.visibility === FeatureInfoVisibility.IfDefined &&
!properties[item]
) {
return obj;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some feature properties that may or may not be defined by the google api (for example: site name, river name). This allows us to hide the property from the pop up if it's not defined

Comment on lines 32 to 34
"river": (
data["river"] if "river" in data and len(data["river"]) > 1 else None
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"river" can come in as a string with just 1 space (" "). This ensures there's a real value

},
"gaugeId": {
"type": "text",
"template": "Gauge ID: %s",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think of a way to make this template translatable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How have we done this in other parts of the app? Can we use a translate wrapper function within the tooltips?

Copy link
Collaborator

@ericboucher ericboucher Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't really used templates in PRISM yet. We usually consider the template as a title and then handle the title and the data separately. So instead of template you would just have "title": "Gauge ID". and then append the value. You can have a look at the PopupContent file for examples. If we think the structure will be simple like that, they that's probably ok.

Another option is to use the translation mapping and have the template be: Gauge ID: {id}, then use it like this:

      <Trans values={{ id }}>
        <Typography>{t(template)}</Typography>
      </Trans>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ericboucher! I'm leaning towards the latter option (translation mapping). We used these templates in react-i18next pretty extensively in the distant past (my Hilton Hotels days). Once we started using them, it gave us a ton of flexibility in terms of copy. If you're ok with it, I'll implement it this way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@gislawill
Copy link
Collaborator

Note: I'm adding pytest-recording to store our google flood responses in local tests and use them in CI/CD. That will fix the failing API test in this PR

@gislawill gislawill linked an issue Aug 19, 2024 that may be closed by this pull request
@gislawill gislawill marked this pull request as ready for review August 21, 2024 01:21
@gislawill gislawill changed the title Adding Google Floods Backend + Creating a Gauge Points; COUNTRY=mozambique Adding Google Floods Backend + Creating Gauge Points; COUNTRY=mozambique Aug 21, 2024
api/app/googleflood.py Outdated Show resolved Hide resolved
@gislawill gislawill changed the title Adding Google Floods Backend + Creating Gauge Points; COUNTRY=mozambique Adding Google Floods Backend + Creating Gauge Points; COUNTRY=cambodia Oct 7, 2024
@wadhwamatic
Copy link
Member

Great to see this nearly complete - thanks @gislawill. I mentioned the map interaction bug that's preventing a full test but hopefully that is resolved soon.

In the meantime, in addition to displaying the gauge ID, can we first show the river name? I see that in Flood Hub interface, hopefully it's also exposed via the API.
Screenshot 2024-10-07 at 13 29 30

Note, we'd need to translate that text as well. I see that Flood Hub offers several language options including Khmer. Ex: https://sites.research.google/floods/e/l/10.96043262736797/103.63535499532549/8.45328318786621/g/hybas_4121148610?layers&hl=km

hl=km

@gislawill
Copy link
Collaborator

In the meantime, in addition to displaying the gauge ID, can we first show the river name? I see that in Flood Hub interface, hopefully it's also exposed via the API.
Note, we'd need to translate that text as well. I see that Flood Hub offers several language options including Khmer. Ex: https://sites.research.google/floods/e/l/10.96043262736797/103.63535499532549/8.45328318786621/g/hybas_4121148610?layers&hl=km

Hey @wadhwamatic, the river name is sometimes provided by the API but often it is not. I've currently set this up so we display the site name if it's provided. If not, we display the river name if it's provided. If not, we display the gauge id (which is always provided). How does that logic sound to you?

Here's how it looks:

This PR Next PR
Screenshot 2024-10-07 at 3 43 11 PM Screenshot 2024-10-07 at 3 39 17 PM

I tried to find the translated names in the API but unfortunately there's no option in the API documentation and the API fails if the hl parameter is included in the request.
Screenshot 2024-10-07 at 3 49 03 PM

I'll update this title component so that at least "site name:" and "river:" can be translated even in the API provided name won't be.

@wadhwamatic
Copy link
Member

Hey @wadhwamatic, the river name is sometimes provided by the API but often it is not. I've currently set this up so we display the site name if it's provided. If not, we display the river name if it's provided. If not, we display the gauge id (which is always provided). How does that logic sound to you?

That logic sounds good - thanks! Is there an example of site name in Cambodia?

That's too bad about the translation via the API but thanks for noting it regardless.

@gislawill
Copy link
Collaborator

That logic sounds good - thanks! Is there an example of site name in Cambodia?

There is not unfortunately. A bunch of rivers but no site names

@gislawill
Copy link
Collaborator

Heads up @wadhwamatic, the today "Date" is now set on these layers
Screenshot 2024-10-09 at 10 00 54 PM

I'll work with @ericboucher to get a new server deployment out for testing

@gislawill
Copy link
Collaborator

Server deployment containing the updates is out (thanks @ericboucher for walking me through it). @wadhwamatic you can resume testing

@wadhwamatic
Copy link
Member

@gislawill - thanks for adding the time dimension here. I tested date intersections a few ways and this is looking good from my side, as does the river gauge info noted in this PR

@gislawill
Copy link
Collaborator

Remaining todo items:

  • Ensure all parts of tooltip are translate-able

@gislawill gislawill changed the title Adding Google Floods Backend + Creating Gauge Points; COUNTRY=cambodia Google Floods Part 1: Adding backend + creating Gauge Points; COUNTRY=cambodia Oct 24, 2024
* Adding graph for google flood data

* Merge conflict resolution and units

* Updating tests

* formatting

* Using superscript

* Supporting rbd

* Add support for Cambodia

* Updating url for data

* api lint

* Fixing date logic on graph look up

* Updates to chart to denote past vs future

* Adding translation to 'future' label

* Fix chart tests using mock

* Requested changes: descriptive labels
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.

[Feature Request]: Google Flood Hub integration
4 participants