Merge branch 'origin/addBoatPositionsInSideBar'

This commit is contained in:
Peter
2017-03-24 11:06:03 +13:00
12 changed files with 194 additions and 95 deletions
+6
View File
@@ -25,6 +25,12 @@
<artifactId>json-simple</artifactId> <artifactId>json-simple</artifactId>
<version>1.1.1</version> <version>1.1.1</version>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.7.13</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
@@ -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<Boat> 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<Boat>() {
@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<Boat> getBoatOrder() {
return boatOrder;
}
}
@@ -53,6 +53,9 @@ public class CanvasController {
@FXML Pane raceTimer; @FXML Pane raceTimer;
@FXML
BoatPositionController teamPositionsController;
private Animation.Status raceStatus = Animation.Status.PAUSED; private Animation.Status raceStatus = Animation.Status.PAUSED;
private final int SCALE = 16000; private final int SCALE = 16000;
@@ -145,6 +148,11 @@ public class CanvasController {
gc.clearRect(0, 0, 19200, 10800); gc.clearRect(0, 0, 19200, 10800);
drawCourse(); drawCourse();
drawBoats(); 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 has started, draw the boats and play the timeline
if (race.getRaceTime() > 1){ if (race.getRaceTime() > 1){
@@ -162,10 +170,8 @@ public class CanvasController {
} }
}; };
generateTimeline(); generateTimelines();
timer.start(); timer.start();
loadTimerView(); loadTimerView();
Double maxDuration = 0.0; Double maxDuration = 0.0;
@@ -174,8 +180,6 @@ public class CanvasController {
for (TimelineInfo timelineInfo : timelineInfos.values()) { for (TimelineInfo timelineInfo : timelineInfos.values()) {
Timeline timeline = timelineInfo.getTimeline(); Timeline timeline = timelineInfo.getTimeline();
System.out.println();
if (timeline.getTotalDuration().toMillis() >= maxDuration) { if (timeline.getTotalDuration().toMillis() >= maxDuration) {
maxDuration = timeline.getTotalDuration().toMillis(); maxDuration = timeline.getTotalDuration().toMillis();
maxTimeline = timeline; maxTimeline = timeline;
@@ -201,7 +205,7 @@ public class CanvasController {
/** /**
* Generates time line for each boat, and stores time time into timelineInfos hash map * Generates time line for each boat, and stores time time into timelineInfos hash map
*/ */
private void generateTimeline() { private void generateTimelines() {
HashMap<Boat, List> boat_events = race.getEvents(); HashMap<Boat, List> boat_events = race.getEvents();
for (Boat boat : boat_events.keySet()) { for (Boat boat : boat_events.keySet()) {
@@ -211,12 +215,13 @@ public class CanvasController {
List<KeyFrame> keyFrames = new ArrayList<>(); List<KeyFrame> keyFrames = new ArrayList<>();
List<Event> events = boat_events.get(boat); List<Event> events = boat_events.get(boat);
// iterates all events and convert each event to keyFrame, then add them into a list // iterates all events and convert each event to keyFrame, then add them into a list
for (Event event : events) { for (Event event : events) {
if (event.getIsFinishingEvent()) { if (event.getIsFinishingEvent()) {
keyFrames.add( keyFrames.add(
new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5), 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(x, event.getThisMark().getLatitude()),
new KeyValue(y, event.getThisMark().getLongitude()) new KeyValue(y, event.getThisMark().getLongitude())
) )
@@ -224,6 +229,7 @@ public class CanvasController {
} else { } else {
keyFrames.add( keyFrames.add(
new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5), new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5),
onFinished -> teamPositionsController.handleEvent(event),
new KeyValue(x, event.getThisMark().getLatitude()), new KeyValue(x, event.getThisMark().getLatitude()),
new KeyValue(y, event.getThisMark().getLongitude()) new KeyValue(y, event.getThisMark().getLongitude())
) )
+9
View File
@@ -13,6 +13,7 @@ public class Boat {
private double lon; // - private double lon; // -
private double distanceToNextMark; private double distanceToNextMark;
private Color color; private Color color;
private int markLastPast;
public Boat(String teamName) { public Boat(String teamName) {
this.teamName = teamName; this.teamName = teamName;
@@ -101,4 +102,12 @@ public class Boat {
public double getSpeedInKnots(){ public double getSpeedInKnots(){
return Math.round((this.velocity * 1.94384) * 100d) / 100d; return Math.round((this.velocity * 1.94384) * 100d) / 100d;
} }
public void setMarkLastPast(int markLastPast) {
this.markLastPast = markLastPast;
}
public int getMarkLastPast() {
return markLastPast;
}
} }
+7 -39
View File
@@ -15,6 +15,7 @@ public class Event {
private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race
private Mark mark1; // This mark private Mark mark1; // This mark
private Mark mark2; // Next 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 eventTime, what time the event happens
* @param eventBoat, the boat that the event belongs to * @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.time = eventTime;
this.boat = eventBoat; this.boat = eventBoat;
//this.leg = eventLeg;
this.mark1 = mark1; this.mark1 = mark1;
this.mark2 = mark2; this.mark2 = mark2;
this.markPosInRace = markPosInRace;
} }
/** /**
@@ -39,27 +40,18 @@ public class Event {
* @param eventTime, what time the event happens * @param eventTime, what time the event happens
* @param eventBoat, the boat that the event belongs to * @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.time = eventTime;
this.boat = eventBoat; this.boat = eventBoat;
this.mark1 = mark1; this.mark1 = mark1;
this.markPosInRace = markPosInRace;
this.isFinishingEvent = true; this.isFinishingEvent = true;
} }
/**
* Gets the time for the event
*
* @return the time for event in millisecond
*/
public double getTime() { public double getTime() {
return this.time; return this.time;
} }
/**
* Sets the time for the event
*
* @param eventTime the time for event in millisecond
*/
public void setTime(double eventTime) { public void setTime(double eventTime) {
this.time = eventTime; this.time = eventTime;
} }
@@ -73,28 +65,14 @@ public class Event {
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time.longValue())); 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() { public Boat getBoat() {
return this.boat; return this.boat;
} }
/**
* Sets the involved boat
*
* @param eventBoat the involved boat
*/
public void setBoat(Boat eventBoat) { public void setBoat(Boat eventBoat) {
this.boat = eventBoat; this.boat = eventBoat;
} }
/**
* Returns true if this event is the boat finishing the race
*/
public boolean getIsFinishingEvent() { public boolean getIsFinishingEvent() {
return this.isFinishingEvent; return this.isFinishingEvent;
} }
@@ -141,21 +119,11 @@ public class Event {
return bearing * 180 / Math.PI; return bearing * 180 / Math.PI;
} }
/**
* Get the mark the event happened on
*
* @return the mark
*/
public Mark getThisMark() { public Mark getThisMark() {
return this.mark1; return this.mark1;
} }
/** public int getMarkPosInRace() {
* Get the next mark return markPosInRace;
*
* @return the next mark
*/
public Mark getNextMark() {
return this.mark2;
} }
} }
+2 -2
View File
@@ -92,7 +92,7 @@ public class Race {
// If there are singleMarks after this event // If there are singleMarks after this event
if (i < numberOfMarks - 1) { 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 { try {
events.get(boat).add(event); events.get(boat).add(event);
@@ -106,7 +106,7 @@ public class Race {
// There are no more marks after this event // There are no more marks after this event
else{ 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); events.get(boat).add(event);
} }
} }
+21 -13
View File
@@ -9,22 +9,19 @@
<?import javafx.scene.canvas.Canvas?> <?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.CanvasController"> <AnchorPane prefHeight="960.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.CanvasController">
<children>
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="220.0" minWidth="220.0" prefWidth="273.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="632.0" minWidth="10.0" prefWidth="246.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="1007.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="1056.0" minWidth="10.0" prefWidth="1034.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" /> <RowConstraints />
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" /> <RowConstraints />
</rowConstraints> </rowConstraints>
<children> <children>
<AnchorPane fx:id="contentAnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: lightblue;" GridPane.columnIndex="1" GridPane.rowSpan="3">
<children>
<Canvas fx:id="canvas" height="960.0" style="-fx-background-color: Aqua;" width="1007.0" />
</children>
</AnchorPane>
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowSpan="3"> <AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowSpan="3">
<children> <children>
<Label layoutX="11.0" layoutY="259.0" text="Team Position" /> <Label layoutX="11.0" layoutY="259.0" text="Team Position" />
@@ -34,7 +31,6 @@
<Label layoutX="11.0" layoutY="88.0" text="Wind direction" /> <Label layoutX="11.0" layoutY="88.0" text="Wind direction" />
<Button layoutX="18.0" layoutY="468.0" mnemonicParsing="false" text="Button" /> <Button layoutX="18.0" layoutY="468.0" mnemonicParsing="false" text="Button" />
<TextArea editable="false" layoutX="11.0" layoutY="640.0" prefHeight="306.0" prefWidth="200.0" /> <TextArea editable="false" layoutX="11.0" layoutY="640.0" prefHeight="306.0" prefWidth="200.0" />
<TextArea editable="false" layoutX="11.0" layoutY="280.0" prefHeight="141.0" prefWidth="200.0" />
<Circle fx:id="windBackgroundCircle" blendMode="DARKEN" fill="#76baf8" layoutX="110.0" layoutY="166.0" radius="35.0" stroke="#686868" strokeType="INSIDE" strokeWidth="3.0" /> <Circle fx:id="windBackgroundCircle" blendMode="DARKEN" fill="#76baf8" layoutX="110.0" layoutY="166.0" radius="35.0" stroke="#686868" strokeType="INSIDE" strokeWidth="3.0" />
<Text fx:id="windArrowText" fill="#686868" layoutX="86.0" layoutY="186.0" strokeType="OUTSIDE" strokeWidth="0.0" text="↑"> <Text fx:id="windArrowText" fill="#686868" layoutX="86.0" layoutY="186.0" strokeType="OUTSIDE" strokeWidth="0.0" text="↑">
<font> <font>
@@ -47,7 +43,19 @@
</font> </font>
</Text> </Text>
<Pane fx:id="raceTimer" layoutX="11.0" layoutY="30.0" prefHeight="51.0" prefWidth="193.0" /> <Pane fx:id="raceTimer" layoutX="11.0" layoutY="30.0" prefHeight="51.0" prefWidth="193.0" />
<AnchorPane layoutX="12.0" layoutY="280.0" prefHeight="140.0" prefWidth="200.0">
<children>
<fx:include fx:id="teamPositions" source="TeamPositions.fxml" />
</children> </children>
</AnchorPane> </AnchorPane>
</children> </children>
</GridPane> </AnchorPane>
<AnchorPane fx:id="contentAnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="960.0" prefWidth="1280.0" GridPane.columnIndex="1" GridPane.rowSpan="3">
<children>
<Canvas fx:id="canvas" height="960.0" width="1056.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</children>
</GridPane>
</children>
</AnchorPane>
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="140.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.BoatPositionController">
<children>
<VBox fx:id="positionVbox" layoutX="119.0" layoutY="50.0" prefHeight="200.0" prefWidth="222.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
+3 -3
View File
@@ -16,14 +16,14 @@ public class EventTest {
@Test @Test
public void getTimeString() throws Exception { public void getTimeString() throws Exception {
Boat boat = new Boat("testBoat"); 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()); assertEquals("20:31:242", event.getTimeString());
} }
@Test @Test
public void testBoatHeading() throws Exception { public void testBoatHeading() throws Exception {
Boat boat = new Boat("testBoat"); 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); assertEquals(event.getBoatHeading(), 221.9733862944651, 1e-15);
} }
@@ -31,7 +31,7 @@ public class EventTest {
@Test @Test
public void testDistanceBetweenMarks() throws Exception { public void testDistanceBetweenMarks() throws Exception {
Boat boat = new Boat("testBoat"); 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); assertEquals(event.getDistanceBetweenMarks(), 339059.653830461, 1e-15);
} }
@@ -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<Boat>(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);
}
}
@@ -29,15 +29,15 @@ public class CourseParserTest {
assertTrue(MarkType.GATE_MARK == course.get(0).getMarkType()); assertTrue(MarkType.GATE_MARK == course.get(0).getMarkType());
GateMark gateMark1 = (GateMark) course.get(0); GateMark gateMark1 = (GateMark) course.get(0);
assertEquals(32.293834, gateMark1.getSingleMark2().getLatitude(), 0.00000001); assertEquals(32.293771, gateMark1.getSingleMark2().getLatitude(), 0.00000001);
assertEquals(-64.855195, gateMark1.getSingleMark2().getLongitude(), 0.00000001); assertEquals(-64.855242, gateMark1.getSingleMark2().getLongitude(), 0.00000001);
GateMark gateMark2 = (GateMark) course.get(5); GateMark gateMark2 = (GateMark) course.get(5);
assertEquals("Finish1", gateMark2.getSingleMark1().getName()); assertEquals("Finish1", gateMark2.getSingleMark1().getName());
assertEquals("Finish2", gateMark2.getSingleMark2().getName()); assertEquals("Finish2", gateMark2.getSingleMark2().getName());
assertEquals(32.318303, gateMark2.getSingleMark2().getLatitude(), 0.00000001); assertEquals(32.317257, gateMark2.getSingleMark2().getLatitude(), 0.00000001);
assertEquals(-64.834974, gateMark2.getSingleMark2().getLongitude(), 0.00000001); assertEquals(-64.83626, gateMark2.getSingleMark2().getLongitude(), 0.00000001);
} }
@Test @Test
@@ -26,10 +26,10 @@ public class TeamsParserTest {
assertEquals(6, boats.size(), 1e-10); assertEquals(6, boats.size(), 1e-10);
assertEquals("Oracle Team USA", boats.get(0).getTeamName()); 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("Groupama Team France", boats.get(5).getTeamName());
assertEquals(28.8, boats.get(5).getVelocity(), 1e-10); assertEquals(10, boats.get(5).getVelocity(), 1e-10);
} }
} }