Skip to content

Commit

Permalink
Realtime stop layer checks for existing stoptimes
Browse files Browse the repository at this point in the history
  • Loading branch information
sharhio committed May 22, 2024
1 parent fe41603 commit ca7e2a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void setUp() {
.withName(name)
.withDescription(desc)
.withCoordinate(50, 10)
.withTimeZone(ZoneIds.HELSINKI)
.build();
stop2 =
StopModel
Expand All @@ -54,6 +55,7 @@ public void setUp() {
.withName(name)
.withDescription(desc)
.withCoordinate(51, 10)
.withTimeZone(ZoneIds.HELSINKI)
.build();
}

Expand Down Expand Up @@ -100,5 +102,6 @@ public TransitAlertService getTransitAlertService() {
assertEquals("name", map.get("name"));
assertEquals("desc", map.get("desc"));
assertEquals(true, map.get("closedByServiceAlert"));
assertEquals(true, map.get("noServiceOnServiceDay"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import static org.opentripplanner.ext.vectortiles.layers.stops.DigitransitStopPropertyMapper.getBaseKeyValues;

import java.time.Instant;
import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import org.opentripplanner.apis.support.mapping.PropertyMapper;
import org.opentripplanner.framework.collection.ListUtils;
import org.opentripplanner.framework.i18n.I18NStringMapper;
import org.opentripplanner.inspector.vector.KeyValue;
import org.opentripplanner.routing.stoptimes.ArrivalDeparture;
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.service.TransitService;

Expand All @@ -32,10 +34,19 @@ protected Collection<KeyValue> map(RegularStop stop) {
.stream()
.anyMatch(alert -> alert.noServiceAt(currentTime));

var serviceDate = LocalDate.ofInstant(currentTime, transitService.getTimeZone());
boolean stopTimesExist = transitService
.getStopTimesForStop(stop, serviceDate, ArrivalDeparture.BOTH, true)
.stream()
.anyMatch(stopTime -> stopTime.times.size() > 0);

Collection<KeyValue> sharedKeyValues = getBaseKeyValues(stop, i18NStringMapper, transitService);
return ListUtils.combine(
sharedKeyValues,
List.of(new KeyValue("closedByServiceAlert", noServiceAlert))
List.of(
new KeyValue("closedByServiceAlert", noServiceAlert),
new KeyValue("noServiceOnServiceDay", !stopTimesExist)
)
);
}
}

0 comments on commit ca7e2a1

Please sign in to comment.