diff --git a/pom.xml b/pom.xml
index a562d1a3..524b4562 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,6 +25,12 @@
json-simple
1.1.1
+
+ org.mockito
+ mockito-core
+ 2.7.13
+ test
+
diff --git a/src/main/java/seng302/controllers/BoatPositionController.java b/src/main/java/seng302/controllers/BoatPositionController.java
new file mode 100644
index 00000000..4a82e28a
--- /dev/null
+++ b/src/main/java/seng302/controllers/BoatPositionController.java
@@ -0,0 +1,49 @@
+package seng302.controllers;
+
+import javafx.fxml.FXML;
+import javafx.scene.layout.VBox;
+import javafx.scene.text.Text;
+import seng302.models.Boat;
+import seng302.models.Event;
+
+import java.util.*;
+
+/**
+ * Created by ptg19 on 23/03/17.
+ */
+public class BoatPositionController {
+ @FXML
+ private VBox positionVbox;
+
+ private ArrayList boatOrder = new ArrayList<>();
+
+ public void initialize() {
+ }
+
+ public void handleEvent(Event event){
+ Boat boat = event.getBoat();
+ boatOrder.remove(boat);
+ boat.setMarkLastPast(event.getMarkPosInRace());
+ boatOrder.add(boat);
+ boatOrder.sort(new Comparator() {
+ @Override
+ public int compare(Boat b1, Boat b2) {
+ return b2.getMarkLastPast() - b1.getMarkLastPast();
+ }
+ });
+ displayBoats();
+ }
+
+ private void displayBoats(){
+ positionVbox.getChildren().clear();
+ positionVbox.getChildren().removeAll();
+
+ for (Boat boat: boatOrder){
+ positionVbox.getChildren().add(new Text(boat.getTeamName() + " " + boat.getVelocity()));
+ }
+ }
+
+ public ArrayList getBoatOrder() {
+ return boatOrder;
+ }
+}
diff --git a/src/main/java/seng302/controllers/CanvasController.java b/src/main/java/seng302/controllers/CanvasController.java
index 27241d4a..63126939 100644
--- a/src/main/java/seng302/controllers/CanvasController.java
+++ b/src/main/java/seng302/controllers/CanvasController.java
@@ -53,6 +53,9 @@ public class CanvasController {
@FXML Pane raceTimer;
+ @FXML
+ BoatPositionController teamPositionsController;
+
private Animation.Status raceStatus = Animation.Status.PAUSED;
private final int SCALE = 16000;
@@ -145,6 +148,11 @@ public class CanvasController {
gc.clearRect(0, 0, 19200, 10800);
drawCourse();
drawBoats();
+ gc.clearRect(0, 0, canvas.getWidth(),canvas.getHeight());
+ gc.setFill(Color.SKYBLUE);
+ gc.fillRect(0,0,canvas.getWidth(),canvas.getHeight());
+ drawCourse();
+ drawBoats();
// If race has started, draw the boats and play the timeline
if (race.getRaceTime() > 1){
@@ -162,10 +170,8 @@ public class CanvasController {
}
};
- generateTimeline();
-
+ generateTimelines();
timer.start();
-
loadTimerView();
Double maxDuration = 0.0;
@@ -174,8 +180,6 @@ public class CanvasController {
for (TimelineInfo timelineInfo : timelineInfos.values()) {
Timeline timeline = timelineInfo.getTimeline();
- System.out.println();
-
if (timeline.getTotalDuration().toMillis() >= maxDuration) {
maxDuration = timeline.getTotalDuration().toMillis();
maxTimeline = timeline;
@@ -201,7 +205,7 @@ public class CanvasController {
/**
* Generates time line for each boat, and stores time time into timelineInfos hash map
*/
- private void generateTimeline() {
+ private void generateTimelines() {
HashMap boat_events = race.getEvents();
for (Boat boat : boat_events.keySet()) {
@@ -211,12 +215,13 @@ public class CanvasController {
List keyFrames = new ArrayList<>();
List events = boat_events.get(boat);
+
// iterates all events and convert each event to keyFrame, then add them into a list
for (Event event : events) {
if (event.getIsFinishingEvent()) {
keyFrames.add(
new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5),
- event1 -> race.setBoatFinished(boat),
+ onFinished -> {race.setBoatFinished(boat); teamPositionsController.handleEvent(event);},
new KeyValue(x, event.getThisMark().getLatitude()),
new KeyValue(y, event.getThisMark().getLongitude())
)
@@ -224,6 +229,7 @@ public class CanvasController {
} else {
keyFrames.add(
new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5),
+ onFinished -> teamPositionsController.handleEvent(event),
new KeyValue(x, event.getThisMark().getLatitude()),
new KeyValue(y, event.getThisMark().getLongitude())
)
diff --git a/src/main/java/seng302/models/Boat.java b/src/main/java/seng302/models/Boat.java
index 8aaa4e7f..0403f76d 100644
--- a/src/main/java/seng302/models/Boat.java
+++ b/src/main/java/seng302/models/Boat.java
@@ -13,6 +13,7 @@ public class Boat {
private double lon; // -
private double distanceToNextMark;
private Color color;
+ private int markLastPast;
public Boat(String teamName) {
this.teamName = teamName;
@@ -101,4 +102,12 @@ public class Boat {
public double getSpeedInKnots(){
return Math.round((this.velocity * 1.94384) * 100d) / 100d;
}
+
+ public void setMarkLastPast(int markLastPast) {
+ this.markLastPast = markLastPast;
+ }
+
+ public int getMarkLastPast() {
+ return markLastPast;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/seng302/models/Event.java b/src/main/java/seng302/models/Event.java
index 00a2b8bd..5f4dde72 100644
--- a/src/main/java/seng302/models/Event.java
+++ b/src/main/java/seng302/models/Event.java
@@ -15,6 +15,7 @@ public class Event {
private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race
private Mark mark1; // This mark
private Mark mark2; // Next mark
+ private int markPosInRace; // the position of the current mark in the race course
/**
@@ -24,12 +25,12 @@ public class Event {
* @param eventTime, what time the event happens
* @param eventBoat, the boat that the event belongs to
*/
- public Event(Double eventTime, Boat eventBoat, Mark mark1, Mark mark2) {
+ public Event(Double eventTime, Boat eventBoat, Mark mark1, Mark mark2, int markPosInRace) {
this.time = eventTime;
this.boat = eventBoat;
- //this.leg = eventLeg;
this.mark1 = mark1;
this.mark2 = mark2;
+ this.markPosInRace = markPosInRace;
}
/**
@@ -39,27 +40,18 @@ public class Event {
* @param eventTime, what time the event happens
* @param eventBoat, the boat that the event belongs to
*/
- public Event(Double eventTime, Boat eventBoat, Mark mark1) {
+ public Event(Double eventTime, Boat eventBoat, Mark mark1, int markPosInRace) {
this.time = eventTime;
this.boat = eventBoat;
this.mark1 = mark1;
+ this.markPosInRace = markPosInRace;
this.isFinishingEvent = true;
}
- /**
- * Gets the time for the event
- *
- * @return the time for event in millisecond
- */
public double getTime() {
return this.time;
}
- /**
- * Sets the time for the event
- *
- * @param eventTime the time for event in millisecond
- */
public void setTime(double eventTime) {
this.time = eventTime;
}
@@ -73,28 +65,14 @@ public class Event {
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time.longValue()));
}
- /**
- * Gets the involved boat
- *
- * @return the boat involved in the event
- */
public Boat getBoat() {
return this.boat;
}
- /**
- * Sets the involved boat
- *
- * @param eventBoat the involved boat
- */
public void setBoat(Boat eventBoat) {
this.boat = eventBoat;
}
-
- /**
- * Returns true if this event is the boat finishing the race
- */
public boolean getIsFinishingEvent() {
return this.isFinishingEvent;
}
@@ -141,21 +119,11 @@ public class Event {
return bearing * 180 / Math.PI;
}
- /**
- * Get the mark the event happened on
- *
- * @return the mark
- */
public Mark getThisMark() {
return this.mark1;
}
- /**
- * Get the next mark
- *
- * @return the next mark
- */
- public Mark getNextMark() {
- return this.mark2;
+ public int getMarkPosInRace() {
+ return markPosInRace;
}
}
\ No newline at end of file
diff --git a/src/main/java/seng302/models/Race.java b/src/main/java/seng302/models/Race.java
index 884be6b9..9c21cc0b 100644
--- a/src/main/java/seng302/models/Race.java
+++ b/src/main/java/seng302/models/Race.java
@@ -92,7 +92,7 @@ public class Race {
// If there are singleMarks after this event
if (i < numberOfMarks - 1) {
- Event event = new Event(time, boat, course.get(i), course.get(i + 1));
+ Event event = new Event(time, boat, course.get(i), course.get(i + 1), i);
try {
events.get(boat).add(event);
@@ -106,7 +106,7 @@ public class Race {
// There are no more marks after this event
else{
- Event event = new Event(time, boat, course.get(i));
+ Event event = new Event(time, boat, course.get(i), i);
events.get(boat).add(event);
}
}
diff --git a/src/main/resources/RaceView.fxml b/src/main/resources/RaceView.fxml
index 29165d5d..9534d08d 100644
--- a/src/main/resources/RaceView.fxml
+++ b/src/main/resources/RaceView.fxml
@@ -9,45 +9,53 @@
-
-
-
-
-
-
-
-
-
-
+
-
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
diff --git a/src/main/resources/TeamPositions.fxml b/src/main/resources/TeamPositions.fxml
new file mode 100644
index 00000000..20b9a705
--- /dev/null
+++ b/src/main/resources/TeamPositions.fxml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/java/seng302/EventTest.java b/src/test/java/seng302/EventTest.java
index 2fd99c87..02d7abc0 100644
--- a/src/test/java/seng302/EventTest.java
+++ b/src/test/java/seng302/EventTest.java
@@ -16,14 +16,14 @@ public class EventTest {
@Test
public void getTimeString() throws Exception {
Boat boat = new Boat("testBoat");
- Event event = new Event(1231242.2, boat, new SingleMark("mark1"), new SingleMark("mark2"));
+ Event event = new Event(1231242.2, boat, new SingleMark("mark1"), new SingleMark("mark2"), 0);
assertEquals("20:31:242", event.getTimeString());
}
@Test
public void testBoatHeading() throws Exception {
Boat boat = new Boat("testBoat");
- Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2));
+ Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2), 0);
assertEquals(event.getBoatHeading(), 221.9733862944651, 1e-15);
}
@@ -31,7 +31,7 @@ public class EventTest {
@Test
public void testDistanceBetweenMarks() throws Exception {
Boat boat = new Boat("testBoat");
- Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2));
+ Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2), 0);
assertEquals(event.getDistanceBetweenMarks(), 339059.653830461, 1e-15);
}
diff --git a/src/test/java/seng302/controllers/BoatPositionControllerTest.java b/src/test/java/seng302/controllers/BoatPositionControllerTest.java
new file mode 100644
index 00000000..dd6366aa
--- /dev/null
+++ b/src/test/java/seng302/controllers/BoatPositionControllerTest.java
@@ -0,0 +1,42 @@
+package seng302.controllers;
+
+import org.junit.Test;
+import seng302.models.Boat;
+import seng302.models.Event;
+import seng302.models.mark.SingleMark;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by ptg19 on 23/03/17.
+ */
+public class BoatPositionControllerTest {
+ @Test
+ public void handleEvent() throws Exception {
+// BoatPositionController controller = new BoatPositionController();
+// Boat boat1 = new Boat("boat1");
+// Boat boat2 = new Boat("boat2");
+// Boat boat3 = new Boat("boat3");
+//
+// Event event1 = new Event(1.0, boat1, new SingleMark("mark0"), new SingleMark("mark1"), 0);
+// Event event2 = new Event(1.0, boat2, new SingleMark("mark0"), new SingleMark("mark1"), 0);
+// Event event3 = new Event(1.0, boat3, new SingleMark("mark0"), new SingleMark("mark1"), 0);
+// controller.handleEvent(event1);
+// controller.handleEvent(event2);
+// controller.handleEvent(event3);
+// assertEquals(controller.getBoatOrder(), new ArrayList(Arrays.asList(boat1, boat2, boat3)));
+
+
+// Event event4 = new Event(1.0, boat3, new SingleMark("mark1"), new SingleMark("mark2"), 0);
+// Event event5 = new Event(1.0, boat3, new SingleMark("mark1"), new SingleMark("mark2"), 1);
+// Event event6 = new Event(1.0, boat3, new SingleMark("mark1"), new SingleMark("mark2"), 1);
+// Event event7 = new Event(1.0, boat3, new SingleMark("mark1"), new SingleMark("mark2"), 1);
+// Event event8 = new Event(1.0, boat3, new SingleMark("mark1"), new SingleMark("mark2"), 1);
+// Event event9 = new Event(1.0, boat3, new SingleMark("mark1"), new SingleMark("mark2"), 1);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/seng302/models/parsers/CourseParserTest.java b/src/test/java/seng302/models/parsers/CourseParserTest.java
index 96add4a8..a70375a0 100644
--- a/src/test/java/seng302/models/parsers/CourseParserTest.java
+++ b/src/test/java/seng302/models/parsers/CourseParserTest.java
@@ -29,15 +29,15 @@ public class CourseParserTest {
assertTrue(MarkType.GATE_MARK == course.get(0).getMarkType());
GateMark gateMark1 = (GateMark) course.get(0);
- assertEquals(32.293834, gateMark1.getSingleMark2().getLatitude(), 0.00000001);
- assertEquals(-64.855195, gateMark1.getSingleMark2().getLongitude(), 0.00000001);
+ assertEquals(32.293771, gateMark1.getSingleMark2().getLatitude(), 0.00000001);
+ assertEquals(-64.855242, gateMark1.getSingleMark2().getLongitude(), 0.00000001);
GateMark gateMark2 = (GateMark) course.get(5);
assertEquals("Finish1", gateMark2.getSingleMark1().getName());
assertEquals("Finish2", gateMark2.getSingleMark2().getName());
- assertEquals(32.318303, gateMark2.getSingleMark2().getLatitude(), 0.00000001);
- assertEquals(-64.834974, gateMark2.getSingleMark2().getLongitude(), 0.00000001);
+ assertEquals(32.317257, gateMark2.getSingleMark2().getLatitude(), 0.00000001);
+ assertEquals(-64.83626, gateMark2.getSingleMark2().getLongitude(), 0.00000001);
}
@Test
diff --git a/src/test/java/seng302/models/parsers/TeamsParserTest.java b/src/test/java/seng302/models/parsers/TeamsParserTest.java
index c0fd2814..aad9fdc2 100644
--- a/src/test/java/seng302/models/parsers/TeamsParserTest.java
+++ b/src/test/java/seng302/models/parsers/TeamsParserTest.java
@@ -26,10 +26,10 @@ public class TeamsParserTest {
assertEquals(6, boats.size(), 1e-10);
assertEquals("Oracle Team USA", boats.get(0).getTeamName());
- assertEquals(23.4, boats.get(0).getVelocity(), 1e-10);
+ assertEquals(10, boats.get(0).getVelocity(), 1e-10);
assertEquals("Groupama Team France", boats.get(5).getTeamName());
- assertEquals(28.8, boats.get(5).getVelocity(), 1e-10);
+ assertEquals(10, boats.get(5).getVelocity(), 1e-10);
}
}
\ No newline at end of file