Skip to content

Commit

Permalink
feat: log stats on traffic data matching
Browse files Browse the repository at this point in the history
  • Loading branch information
aoles committed Jan 11, 2024
1 parent 9463605 commit 51c247c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ RELEASING:
- spring-boot-starter-parent to v3.1.6 ([#1630](https://github.com/GIScience/openrouteservice/issues/1630))
- silence traffic map-matching internal errors ([#1635](https://github.com/GIScience/openrouteservice/pulls/1635))
- fix IN1-JAVA-ORGMOZILLA-1314295 ([#1627](https://github.com/GIScience/openrouteservice/issues/1627))
- log summary stats of traffic mapmatching and use progress bar only in debug mode ([#1647](https://github.com/GIScience/openrouteservice/pull/1647))

### Deprecated
- JSON configuration and related classes ([#1506](https://github.com/GIScience/openrouteservice/pull/1506))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,13 @@ public void setMaxTrafficSpeeds() {
}
}

/**
* @return number of processed traffic patterns
*/
public int getPatternCount() {
return patternCount;
}

public void setZoneId(ZoneId zoneId) {
this.zoneId = zoneId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import com.graphhopper.storage.GraphExtension;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.FetchMode;
import me.tongfei.progressbar.DelegatingProgressBarConsumer;
import me.tongfei.progressbar.ProgressBar;
import me.tongfei.progressbar.ProgressBarBuilder;
import org.apache.log4j.Logger;
import org.geotools.data.DataUtilities;
import org.geotools.feature.DefaultFeatureCollection;
Expand Down Expand Up @@ -87,6 +85,7 @@ public class HereTrafficGraphStorageBuilder extends AbstractGraphStorageBuilder
private TrafficEdgeFilter trafficEdgeFilter;
private final IntHashSet matchedHereLinks = new IntHashSet();
private final ArrayList<String> matchedOSMLinks = new ArrayList<>();
private boolean showProgressBar;

/**
* Initialize the Here Traffic graph extension <br/><br/>
Expand Down Expand Up @@ -139,6 +138,7 @@ public GraphExtension init(GraphHopper graphhopper) throws UnsupportedOperationE

gh = graphhopper;
mMapMatcher = new GhMapMatcher(graphhopper, parameters.get("gh_profile"));
showProgressBar = LOGGER.isDebugEnabled();
return storage;
}

Expand Down Expand Up @@ -257,6 +257,10 @@ public void addHereSegmentForLogging(Integer linkID) {
matchedHereLinks.add(linkID);
}

private int getMatchedHereLinksCount() {
return matchedHereLinks.size();
}

public void addOSMGeometryForLogging(String osmGeometry) {
matchedOSMLinks.add(osmGeometry);
}
Expand Down Expand Up @@ -309,25 +313,36 @@ public void postProcess(ORSGraphHopper graphHopper) throws SchemaException {
}

private void processTrafficPatterns(IntObjectHashMap<TrafficPattern> patterns) {
try (ProgressBar pb = new ProgressBarBuilder().setTaskName("Processing traffic patterns").setInitialMax(patterns.values().size()).setConsumer(new DelegatingProgressBarConsumer(LOGGER::debug)).build()) {
try {
ProgressBar pb = null;
if (showProgressBar)
pb = new ProgressBar("Processing traffic patterns", patterns.values().size());
for (ObjectCursor<TrafficPattern> pattern : patterns.values()) {
storage.setTrafficPatterns(pattern.value.getPatternId(), pattern.value.getValues());
pb.step();
if (showProgressBar)
pb.step();
}
LOGGER.info("Processed " + storage.getPatternCount() + " traffic patterns");
} catch (Exception e) {
LOGGER.error("Error processing here traffic patterns with error: " + e);
}
}

private void processLinks(ORSGraphHopper graphHopper, IntObjectHashMap<TrafficLink> links) {
try (ProgressBar pb = new ProgressBarBuilder().setTaskName("Matching Here Links").setInitialMax(links.values().size()).setConsumer(new DelegatingProgressBarConsumer(LOGGER::debug)).build()) {
int trafficLinksCount = links.values().size();
try {
ProgressBar pb = null;
if (showProgressBar)
pb = new ProgressBar("Matching Here Links", trafficLinksCount);
int counter = 0;
int step = trafficLinksCount / 100 + ((trafficLinksCount % 100 == 0) ? 0 : 1);
for (ObjectCursor<TrafficLink> trafficLink : links.values()) {
counter++;
processLink(graphHopper, trafficLink.value);
counter += 1;
if (counter % 2000 == 0)
pb.stepBy(2000);
if (showProgressBar && counter % step == 0)
pb.stepBy(step);
}
LOGGER.info("Matched " + 100 * getMatchedHereLinksCount()/trafficLinksCount + "% Here links (" + getMatchedHereLinksCount() + " out of " + trafficLinksCount + ")");
} catch (Exception e) {
LOGGER.error("Error processing here traffic links with error: " + e);
}
Expand Down Expand Up @@ -376,10 +391,10 @@ private void processSegment(GraphHopper gh, Map<TrafficEnums.WeekDay, Integer> t
}
final int priority = (int) Math.round(edge.getDistance() / gh.getGraphHopperStorage().getEdgeIteratorStateForKey(originalEdgeKey).getDistance() * 255);
trafficPatternIds.forEach((weekDay, patternId) -> storage.setEdgeIdTrafficPatternLookup(originalEdgeKey, patternId, weekDay, priority));
addHereSegmentForLogging(trafficLinkId);
if (outputLog) {
LineString lineString = edge.fetchWayGeometry(FetchMode.ALL).toLineString(false);
addOSMGeometryForLogging(lineString.toString());
addHereSegmentForLogging(trafficLinkId);
}
}
}
Expand Down

0 comments on commit 51c247c

Please sign in to comment.