Cherrypicked changes allowing vis to display est time from bugged branch to current master.

#story[875]
main
Erika Savell 9 years ago
parent e9f3467d97
commit 92e5dc4490

@ -98,7 +98,6 @@ public class StartController extends Controller implements Observer {
raceStat = visualiserInput.getRaceStatus().getRaceStatus(); raceStat = visualiserInput.getRaceStatus().getRaceStatus();
raceStatusLabel.setText("Race Status: " + visualiserInput.getRaceStatus().getRaceStatus()); raceStatusLabel.setText("Race Status: " + visualiserInput.getRaceStatus().getRaceStatus());
if (raceStat==2 || raceStat == 3) { if (raceStat==2 || raceStat == 3) {
System.out.println("countdown finished!");//TEMP DEBUG REMOVE
stop(); stop();
startWrapper.setVisible(false); startWrapper.setVisible(false);

@ -114,16 +114,17 @@ public class StreamedRace implements Runnable {
* Updates the boat's gps coordinates * Updates the boat's gps coordinates
* *
* @param boat to be updated * @param boat to be updated
* @param millisecondsElapsed time since last update
*/ */
private void updatePosition(Boat boat, int millisecondsElapsed) { private void updatePosition(Boat boat) {
int sourceID = boat.getSourceID(); int sourceID = boat.getSourceID();
BoatLocation boatLocation = visualiserInput.getBoatLocationMessage(sourceID); BoatLocation boatLocation = visualiserInput.getBoatLocationMessage(sourceID);
BoatStatus boatStatus = visualiserInput.getBoatStatusMessage(sourceID);
if(boatLocation != null) { if(boatLocation != null) {
double lat = boatLocation.getLatitudeDouble(); double lat = boatLocation.getLatitudeDouble();
double lon = boatLocation.getLongitudeDouble(); double lon = boatLocation.getLongitudeDouble();
boat.setCurrentPosition(new GPSCoordinate(lat, lon)); boat.setCurrentPosition(new GPSCoordinate(lat, lon));
boat.setHeading(boatLocation.getHeadingDegrees()); boat.setHeading(boatLocation.getHeadingDegrees());
boat.setEstTime(convertEstTime(boatStatus.getEstTimeAtNextMark(), boatLocation.getTime()));
double MMPS_TO_KN = 0.001944; double MMPS_TO_KN = 0.001944;
boat.setVelocity(boatLocation.getBoatSOG() * MMPS_TO_KN); boat.setVelocity(boatLocation.getBoatSOG() * MMPS_TO_KN);
} }
@ -200,16 +201,17 @@ public class StreamedRace implements Runnable {
for (Boat boat : startingBoats) { for (Boat boat : startingBoats) {
if (boat != null && !boat.isFinished()) { if (boat != null && !boat.isFinished()) {
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS)); updatePosition(boat);
checkPosition(boat, totalTimeElapsed); checkPosition(boat, totalTimeElapsed);
} }
} }
for (Marker mark: boatMarkers){ for (Marker mark: boatMarkers){
if (mark != null){ if (mark != null){
updateMarker(mark); updateMarker(mark);
} }
} }
//System.out.println(boatsFinished + ":" + startingBoats.size());
if (visualiserInput.getRaceStatus().isFinished()) { if (visualiserInput.getRaceStatus().isFinished()) {
controller.finishRace(startingBoats); controller.finishRace(startingBoats);
stop(); stop();
@ -258,4 +260,18 @@ public class StreamedRace implements Runnable {
return startingBoats; return startingBoats;
} }
/**
* Takes an estimated time an event will occur, and converts it to the number of seconds before the event will occur.
*
* @param estTimeMillis
* @return int difference between time the race started and the estimated time
*/
private int convertEstTime(long estTimeMillis, long currentTime) {
long estElapsedMillis = estTimeMillis - currentTime;
int estElapsedSecs = Math.round(estElapsedMillis/1000);
return estElapsedSecs;
}
} }

@ -29,6 +29,7 @@ public class Boat {
private boolean started = false; private boolean started = false;
private boolean dnf = false; private boolean dnf = false;
private int sourceID; private int sourceID;
private int estTime;
private final Queue<TrackPoint> track = new ConcurrentLinkedQueue<>(); private final Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
private long nextValidTime = 0; private long nextValidTime = 0;
@ -248,4 +249,21 @@ public class Boat {
public void setTimeSinceLastMark(ZonedDateTime timeSinceLastMark) { public void setTimeSinceLastMark(ZonedDateTime timeSinceLastMark) {
this.timeSinceLastMark = timeSinceLastMark; this.timeSinceLastMark = timeSinceLastMark;
} }
public void setEstTime(int estTime) { this.estTime = estTime; }
public String getFormattedEstTime() {
if (estTime < 0) {
return " -";
}
if (estTime <= 60) {
return " " + estTime + "s";
} else {
int seconds = estTime % 60;
int minutes = (estTime - seconds) / 60;
return String.format(" %dm %ds", minutes, seconds);
}
}
} }

@ -31,6 +31,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
private boolean annoAbbrev = true; private boolean annoAbbrev = true;
private boolean annoSpeed = true; private boolean annoSpeed = true;
private boolean annoPath = true; private boolean annoPath = true;
private boolean annoEstTime = true;
private boolean annoTimeSinceLastMark = true; private boolean annoTimeSinceLastMark = true;
private List<Color> colours; private List<Color> colours;
private final List<Marker> markers; private final List<Marker> markers;
@ -177,7 +178,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
* @param coordinate coordinate the text appears * @param coordinate coordinate the text appears
* @param timeSinceLastMark time since the last mark was passed * @param timeSinceLastMark time since the last mark was passed
*/ */
private void displayText(String name, String abbrev, double speed, GraphCoordinate coordinate, ZonedDateTime timeSinceLastMark) { private void displayText(String name, String abbrev, double speed, GraphCoordinate coordinate, String estTime, ZonedDateTime timeSinceLastMark) {
String text = ""; String text = "";
//Check name toggle value //Check name toggle value
if (annoName){ if (annoName){
@ -191,10 +192,13 @@ public class ResizableRaceCanvas extends ResizableCanvas {
if (annoSpeed){ if (annoSpeed){
text += String.format("%.2fkn ", speed); text += String.format("%.2fkn ", speed);
} }
if (annoEstTime) {
text += estTime;
}
//Check time since last mark toggle value //Check time since last mark toggle value
if(annoTimeSinceLastMark){ if(annoTimeSinceLastMark){
Duration timeSince = Duration.between(timeSinceLastMark, raceClock.getTime()); Duration timeSince = Duration.between(timeSinceLastMark, raceClock.getTime());
text += String.format("%d", timeSince.getSeconds()); text += String.format(" %ds ", timeSince.getSeconds());
} }
//String text = String.format("%s, %2$.2fkn", name, speed); //String text = String.format("%s, %2$.2fkn", name, speed);
long xCoord = coordinate.getX() + 20; long xCoord = coordinate.getX() + 20;
@ -277,6 +281,10 @@ public class ResizableRaceCanvas extends ResizableCanvas {
annoPath = !annoPath; annoPath = !annoPath;
} }
public void toggleEstTime() {
annoEstTime = !annoEstTime;
}
/** /**
* Toggle boat time display in annotation * Toggle boat time display in annotation
*/ */
@ -320,7 +328,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
if (Duration.between(boat.getTimeSinceLastMark(), raceClock.getTime()).getSeconds() < 0) { if (Duration.between(boat.getTimeSinceLastMark(), raceClock.getTime()).getSeconds() < 0) {
boat.setTimeSinceLastMark(raceClock.getTime()); boat.setTimeSinceLastMark(raceClock.getTime());
} }
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()), boat.getTimeSinceLastMark()); displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()), boat.getFormattedEstTime(), boat.getTimeSinceLastMark());
//TODO this needs to be fixed. //TODO this needs to be fixed.
drawTrack(boat, boatColours.get(sourceID)); drawTrack(boat, boatColours.get(sourceID));
} }

@ -88,6 +88,10 @@ public class VisualiserInput implements Runnable {
return boatLocationMap.get(sourceID); return boatLocationMap.get(sourceID);
} }
public BoatStatus getBoatStatusMessage(int sourceID) {
return boatStatusMap.get(sourceID);
}
/** /**
* Calculates the time since last heartbeat, in milliseconds. * Calculates the time since last heartbeat, in milliseconds.
* @return Time since last heartbeat, in milliseconds.. * @return Time since last heartbeat, in milliseconds..

Loading…
Cancel
Save