Prepared StreamParser.java, BoatGroup.java, Yacht.java for leg timer annotation (story 36)

#story[927]
This commit is contained in:
Zhi You Tan
2017-05-15 13:47:30 +12:00
parent 39efafc75f
commit e62a609b6b
4 changed files with 40 additions and 17 deletions
+19 -2
View File
@@ -28,6 +28,8 @@ public class BoatGroup extends RaceObject{
private static final double VELOCITY_Y_OFFSET = -17d;
private static final double ESTTIMETONEXTMARK_X_OFFSET = 10d;
private static final double ESTTIMETONEXTMARK_Y_OFFSET = -5d;
private static final double LEGTIME_X_OFFSET = 10d;
private static final double LEGTIME_Y_OFFSET = 7d;
private static final double BOAT_HEIGHT = 15d;
private static final double BOAT_WIDTH = 10d;
//Variables for boat logic.
@@ -41,6 +43,7 @@ public class BoatGroup extends RaceObject{
private Text teamNameObject;
private Text velocityObject;
private Text estTimeToNextMarkObject;
private Text legTimeObject;
private Wake wake;
//Handles boat moving when connecting to a stream
private boolean setToInitialLocation = false;
@@ -87,6 +90,7 @@ public class BoatGroup extends RaceObject{
teamNameObject = new Text(boat.getShortName());
velocityObject = new Text(String.valueOf(boat.getVelocity()));
estTimeToNextMarkObject = new Text(String.valueOf(boat.getEstimateTimeAtNextMark()));
legTimeObject = new Text(String.valueOf(boat.getMarkRoundingTime()));
teamNameObject.setX(TEAMNAME_X_OFFSET);
teamNameObject.setY(TEAMNAME_Y_OFFSET);
@@ -101,8 +105,12 @@ public class BoatGroup extends RaceObject{
estTimeToNextMarkObject.setY(ESTTIMETONEXTMARK_Y_OFFSET);
estTimeToNextMarkObject.relocate(estTimeToNextMarkObject.getX(), estTimeToNextMarkObject.getY());
legTimeObject.setX(LEGTIME_X_OFFSET);
legTimeObject.setY(LEGTIME_Y_OFFSET);
legTimeObject.relocate(legTimeObject.getX(), legTimeObject.getY());
wake = new Wake(0, -BOAT_HEIGHT);
super.getChildren().addAll(teamNameObject, velocityObject, boatPoly, estTimeToNextMarkObject);
super.getChildren().addAll(teamNameObject, velocityObject, boatPoly, estTimeToNextMarkObject, legTimeObject);
}
/**
@@ -130,6 +138,8 @@ public class BoatGroup extends RaceObject{
velocityObject.setLayoutY(velocityObject.getLayoutY() + dy);
estTimeToNextMarkObject.setLayoutX(estTimeToNextMarkObject.getLayoutX() + dx);
estTimeToNextMarkObject.setLayoutY(estTimeToNextMarkObject.getLayoutY() + dy);
legTimeObject.setLayoutX(legTimeObject.getLayoutX() + dx);
legTimeObject.setLayoutY(legTimeObject.getLayoutY() + dy);
wake.setLayoutX(wake.getLayoutX() + dx);
wake.setLayoutY(wake.getLayoutY() + dy);
rotateTo(rotation + currentRotation);
@@ -160,6 +170,8 @@ public class BoatGroup extends RaceObject{
velocityObject.setLayoutY(y);
estTimeToNextMarkObject.setLayoutX(x);
estTimeToNextMarkObject.setLayoutY(y);
legTimeObject.setLayoutX(x);
legTimeObject.setLayoutY(y);
wake.setLayoutX(x);
wake.setLayoutY(y);
wake.rotate(currentRotation);
@@ -237,6 +249,7 @@ public class BoatGroup extends RaceObject{
}
velocityObject.setText(String.format("%.2f m/s", boat.getVelocity()));
estTimeToNextMarkObject.setText(String.valueOf(boat.getEstimateTimeAtNextMark()));
legTimeObject.setText(String.valueOf(boat.getMarkRoundingTime()));
} else {
setToInitialLocation = true;
rotationalGoal = rotation;
@@ -300,10 +313,14 @@ public class BoatGroup extends RaceObject{
velocityObject.setVisible(visible);
}
public void setEstTimeToNextMarkVisible(Boolean visible) {
public void setEstTimeToNextMarkObjectVisible(Boolean visible) {
estTimeToNextMarkObject.setVisible(visible);
}
public void setLegObjectTime(Boolean visible) {
legTimeObject.setVisible(visible);
}
public void setLineGroupVisible(Boolean visible) {
lineGroup.setVisible(visible);
}
+7 -5
View File
@@ -12,9 +12,9 @@ import java.text.SimpleDateFormat;
* also done outside Boat class because some old variables are not used anymore.
*/
public class Yacht {
// Used in boat group
private Color colour;
private double velocity;
private Integer markLastPast;
private String boatType;
private Integer sourceID;
@@ -30,6 +30,8 @@ public class Yacht {
private Long estimateTimeAtNextMark;
private Long estimateTimeAtFinish;
private String position;
// Mark rounding
private Long markRoundingTime;
/**
* Used in EventTest and RaceTest.
@@ -157,11 +159,11 @@ public class Yacht {
this.velocity = velocity;
}
public Integer getMarkLastPast() {
return markLastPast;
public Long getMarkRoundingTime() {
return markRoundingTime;
}
public void setMarkLastPast(Integer markLastPast) {
this.markLastPast = markLastPast;
public void setMarkRoundingTime(Long markRoundingTime) {
this.markRoundingTime = markRoundingTime;
}
}
@@ -39,6 +39,7 @@ public class StreamParser extends Thread{
private static Map<Integer, Yacht> boats = new HashMap<>();
private static Map<Long, Yacht> boatsPos = new TreeMap<>();
private static double windDirection = 0;
private static Long currentTimeLong;
private static String currentTimeString;
private static boolean appRunning;
@@ -196,9 +197,11 @@ public class StreamParser extends Thread{
long currentTime = bytesToLong(Arrays.copyOfRange(payload,1,7));
long raceId = bytesToLong(Arrays.copyOfRange(payload,7,11));
int raceStatus = payload[11];
// System.out.println("raceStatus = " + raceStatus);
long expectedStartTime = bytesToLong(Arrays.copyOfRange(payload,12,18));
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
long windSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22));
currentTimeLong = currentTime;
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
if (xmlObject.getRegattaXML() != null) {
format.setTimeZone(TimeZone.getTimeZone(getTimeZoneString()));
@@ -206,7 +209,6 @@ public class StreamParser extends Thread{
}
long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000;
if (timeTillStart > 0) {
timeSinceStart = timeTillStart;
//System.out.println("Time till start: " + timeTillStart + " Seconds");
@@ -223,10 +225,10 @@ public class StreamParser extends Thread{
//System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
timeSinceStart = timeTillStart;
}
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
double windDirFactor = 0x4000 / 90; //0x4000 is 90 degrees, 0x8000 is 180 degrees, etc...
windDirection = windDir / windDirFactor;
long windSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22));
int noBoats = payload[22];
int raceType = payload[23];
// ArrayList<String> boatStatuses = new ArrayList<>();
@@ -429,6 +431,9 @@ public class StreamParser extends Thread{
int roundingSide = payload[18];
int markType = payload[19];
int markId = payload[20];
// assign mark rounding time to boat
boats.get((int)subjectId).setMarkRoundingTime(timeStamp);
}
/**