From 7434c12b3198dfce53d7050fd3ca2fe380b94630 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Sun, 26 Feb 2023 13:02:39 +0100 Subject: [PATCH] change output rules --- .../src/main/java/btools/router/OsmTrack.java | 287 +++++++++++++++--- .../java/btools/router/RoutingContext.java | 2 + .../java/btools/router/RoutingEngine.java | 3 + 3 files changed, 254 insertions(+), 38 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/OsmTrack.java b/brouter-core/src/main/java/btools/router/OsmTrack.java index 2896b9d..fd36362 100644 --- a/brouter-core/src/main/java/btools/router/OsmTrack.java +++ b/brouter-core/src/main/java/btools/router/OsmTrack.java @@ -21,9 +21,13 @@ import java.io.InputStreamReader; import java.io.StringWriter; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.Map; +import java.util.TimeZone; import btools.mapaccess.MatchedWaypoint; import btools.mapaccess.OsmPos; @@ -45,6 +49,9 @@ public final class OsmTrack { public boolean showspeed; public boolean showSpeedProfile; + public boolean showTime; + + public Map params; public List pois = new ArrayList(); @@ -414,12 +421,14 @@ public final class OsmTrack { int turnInstructionMode = voiceHints != null ? voiceHints.turnInstructionMode : 0; sb.append("\n"); - for (int i = messageList.size() - 1; i >= 0; i--) { - String message = messageList.get(i); - if (i < messageList.size() - 1) - message = "(alt-index " + i + ": " + message + " )"; - if (message != null) - sb.append("\n"); + if (turnInstructionMode != 9) { + for (int i = messageList.size() - 1; i >= 0; i--) { + String message = messageList.get(i); + if (i < messageList.size() - 1) + message = "(alt-index " + i + ": " + message + " )"; + if (message != null) + sb.append("\n"); + } } if (turnInstructionMode == 4) // comment style @@ -436,8 +445,10 @@ public final class OsmTrack { sb.append("\n"); } - - if (turnInstructionMode == 3) // osmand style + if (turnInstructionMode == 9) { + sb.append(" \n"); + sb.append(" ").append(name).append("\n"); + sb.append(" \n"); + sb.append(" ").append(messageList.get(0)).append("\n"); + if (params != null && params.size() > 0) { + sb.append(" e : params.entrySet()) { + if (i++ != 0) sb.append("&"); + sb.append(e.getKey()).append("=").append(e.getValue()); + } + sb.append("]]>\n"); + } + sb.append(" \n"); + sb.append(" \n"); + } + if (turnInstructionMode == 3 || turnInstructionMode == 8) // osmand style, cruiser { float lastRteTime = 0; sb.append(" \n"); - sb.append(" \n") - .append(" start\n \n"); - float rteTime = getVoiceHintTime(0); - - if (rteTime != lastRteTime) // add timing only if available + StringBuffer first = new StringBuffer(); + // define start point { - double t = rteTime - lastRteTime; - sb.append(" \n"); - lastRteTime = rteTime; + first.append(" \n") + .append(" start\n \n"); + if (rteTime != lastRteTime) // add timing only if available + { + double t = rteTime - lastRteTime; + first.append(" \n"); + lastRteTime = rteTime; + } + first.append(" 0\n \n \n"); + } + if (turnInstructionMode == 8) { + if (matchedWaypoints.get(0).direct && voiceHints.list.get(0).indexInTrack == 0) { + // has a voice hint do nothing, voice hint will do + } else { + sb.append(first.toString()); + } + } else { + sb.append(first.toString()); } - sb.append(" 0\n \n \n"); for (int i = 0; i < voiceHints.list.size(); i++) { VoiceHint hint = voiceHints.list.get(i); sb.append(" \n") - .append(" ").append(hint.getMessageString()).append("\n \n"); + .append(" ") + .append(turnInstructionMode == 3 ? hint.getMessageString() : hint.getCruiserMessageString()) + .append("\n \n"); rteTime = getVoiceHintTime(i + 1); @@ -482,7 +522,9 @@ public final class OsmTrack { sb.append(" \n"); lastRteTime = rteTime; } - sb.append(" ").append(hint.getCommandString()).append("\n ").append("" + (int) hint.angle) + sb.append(" ") + .append(turnInstructionMode == 3 ? hint.getCommandString() : hint.getCruiserCommandString()) + .append("\n ").append("" + (int) hint.angle) .append("\n ").append("" + hint.indexInTrack).append("\n \n \n"); } sb.append(" \n"); } - if (turnInstructionMode == 2) // locus style + if (turnInstructionMode == 7) // old locus style { float lastRteTime = getVoiceHintTime(0); @@ -537,12 +579,12 @@ public final class OsmTrack { .append(formatILon(hint.ilon)).append("\">") .append(hint.selev == Short.MIN_VALUE ? "" : "" + (hint.selev / 4.) + "") .append("\n" + - "\n" + - "").append("" + hint.getOruxAction()) + " \n" + + " ").append("" + hint.getOruxAction()) .append("\n" + - "\n" + - "\n" + - ""); + " \n" + + " \n" + + " \n"); } } @@ -571,13 +613,14 @@ public final class OsmTrack { } } sb.append(" \n"); - sb.append(" ").append(name).append("\n"); - if (turnInstructionMode == 1) // trkpt/sym style - { + if (turnInstructionMode == 9) { // brouter style + sb.append(" ").append(name).append("\n"); sb.append(" ").append(voiceHints.getTransportMode()).append("\n"); + } else { + sb.append(" ").append(name).append("\n"); } - if (turnInstructionMode == 2) { + if (turnInstructionMode == 7) { sb.append(" \n"); sb.append(" ").append("" + voiceHints.getLocusRouteType()).append("\n"); sb.append(" 1\n"); @@ -585,20 +628,168 @@ public final class OsmTrack { } sb.append(" \n"); + String lastway = ""; + boolean bNextDirect = false; + OsmPathElement nn = null; + String aSpeed; for (int idx = 0; idx < nodes.size(); idx++) { OsmPathElement n = nodes.get(idx); String sele = n.getSElev() == Short.MIN_VALUE ? "" : "" + n.getElev() + ""; - if (turnInstructionMode == 1) // trkpt/sym style + VoiceHint hint = getVoiceHint(idx); + MatchedWaypoint mwpt = getMatchedWaypoint(idx); + + if (showTime) { + sele += ""; + } + + boolean bNeedHeader = false; + if (turnInstructionMode == 9 || turnInstructionMode == 2) // trkpt/sym style // locus style new { - for (VoiceHint hint : voiceHints.list) { - if (hint.indexInTrack == idx) { - sele += "" + hint.getCommandString() + ""; + if (hint != null) { + if (turnInstructionMode == 9) { + if (mwpt != null && !mwpt.name.startsWith("via")) { + sele += "" + mwpt.name + ""; + } + sele += "" + hint.getMessageString() + ""; + sele += "" + hint.getCommandString(hint.cmd) + ""; + sele += ""; + if (showspeed) { + double speed = 0; + if (nn != null) { + int dist = n.calcDistance(nn); + float dt = n.getTime() - nn.getTime(); + if (dt != 0.f) { + speed = ((3.6f * dist) / dt + 0.5); + } + } + sele += "" + (((int) (speed * 10)) / 10.f) + ""; + } + + sele += "" + hint.getCommandString() + ";" + (int) (hint.distanceToNext) + "," + hint.formatGeometry() + ""; + if (n.message != null && n.message.wayKeyValues != null && !n.message.wayKeyValues.equals(lastway)) { + sele += "" + n.message.wayKeyValues + ""; + lastway = n.message.wayKeyValues; + } + if (n.message != null && n.message.nodeKeyValues != null) { + sele += "" + n.message.nodeKeyValues + ""; + } + sele += ""; + } else if (turnInstructionMode == 2) { + sele += "" + hint.getLocusSymbolString() + ""; + } + } + if (idx == 0) { + if (turnInstructionMode == 2) { + int pos = sele.indexOf(""; + if (mwpt != null && mwpt.direct) { + bNextDirect = true; + } + sele += "pass_place"; + sele += "Via"; + } else { + if (mwpt != null && mwpt.direct) { + sele += "beeline"; + } else { + sele += "start"; + } + sele += "Via"; + } + } else if (idx == nodes.size() - 1) { + if (turnInstructionMode == 2) { + int pos = sele.indexOf(""; + if (bNextDirect) { + sele += "beeline"; + } + sele += "pass_place"; + sele += "Via"; + } else { + sele += "end"; + sele += "Via"; + } + } else if (turnInstructionMode == 2) { + if (mwpt != null) { + if (sele.contains("sym") && + !sele.contains("name") && + !mwpt.name.startsWith("via")) { + int pos = sele.indexOf("" + mwpt.name + "" + sele.substring(pos) + "Via"; + } else if (sele.contains("sym") && mwpt.name.startsWith("via")) { + sele += "Via"; + } else if (mwpt.direct && bNextDirect) { + sele += "beelinepass_placeShaping"; + bNextDirect = true; + } else if (mwpt.direct) { + sele += "pass_placeShaping"; + bNextDirect = true; + } else if (mwpt.name.startsWith("via")) { + if (bNextDirect) { + sele += "beelinepass_placeShaping"; + } else { + sele += "pass_placeShaping"; + } + bNextDirect = false; + } else { + sele += "" + mwpt.name + ""; + sele += "pass_placeVia"; + } + } + } else if (turnInstructionMode == 9) { + if (mwpt != null && hint == null) { + if (mwpt.direct) { + // bNextDirect = true; + sele += "beeline"; + } else { + sele += "" + mwpt.name + ""; + } + sele += "Via"; + bNextDirect = false; + } + } + + + if (turnInstructionMode == 9 && hint == null) { + bNeedHeader = (showspeed || (n.message != null && n.message.wayKeyValues != null && !n.message.wayKeyValues.equals(lastway))) || + (n.message != null && n.message.nodeKeyValues != null); + if (bNeedHeader) { + sele += ""; + if (showspeed) { + double speed = 0; + if (nn != null) { + int dist = n.calcDistance(nn); + float dt = n.getTime() - nn.getTime(); + if (dt != 0.f) { + speed = ((3.6f * dist) / dt + 0.5); + } + } + sele += "" + (((int) (speed * 10)) / 10.f) + ""; + } + if (n.message != null && n.message.wayKeyValues != null && !n.message.wayKeyValues.equals(lastway)) { + sele += "" + n.message.wayKeyValues + ""; + lastway = n.message.wayKeyValues; + } + if (n.message != null && n.message.nodeKeyValues != null) { + sele += "" + n.message.nodeKeyValues + ""; + } + sele += ""; } } } sb.append(" ").append(sele).append("\n"); + + nn = n; } sb.append(" \n"); @@ -921,6 +1112,18 @@ public final class OsmTrack { return time; } + SimpleDateFormat TIMESTAMP_FORMAT; + + public String getFormattedTime3(float time) { + if (TIMESTAMP_FORMAT == null) { + TIMESTAMP_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); + TIMESTAMP_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); + } + // yyyy-mm-ddThh:mm:ss.SSSZ + Date d = new Date((long) (time * 1000f)); + return TIMESTAMP_FORMAT.format(d); + } + public String getFormattedEnergy() { return format1(energy / 3600000.) + "kwh"; } @@ -1060,6 +1263,14 @@ public final class OsmTrack { input.indexInTrack = --nodeNr; input.goodWay = node.message; input.oldWay = node.origin.message == null ? node.message : node.origin.message; + if (rc.turnInstructionMode == 8) { + MatchedWaypoint mwpt = getMatchedWaypoint(nodeNr); + if (mwpt != null && mwpt.direct) { + input.cmd = VoiceHint.BL; + input.angle = (float) node.message.turnangle; + input.distanceToNext = node.calcDistance(node.origin); + } + } OsmPathElementHolder detours = detourMap.get(node.origin.getIdFromPos()); if (nodeNr >= 0 && detours != null) { OsmPathElementHolder h = detours; @@ -1081,8 +1292,8 @@ public final class OsmTrack { List results = vproc.process(inputs); double minDistance = getMinDistance(); - List < VoiceHint > resultsLast = vproc.postProcess(results, rc.turnInstructionCatchingRange, minDistance); - for (VoiceHint hint: resultsLast) { + List resultsLast = vproc.postProcess(results, rc.turnInstructionCatchingRange, minDistance); + for (VoiceHint hint : resultsLast) { voiceHints.list.add(hint); } diff --git a/brouter-core/src/main/java/btools/router/RoutingContext.java b/brouter-core/src/main/java/btools/router/RoutingContext.java index 8af9c9f..99d564b 100644 --- a/brouter-core/src/main/java/btools/router/RoutingContext.java +++ b/brouter-core/src/main/java/btools/router/RoutingContext.java @@ -171,6 +171,7 @@ public final class RoutingContext { showspeed = 0.f != expctxGlobal.getVariableValue("showspeed", 0.f); showSpeedProfile = 0.f != expctxGlobal.getVariableValue("showSpeedProfile", 0.f); inverseRouting = 0.f != expctxGlobal.getVariableValue("inverseRouting", 0.f); + showTime = 0.f != expctxGlobal.getVariableValue("showtime", 0.f); int tiMode = (int) expctxGlobal.getVariableValue("turnInstructionMode", 0.f); if (tiMode != 1) // automatic selection from coordinate source @@ -233,6 +234,7 @@ public final class RoutingContext { public boolean showspeed; public boolean showSpeedProfile; public boolean inverseRouting; + public boolean showTime; public OsmPrePath firstPrePath; diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index b5a2d89..7ddc011 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -511,6 +511,9 @@ public class RoutingEngine extends Thread { totaltrack.processVoiceHints(routingContext); totaltrack.prepareSpeedProfile(routingContext); + totaltrack.showTime = routingContext.showTime; + totaltrack.params = routingContext.keyValues; + if (routingContext.poipoints != null) totaltrack.pois = routingContext.poipoints; totaltrack.matchedWaypoints = matchedWaypoints;