Cherrypicked changes allowing vis to display est time from bugged branch to current master.
#story[875]
This commit is contained in:
@@ -98,7 +98,6 @@ public class StartController extends Controller implements Observer {
|
||||
raceStat = visualiserInput.getRaceStatus().getRaceStatus();
|
||||
raceStatusLabel.setText("Race Status: " + visualiserInput.getRaceStatus().getRaceStatus());
|
||||
if (raceStat==2 || raceStat == 3) {
|
||||
System.out.println("countdown finished!");//TEMP DEBUG REMOVE
|
||||
stop();
|
||||
|
||||
startWrapper.setVisible(false);
|
||||
|
||||
@@ -114,16 +114,17 @@ public class StreamedRace implements Runnable {
|
||||
* Updates the boat's gps coordinates
|
||||
*
|
||||
* @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();
|
||||
BoatLocation boatLocation = visualiserInput.getBoatLocationMessage(sourceID);
|
||||
BoatStatus boatStatus = visualiserInput.getBoatStatusMessage(sourceID);
|
||||
if(boatLocation != null) {
|
||||
double lat = boatLocation.getLatitudeDouble();
|
||||
double lon = boatLocation.getLongitudeDouble();
|
||||
boat.setCurrentPosition(new GPSCoordinate(lat, lon));
|
||||
boat.setHeading(boatLocation.getHeadingDegrees());
|
||||
boat.setEstTime(convertEstTime(boatStatus.getEstTimeAtNextMark(), boatLocation.getTime()));
|
||||
double MMPS_TO_KN = 0.001944;
|
||||
boat.setVelocity(boatLocation.getBoatSOG() * MMPS_TO_KN);
|
||||
}
|
||||
@@ -200,17 +201,18 @@ public class StreamedRace implements Runnable {
|
||||
|
||||
for (Boat boat : startingBoats) {
|
||||
if (boat != null && !boat.isFinished()) {
|
||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||
updatePosition(boat);
|
||||
checkPosition(boat, totalTimeElapsed);
|
||||
}
|
||||
|
||||
}
|
||||
for (Marker mark: boatMarkers){
|
||||
if (mark != null){
|
||||
updateMarker(mark);
|
||||
}
|
||||
}
|
||||
//System.out.println(boatsFinished + ":" + startingBoats.size());
|
||||
if (visualiserInput.getRaceStatus().isFinished()){
|
||||
|
||||
if (visualiserInput.getRaceStatus().isFinished()) {
|
||||
controller.finishRace(startingBoats);
|
||||
stop();
|
||||
}
|
||||
@@ -258,4 +260,18 @@ public class StreamedRace implements Runnable {
|
||||
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 dnf = false;
|
||||
private int sourceID;
|
||||
private int estTime;
|
||||
private final Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
|
||||
private long nextValidTime = 0;
|
||||
|
||||
@@ -248,4 +249,21 @@ public class Boat {
|
||||
public void setTimeSinceLastMark(ZonedDateTime 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 annoSpeed = true;
|
||||
private boolean annoPath = true;
|
||||
private boolean annoEstTime = true;
|
||||
private boolean annoTimeSinceLastMark = true;
|
||||
private List<Color> colours;
|
||||
private final List<Marker> markers;
|
||||
@@ -177,7 +178,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
* @param coordinate coordinate the text appears
|
||||
* @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 = "";
|
||||
//Check name toggle value
|
||||
if (annoName){
|
||||
@@ -191,10 +192,13 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
if (annoSpeed){
|
||||
text += String.format("%.2fkn ", speed);
|
||||
}
|
||||
if (annoEstTime) {
|
||||
text += estTime;
|
||||
}
|
||||
//Check time since last mark toggle value
|
||||
if(annoTimeSinceLastMark){
|
||||
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);
|
||||
long xCoord = coordinate.getX() + 20;
|
||||
@@ -277,6 +281,10 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
annoPath = !annoPath;
|
||||
}
|
||||
|
||||
public void toggleEstTime() {
|
||||
annoEstTime = !annoEstTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle boat time display in annotation
|
||||
*/
|
||||
@@ -320,7 +328,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
||||
if (Duration.between(boat.getTimeSinceLastMark(), raceClock.getTime()).getSeconds() < 0) {
|
||||
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.
|
||||
drawTrack(boat, boatColours.get(sourceID));
|
||||
}
|
||||
|
||||
@@ -88,6 +88,10 @@ public class VisualiserInput implements Runnable {
|
||||
return boatLocationMap.get(sourceID);
|
||||
}
|
||||
|
||||
public BoatStatus getBoatStatusMessage(int sourceID) {
|
||||
return boatStatusMap.get(sourceID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the time since last heartbeat, in milliseconds.
|
||||
* @return Time since last heartbeat, in milliseconds..
|
||||
|
||||
Reference in New Issue
Block a user