calculate surface, class and smoothness route statistics

This commit is contained in:
evgenij27 2018-10-26 19:07:14 +03:00
parent 91361c1dde
commit 8fb2280e2e
5 changed files with 153 additions and 64 deletions

View file

@ -204,6 +204,15 @@ public class RoutePlannerFrontEnd {
makeStartEndPointsPrecise(res, start, end, intermediates);
if (res != null) {
new RouteResultPreparation().printResults(ctx, start, end, res);
RouteStatistics routeStatistics = RouteStatistics.calculate(res);
System.out.println("Smoothness");
System.out.println(routeStatistics.getRouteSmoothnessStatistic());
System.out.println("Surface");
System.out.println(routeStatistics.getRouteSurfaceStatistic());
System.out.println("Highway");
System.out.println(routeStatistics.getRouteClassStatistic());
}
return res;
}

View file

@ -10,10 +10,8 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapIndexReader;
@ -37,7 +35,6 @@ public class RouteResultPreparation {
public static String PRINT_TO_GPX_FILE = null;
private static final float TURN_DEGREE_MIN = 45;
public static final int SHIFT_ID = 6;
private static final String UNDEFINED_ROAD_SURFACE = "undefined";
private Log log = PlatformUtil.getLog(RouteResultPreparation.class);
/**
* Helper method to prepare final result
@ -1722,25 +1719,5 @@ public class RouteResultPreparation {
MapUtils.get31LatitudeY(y2), MapUtils.get31LongitudeX(x2));
}
public List<RouteSegmentSurface> splitBySurfaceType(List<RouteSegmentResult> segments) {
int index = 0;
List<RouteSegmentSurface> routeSurfaces = new ArrayList<>();
String prevSurface = null;
for (RouteSegmentResult segment : segments) {
String currentSurface = segment.getSurface();
if (currentSurface == null) {
currentSurface = UNDEFINED_ROAD_SURFACE;
}
if (prevSurface != null && !prevSurface.equals(currentSurface)) {
index++;
}
if (index >= routeSurfaces.size()) {
routeSurfaces.add(new RouteSegmentSurface(index, currentSurface));
}
RouteSegmentSurface surface = routeSurfaces.get(index);
surface.incrementDistanceBy(segment.getDistance());
prevSurface = currentSurface;
}
return routeSurfaces;
}
}

View file

@ -221,4 +221,12 @@ public class RouteSegmentResult {
public String getSurface() {
return object.getValue("surface");
}
public String getSmoothness() {
return object.getValue("smoothness");
}
public String getHighway() {
return object.getHighway();
}
}

View file

@ -1,40 +0,0 @@
package net.osmand.router;
public class RouteSegmentSurface {
private final int index;
private final String surface;
private float distance;
public RouteSegmentSurface(int index, String surface) {
this.index = index;
this.surface = surface;
}
public int getIndex() {
return index;
}
public String getSurface() {
return surface;
}
public float getDistance() {
return distance;
}
public void incrementDistanceBy(float distance) {
this.distance += distance;
}
@Override
public String toString() {
return "{" +
"index=" + index +
", surface='" + surface + '\'' +
", distance=" + distance +
'}';
}
}

View file

@ -0,0 +1,135 @@
package net.osmand.router;
import java.util.ArrayList;
import java.util.List;
public class RouteStatistics {
private static final String UNDEFINED = "undefined";
private final List<RouteSegmentAttribute> routeSurfaceStatistic;
private final List<RouteSegmentAttribute> routeSmoothnessStatistic;
private final List<RouteSegmentAttribute> routeClassStatistic;
public RouteStatistics(List<RouteSegmentAttribute> routeSurfaceStatistic,
List<RouteSegmentAttribute> routeSmoothnessStatistic,
List<RouteSegmentAttribute> routeClassStatistic) {
this.routeSurfaceStatistic = routeSurfaceStatistic;
this.routeSmoothnessStatistic = routeSmoothnessStatistic;
this.routeClassStatistic = routeClassStatistic;
}
public static RouteStatistics calculate(List<RouteSegmentResult> route) {
RouteStatisticComputer routeSurfaceStatisticComputer = new RouteSegmentSurfaceStatisticComputer();
RouteStatisticComputer routeSmoothnessStatisticComputer = new RouteSegmentSmoothnessStatisticComputer();
RouteStatisticComputer routeClassStatisticComputer = new RouteSegmentClassStatisticComputer();
return new RouteStatistics(routeSurfaceStatisticComputer.computeStatistic(route),
routeSmoothnessStatisticComputer.computeStatistic(route),
routeClassStatisticComputer.computeStatistic(route));
}
public List<RouteSegmentAttribute> getRouteSurfaceStatistic() {
return routeSurfaceStatistic;
}
public List<RouteSegmentAttribute> getRouteSmoothnessStatistic() {
return routeSmoothnessStatistic;
}
public List<RouteSegmentAttribute> getRouteClassStatistic() {
return routeClassStatistic;
}
private abstract static class RouteStatisticComputer {
protected List<RouteSegmentAttribute> computeStatistic(List<RouteSegmentResult> segments) {
int index = 0;
List<RouteSegmentAttribute> routeSurfaces = new ArrayList<>();
String prev = null;
for (RouteSegmentResult segment : segments) {
String current = getAttribute(segment);
if (current == null) {
current = UNDEFINED;
}
if (prev != null && !prev.equals(current)) {
index++;
}
if (index >= routeSurfaces.size()) {
routeSurfaces.add(new RouteSegmentAttribute(index, current));
}
RouteSegmentAttribute surface = routeSurfaces.get(index);
surface.incrementDistanceBy(segment.getDistance());
prev = current;
}
return routeSurfaces;
}
public abstract String getAttribute(RouteSegmentResult segment);
}
private static class RouteSegmentSurfaceStatisticComputer extends RouteStatisticComputer {
@Override
public String getAttribute(RouteSegmentResult segment) {
return segment.getSurface();
}
}
private static class RouteSegmentSmoothnessStatisticComputer extends RouteStatisticComputer {
@Override
public String getAttribute(RouteSegmentResult segment) {
return segment.getSmoothness();
}
}
private static class RouteSegmentClassStatisticComputer extends RouteStatisticComputer {
@Override
public String getAttribute(RouteSegmentResult segment) {
return segment.getHighway();
}
}
public static class RouteSegmentAttribute {
private final int index;
private final String attribute;
private float distance;
public RouteSegmentAttribute(int index, String attribute) {
this.index = index;
this.attribute = attribute;
}
public int getIndex() {
return index;
}
public String getAttribute() {
return attribute;
}
public float getDistance() {
return distance;
}
public void incrementDistanceBy(float distance) {
this.distance += distance;
}
@Override
public String toString() {
return "{" +
"index=" + index +
", attribute='" + attribute + '\'' +
", distance=" + distance +
'}';
}
}
}