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

This commit is contained in:
Michael Rausch
2017-05-04 13:53:49 +12:00
18 changed files with 446 additions and 363 deletions
@@ -14,10 +14,7 @@ import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon; import javafx.scene.shape.Polygon;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.stage.Stage; import javafx.stage.Stage;
import seng302.models.Boat; import seng302.models.*;
import seng302.models.BoatGroup;
import seng302.models.Colors;
import seng302.models.RaceObject;
import seng302.models.mark.*; import seng302.models.mark.*;
import seng302.models.parsers.StreamParser; import seng302.models.parsers.StreamParser;
import seng302.models.parsers.packets.BoatPositionPacket; import seng302.models.parsers.packets.BoatPositionPacket;
@@ -326,13 +323,16 @@ public class CanvasController {
*/ */
private void drawBoats() { private void drawBoats() {
// Map<Boat, TimelineInfo> timelineInfos = raceViewController.getTimelineInfos(); // Map<Boat, TimelineInfo> timelineInfos = raceViewController.getTimelineInfos();
List<Boat> boats = raceViewController.getStartingBoats(); // List<Boat> boats = raceViewController.getStartingBoats();
Map<Integer, Yacht> boats = StreamParser.getBoats();
Double startingX = raceObjects.get(0).getLayoutX(); Double startingX = raceObjects.get(0).getLayoutX();
Double startingY = raceObjects.get(0).getLayoutY(); Double startingY = raceObjects.get(0).getLayoutY();
Group boatAnnotations = new Group(); Group boatAnnotations = new Group();
for (Boat boat : boats) { for (Yacht boat : boats.values()) {
BoatGroup boatGroup = new BoatGroup(boat, Colors.getColor()); // for (Boat boat : boats) {
boat.setColour(Colors.getColor());
BoatGroup boatGroup = new BoatGroup(boat, boat.getColour());
boatGroup.moveTo(startingX, startingY, 0d); boatGroup.moveTo(startingX, startingY, 0d);
//boatGroup.setStage(raceViewController.getStage()); //boatGroup.setStage(raceViewController.getStage());
raceObjects.add(boatGroup); raceObjects.add(boatGroup);
@@ -65,9 +65,7 @@ public class Controller implements Initializable {
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("UTC"));
realTime.setText(format.format(System.currentTimeMillis()));
} }
/** /**
@@ -144,14 +142,14 @@ public class Controller implements Initializable {
posCol.setCellValueFactory( posCol.setCellValueFactory(
new PropertyValueFactory<>("position") new PropertyValueFactory<>("position")
); );
if (StreamParser.isRaceStarted()) { // if (StreamParser.isRaceStarted()) {
data.addAll(StreamParser.getBoatsPos().values()); data.addAll(StreamParser.getBoatsPos().values());
} else { // } else {
for (Yacht boat : StreamParser.getBoats().values()) { // for (Yacht boat : StreamParser.getBoats().values()) {
boat.setPosition("-"); // boat.setPosition("-");
data.add(boat); // data.add(boat);
} // }
} // }
teamList.refresh(); teamList.refresh();
// posCol.setSortType(TableColumn.SortType.ASCENDING); // posCol.setSortType(TableColumn.SortType.ASCENDING);
@@ -1,15 +1,15 @@
package seng302.controllers; package seng302.controllers;
import seng302.models.Boat;
import seng302.models.Race; import seng302.models.Race;
import seng302.models.Yacht;
import seng302.models.parsers.ConfigParser; import seng302.models.parsers.ConfigParser;
import seng302.models.parsers.CourseParser; import seng302.models.parsers.CourseParser;
import seng302.models.parsers.StreamParser; import seng302.models.parsers.StreamParser;
import seng302.models.parsers.TeamsParser;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
import java.util.Random; import java.util.Random;
/** /**
@@ -41,23 +41,24 @@ public class RaceController {
Race race = new Race(); Race race = new Race();
// StreamParser.xmlObject // StreamParser.xmlObject
// Read team names from file // Read team names from file
TeamsParser tp = new TeamsParser(teamsConfigFile); // TeamsParser tp = new TeamsParser(teamsConfigFile);
// Read course from file // Read course from file
ConfigParser config = new ConfigParser(configFile); // ConfigParser config = new ConfigParser(configFile);
ArrayList<String> boatNames = new ArrayList<>(); ArrayList<String> boatNames = new ArrayList<>();
ArrayList<Boat> teams = tp.getBoats(); // ArrayList<Boat> teams = tp.getBoats();
Map<Long, Yacht> teams = StreamParser.getBoatsPos();
//get race size //get race size
int numberOfBoats = teams.size(); int numberOfBoats = teams.size();
//get time scale //get time scale
double timeScale = config.getTimeScale(); // double timeScale = config.getTimeScale();
race.setTimeScale(timeScale); // race.setTimeScale(timeScale);
for (Boat boat : teams) { for (Yacht boat : teams.values()) {
boatNames.add(boat.getTeamName()); boatNames.add(boat.getBoatName());
race.addBoat(boat); race.addBoat(boat);
} }
@@ -27,7 +27,7 @@ public class RaceResultController implements Initializable{
int boatPosition = this.race.getFinishedBoats().length; int boatPosition = this.race.getFinishedBoats().length;
for (int i = this.race.getFinishedBoats().length - 1; i >= 0; i--){ for (int i = this.race.getFinishedBoats().length - 1; i >= 0; i--){
resultsVBox.getChildren().add(0, new Text(boatPosition + ": " + this.race.getFinishedBoats()[i].getTeamName())); resultsVBox.getChildren().add(0, new Text(boatPosition + ": " + this.race.getFinishedBoats()[i].getBoatName()));
boatPosition--; boatPosition--;
} }
@@ -1,5 +1,6 @@
package seng302.controllers; package seng302.controllers;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import javafx.animation.Animation; import javafx.animation.Animation;
import javafx.animation.KeyFrame; import javafx.animation.KeyFrame;
import javafx.animation.Timeline; import javafx.animation.Timeline;
@@ -44,11 +45,11 @@ public class RaceViewController extends Thread{
@FXML @FXML
private CanvasController includedCanvasController; private CanvasController includedCanvasController;
private ArrayList<Boat> startingBoats = new ArrayList<>(); private ArrayList<Yacht> startingBoats = new ArrayList<>();
private boolean displayFps; private boolean displayFps;
private Timeline timerTimeline; private Timeline timerTimeline;
private Map<Boat, TimelineInfo> timelineInfos = new HashMap<>(); private Map<Yacht, TimelineInfo> timelineInfos = new HashMap<>();
private ArrayList<Boat> boatOrder = new ArrayList<>(); private ArrayList<Yacht> boatOrder = new ArrayList<>();
private Race race; private Race race;
private Stage stage; private Stage stage;
@@ -57,7 +58,7 @@ public class RaceViewController extends Thread{
RaceController raceController = new RaceController(); RaceController raceController = new RaceController();
raceController.initializeRace(); raceController.initializeRace();
race = raceController.getRace(); race = raceController.getRace();
for (Boat boat : race.getBoats()) { for (Yacht boat : race.getBoats()) {
startingBoats.add(boat); startingBoats.add(boat);
} }
// try{ // try{
@@ -72,6 +73,7 @@ public class RaceViewController extends Thread{
initializeTimer(); initializeTimer();
initializeSettings(); initializeSettings();
initialiseWindDirection(); initialiseWindDirection();
initialisePositionVBox();
//set wind direction!!!!!!! can't find another place to put my code --haoming //set wind direction!!!!!!! can't find another place to put my code --haoming
// double windDirection = new ConfigParser("/config/config.xml").getWindDirection(); // double windDirection = new ConfigParser("/config/config.xml").getWindDirection();
// windDirectionText.setText(String.format("%.1f°", windDirection)); // windDirectionText.setText(String.format("%.1f°", windDirection));
@@ -160,12 +162,26 @@ public class RaceViewController extends Thread{
windDirTimeline.playFromStart(); windDirTimeline.playFromStart();
} }
private void initialisePositionVBox() {
Timeline posVBoxTimeline = new Timeline();
posVBoxTimeline.setCycleCount(Timeline.INDEFINITE);
posVBoxTimeline.getKeyFrames().add(
new KeyFrame(Duration.seconds(1),
event -> {
showOrder();
})
);
posVBoxTimeline.playFromStart();
}
/** /**
* 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 initializeTimelines() { private void initializeTimelines() {
HashMap<Boat, List> boat_events = race.getEvents(); HashMap<Yacht, List> boat_events = race.getEvents();
for (Boat boat : boat_events.keySet()) { for (Yacht boat : boat_events.keySet()) {
startingBoats.add(boat); startingBoats.add(boat);
// // x, y are the real time coordinates // // x, y are the real time coordinates
// DoubleProperty x = new SimpleDoubleProperty(); // DoubleProperty x = new SimpleDoubleProperty();
@@ -271,13 +287,13 @@ public class RaceViewController extends Thread{
} }
public void handleEvent(Event event) { public void handleEvent(Event event) {
Boat boat = event.getBoat(); Yacht boat = event.getBoat();
boatOrder.remove(boat); boatOrder.remove(boat);
boat.setMarkLastPast(event.getMarkPosInRace()); boat.setMarkLastPast(event.getMarkPosInRace());
boatOrder.add(boat); boatOrder.add(boat);
boatOrder.sort(new Comparator<Boat>() { boatOrder.sort(new Comparator<Yacht>() {
@Override @Override
public int compare(Boat b1, Boat b2) { public int compare(Yacht b1, Yacht b2) {
return b2.getMarkLastPast() - b1.getMarkLastPast(); return b2.getMarkLastPast() - b1.getMarkLastPast();
} }
}); });
@@ -288,8 +304,20 @@ public class RaceViewController extends Thread{
positionVbox.getChildren().clear(); positionVbox.getChildren().clear();
positionVbox.getChildren().removeAll(); positionVbox.getChildren().removeAll();
for (Boat boat : boatOrder) { // for (Boat boat : boatOrder) {
positionVbox.getChildren().add(new Text(boat.getShortName() + " " + boat.getSpeedInKnots() + " Knots")); // positionVbox.getChildren().add(new Text(boat.getShortName() + " " + boat.getSpeedInKnots() + " Knots"));
// }
for (Yacht boat : StreamParser.getBoatsPos().values()) {
System.out.println(boat.getBoatStatus());
if (boat.getBoatStatus() == 3) { // 3 is finish status
positionVbox.getChildren().add(new Text(boat.getPosition() + ". " +
boat.getShortName() + " (Finished)"));
} else {
positionVbox.getChildren().add(new Text(boat.getPosition() + ". " +
boat.getShortName() + " "));
}
} }
} }
@@ -341,11 +369,11 @@ public class RaceViewController extends Thread{
return race; return race;
} }
public Map<Boat, TimelineInfo> getTimelineInfos() { public Map<Yacht, TimelineInfo> getTimelineInfos() {
return timelineInfos; return timelineInfos;
} }
public ArrayList<Boat> getStartingBoats(){ public ArrayList<Yacht> getStartingBoats(){
return startingBoats; return startingBoats;
} }
+143 -147
View File
@@ -1,147 +1,143 @@
package seng302.models; //package seng302.models;
//
import javafx.geometry.Point2D; //import javafx.geometry.Point2D;
import javafx.scene.paint.Color; //import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon; //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.scene.transform.Translate; //import javafx.scene.transform.Translate;
import javafx.util.Pair; //import javafx.util.Pair;
//
/** ///**
* Represents a boat in the race. //* Represents a boat in the race.
*/ //*/
public class Boat { //public class Boat {
//
private String teamName; // private String teamName;
private double velocity; // private double velocity;
private double lat; // private double lat;
private double lon; // private double lon;
private double heading; // private double heading;
private int markLastPast; // private int markLastPast;
private String shortName; // private String shortName;
private int id; // private int id;
//
/** // public Boat(String teamName) {
* For testing only. // this.teamName = teamName;
* @param teamName Boat team name. // this.velocity = 10; // Default velocity
*/ // this.lat = 0.0;
public Boat(String teamName) { // this.lon = 0.0;
this.teamName = teamName; // this.shortName = "";
this.velocity = 10; // Default velocity // }
this.lat = 0.0; //
this.lon = 0.0; //
this.shortName = ""; // /**
} // * Represents a boat in the race.
// *
// * @param teamName The name of the team sailing the boat
/** // * @param boatVelocity The speed of the boat in meters/second
* Represents a boat in the race. // * @param shortName A shorter version of the teams name
* // */
* @param teamName The name of the team sailing the boat // public Boat(String teamName, double boatVelocity, String shortName, int id) {
* @param boatVelocity The speed of the boat in meters/second // this.teamName = teamName;
* @param shortName A shorter version of the teams name // this.velocity = boatVelocity;
*/ // this.shortName = shortName;
public Boat(String teamName, double boatVelocity, String shortName, int id) { // this.id = id;
this.teamName = teamName; // }
this.velocity = boatVelocity; //
this.shortName = shortName; // /**
this.id = id; // * Returns the name of the team sailing the boat
} // *
// * @return The name of the team
/** // */
* Returns the name of the team sailing the boat // public String getTeamName() {
* // return this.teamName;
* @return The name of the team // }
*/ //
public String getTeamName() { // /**
return this.teamName; // * Sets the name of the team sailing the boat
} // *
// * @param teamName The name of the team
/** // */
* Sets the name of the team sailing the boat // public void setTeamName(String teamName) {
* // this.teamName = teamName;
* @param teamName The name of the team // }
*/ //
public void setTeamName(String teamName) { // /**
this.teamName = teamName; // * Gets velocity of the boat
} // *
// * @return a float number of the boat velocity
/** // */
* Gets velocity of the boat // public double getVelocity() {
* // return this.velocity;
* @return a float number of the boat velocity // }
*/ //
public double getVelocity() { // /**
return this.velocity; // * Sets velocity of the boat
} // *
// * @param velocity The velocity of boat
/** // */
* Sets velocity of the boat // public void setVelocity(double velocity) {
* // this.velocity = velocity;
* @param velocity The velocity of boat // }
*/ //
public void setVelocity(double velocity) { // /**
this.velocity = velocity; // * Sets the boats location
} // *
// * @param lat, the boats latitude
/** // * @param lon, the boats longitude
* Sets the boats location // */
* // public void setLocation(double lat, double lon) {
* @param lat, the boats latitude // this.lat = lat;
* @param lon, the boats longitude // this.lon = lon;
*/ // }
public void setLocation(double lat, double lon) { //
this.lat = lat; // public Pair<Double, Double> getLocation ()
this.lon = lon; // {
} // return new Pair<>(this.lat, this.lon);
// }
public Pair<Double, Double> getLocation () //
{ // public double getLatitude(){
return new Pair<>(this.lat, this.lon); // return this.lat;
} // }
//
public double getLatitude(){ // public double getLongitude(){
return this.lat; // return this.lon;
} // }
//
public double getLongitude(){ // public void setLatitude (double latitude) {
return this.lon; // this.lat = latitude;
} // }
//
public void setLatitude (double latitude) { // public void setlongitude (double longitude) {
this.lat = latitude; // this.lon =longitude;
} // }
//
public void setlongitude (double longitude) { // public double getSpeedInKnots(){
this.lon =longitude; // return Math.round((this.velocity * 1.94384) * 100d) / 100d;
} // }
//
public double getSpeedInKnots(){ // public void setMarkLastPast(int markLastPast) {
return Math.round((this.velocity * 1.94384) * 100d) / 100d; // this.markLastPast = markLastPast;
} // }
//
public void setMarkLastPast(int markLastPast) { // public int getMarkLastPast() {
this.markLastPast = markLastPast; // return markLastPast;
} // }
//
public int getMarkLastPast() { // public double getHeading(){
return markLastPast; // return this.heading;
} // }
//
public double getHeading(){ // public void setHeading(double heading) {
return this.heading; // this.heading = heading;
} // }
//
public void setHeading(double heading) { // public String getShortName(){
this.heading = heading; // return this.shortName;
} // }
//
public String getShortName(){ // public int getId() {
return this.shortName; // return id;
} // }
//}
public int getId() {
return id;
}
}
+6 -6
View File
@@ -33,7 +33,7 @@ public class BoatGroup extends RaceObject{
private int wakeGenerationDelay = 10; private int wakeGenerationDelay = 10;
private double distanceTravelled; private double distanceTravelled;
//Graphical objects //Graphical objects
private Boat boat; private Yacht boat;
private Group lineGroup = new Group(); private Group lineGroup = new Group();
private Polygon boatPoly; private Polygon boatPoly;
private Text teamNameObject; private Text teamNameObject;
@@ -54,7 +54,7 @@ public class BoatGroup extends RaceObject{
* BoatGroup to update. * BoatGroup to update.
* @param color The colour of the boat polygon and the trailing line. * @param color The colour of the boat polygon and the trailing line.
*/ */
public BoatGroup (Boat boat, Color color){ public BoatGroup (Yacht boat, Color color){
this.boat = boat; this.boat = boat;
initChildren(color); initChildren(color);
} }
@@ -66,7 +66,7 @@ public class BoatGroup extends RaceObject{
* @param color The colour of the boat polygon and the trailing line. * @param color The colour of the boat polygon and the trailing line.
* @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat polygon. * @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat polygon.
*/ */
public BoatGroup (Boat boat, Color color, double... points) public BoatGroup (Yacht boat, Color color, double... points)
{ {
this.boat = boat; this.boat = boat;
initChildren(color, points); initChildren(color, points);
@@ -295,7 +295,7 @@ public class BoatGroup extends RaceObject{
wake.setVisible(visible); wake.setVisible(visible);
} }
public Boat getBoat() { public Yacht getBoat() {
return boat; return boat;
} }
@@ -307,7 +307,7 @@ public class BoatGroup extends RaceObject{
*/ */
public boolean hasRaceId (int... raceIds) { public boolean hasRaceId (int... raceIds) {
for (int id : raceIds) { for (int id : raceIds) {
if (id == boat.getId()) if (id == boat.getSourceID())
return true; return true;
} }
return false; return false;
@@ -319,7 +319,7 @@ public class BoatGroup extends RaceObject{
* @return An array containing all ID's associated with this RaceObject. * @return An array containing all ID's associated with this RaceObject.
*/ */
public int[] getRaceIds () { public int[] getRaceIds () {
return new int[] {boat.getId()}; return new int[] {boat.getSourceID()};
} }
/** /**
+7 -7
View File
@@ -11,7 +11,7 @@ import java.util.Date;
*/ */
public class Event { public class Event {
private Double time; // Time the event occurs private Double time; // Time the event occurs
private Boat boat; private Yacht boat;
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
@@ -28,7 +28,7 @@ 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, int markPosInRace) { public Event(Double eventTime, Yacht eventBoat, Mark mark1, Mark mark2, int markPosInRace) {
this.time = eventTime; this.time = eventTime;
this.boat = eventBoat; this.boat = eventBoat;
this.mark1 = mark1; this.mark1 = mark1;
@@ -45,7 +45,7 @@ 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, int markPosInRace) { public Event(Double eventTime, Yacht eventBoat, Mark mark1, int markPosInRace) {
this.time = eventTime; this.time = eventTime;
this.boat = eventBoat; this.boat = eventBoat;
this.mark1 = mark1; this.mark1 = mark1;
@@ -70,11 +70,11 @@ 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()));
} }
public Boat getBoat() { public Yacht getBoat() {
return this.boat; return this.boat;
} }
public void setBoat(Boat eventBoat) { public void setBoat(Yacht eventBoat) {
this.boat = eventBoat; this.boat = eventBoat;
} }
@@ -90,10 +90,10 @@ public class Event {
public String getEventString() { public String getEventString() {
// This event is a boat finishing the race // This event is a boat finishing the race
if (this.isFinishingEvent) { if (this.isFinishingEvent) {
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race"); return (this.getTimeString() + ", " + this.getBoat().getBoatName() + " finished the race");
} }
// System.out.println(this.getDistanceBetweenMarks()); // System.out.println(this.getDistanceBetweenMarks());
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.mark1.getName() + " going heading " + this.getBoatHeading() + "°"); return (this.getTimeString() + ", " + this.getBoat().getBoatName() + " passed " + this.mark1.getName() + " going heading " + this.getBoatHeading() + "°");
} }
/** /**
+13 -13
View File
@@ -10,9 +10,9 @@ import java.util.*;
*/ */
public class Race { public class Race {
private ArrayList<Boat> boats; // The boats in the race private ArrayList<Yacht> boats; // The boats in the race
private ArrayList<Boat> finishingOrder; // The order in which the boats finish the race private ArrayList<Yacht> finishingOrder; // The order in which the boats finish the race
private HashMap<Boat, List> events = new HashMap<>(); // The events that occur in the race private HashMap<Yacht, List> events = new HashMap<>(); // The events that occur in the race
private List<Mark> course; // Marks in the race private List<Mark> course; // Marks in the race
private long startTime = 0; private long startTime = 0;
private double timeScale = 1; private double timeScale = 1;
@@ -33,7 +33,7 @@ public class Race {
* *
* @param boat, the boat to add * @param boat, the boat to add
*/ */
public void addBoat(Boat boat) { public void addBoat(Yacht boat) {
boats.add(boat); boats.add(boat);
} }
@@ -42,12 +42,12 @@ public class Race {
* *
* @return a list of boats * @return a list of boats
*/ */
public Boat[] getShuffledBoats() { public Yacht[] getShuffledBoats() {
// Shuffle the list of boats // Shuffle the list of boats
long seed = System.nanoTime(); long seed = System.nanoTime();
Collections.shuffle(this.boats, new Random(seed)); Collections.shuffle(this.boats, new Random(seed));
return boats.toArray(new Boat[boats.size()]); return boats.toArray(new Yacht[boats.size()]);
} }
/** /**
@@ -56,8 +56,8 @@ public class Race {
* *
* @return a list of boats * @return a list of boats
*/ */
public Boat[] getFinishedBoats() { public Yacht[] getFinishedBoats() {
return this.finishingOrder.toArray(new Boat[this.finishingOrder.size()]); return this.finishingOrder.toArray(new Yacht[this.finishingOrder.size()]);
} }
@@ -66,8 +66,8 @@ public class Race {
* *
* @return a list of the boats competing in the race * @return a list of the boats competing in the race
*/ */
public Boat[] getBoats() { public Yacht[] getBoats() {
return boats.toArray(new Boat[boats.size()]); return boats.toArray(new Yacht[boats.size()]);
} }
/** /**
@@ -84,7 +84,7 @@ public class Race {
*/ */
private void generateEvents() { private void generateEvents() {
for (Boat boat : this.boats) { for (Yacht boat : this.boats) {
double totalDistance = 0; double totalDistance = 0;
int numberOfMarks = this.course.size(); int numberOfMarks = this.course.size();
@@ -146,7 +146,7 @@ public class Race {
* Get a map of the events in the race * Get a map of the events in the race
* @return * @return
*/ */
public HashMap<Boat, List> getEvents() { public HashMap<Yacht, List> getEvents() {
return events; return events;
} }
@@ -154,7 +154,7 @@ public class Race {
* Set a boat as finished * Set a boat as finished
* @param boat The boat that has finished the race/home/cosc/student/wmu16 * @param boat The boat that has finished the race/home/cosc/student/wmu16
*/ */
public void setBoatFinished(Boat boat){ public void setBoatFinished(Yacht boat){
this.finishingOrder.add(boat); this.finishingOrder.add(boat);
} }
+53
View File
@@ -1,5 +1,7 @@
package seng302.models; package seng302.models;
import javafx.scene.paint.Color;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@@ -10,6 +12,10 @@ import java.text.SimpleDateFormat;
* also done outside Boat class because some old variables are not used anymore. * also done outside Boat class because some old variables are not used anymore.
*/ */
public class Yacht { public class Yacht {
private Color colour;
private double velocity;
private Integer markLastPast;
private String boatType; private String boatType;
private Integer sourceID; private Integer sourceID;
private String hullID; //matches HullNum in the XML spec. private String hullID; //matches HullNum in the XML spec.
@@ -25,6 +31,29 @@ public class Yacht {
private Long estimateTimeAtFinish; private Long estimateTimeAtFinish;
private String position; private String position;
/**
* Used in EventTest and RaceTest.
*
* @param boatName Create a yacht object with name.
*/
public Yacht (String boatName) {
this.boatName = boatName;
}
/**
* Used in BoatGroupTest.
*
* @param boatName The name of the team sailing the boat
* @param boatVelocity The speed of the boat in meters/second
* @param shortName A shorter version of the teams name
*/
public Yacht(String boatName, double boatVelocity, String shortName, int id) {
this.boatName = boatName;
this.velocity = boatVelocity;
this.shortName = shortName;
this.sourceID = id;
}
public Yacht(String boatType, Integer sourceID, String hullID, String shortName, String boatName, String country) { public Yacht(String boatType, Integer sourceID, String hullID, String shortName, String boatName, String country) {
this.boatType = boatType; this.boatType = boatType;
this.sourceID = sourceID; this.sourceID = sourceID;
@@ -111,4 +140,28 @@ public class Yacht {
public void setPosition(String position) { public void setPosition(String position) {
this.position = position; this.position = position;
} }
public Color getColour() {
return colour;
}
public void setColour(Color colour) {
this.colour = colour;
}
public double getVelocity() {
return velocity;
}
public void setVelocity(double velocity) {
this.velocity = velocity;
}
public Integer getMarkLastPast() {
return markLastPast;
}
public void setMarkLastPast(Integer markLastPast) {
this.markLastPast = markLastPast;
}
} }
@@ -231,11 +231,17 @@ public class StreamParser extends Thread{
// boatStatus += "\nEstTimeAtFinish: " + bytesToLong(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20))); // boatStatus += "\nEstTimeAtFinish: " + bytesToLong(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20)));
// boatStatuses.add(boatStatus); // boatStatuses.add(boatStatus);
} }
if (isRaceStarted()) {
int pos = 1; int pos = 1;
for (Yacht yacht : boatsPos.values()) { for (Yacht yacht : boatsPos.values()) {
yacht.setPosition(String.valueOf(pos)); yacht.setPosition(String.valueOf(pos));
pos++; pos++;
} }
} else {
for (Yacht yacht : boatsPos.values()) {
yacht.setPosition("-");
}
}
} }
/** /**
@@ -1,64 +1,64 @@
package seng302.models.parsers; //package seng302.models.parsers;
//
import org.w3c.dom.*; //import org.w3c.dom.*;
import seng302.models.Boat; //import seng302.models.Yacht;
//
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.NoSuchElementException; //import java.util.NoSuchElementException;
//
public class TeamsParser extends FileParser { //public class TeamsParser extends FileParser {
//
private Document doc; // private Document doc;
//
public TeamsParser(String path) { // public TeamsParser(String path) {
super(path); // super(path);
this.doc = this.parseFile(); // this.doc = this.parseFile();
} // }
//
/** // /**
* Create a boat instance by a given team node // * Create a boat instance by a given team node
* @param node a boat node containing name, alias and velocity // * @param node a boat node containing name, alias and velocity
* @return an instance of Boat // * @return an instance of Boat
*/ // */
private Boat parseBoat(Node node) { // private Yacht parseBoat(Node node) {
try { // try {
if (node.getNodeType() == Node.ELEMENT_NODE) { // if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node; // Element element = (Element) node;
String name = element.getElementsByTagName("name").item(0).getTextContent(); // String name = element.getElementsByTagName("name").item(0).getTextContent();
String alias = element.getElementsByTagName("alias").item(0).getTextContent(); // String alias = element.getElementsByTagName("alias").item(0).getTextContent();
double velocity = Double.valueOf(element.getElementsByTagName("velocity").item(0).getTextContent()); // double velocity = Double.valueOf(element.getElementsByTagName("velocity").item(0).getTextContent());
int id = Integer.valueOf(element.getElementsByTagName("id").item(0).getTextContent()); // int id = Integer.valueOf(element.getElementsByTagName("id").item(0).getTextContent());
Boat boat = new Boat(name, velocity, alias, id); // Yacht boat = new Yacht(name, velocity, alias, id);
return boat; // return boat;
} else { // } else {
throw new NoSuchElementException("Cannot generate a boat by given node"); // throw new NoSuchElementException("Cannot generate a boat by given node");
} // }
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
return null; // return null;
} // }
} // }
//
/** // /**
* Create an arraylist of boats instance. // * Create an arraylist of boats instance.
* @return an arraylist of boats in teams file // * @return an arraylist of boats in teams file
*/ // */
public ArrayList<Boat> getBoats() { // public ArrayList<Yacht> getBoats() {
ArrayList<Boat> boats = new ArrayList<>(); // ArrayList<Yacht> boats = new ArrayList<>();
//
try { // try {
NodeList nodes = this.doc.getElementsByTagName("team"); // NodeList nodes = this.doc.getElementsByTagName("team");
for (int i = 0; i < nodes.getLength(); i++) { // for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i); // Node node = nodes.item(i);
boats.add(parseBoat(node)); // boats.add(parseBoat(node));
} // }
return boats; // return boats;
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
return null; // return null;
} // }
} // }
//
//
} //}
//
@@ -120,6 +120,6 @@ public class Boat {
} }
public long getEstimatedTimeTillFinish(){ public long getEstimatedTimeTillFinish(){
return (long) (getSpeed()) + System.currentTimeMillis(); return (long) (-getSpeed()) + System.currentTimeMillis();
} }
} }
+35 -35
View File
@@ -1,35 +1,35 @@
package seng302; //package seng302;
//
import org.junit.Test; //import org.junit.Test;
import seng302.models.Boat; //import seng302.models.Boat;
//
import static org.junit.Assert.assertEquals; //import static org.junit.Assert.assertEquals;
//
/** ///**
* Unit test for the Team class. // * Unit test for the Team class.
*/ // */
public class BoatTest { //public class BoatTest {
//
@Test // @Test
public void testBoatCreation() { // public void testBoatCreation() {
Boat boat1 = new Boat("Team 1"); // Boat boat1 = new Boat("Team 1");
assertEquals(boat1.getTeamName(), "Team 1"); // assertEquals(boat1.getTeamName(), "Team 1");
assertEquals(boat1.getVelocity(), (double) 10.0, 1e-15); // assertEquals(boat1.getVelocity(), (double) 10.0, 1e-15);
} // }
//
@Test // @Test
public void testChangeTeamName() { // public void testChangeTeamName() {
Boat boat1 = new Boat("Team 1"); // Boat boat1 = new Boat("Team 1");
boat1.setTeamName("Team 2"); // boat1.setTeamName("Team 2");
assertEquals(boat1.getTeamName(), "Team 2"); // assertEquals(boat1.getTeamName(), "Team 2");
} // }
//
@Test // @Test
public void testSetVelocity() { // public void testSetVelocity() {
Boat boat1 = new Boat("Team 1", 29.0, "", 100); // Boat boat1 = new Boat("Team 1", 29.0, "", 100);
assertEquals(boat1.getVelocity(), (double) 29.0, 1e-15); // assertEquals(boat1.getVelocity(), (double) 29.0, 1e-15);
//
boat1.setVelocity(12.0); // boat1.setVelocity(12.0);
assertEquals(boat1.getVelocity(), (double)12.0, 1e-15); // assertEquals(boat1.getVelocity(), (double)12.0, 1e-15);
} // }
} //}
+4 -4
View File
@@ -1,8 +1,8 @@
package seng302; package seng302;
import org.junit.Test; import org.junit.Test;
import seng302.models.Boat;
import seng302.models.Event; import seng302.models.Event;
import seng302.models.Yacht;
import seng302.models.mark.SingleMark; import seng302.models.mark.SingleMark;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -15,14 +15,14 @@ public class EventTest {
@Test @Test
public void getTimeString() throws Exception { public void getTimeString() throws Exception {
Boat boat = new Boat("testBoat"); Yacht boat = new Yacht("testBoat");
Event event = new Event(1231242.2, boat, new SingleMark("mark1"), new SingleMark("mark2"), 0); 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"); Yacht boat = new Yacht("testBoat");
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1, 1), new SingleMark("mark2", 121.9,99.2, 2), 0); Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1, 1), new SingleMark("mark2", 121.9,99.2, 2), 0);
assertEquals(event.getBoatHeading(), 228.0266137055349, 1e-15); assertEquals(event.getBoatHeading(), 228.0266137055349, 1e-15);
@@ -30,7 +30,7 @@ public class EventTest {
@Test @Test
public void testDistanceBetweenMarks() throws Exception { public void testDistanceBetweenMarks() throws Exception {
Boat boat = new Boat("testBoat"); Yacht boat = new Yacht("testBoat");
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1, 1), new SingleMark("mark2", 121.9,99.2, 2), 0); Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1, 1), new SingleMark("mark2", 121.9,99.2, 2), 0);
assertEquals(event.getDistanceBetweenMarks(), 339059.653830461, 1e-15); assertEquals(event.getDistanceBetweenMarks(), 339059.653830461, 1e-15);
+5 -5
View File
@@ -1,8 +1,8 @@
package seng302; package seng302;
import org.junit.Test; import org.junit.Test;
import seng302.models.Boat;
import seng302.models.Race; import seng302.models.Race;
import seng302.models.Yacht;
import java.lang.reflect.Array; import java.lang.reflect.Array;
@@ -17,8 +17,8 @@ public class RaceTest {
*/ */
@Test @Test
public void testAddingBoatsToRace() { public void testAddingBoatsToRace() {
Boat boat1 = new Boat("Team 1"); Yacht boat1 = new Yacht("Team 1");
Boat boat2 = new Boat("Team 2"); Yacht boat2 = new Yacht("Team 2");
Race race = new Race(); Race race = new Race();
race.addBoat(boat1); race.addBoat(boat1);
@@ -29,8 +29,8 @@ public class RaceTest {
@Test @Test
public void testGetShuffledBoats(){ public void testGetShuffledBoats(){
Boat boat1 = new Boat("Team 1"); Yacht boat1 = new Yacht("Team 1");
Boat boat2 = new Boat("Team 2"); Yacht boat2 = new Yacht("Team 2");
Race race = new Race(); Race race = new Race();
race.addBoat(boat1); race.addBoat(boat1);
@@ -16,7 +16,7 @@ public class BoatGroupTest {
BoatGroup boatGroup; BoatGroup boatGroup;
@Before @Before
public void setUp () { public void setUp () {
Boat b = new Boat("TEST", 0.0, "T" ,0); Yacht b = new Yacht("TEST", 0.0, "T" ,0);
boatGroup = new BoatGroup(b, Color.BLACK); boatGroup = new BoatGroup(b, Color.BLACK);
} }
@@ -1,35 +1,36 @@
package seng302.models.parsers; //package seng302.models.parsers;
//
import org.junit.Before; //import org.junit.Before;
import org.junit.Test; //import org.junit.Test;
import seng302.models.Boat; //import seng302.models.Boat;
//import seng302.models.Yacht;
import java.util.ArrayList; //
//import java.util.ArrayList;
import static org.junit.Assert.*; //
//import static org.junit.Assert.*;
/** //
* Created by Haoming on 18/03/17. ///**
*/ // * Created by Haoming on 18/03/17.
public class TeamsParserTest { // */
//public class TeamsParserTest {
private TeamsParser tp; //
@Before // private TeamsParser tp;
public void readFile() { // @Before
tp = new TeamsParser("/config/teams.xml"); // public void readFile() {
} // tp = new TeamsParser("/config/teams.xml");
// }
@Test //
public void getBoats() throws Exception { // @Test
ArrayList<Boat> boats = tp.getBoats(); // public void getBoats() throws Exception {
// ArrayList<Yacht> boats = tp.getBoats();
assertEquals(6, boats.size(), 1e-10); //
// assertEquals(6, boats.size(), 1e-10);
assertEquals("Oracle Team USA", boats.get(0).getTeamName()); //
//assertEquals(30.9, boats.get(0).getVelocity(), 1e-10); // assertEquals("Oracle Team USA", boats.get(0).getBoatName());
// //assertEquals(30.9, boats.get(0).getVelocity(), 1e-10);
assertEquals("Groupama Team France", boats.get(5).getTeamName()); //
//assertEquals(45.6, boats.get(5).getVelocity(), 1e-10); // assertEquals("Groupama Team France", boats.get(5).getBoatName());
} // //assertEquals(45.6, boats.get(5).getVelocity(), 1e-10);
// }
} //
//}