diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java index cad29d75e3..c0df50a35e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java @@ -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; } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java index cb208731e0..46996428e1 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteResultPreparation.java @@ -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 splitBySurfaceType(List segments) { - int index = 0; - List 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; - } + } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java index e993f0bea0..fae75bf21a 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java @@ -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(); + } } \ No newline at end of file diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentSurface.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentSurface.java deleted file mode 100644 index d6dda2a62f..0000000000 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentSurface.java +++ /dev/null @@ -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 + - '}'; - } -} diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteStatistics.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteStatistics.java new file mode 100644 index 0000000000..da57075c4e --- /dev/null +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteStatistics.java @@ -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 routeSurfaceStatistic; + private final List routeSmoothnessStatistic; + private final List routeClassStatistic; + + public RouteStatistics(List routeSurfaceStatistic, + List routeSmoothnessStatistic, + List routeClassStatistic) { + this.routeSurfaceStatistic = routeSurfaceStatistic; + this.routeSmoothnessStatistic = routeSmoothnessStatistic; + this.routeClassStatistic = routeClassStatistic; + } + + public static RouteStatistics calculate(List 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 getRouteSurfaceStatistic() { + return routeSurfaceStatistic; + } + + public List getRouteSmoothnessStatistic() { + return routeSmoothnessStatistic; + } + + public List getRouteClassStatistic() { + return routeClassStatistic; + } + + private abstract static class RouteStatisticComputer { + + protected List computeStatistic(List segments) { + int index = 0; + List 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 + + '}'; + } + } +}