-
Notifications
You must be signed in to change notification settings - Fork 34
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
lowriech
wants to merge
28
commits into
master
Choose a base branch
from
feature/google-floods/1317
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c5c1215
Adding Google Floods Backend
b9722d3
Viewing the gauges on the frontend, adding error handling to backend
gislawill bc92d38
Update comment
gislawill 08a4499
Updates to support tooltip content
gislawill 0653f1e
copy update
gislawill 7cd866d
Refactor title state management
gislawill 94e1588
Fixing and adding server tests
gislawill 6ac3aad
update set_env
ericboucher eb29b6e
Merge branch 'master' into feature/google-floods/1317
ericboucher 6be26d7
update snapshots
ericboucher 2fe481a
Merge branch 'master' into feature/google-floods/1317
gislawill 8e84cbb
Adding support for multi country deployments and adding google flood …
gislawill efdf2c9
Use interpolation for popup titles
gislawill 8fa327c
Adding pytest-recording
gislawill f5ffbf6
Merge branch 'master' into feature/google-floods/1317
ericboucher 438ee04
Update test_google_floods_api.py
ericboucher e369704
Merge branch 'feature/google-floods/1317' of https://github.com/WFP-V…
ericboucher 6547f3b
Fixing river template
gislawill ac58dca
More selective with pytest recording
gislawill 65af7e7
Merge branch 'master' into feature/google-floods/1317
ericboucher 0adb49d
Update API URL
ericboucher dc94f60
Merge branch 'master' into feature/google-floods/1317
ericboucher b0780fa
Merge branch 'master' into feature/google-floods/1317
gislawill 7f401bb
Adding support for Cambodia
gislawill 341a3a7
Merge branch 'master' into feature/google-floods/1317
gislawill 1e51479
Merge branch 'master' into feature/google-floods/1317
gislawill 2a890cf
Adding date support
gislawill 6d33543
Google Floods Part 2: Adding tooltip graph; COUNTRY=cambodia (#1330)
gislawill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Get data from Humanitarian Data Cube (HDC) API""" | ||
import logging | ||
from os import getenv | ||
|
||
import requests | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
GOOGLE_FLOODS_API_KEY = getenv("GOOGLE_FLOODS_API_KEY", "") | ||
if GOOGLE_FLOODS_API_KEY == "": | ||
logger.warning("Missing backend parameter: GOOGLE_FLOODS_API_KEY") | ||
|
||
def format_to_geojson(data): | ||
geojson = { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [data["gaugeLocation"]["longitude"], data["gaugeLocation"]["latitude"]] | ||
}, | ||
"properties": { | ||
"gaugeId": data["gaugeId"], | ||
"issuedTime": data["issuedTime"], | ||
# "forecastTimeRange": data["forecastTimeRange"], | ||
# "forecastChange": data["forecastChange"], | ||
# "forecastTrend": data["forecastTrend"], | ||
"severity": data["severity"], | ||
"source": data["source"], | ||
"qualityVerified": data["qualityVerified"] | ||
} | ||
} | ||
if "inundationMapSet" in data: | ||
geojson["properties"]["inundationMapSet"] = data["inundationMapSet"] | ||
return geojson | ||
|
||
|
||
def get_google_floods_gauges( | ||
iso2: str, | ||
asGeojson: bool = True, | ||
): | ||
"""Get statistical charts data""" | ||
logging.info(GOOGLE_FLOODS_API_KEY) | ||
|
||
URL = f'https://floodforecasting.googleapis.com/v1/floodStatus:searchLatestFloodStatusByArea?key={GOOGLE_FLOODS_API_KEY}' | ||
response = requests.post( | ||
URL, | ||
json={'regionCode': iso2} | ||
).json().get('floodStatuses', []) | ||
|
||
if asGeojson: | ||
geojson_feature_collection = { | ||
"type": "FeatureCollection", | ||
"features": [format_to_geojson(data) for data in response] | ||
} | ||
return geojson_feature_collection | ||
return response | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
log_cli = true | ||
log_cli_level = INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from app.googleflood import get_google_floods_gauges | ||
from app.main import app | ||
from fastapi.testclient import TestClient | ||
import logging, json | ||
|
||
client = TestClient(app) | ||
|
||
def test_get_google_floods_gauges(): | ||
gauges = get_google_floods_gauges("BD") | ||
assert len(gauges) > 0 | ||
|
||
|
||
def test_get_google_floods_gauges_api(): | ||
response = client.get("/google-floods-gauges?iso2=BD") | ||
assert response.status_code == 200 | ||
logging.info(json.dumps(response.json())) | ||
# logging.info(response.json()) | ||
assert len(response.json()) > 0 | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.