-
Notifications
You must be signed in to change notification settings - Fork 126
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
[Jormungandr] Manage address within zones in journeys #4071
Changes from 7 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -494,6 +494,30 @@ def get_pt_object_from_json(dict_pt_object, instance): | |||||||||||||
return pt_object | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def transform_entrypoint(dict_pt_object, uri): | ||||||||||||||
if not dict_pt_object: | ||||||||||||||
return None | ||||||||||||||
if MAP_STRING_PTOBJECT_TYPE.get(dict_pt_object.get("embedded_type")) != type_pb2.ADDRESS: | ||||||||||||||
return dict_pt_object | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if you should have a second sub-function here. The goal of a sub-function is for documentation. Since the sub-function also has a name, it helps to understand a sub-part of the code.
Suggested change
All the code below would go in the new function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||||||
first_within_zone = next( | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could rename this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||||||
( | ||||||||||||||
wz | ||||||||||||||
for wz in dict_pt_object.get("within_zones", []) | ||||||||||||||
if MAP_STRING_PTOBJECT_TYPE.get(wz.get("embedded_type")) == type_pb2.POI | ||||||||||||||
and wz.get("poi", {}).get("children", []) | ||||||||||||||
), | ||||||||||||||
None, | ||||||||||||||
) | ||||||||||||||
if not first_within_zone: | ||||||||||||||
return dict_pt_object | ||||||||||||||
if not is_coord(uri): | ||||||||||||||
return dict_pt_object | ||||||||||||||
lon, lat = get_lon_lat(uri) | ||||||||||||||
first_within_zone["poi"]["coord"]["lon"] = "{}".format(lon) | ||||||||||||||
first_within_zone["poi"]["coord"]["lat"] = "{}".format(lat) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would put a comment here to express why we're changing the coordinate. Here is a suggestion.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Done |
||||||||||||||
return first_within_zone | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def json_address_from_uri(uri): | ||||||||||||||
if is_coord(uri): | ||||||||||||||
lon, lat = get_lon_lat(uri) | ||||||||||||||
|
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 can't find a good name for this function... but I'd say we should try to find another name. Here are suggestions for brainstorming, maybe you will find other ideas?
Building the name of the function with this shape.
<verb>_<name>
<verbs>
:<names>
:replace_address
for example)other ideas:
rectify_entrypoint_with_uri
entrypoint_uri_refocus
(I kind of like this one, we're changing back the entrypoint to refocus on the end-user information: thefrom
or theto
)None of them are really good, but I'm hoping to help find ideas.
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.
Done