Skip to content

Commit

Permalink
refactor: Add logging of wholes in the stop-index.
Browse files Browse the repository at this point in the history
  • Loading branch information
t2gran committed Jul 3, 2024
1 parent 23f04a0 commit d6c9f6f
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.opentripplanner.transit.service;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Nullable;
import org.locationtech.jts.geom.Envelope;
import org.opentripplanner.framework.collection.CollectionsView;
import org.opentripplanner.framework.geometry.HashGridSpatialIndex;
Expand All @@ -12,6 +15,9 @@
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.model.site.Station;
import org.opentripplanner.transit.model.site.StopLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;

/**
* Indexed access to Stop entities.
Expand All @@ -20,6 +26,8 @@
*/
class StopModelIndex {

private static final Logger LOG = LoggerFactory.getLogger(StopModelIndex.class);

private final HashGridSpatialIndex<RegularStop> regularStopSpatialIndex = new HashGridSpatialIndex<>();
private final Map<Station, MultiModalStation> multiModalStationForStations = new HashMap<>();
private final HashGridSpatialIndex<AreaStop> locationIndex = new HashGridSpatialIndex<>();
Expand Down Expand Up @@ -58,6 +66,8 @@ class StopModelIndex {
// Trim the sizes of the indices
regularStopSpatialIndex.compact();
locationIndex.compact();

logWholesInIndex();
}

/**
Expand All @@ -71,6 +81,7 @@ MultiModalStation getMultiModalStationForStation(Station station) {
return multiModalStationForStations.get(station);
}

@Nullable
StopLocation stopByIndex(int index) {
return stopsByIndex[index];
}
Expand All @@ -82,4 +93,19 @@ int stopIndexSize() {
Collection<AreaStop> findAreaStops(Envelope envelope) {
return locationIndex.query(envelope);
}

/**
* A small number of wholes in the stop-index is ok, but if there are many, it will affect
* the Raptor performance.
*/
private void logWholesInIndex() {
int c = (int) Arrays.stream(stopsByIndex).filter(Objects::isNull).count();
if (c > 0) {
double p = (100.0 * c) / stopsByIndex.length;
// Log this as warning is more than 5% of the space is null
LOG
.atLevel(p >= 5.0 ? Level.WARN : Level.INFO)
.log("The stop index contains wholes in it. {} of {} is null.", c, stopsByIndex.length);
}
}
}

0 comments on commit d6c9f6f

Please sign in to comment.