-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Cluster consolidated stops in geocoder #5907
Merged
leonardehrenfried
merged 13 commits into
opentripplanner:dev-2.x
from
ibi-group:cluster-consolidated-stops
Jul 29, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
baa1a75
Create geocoder with Dagger
leonardehrenfried f554b8f
Add lucene index to OTP server context
leonardehrenfried 9e21b04
Wire up Geocoder with Dagger
leonardehrenfried 5a7b2ef
Add consolidated stops to geocoder
leonardehrenfried d826aeb
Filter nullable codes
leonardehrenfried ba12693
Remove logging
leonardehrenfried 8258a1e
Add Google's truth test assertion library, add test
leonardehrenfried 6755cbc
Update Javadoc
leonardehrenfried 4bbe43e
Re-add backwards-compatibility
leonardehrenfried a714a53
Inject transit model instead of transit service
leonardehrenfried 29a750d
Add comment
leonardehrenfried 9b17f97
Remove trailing and leading whitespace
leonardehrenfried f95fd60
Add comment about unusal instantiation of DefaultTransitService
leonardehrenfried 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
57 changes: 57 additions & 0 deletions
57
src/ext-test/java/org/opentripplanner/ext/geocoder/StopClusterMapperTest.java
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 @@ | ||
package org.opentripplanner.ext.geocoder; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner.ext.stopconsolidation.internal.DefaultStopConsolidationRepository; | ||
import org.opentripplanner.ext.stopconsolidation.internal.DefaultStopConsolidationService; | ||
import org.opentripplanner.ext.stopconsolidation.model.ConsolidatedStopGroup; | ||
import org.opentripplanner.transit.model._data.TransitModelForTest; | ||
import org.opentripplanner.transit.model.framework.Deduplicator; | ||
import org.opentripplanner.transit.model.site.RegularStop; | ||
import org.opentripplanner.transit.model.site.StopLocation; | ||
import org.opentripplanner.transit.service.DefaultTransitService; | ||
import org.opentripplanner.transit.service.StopModel; | ||
import org.opentripplanner.transit.service.TransitModel; | ||
|
||
class StopClusterMapperTest { | ||
|
||
private static final TransitModelForTest TEST_MODEL = TransitModelForTest.of(); | ||
private static final RegularStop STOP_A = TEST_MODEL.stop("A").build(); | ||
private static final RegularStop STOP_B = TEST_MODEL.stop("B").build(); | ||
private static final RegularStop STOP_C = TEST_MODEL.stop("C").build(); | ||
private static final List<RegularStop> STOPS = List.of(STOP_A, STOP_B, STOP_C); | ||
private static final StopModel STOP_MODEL = TEST_MODEL | ||
.stopModelBuilder() | ||
.withRegularStops(STOPS) | ||
.build(); | ||
private static final TransitModel TRANSIT_MODEL = new TransitModel( | ||
STOP_MODEL, | ||
new Deduplicator() | ||
); | ||
private static final List<StopLocation> LOCATIONS = STOPS | ||
.stream() | ||
.map(StopLocation.class::cast) | ||
.toList(); | ||
|
||
@Test | ||
void clusterConsolidatedStops() { | ||
var repo = new DefaultStopConsolidationRepository(); | ||
repo.addGroups(List.of(new ConsolidatedStopGroup(STOP_A.getId(), List.of(STOP_B.getId())))); | ||
|
||
var service = new DefaultStopConsolidationService(repo, TRANSIT_MODEL); | ||
var mapper = new StopClusterMapper(new DefaultTransitService(TRANSIT_MODEL), service); | ||
|
||
var clusters = mapper.generateStopClusters(LOCATIONS, List.of()); | ||
|
||
var expected = new LuceneStopCluster( | ||
STOP_A.getId().toString(), | ||
List.of(STOP_B.getId().toString()), | ||
List.of(STOP_A.getName(), STOP_B.getName()), | ||
List.of(STOP_A.getCode(), STOP_B.getCode()), | ||
new StopCluster.Coordinate(STOP_A.getLat(), STOP_A.getLon()) | ||
); | ||
assertThat(clusters).contains(expected); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/ext/java/org/opentripplanner/ext/geocoder/configure/GeocoderModule.java
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,31 @@ | ||
package org.opentripplanner.ext.geocoder.configure; | ||
|
||
import dagger.Module; | ||
import dagger.Provides; | ||
import jakarta.inject.Singleton; | ||
import javax.annotation.Nullable; | ||
import org.opentripplanner.ext.geocoder.LuceneIndex; | ||
import org.opentripplanner.ext.stopconsolidation.StopConsolidationService; | ||
import org.opentripplanner.framework.application.OTPFeature; | ||
import org.opentripplanner.transit.service.TransitModel; | ||
|
||
/** | ||
* This module builds the Lucene geocoder based on whether the feature flag is on or off. | ||
*/ | ||
@Module | ||
public class GeocoderModule { | ||
|
||
@Provides | ||
@Singleton | ||
@Nullable | ||
LuceneIndex luceneIndex( | ||
TransitModel transitModel, | ||
@Nullable StopConsolidationService stopConsolidationService | ||
) { | ||
if (OTPFeature.SandboxAPIGeocoder.isOn()) { | ||
return new LuceneIndex(transitModel, stopConsolidationService); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
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.
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.
The transit service is request scoped, is the LuceneIndex request-scoped?
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.
No, it isn't and I've reworked this in the newest commits. However, I do need a few methods from TransitService. Is it ok to instantiate it myself or should I create my own wrapper around the TransitModel?