moved some format routines
This commit is contained in:
parent
24e15b5466
commit
fcbaf598aa
3 changed files with 44 additions and 3 deletions
|
@ -250,7 +250,7 @@ public class FormatGpx extends Formatter {
|
||||||
MatchedWaypoint mwpt = t.getMatchedWaypoint(idx);
|
MatchedWaypoint mwpt = t.getMatchedWaypoint(idx);
|
||||||
|
|
||||||
if (t.showTime) {
|
if (t.showTime) {
|
||||||
sele += "<time>" + t.getFormattedTime3(n.getTime()) + "</time>";
|
sele += "<time>" + getFormattedTime3(n.getTime()) + "</time>";
|
||||||
}
|
}
|
||||||
if (turnInstructionMode == 8) {
|
if (turnInstructionMode == 8) {
|
||||||
if (mwpt != null &&
|
if (mwpt != null &&
|
||||||
|
|
|
@ -2,6 +2,10 @@ package btools.router;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
public abstract class Formatter {
|
public abstract class Formatter {
|
||||||
private static final int OUTPUT_FORMAT_GPX = 0;
|
private static final int OUTPUT_FORMAT_GPX = 0;
|
||||||
|
@ -70,4 +74,41 @@ public abstract class Formatter {
|
||||||
return new String(ac, i + 1, 11 - i);
|
return new String(ac, i + 1, 11 - i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFormattedTime2(int s) {
|
||||||
|
int seconds = (int) (s + 0.5);
|
||||||
|
int hours = seconds / 3600;
|
||||||
|
int minutes = (seconds - hours * 3600) / 60;
|
||||||
|
seconds = seconds - hours * 3600 - minutes * 60;
|
||||||
|
String time = "";
|
||||||
|
if (hours != 0)
|
||||||
|
time = "" + hours + "h ";
|
||||||
|
if (minutes != 0)
|
||||||
|
time = time + minutes + "m ";
|
||||||
|
if (seconds != 0)
|
||||||
|
time = time + seconds + "s";
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public String getFormattedEnergy(int energy) {
|
||||||
|
return format1(energy / 3600000.) + "kwh";
|
||||||
|
}
|
||||||
|
|
||||||
|
static private String format1(double n) {
|
||||||
|
String s = "" + (long) (n * 10 + 0.5);
|
||||||
|
int len = s.length();
|
||||||
|
return s.substring(0, len - 1) + "." + s.charAt(len - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static final String dateformat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||||
|
|
||||||
|
static public String getFormattedTime3(float time) {
|
||||||
|
SimpleDateFormat TIMESTAMP_FORMAT = new SimpleDateFormat(dateformat, 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ public class RoutingEngine extends Thread {
|
||||||
track.message = "track-length = " + track.distance + " filtered ascend = " + track.ascend
|
track.message = "track-length = " + track.distance + " filtered ascend = " + track.ascend
|
||||||
+ " plain-ascend = " + track.plainAscend + " cost=" + track.cost;
|
+ " plain-ascend = " + track.plainAscend + " cost=" + track.cost;
|
||||||
if (track.energy != 0) {
|
if (track.energy != 0) {
|
||||||
track.message += " energy=" + track.getFormattedEnergy() + " time=" + track.getFormattedTime2();
|
track.message += " energy=" + Formatter.getFormattedEnergy(track.energy) + " time=" + Formatter.getFormattedTime2(track.getTotalSeconds());
|
||||||
}
|
}
|
||||||
track.name = "brouter_" + routingContext.getProfileName() + "_" + i;
|
track.name = "brouter_" + routingContext.getProfileName() + "_" + i;
|
||||||
|
|
||||||
|
@ -1676,7 +1676,7 @@ public class RoutingEngine extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTime() {
|
public String getTime() {
|
||||||
return foundTrack.getFormattedTime2();
|
return Formatter.getFormattedTime2(foundTrack.getTotalSeconds());
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsmTrack getFoundTrack() {
|
public OsmTrack getFoundTrack() {
|
||||||
|
|
Loading…
Reference in a new issue