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

📍 Use the server-side geocoded addresses for place names #1166

Merged
merged 1 commit into from
Aug 24, 2024

Conversation

JGreenlee
Copy link
Collaborator

@JGreenlee JGreenlee commented Aug 19, 2024

Since the server now fills in geocoded_address (we may later change this to reverse_geocode), we will only need to perform a client-side nominatim request for unprocessed trips. If either field is present, we'll use that; otherwise schedule a request like before.

Updated types:

-Since the CompositeTrip type definition is based on the return type of Timeline.readAllCompositeTrips, which is after "unpacking", start_confirmed_place and end_confirmed_place are simply ConfirmedPlace, not BEMData<ConfirmedPlace>
-ConfirmedPlace.location is a Point, (having coordinates) not just a generic Geometry
-added geocoded_address and reverse_geocode, both optional since it depends on e-mission/e-mission-server#973

Since the server now fills in geocoded_address (we may later change this to reverse_geocode), we will only need to perform a client-side nominatim request for unprocessed trips.
If either field is present, we'll use that; otherwise schedule a request like before.

Updated types:

-Since the CompositeTrip type definition is based on the return type of Timeline.readAllCompositeTrips, which is after "unpacking", start_confirmed_place and end_confirmed_place are simply ConfirmedPlace, not BEMData<ConfirmedPlace>
-ConfirmedPlace.location is a `Point`, (having `coordinates`) not just a generic `Geometry`
-added geocoded_address and reverse_geocode, both as optional since it depends on e-mission/e-mission-server#973
@JGreenlee
Copy link
Collaborator Author

This PR works with either geocoded_address or reverse_geojson.
If this is merged before e-mission/e-mission-server#973 is merged, it will switch over seamlessly.

If e-mission/e-mission-server#973 is merged first, I can update this PR to only use reverse_geojson

@JGreenlee JGreenlee marked this pull request as ready for review August 19, 2024 16:51
@JGreenlee JGreenlee changed the title Use the server-side geocoded addresses for place names 📍 Use the server-side geocoded addresses for place names Aug 19, 2024
@shankari
Copy link
Contributor

I can merge e-mission/e-mission-server#973 soon. I am just waiting to merge the automatic build PRs (e.g. e-mission/op-admin-dashboard#113) so that I could see it work! All the public PRs are merged, the internal ones need to be fixed @MukuFlash03

@shankari
Copy link
Contributor

Note that even after e-mission/e-mission-server#973 is merged, the older trips will still have only the geocoded_address field. You need to update this PR to check for reverse_geocode and then for geocoded_address and then fall back to looking it up.

We should then also write a migration script to copy over all of the geocoded_address into reverse_geocode so that we have all the info we need for the footprint calculations. It may be a bit tricky because the geocoded_address doesn't actually have all the info we need for the carbon footprint calculations, and so we probably have to look it up again. Hopefully we get the same result as before, but if we don't, we have to likely use the new version. I don't think it will affect the calculation outputs because the census tract is unlikely to have changed in the interim.

@JGreenlee
Copy link
Collaborator Author

You need to update this PR to check for reverse_geocode and then for geocoded_address and then fall back to looking it up.

That is what this PR already does because I anticipated that we may need to support both fields.

We should then also write a migration script to copy over all of the geocoded_address into reverse_geocode so that we have all the info we need for the footprint calculations.

Actually, this no longer has anything to do with the footprint calculations. I wanted to use the zip codes, but they aren't reliable enough. Sometimes they are missing from the response, and sometimes there isn't a clear mapping to the urban area or eGRID region.

I do think we should write the migration script, but it isn't blocking footprint calculations if we are ok with having both fields temporarily.

@shankari
Copy link
Contributor

Ah I am clearly not on top of the changes to the carbon footprint calculations.

Copy link
Contributor

@shankari shankari left a comment

Choose a reason for hiding this comment

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

My comments are just requests for clarification to help me better understand this.

Comment on lines +162 to +164
const data = place.reverse_geocode || { address: place.geocoded_address };
localStorage.setItem(coordsStr, JSON.stringify(data));
publish(coordsStr, JSON.stringify(data));
Copy link
Contributor

Choose a reason for hiding this comment

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

nice! great idea to reuse the data from prior mappings even for trips that don't have the address instead of looking it up.

@@ -96,7 +102,7 @@ export type CompositeTrip = {
confirmed_trip: ObjectId;
distance: number;
duration: number;
end_confirmed_place: BEMData<ConfirmedPlace>;
end_confirmed_place: ConfirmedPlace;
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious about what this change does. Why did we have BEMData before and why don't we need it now?

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 was just incorrect. I noticed because Typescript complained when I accessed properties on the place objects while making the changes

Updated types:

-Since the CompositeTrip type definition is based on the return type of Timeline.readAllCompositeTrips, which is after "unpacking", start_confirmed_place and end_confirmed_place are simply ConfirmedPlace, not BEMData
-ConfirmedPlace.location is a Point, (having coordinates) not just a generic Geometry
-added geocoded_address and reverse_geocode, both as optional since it depends on e-mission/e-mission-server#973

@shankari shankari merged commit d1c9646 into e-mission:master Aug 24, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants