-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add wis2 compliant mqtt publishing #223
Open
Teddy-1000
wants to merge
8
commits into
main
Choose a base branch
from
add-wis2-compliant-mqtt-publishing
base: main
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
16d2d3b
Add wis2 pydantic model
Teddy-1000 5de1613
Add wis2 pydantic model
Teddy-1000 96a8019
Merge remote-tracking branch 'origin/main' into add-wis2-compliant-mq…
Teddy-1000 dee5226
Add option for WIS2 complient mqtt message
Teddy-1000 c66c9a3
Add more ENV variables
Teddy-1000 0dee0f2
Add content to wis2 mqtt message
Teddy-1000 e7c5a0d
Fix error when WIS2 mqtt was not configured
Teddy-1000 d1bb120
Add mosquitto mqtt to compose
Teddy-1000 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
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,72 @@ | ||
import os | ||
import json | ||
|
||
|
||
from api.model import Geometry | ||
from api.model import Link | ||
from api.wis2_model import Wis2MessageSchema | ||
from api.wis2_model import Properties | ||
from api.wis2_model import Content | ||
|
||
|
||
def get_api_timeseries_query(location_id: str, baseURL: str) -> str: | ||
query = "/collections/observations/locations/" + location_id | ||
baseURL = os.getenv("EDR_API_URL", baseURL) | ||
return baseURL + query | ||
|
||
|
||
def generate_wis2_topic() -> str: | ||
"""This function will generate the WIS2 complient toipc name""" | ||
wis2_topic = os.getenv("WIS2_TOPIC") | ||
if not wis2_topic: | ||
raise ValueError("WIS2_TOPIC env variable not set. Aborting publish to wis2") | ||
return wis2_topic | ||
|
||
|
||
def generate_wis2_payload(message: dict, request_url: str) -> Wis2MessageSchema: | ||
""" | ||
This function will generate the WIS2 complient payload based on the JSON schema for ESOH | ||
""" | ||
wis2_payload = Wis2MessageSchema( | ||
type="Feature", | ||
id=message["id"], | ||
version="v04", | ||
geometry=Geometry(**message["geometry"]), | ||
properties=Properties( | ||
producer=message["properties"]["naming_authority"], | ||
data_id=message["properties"]["data_id"], | ||
metadata_id=os.getenv( | ||
"WIS2_METADATA_RECORD_ID", None | ||
), # Need to figure out how we generate this? Is it staic or dynamic? | ||
datetime=message["properties"]["datetime"], | ||
pubtime=message["properties"]["pubtime"], | ||
content=Content( | ||
value=json.dumps( | ||
{ | ||
"type": "Feature", | ||
"geometry": message["geometry"], | ||
"properties": { | ||
"observation": message["properties"]["content"]["value"], | ||
"CF_standard_name": message["properties"]["content"]["standard_name"], | ||
"unit": message["properties"]["content"]["unit"], | ||
}, | ||
}, | ||
separators=(",", ":"), | ||
), | ||
unit=message["properties"]["content"]["unit"], | ||
encoding="utf-8", | ||
), | ||
), | ||
links=( | ||
[ | ||
Link( | ||
href=get_api_timeseries_query(message["properties"]["platform"], request_url), | ||
rel="canonical", | ||
type="application/prs.coverage+json", | ||
) | ||
] | ||
) | ||
+ (lambda x: x if x else [])(message["links"]), | ||
) | ||
|
||
return wis2_payload |
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
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
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
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.