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

[Jormungandr] Manage address within zones in journeys #4071

Merged
merged 8 commits into from
Jul 19, 2023

Conversation

azime
Copy link
Contributor

@azime azime commented Jul 17, 2023

Jira: NAV-2158

From = coord in Poi shape (Jardin du Luxembourg (Paris))
image

From=POI (Jardin du Luxembourg (Paris))
image

@sonarcloud
Copy link

sonarcloud bot commented Jul 18, 2023

Please retry analysis of this Pull-Request directly on SonarCloud.

@sonarcloud
Copy link

sonarcloud bot commented Jul 19, 2023

Please retry analysis of this Pull-Request directly on SonarCloud.

Copy link
Contributor

@woshilapin woshilapin left a comment

Choose a reason for hiding this comment

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

As discussed together, the code is fine. All of my comments are only suggestions to try to make the code more maintainable in the long term.

Comment on lines 500 to 501
if MAP_STRING_PTOBJECT_TYPE.get(dict_pt_object.get("embedded_type")) != type_pb2.ADDRESS:
return dict_pt_object
Copy link
Contributor

Choose a reason for hiding this comment

The 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
if MAP_STRING_PTOBJECT_TYPE.get(dict_pt_object.get("embedded_type")) != type_pb2.ADDRESS:
return dict_pt_object
if MAP_STRING_PTOBJECT_TYPE.get(dict_pt_object.get("embedded_type")) == type_pb2.ADDRESS:
replace_address_with_custom_poi(dict_pt_object, uri)
else:
return dict_pt_object

All the code below would go in the new function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return None
if MAP_STRING_PTOBJECT_TYPE.get(dict_pt_object.get("embedded_type")) != type_pb2.ADDRESS:
return dict_pt_object
first_within_zone = next(
Copy link
Contributor

Choose a reason for hiding this comment

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

You could rename this new_poi to express better the fact that we're actually creating a new object (based on an existing POI, but with custom coordinates).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 516 to 517
first_within_zone["poi"]["coord"]["lon"] = "{}".format(lon)
first_within_zone["poi"]["coord"]["lat"] = "{}".format(lat)
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

# We're putting back the coordinate of the end-user, who is in a POI area (with entrypoints).
# If we don't, barycenter of the POI area will be displayed which means nothing for the end user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Done

@@ -494,6 +494,30 @@ def get_pt_object_from_json(dict_pt_object, instance):
return pt_object


def transform_entrypoint(dict_pt_object, uri):
Copy link
Contributor

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>:

  • improve
  • customize
  • replace
  • rectify

<names>:

  • entrypoint_detail
  • address (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: the from or the to)

None of them are really good, but I'm hoping to help find ideas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -494,6 +494,36 @@ def get_pt_object_from_json(dict_pt_object, instance):
return pt_object


def replace_address_with_custom_poi(dict_pt_object, uri):
new_poi = next(
Copy link
Member

Choose a reason for hiding this comment

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

my question may be pedantic:

could the address be included in more than one shape? if so, how could you be sure that the within_zones are sorted in a deterministic order?

Copy link
Contributor

Choose a reason for hiding this comment

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

On bragi, the within_zones are order by distance to the coordinate. See https://github.com/hove-io/mimirsbrunn/pull/849/files.

@sonarcloud
Copy link

sonarcloud bot commented Jul 19, 2023

Please retry analysis of this Pull-Request directly on SonarCloud.

@azime azime merged commit c6c21c4 into dev Jul 19, 2023
7 of 8 checks passed
@azime azime deleted the manage_address_within_zones_in_journeys branch July 19, 2023 13:29
@pbougue pbougue changed the title Manage address within zones in journeys [Jormungandr] Manage address within zones in journeys Aug 11, 2023
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.

3 participants