Merge remote-tracking branch 'origin/develop' into story36_elapsed_time

# Conflicts:
#	src/main/java/seng302/models/BoatGroup.java
This commit is contained in:
Zhi You Tan
2017-05-15 15:54:44 +12:00
3 changed files with 24 additions and 4 deletions
+2
View File
@@ -62,6 +62,8 @@ 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("localhost", 4949, "RaceStream"); sr = new StreamReceiver("localhost", 4949, "RaceStream");
} }
@@ -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;
@@ -91,6 +94,9 @@ public class BoatGroup extends RaceObject{
velocityObject = new Text(String.valueOf(boat.getVelocity())); velocityObject = new Text(String.valueOf(boat.getVelocity()));
estTimeToNextMarkObject = new Text(String.valueOf(boat.getEstimateTimeAtNextMark())); estTimeToNextMarkObject = new Text(String.valueOf(boat.getEstimateTimeAtNextMark()));
legTimeObject = new Text(String.valueOf(boat.getMarkRoundingTime())); legTimeObject = new Text(String.valueOf(boat.getMarkRoundingTime()));
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);
@@ -250,6 +256,9 @@ public class BoatGroup extends RaceObject{
velocityObject.setText(String.format("%.2f m/s", boat.getVelocity())); velocityObject.setText(String.format("%.2f m/s", boat.getVelocity()));
estTimeToNextMarkObject.setText(String.valueOf(boat.getEstimateTimeAtNextMark())); estTimeToNextMarkObject.setText(String.valueOf(boat.getEstimateTimeAtNextMark()));
legTimeObject.setText(String.valueOf(boat.getMarkRoundingTime())); legTimeObject.setText(String.valueOf(boat.getMarkRoundingTime()));
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;
@@ -238,11 +238,11 @@ public class StreamParser extends Thread{
Yacht boat = boats.get((int)(long) boatStatusSourceID); Yacht boat = boats.get((int)(long) boatStatusSourceID);
boat.setBoatStatus((int)payload[28 + (i * 20)]); boat.setBoatStatus((int)payload[28 + (i * 20)]);
boat.setLegNumber((int)payload[29 + (i * 20)]); boat.setLegNumber((int)payload[29 + (i * 20)]);
boat.setPenaltiesAwarded((int)payload[29 + (i * 20)]); boat.setPenaltiesAwarded((int)payload[30 + (i * 20)]);
boat.setPenaltiesServed((int)payload[30 + (i * 20)]); boat.setPenaltiesServed((int)payload[31 + (i * 20)]);
Long estTimeAtNextMark = bytesToLong(Arrays.copyOfRange(payload,31 + (i * 20),37+ (i * 20))); Long estTimeAtNextMark = bytesToLong(Arrays.copyOfRange(payload,32 + (i * 20),38+ (i * 20)));
boat.setEstimateTimeAtNextMark(estTimeAtNextMark); boat.setEstimateTimeAtNextMark(estTimeAtNextMark);
Long estTimeAtFinish = bytesToLong(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20))); Long estTimeAtFinish = bytesToLong(Arrays.copyOfRange(payload,38 + (i * 20),44+ (i * 20)));
boat.setEstimateTimeAtFinish(estTimeAtFinish); boat.setEstimateTimeAtFinish(estTimeAtFinish);
boatsPos.put(estTimeAtFinish, boat); boatsPos.put(estTimeAtFinish, boat);
// String boatStatus = "SourceID: " + boatStatusSourceID; // String boatStatus = "SourceID: " + boatStatusSourceID;
@@ -580,6 +580,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");