Fixed estimate time to next mark to match acceptance criteria which is countdown in minutes and seconds.

#story[924]
This commit is contained in:
Zhi You Tan
2017-05-15 15:49:21 +12:00
parent 081d7e3dcb
commit 2e914a7704
4 changed files with 26 additions and 8 deletions
+2 -2
View File
@@ -62,9 +62,9 @@ public class App extends Application
} }
//Change the StreamReceiver in this else block to change the default data source. //Change the StreamReceiver in this else block to change the default data source.
else{ else{
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); // sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
// sr = new StreamReceiver("localhost", 4949, "RaceStream"); sr = new StreamReceiver("localhost", 4949, "RaceStream");
} }
sr.start(); sr.start();
+9 -2
View File
@@ -8,7 +8,10 @@ import javafx.scene.shape.Polygon;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.scene.transform.Rotate; import javafx.scene.transform.Rotate;
import javafx.stage.Stage; import javafx.stage.Stage;
import seng302.models.parsers.StreamParser;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -86,7 +89,9 @@ public class BoatGroup extends RaceObject{
teamNameObject = new Text(boat.getShortName()); teamNameObject = new Text(boat.getShortName());
velocityObject = new Text(String.valueOf(boat.getVelocity())); velocityObject = new Text(String.valueOf(boat.getVelocity()));
estTimeToNextMarkObject = new Text(String.valueOf(boat.getEstimateTimeAtNextMark())); DateFormat format = new SimpleDateFormat("mm:ss");
String timeToNextMark = format.format(boat.getEstimateTimeAtNextMark() - StreamParser.getCurrentTimeLong());
estTimeToNextMarkObject = new Text("Next mark: " + timeToNextMark);
teamNameObject.setX(TEAMNAME_X_OFFSET); teamNameObject.setX(TEAMNAME_X_OFFSET);
teamNameObject.setY(TEAMNAME_Y_OFFSET); teamNameObject.setY(TEAMNAME_Y_OFFSET);
@@ -236,7 +241,9 @@ public class BoatGroup extends RaceObject{
wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, boat.getVelocity()); wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, boat.getVelocity());
} }
velocityObject.setText(String.format("%.2f m/s", boat.getVelocity())); velocityObject.setText(String.format("%.2f m/s", boat.getVelocity()));
estTimeToNextMarkObject.setText(String.valueOf(boat.getEstimateTimeAtNextMark())); DateFormat format = new SimpleDateFormat("mm:ss");
String timeToNextMark = format.format(boat.getEstimateTimeAtNextMark() - StreamParser.getCurrentTimeLong());
estTimeToNextMarkObject.setText("Next mark: " + timeToNextMark);
} else { } else {
setToInitialLocation = true; setToInitialLocation = true;
rotationalGoal = rotation; rotationalGoal = rotation;
+4 -4
View File
@@ -114,10 +114,10 @@ public class Yacht {
this.penaltiesServed = penaltiesServed; this.penaltiesServed = penaltiesServed;
} }
public String getEstimateTimeAtNextMark() { public Long getEstimateTimeAtNextMark() {
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); // DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
return format.format(estimateTimeAtNextMark); // return format.format(estimateTimeAtNextMark);
// return estimateTimeAtNextMark; return estimateTimeAtNextMark;
} }
public void setEstimateTimeAtNextMark(Long estimateTimeAtNextMark) { public void setEstimateTimeAtNextMark(Long estimateTimeAtNextMark) {
@@ -39,6 +39,7 @@ public class StreamParser extends Thread{
private static Map<Integer, Yacht> boats = new HashMap<>(); private static Map<Integer, Yacht> boats = new HashMap<>();
private static Map<Long, Yacht> boatsPos = new TreeMap<>(); private static Map<Long, Yacht> boatsPos = new TreeMap<>();
private static double windDirection = 0; private static double windDirection = 0;
private static Long currentTimeLong;
private static String currentTimeString; private static String currentTimeString;
private static boolean appRunning; private static boolean appRunning;
@@ -199,6 +200,7 @@ public class StreamParser extends Thread{
// System.out.println("raceStatus = " + raceStatus); // System.out.println("raceStatus = " + raceStatus);
long expectedStartTime = bytesToLong(Arrays.copyOfRange(payload,12,18)); long expectedStartTime = bytesToLong(Arrays.copyOfRange(payload,12,18));
currentTimeLong = currentTime;
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
if (xmlObject.getRegattaXML() != null) { if (xmlObject.getRegattaXML() != null) {
format.setTimeZone(TimeZone.getTimeZone(getTimeZoneString())); format.setTimeZone(TimeZone.getTimeZone(getTimeZoneString()));
@@ -575,6 +577,15 @@ public class StreamParser extends Thread{
return boatsPos; return boatsPos;
} }
/**
* returns current time in stream in long
*
* @return a long value of current time
*/
public static Long getCurrentTimeLong() {
return currentTimeLong;
}
public static void appClose(){ public static void appClose(){
appRunning = false; appRunning = false;
System.out.println("[CLIENT] Shutting down stream parser"); System.out.println("[CLIENT] Shutting down stream parser");