This commit is contained in:
Victor Shcherb 2019-07-08 00:37:20 +02:00
parent 907b380433
commit 8232b8e998
2 changed files with 77 additions and 18 deletions

View file

@ -1,34 +1,42 @@
package net.osmand.router;
import gnu.trove.iterator.TIntIterator;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.set.hash.TIntHashSet;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import gnu.trove.iterator.TIntIterator;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.set.hash.TIntHashSet;
import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon;
import net.osmand.osm.MapRenderingTypes;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver;
import net.osmand.router.BinaryRoutePlanner.FinalRouteSegment;
import net.osmand.router.BinaryRoutePlanner.RouteSegment;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
import net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode;
import net.osmand.router.RouteStatisticsHelper.RouteStatistics;
import net.osmand.util.Algorithms;
import net.osmand.util.MapAlgorithms;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
public class RouteResultPreparation {
public static boolean PRINT_TO_CONSOLE_ROUTE_INFORMATION_TO_TEST = false;
@ -603,6 +611,52 @@ public class RouteResultPreparation {
}
println("</test>");
println(msg);
// calculateStatistics(result);
}
private void calculateStatistics(List<RouteSegmentResult> result) {
InputStream is = RenderingRulesStorage.class.getResourceAsStream("default.render.xml");
final Map<String, String> renderingConstants = new LinkedHashMap<String, String>();
try {
InputStream pis = RenderingRulesStorage.class.getResourceAsStream("default.render.xml");
try {
XmlPullParser parser = PlatformUtil.newXMLPullParser();
parser.setInput(pis, "UTF-8");
int tok;
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (tok == XmlPullParser.START_TAG) {
String tagName = parser.getName();
if (tagName.equals("renderingConstant")) {
if (!renderingConstants.containsKey(parser.getAttributeValue("", "name"))) {
renderingConstants.put(parser.getAttributeValue("", "name"),
parser.getAttributeValue("", "value"));
}
}
}
}
} finally {
pis.close();
}
RenderingRulesStorage rrs = new RenderingRulesStorage("default", renderingConstants);
rrs.parseRulesFromXmlInputStream(is, new RenderingRulesStorageResolver() {
@Override
public RenderingRulesStorage resolve(String name, RenderingRulesStorageResolver ref)
throws XmlPullParserException, IOException {
throw new UnsupportedOperationException();
}
});
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
List<RouteStatistics> rsr = RouteStatisticsHelper.calculateRouteStatistic(result, null, rrs, null, req);
for(RouteStatistics r : rsr) {
System.out.println(r);
}
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
private void printAdditionalPointInfo(RouteSegmentResult res) {

View file

@ -32,7 +32,7 @@ public class RouteStatisticsHelper {
BOUNDARIES_CLASS[0] = "steepness=" + (MIN_INCLINE + 1) + "_" + MIN_DIVIDED_INCLINE;
for (int i = 1; i < NUM - 1; i++) {
BOUNDARIES_ARRAY[i] = MIN_DIVIDED_INCLINE + (i - 1) * STEP;
BOUNDARIES_CLASS[NUM - 1] = "steepness=" + (BOUNDARIES_ARRAY[i - 1] + 1) + "_" + BOUNDARIES_ARRAY[i];
BOUNDARIES_CLASS[i] = "steepness=" + (BOUNDARIES_ARRAY[i - 1] + 1) + "_" + BOUNDARIES_ARRAY[i];
}
BOUNDARIES_ARRAY[NUM - 1] = MAX_INCLINE;
BOUNDARIES_CLASS[NUM - 1] = "steepness="+MAX_DIVIDED_INCLINE+"_"+MAX_INCLINE;
@ -70,11 +70,13 @@ public class RouteStatisticsHelper {
RenderingRuleSearchRequest defaultSearchRequest) {
List<RouteSegmentWithIncline> routeSegmentWithInclines = calculateInclineRouteSegments(route);
List<String> attributeNames = new ArrayList<>();
if (currentRenderer != null) {
for (String s : currentRenderer.getRenderingAttributeNames()) {
if (s.startsWith("routeInfo_")) {
attributeNames.add(s);
}
}
}
if(attributeNames.isEmpty()) {
for (String s : defaultRenderer.getRenderingAttributeNames()) {
if (s.startsWith("routeInfo_")) {
@ -117,10 +119,11 @@ public class RouteStatisticsHelper {
float distCum = 0;
prevH = heightValues[1];
incl.h = prevH ;
if(incl.interpolatedHeightByStep.length > indStep) {
if(incl.interpolatedHeightByStep != null && incl.interpolatedHeightByStep.length > indStep) {
incl.interpolatedHeightByStep[indStep++] = prevH;
}
while(indStep < incl.interpolatedHeightByStep.length && indH < heightValues.length) {
while(incl.interpolatedHeightByStep != null &&
indStep < incl.interpolatedHeightByStep.length && indH < heightValues.length) {
float dist = heightValues[indH] + distCum;
if(dist > indStep * H_STEP) {
if(dist == distCum) {
@ -141,7 +144,8 @@ public class RouteStatisticsHelper {
} else {
incl.h = prevH;
}
while(indStep < incl.interpolatedHeightByStep.length) {
while(incl.interpolatedHeightByStep != null &&
indStep < incl.interpolatedHeightByStep.length) {
incl.interpolatedHeightByStep[indStep++] = prevH;
}
prevHeight = prevH;
@ -191,10 +195,10 @@ public class RouteStatisticsHelper {
rswi.slopeClassUserString = new String[rswi.slopeByStep.length];
for (int t = 0; t < rswi.slopeClass.length; t++) {
for (int k = 0; k < BOUNDARIES_ARRAY.length - 1; k++) {
for (int k = 0; k < BOUNDARIES_ARRAY.length; k++) {
if (rswi.slopeByStep[t] <= BOUNDARIES_ARRAY[k] || k == BOUNDARIES_ARRAY.length - 1) {
rswi.slopeClass[k] = BOUNDARIES_CLASS[k];
rswi.slopeClassUserString[k] = classFormattedStrings[k];
rswi.slopeClass[t] = BOUNDARIES_CLASS[k];
rswi.slopeClassUserString[t] = classFormattedStrings[k];
break;
}
}
@ -297,8 +301,9 @@ public class RouteStatisticsHelper {
public RouteSegmentAttribute classifySegment(String attribute, String slopeClass, RouteSegmentWithIncline segment) {
RouteSegmentAttribute res = new RouteSegmentAttribute(UNDEFINED_ATTR, 0);
RenderingRuleSearchRequest currentRequest = new RenderingRuleSearchRequest(currentRenderingRuleSearchRequest);
if (searchRenderingAttribute(attribute, currentRenderer, currentRequest, segment, slopeClass)) {
RenderingRuleSearchRequest currentRequest =
currentRenderer == null ? null : new RenderingRuleSearchRequest(currentRenderingRuleSearchRequest);
if (currentRenderer != null && searchRenderingAttribute(attribute, currentRenderer, currentRequest, segment, slopeClass)) {
res = new RouteSegmentAttribute(currentRequest.getStringPropertyValue(currentRenderer.PROPS.R_ATTR_STRING_VALUE),
currentRequest.getIntPropertyValue(currentRenderer.PROPS.R_ATTR_COLOR_VALUE));
} else {