forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter stops by current service week
- Loading branch information
1 parent
15a5bd2
commit 5f3cd3a
Showing
5 changed files
with
67 additions
and
17 deletions.
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
31 changes: 31 additions & 0 deletions
31
src/ext/java/org/opentripplanner/ext/vectortiles/layers/stops/Predicates.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.vectortiles.layers.stops; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalDate; | ||
import java.time.temporal.TemporalAdjusters; | ||
import java.util.function.Predicate; | ||
import org.opentripplanner.apis.gtfs.PatternByServiceDatesFilter; | ||
import org.opentripplanner.apis.gtfs.model.LocalDateRange; | ||
import org.opentripplanner.transit.model.site.RegularStop; | ||
import org.opentripplanner.transit.service.TransitService; | ||
|
||
public class Predicates { | ||
|
||
public static final Predicate<RegularStop> NO_FILTER = x -> true; | ||
|
||
public static Predicate<RegularStop> currentServiceWeek(TransitService transitService) { | ||
var serviceDate = LocalDate.now(transitService.getTimeZone()); | ||
var lastSunday = serviceDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)); | ||
var nextSunday = serviceDate.with(TemporalAdjusters.next(DayOfWeek.SUNDAY)).plusDays(1); | ||
var filter = new PatternByServiceDatesFilter( | ||
new LocalDateRange(lastSunday, nextSunday), | ||
transitService | ||
); | ||
|
||
return regularStop -> { | ||
var patterns = transitService.getPatternsForStop(regularStop); | ||
var patternsInCurrentWeek = filter.filterPatterns(patterns); | ||
return !patternsInCurrentWeek.isEmpty(); | ||
}; | ||
} | ||
} |
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