Merge branch 'splitIntoTwoModules' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into isolatingMock
This commit is contained in:
@@ -9,6 +9,7 @@ import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Mock.StreamedRace;
|
||||
import seng302.Model.*;
|
||||
import seng302.RaceDataSource;
|
||||
import seng302.RaceXMLReader;
|
||||
@@ -116,14 +117,14 @@ public class RaceController extends Controller {
|
||||
* @param scaleFactor scale value of race
|
||||
*/
|
||||
public void startRace(int scaleFactor, RaceDataSource raceData) {
|
||||
ConstantVelocityRace newRace = new ConstantVelocityRace(raceData, this, scaleFactor);
|
||||
newRace.initialiseBoats();
|
||||
StreamedRace newRace = new StreamedRace(raceData, this, scaleFactor);
|
||||
//newRace.initialiseBoats();
|
||||
|
||||
raceMap = new ResizableRaceCanvas(raceData);
|
||||
raceMap.setMouseTransparent(true);
|
||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
||||
raceMap.setBoats(newRace.getStartingBoats());
|
||||
//raceMap.setBoats(newRace.getStartingBoats());
|
||||
raceMap.setRaceBoundaries(raceData.getBoundary());
|
||||
raceMap.drawRaceMap();
|
||||
raceMap.setVisible(true);
|
||||
@@ -133,7 +134,7 @@ public class RaceController extends Controller {
|
||||
|
||||
//Initialize save annotation array, fps listener, and annotation listeners
|
||||
//timezone
|
||||
RaceClock raceClock = new RaceClock(raceData.getMark());
|
||||
RaceClock raceClock = new RaceClock(raceData.getZonedDateTime());
|
||||
timeZone.setText(raceClock.getTimeZone());
|
||||
initializeFPS();
|
||||
initializeAnnotations();
|
||||
|
||||
@@ -13,6 +13,7 @@ import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Mock.*;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.Model.RaceClock;
|
||||
import seng302.RaceDataSource;
|
||||
@@ -21,6 +22,7 @@ import seng302.RaceXMLReader;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@@ -46,6 +48,7 @@ public class StartController extends Controller {
|
||||
private RaceClock raceClock;
|
||||
|
||||
private RaceDataSource raceData;
|
||||
private long timeLeft = 1;
|
||||
|
||||
/**
|
||||
* Begins the race with a scale factor of 15
|
||||
@@ -80,15 +83,23 @@ public class StartController extends Controller {
|
||||
public void initialize(URL location, ResourceBundle resources){
|
||||
raceData = null;
|
||||
try {
|
||||
raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
||||
StreamedCourse streamedCourse = new StreamedCourse(new BoatXMLReader("mockXML/boatXML/boatTest.xml"));
|
||||
streamedCourse.setStreamedCourseXMLReader(new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml"));
|
||||
streamedCourse.setRegattaXMLReader(new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml"));
|
||||
raceData = streamedCourse;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SAXException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
} catch (StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
initialiseTables();
|
||||
setRaceClock();
|
||||
}
|
||||
|
||||
public AnchorPane startWrapper(){
|
||||
@@ -102,9 +113,6 @@ public class StartController extends Controller {
|
||||
boatNameTable.setItems(observableBoats);
|
||||
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatCodeColumn.setCellValueFactory(new PropertyValueFactory<>("abbrev"));
|
||||
//timezone
|
||||
raceClock = new RaceClock(raceData.getMark());
|
||||
timeZoneTime.textProperty().bind(raceClock.timeProperty());
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +138,6 @@ public class StartController extends Controller {
|
||||
long currentTimeInSeconds;
|
||||
long remainingSeconds;
|
||||
long hours;
|
||||
long timeLeft;
|
||||
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
@@ -148,7 +155,6 @@ public class StartController extends Controller {
|
||||
hours = minutes / 60;
|
||||
minutes = minutes % 60;
|
||||
updateTime(String.format("Race Clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
|
||||
raceClock.updateTime();
|
||||
|
||||
}
|
||||
currentTime = System.currentTimeMillis();
|
||||
@@ -156,4 +162,20 @@ public class StartController extends Controller {
|
||||
}.start();
|
||||
}
|
||||
|
||||
protected void setRaceClock() {
|
||||
raceClock = new RaceClock(raceData.getZonedDateTime());
|
||||
timeZoneTime.textProperty().bind(raceClock.timeStringProperty());
|
||||
|
||||
new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
if (timeLeft > 0) {
|
||||
raceClock.updateTime();
|
||||
} else {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.XMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by Joseph on 24/04/2017.
|
||||
*/
|
||||
public class BoatXMLReader extends XMLReader {
|
||||
Map<Integer, StreamedBoat> streamedBoatMap = new HashMap<>();
|
||||
Map<Integer, StreamedBoat> participants = new HashMap<>();
|
||||
private List<Color> colours;
|
||||
private static int currentColourIndex = 0;
|
||||
|
||||
/**
|
||||
* Constructor for Boat XML Reader
|
||||
* @param filePath path of the file
|
||||
* @throws IOException error
|
||||
* @throws SAXException error
|
||||
* @throws ParserConfigurationException error
|
||||
*/
|
||||
public BoatXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException {
|
||||
this(filePath, false);
|
||||
makeColours();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for Boat XML Reader
|
||||
* @param filePath file path to read
|
||||
* @param read whether or not to read and store the files straight away.
|
||||
* @throws IOException error
|
||||
* @throws SAXException error
|
||||
* @throws ParserConfigurationException error
|
||||
*/
|
||||
public BoatXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException {
|
||||
super(filePath);
|
||||
makeColours();
|
||||
if (read) {
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
public void read() {
|
||||
readSettings();
|
||||
readShapes();
|
||||
readBoats();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads boats settings.
|
||||
* INFORMATION FROM HERE IS IGNORED FOR NOW
|
||||
*/
|
||||
private void readSettings() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads different kinds of boat.
|
||||
* INFORMATION FROM HERE IS IGNORED FOR NOW
|
||||
*/
|
||||
private void readShapes() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the boats in the race
|
||||
*/
|
||||
private void readBoats() {
|
||||
Element nBoats = (Element) doc.getElementsByTagName("Boats").item(0);
|
||||
for (int i = 0; i < nBoats.getChildNodes().getLength(); i++) {
|
||||
Node boat = nBoats.getChildNodes().item(i);
|
||||
if (boat.getNodeName().equals("Boat")) {
|
||||
readSingleBoat(boat);
|
||||
currentColourIndex = (currentColourIndex + 1) % colours.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the information about one boat
|
||||
* Ignored values: ShapeID, StoweName, HullNum, Skipper
|
||||
*/
|
||||
private void readSingleBoat(Node boat) {
|
||||
StreamedBoat streamedBoat;
|
||||
String type = "None";
|
||||
int sourceID = -1;
|
||||
String boatName = null;
|
||||
String shortName = null;
|
||||
String country = null;
|
||||
if (exists(boat, "Type")) type = boat.getAttributes().getNamedItem("Type").getTextContent();
|
||||
if (exists(boat, "SourceID")) sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent());
|
||||
if (exists(boat, "BoatName")) boatName = boat.getAttributes().getNamedItem("BoatName").getTextContent();
|
||||
if (exists(boat, "ShortName")) shortName = boat.getAttributes().getNamedItem("ShortName").getTextContent();
|
||||
if (exists(boat, "Country")) country = boat.getAttributes().getNamedItem("Country").getTextContent();
|
||||
|
||||
// Ignore all non participating boats
|
||||
if (participants.containsKey(sourceID)) {
|
||||
|
||||
if (!streamedBoatMap.containsKey(sourceID)) {
|
||||
if (country != null) {
|
||||
streamedBoat = new StreamedBoat(sourceID, boatName, colours.get(currentColourIndex), country);
|
||||
} else {
|
||||
streamedBoat = new StreamedBoat(sourceID, boatName, colours.get(currentColourIndex), shortName);
|
||||
}
|
||||
streamedBoatMap.put(sourceID, streamedBoat);
|
||||
// Override boat with new boat
|
||||
participants.put(sourceID, streamedBoat);
|
||||
}
|
||||
|
||||
for (int i = 0; i < boat.getChildNodes().getLength(); i++) {
|
||||
Node GPSPosition = boat.getChildNodes().item(i);
|
||||
if (GPSPosition.getNodeName().equals("GPSposition")) readBoatPositionInformation(sourceID, GPSPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the positional information about a boat
|
||||
* Ignored values: FlagPosition, MastTop, Z value of GPSposition
|
||||
*/
|
||||
private void readBoatPositionInformation(int sourceID, Node GPSPosition) {
|
||||
// TODO Get relative point before implementing. (GPSposition is based off a relative point).
|
||||
}
|
||||
|
||||
private void makeColours() {
|
||||
colours = new ArrayList<Color>(Arrays.asList(
|
||||
Color.BLUEVIOLET,
|
||||
Color.BLACK,
|
||||
Color.RED,
|
||||
Color.ORANGE,
|
||||
Color.DARKOLIVEGREEN,
|
||||
Color.LIMEGREEN,
|
||||
Color.PURPLE,
|
||||
Color.DARKGRAY,
|
||||
Color.YELLOW
|
||||
));
|
||||
}
|
||||
|
||||
public void setParticipants(Map<Integer, StreamedBoat> participants) {
|
||||
this.participants = participants;
|
||||
}
|
||||
|
||||
public Map<Integer, StreamedBoat> getStreamedBoatMap() {
|
||||
return streamedBoatMap;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 19/04/17.
|
||||
*/
|
||||
@@ -96,4 +98,8 @@ public class Regatta {
|
||||
public void setMagneticVariation(float magneticVariation) {
|
||||
this.magneticVariation = magneticVariation;
|
||||
}
|
||||
|
||||
public GPSCoordinate getGPSCoordinate() {
|
||||
return new GPSCoordinate(centralLatitude, centralLongitude);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package seng302.Mock;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.RaceDataSource;
|
||||
import seng302.XMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.BoatInRace;
|
||||
|
||||
/**
|
||||
* Created by Joseph on 24/04/2017.
|
||||
*/
|
||||
public class StreamedBoat extends BoatInRace {
|
||||
private int sourceID;
|
||||
private boolean complete;
|
||||
|
||||
public StreamedBoat(int sourceID, String name, Color colour, String abbrev) {
|
||||
super(name, colour, abbrev);
|
||||
this.sourceID = sourceID;
|
||||
this.complete = true;
|
||||
}
|
||||
|
||||
public StreamedBoat(int sourceID) {
|
||||
super("None", Color.BLACK, "None");
|
||||
this.sourceID = sourceID;
|
||||
this.complete = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Overridden to ignore this function
|
||||
* @deprecated
|
||||
* @return 0
|
||||
*/
|
||||
public double getScaledVelocity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden to ignore this function
|
||||
* @deprecated
|
||||
* @param velocity of boat
|
||||
*/
|
||||
public void setScaledVelocity(double velocity) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.RaceClock;
|
||||
import seng302.RaceDataSource;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 21/04/17.
|
||||
*/
|
||||
public class StreamedCourse implements RaceDataSource {
|
||||
StreamedCourseXMLReader streamedCourseXMLReader = null;
|
||||
BoatXMLReader boatXMLReader = null;
|
||||
RegattaXMLReader regattaXMLReader = null;
|
||||
List<GPSCoordinate> boundary = new ArrayList<>();
|
||||
|
||||
public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) {
|
||||
this.streamedCourseXMLReader = streamedCourseXMLReader;
|
||||
}
|
||||
|
||||
public StreamedCourse(BoatXMLReader boatXMLReader) {
|
||||
this.boatXMLReader = boatXMLReader;
|
||||
}
|
||||
|
||||
public void setBoatXMLReader(BoatXMLReader boatXMLReader) {
|
||||
this.boatXMLReader = boatXMLReader;
|
||||
if (streamedCourseXMLReader != null) {
|
||||
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
|
||||
boatXMLReader.read();
|
||||
}
|
||||
}
|
||||
|
||||
public void setStreamedCourseXMLReader(StreamedCourseXMLReader streamedCourseXMLReader) {
|
||||
this.streamedCourseXMLReader = streamedCourseXMLReader;
|
||||
if (streamedCourseXMLReader != null) {
|
||||
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
|
||||
boatXMLReader.read();
|
||||
}
|
||||
}
|
||||
|
||||
public void setRegattaXMLReader(RegattaXMLReader regattaXMLReader) {
|
||||
this.regattaXMLReader = regattaXMLReader;
|
||||
}
|
||||
|
||||
public RegattaXMLReader getRegattaXMLReader() {
|
||||
return regattaXMLReader;
|
||||
}
|
||||
|
||||
public List<BoatInRace> getBoats() {
|
||||
return new ArrayList<>(boatXMLReader.getStreamedBoatMap().values());
|
||||
}
|
||||
|
||||
public List<Leg> getLegs() {
|
||||
return streamedCourseXMLReader.getLegs();
|
||||
}
|
||||
|
||||
public List<GPSCoordinate> getBoundary() {
|
||||
return streamedCourseXMLReader.getBoundary();
|
||||
}
|
||||
|
||||
public ZonedDateTime getZonedDateTime() {
|
||||
return RaceClock.getCurrentZonedDateTime(regattaXMLReader.getRegatta().getGPSCoordinate());
|
||||
}
|
||||
|
||||
public GPSCoordinate getMapTopLeft() {
|
||||
return streamedCourseXMLReader.getMapTopLeft();
|
||||
}
|
||||
|
||||
public GPSCoordinate getMapBottomRight() {
|
||||
return streamedCourseXMLReader.getMapBottomRight();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package seng302.Mock;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 25/04/17.
|
||||
*/
|
||||
public class StreamedCourseXMLException extends Throwable {
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.Marker;
|
||||
import seng302.XMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 21/04/17.
|
||||
*/
|
||||
public class StreamedCourseXMLReader extends XMLReader {
|
||||
private static double COORDINATEPADDING = 0.0005;
|
||||
private GPSCoordinate mapTopLeft, mapBottomRight;
|
||||
private List<GPSCoordinate> boundary = new ArrayList<>();
|
||||
private Map<Integer,Element> marks = new HashMap<>();
|
||||
private Map<Integer, StreamedBoat> participants = new HashMap<>();
|
||||
private List<Leg> legs = new ArrayList<>();
|
||||
Date creationTimeDate;
|
||||
Date raceStartTime;
|
||||
int raceID;
|
||||
String raceType;
|
||||
boolean postpone;
|
||||
|
||||
/**
|
||||
* Constructor for Streamed Race XML
|
||||
* @param filePath path of the file
|
||||
* @throws IOException error
|
||||
* @throws SAXException error
|
||||
* @throws ParserConfigurationException error
|
||||
*/
|
||||
public StreamedCourseXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException {
|
||||
this(filePath, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for Streamed Race XML
|
||||
* @param filePath file path to read
|
||||
* @param read whether or not to read and store the files straight away.
|
||||
* @throws IOException error
|
||||
* @throws SAXException error
|
||||
* @throws ParserConfigurationException error
|
||||
*/
|
||||
public StreamedCourseXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException {
|
||||
super(filePath);
|
||||
if (read) {
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
private void read() throws ParseException, StreamedCourseXMLException {
|
||||
readRace();
|
||||
readParticipants();
|
||||
readCourse();
|
||||
}
|
||||
|
||||
private void readRace() throws ParseException {
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
|
||||
|
||||
raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID"));
|
||||
raceType = getTextValueOfNode(settings, "RaceType");
|
||||
creationTimeDate = dateFormat.parse(getTextValueOfNode(settings, "CreationTimeDate"));
|
||||
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();
|
||||
raceStartTime = dateFormat.parse(raceTimeTag.getNamedItem("Time").getTextContent());
|
||||
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
|
||||
}
|
||||
|
||||
private void readParticipants() {
|
||||
Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0);
|
||||
for (int i = 0; i < nParticipants.getChildNodes().getLength(); i++) {
|
||||
int sourceID;
|
||||
Node yacht = nParticipants.getChildNodes().item(i);
|
||||
if (yacht.getNodeName().equals("Yacht")) {
|
||||
if (exists(yacht, "SourceID")) {
|
||||
sourceID = Integer.parseInt(yacht.getAttributes().getNamedItem("SourceID").getTextContent());
|
||||
participants.put(sourceID, new StreamedBoat(sourceID));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void readCourse() throws StreamedCourseXMLException {
|
||||
readCompoundMarks();
|
||||
readCompoundMarkSequence();
|
||||
readCourseLimit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexes CompoundMark elements by their ID for use in generating the course.
|
||||
*/
|
||||
private void readCompoundMarks() {
|
||||
Element nCourse = (Element) doc.getElementsByTagName("Course").item(0);
|
||||
for(int i = 0; i < nCourse.getChildNodes().getLength(); i++) {
|
||||
Node compoundMark = nCourse.getChildNodes().item(i);
|
||||
if(compoundMark.getNodeName().equals("CompoundMark")) {
|
||||
marks.put(getCompoundMarkID((Element)compoundMark),(Element)compoundMark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Marker from the CompoundMark element with given ID.
|
||||
* @param compoundMarkID index of required CompoundMark element
|
||||
* @return generated Marker
|
||||
* @throws StreamedCourseXMLException if CompoundMark element contains unhandled number of marks
|
||||
* @see seng302.Model.Marker
|
||||
*/
|
||||
private Marker getMarker(int compoundMarkID) throws StreamedCourseXMLException {
|
||||
Element compoundMark = marks.get(compoundMarkID);
|
||||
NodeList nMarks = compoundMark.getElementsByTagName("Mark");
|
||||
Marker marker;
|
||||
|
||||
switch(nMarks.getLength()) {
|
||||
case 1: marker = new Marker(getCoordinate((Element)nMarks.item(0))); break;
|
||||
case 2: marker = new Marker(getCoordinate((Element)nMarks.item(0)), getCoordinate((Element)nMarks.item(1))); break;
|
||||
default: throw new StreamedCourseXMLException();
|
||||
}
|
||||
|
||||
return marker;
|
||||
}
|
||||
|
||||
private GPSCoordinate getCoordinate(Element mark) {
|
||||
double lat = Double.parseDouble(mark.getAttribute("TargetLat"));
|
||||
double lon = Double.parseDouble(mark.getAttribute("TargetLng"));
|
||||
return new GPSCoordinate(lat,lon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads "compoundMarkID" attribute of CompoundMark or Corner element
|
||||
* @param element with "compoundMarkID" attribute
|
||||
* @return value of "compoundMarkID" attribute
|
||||
*/
|
||||
private int getCompoundMarkID(Element element) {
|
||||
return Integer.parseInt(element.getAttribute("CompoundMarkID"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads "name" attribute of CompoundMark element with corresponding CompoundMarkID
|
||||
* @param compoundMarkID unique ID for CompoundMark element
|
||||
* @return value of "name" attribute
|
||||
*/
|
||||
private String getCompoundMarkName(int compoundMarkID) {
|
||||
return marks.get(compoundMarkID).getAttribute("Name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates list of legs given CompoundMarkSequence element and referenced CompoundMark elements.
|
||||
* @throws StreamedCourseXMLException if markers cannot be resolved from CompoundMark
|
||||
*/
|
||||
private void readCompoundMarkSequence() throws StreamedCourseXMLException {
|
||||
Element nCompoundMarkSequence = (Element) doc.getElementsByTagName("CompoundMarkSequence").item(0);
|
||||
NodeList nCorners = nCompoundMarkSequence.getElementsByTagName("Corner");
|
||||
Marker lastMarker = getMarker(getCompoundMarkID((Element)nCorners.item(0)));
|
||||
String legName = getCompoundMarkName(getCompoundMarkID((Element)nCorners.item(0)));
|
||||
for(int i = 1; i < nCorners.getLength(); i++) {
|
||||
Element markXML = (Element)nCorners.item(i);
|
||||
Marker currentMarker = getMarker(getCompoundMarkID(markXML));
|
||||
legs.add(new Leg(legName, lastMarker, currentMarker, i-1));
|
||||
lastMarker = currentMarker;
|
||||
legName = getCompoundMarkName(getCompoundMarkID(markXML));
|
||||
}
|
||||
}
|
||||
|
||||
private void readCourseLimit() {
|
||||
Element nCourseLimit = (Element) doc.getElementsByTagName("CourseLimit").item(0);
|
||||
for(int i = 0; i < nCourseLimit.getChildNodes().getLength(); i++) {
|
||||
Node limit = nCourseLimit.getChildNodes().item(i);
|
||||
if (limit.getNodeName().equals("Limit")) {
|
||||
double lat = Double.parseDouble(limit.getAttributes().getNamedItem("Lat").getTextContent());
|
||||
double lon = Double.parseDouble(limit.getAttributes().getNamedItem("Lon").getTextContent());
|
||||
boundary.add(new GPSCoordinate(lat, lon));
|
||||
}
|
||||
}
|
||||
|
||||
double maxLatitude = boundary.stream().max(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING;
|
||||
double maxLongitude = boundary.stream().max(Comparator.comparingDouble(GPSCoordinate::getLongitude)).get().getLongitude() + COORDINATEPADDING;
|
||||
double minLatitude = boundary.stream().min(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING;
|
||||
double minLongitude = boundary.stream().min(Comparator.comparingDouble(GPSCoordinate::getLongitude)).get().getLongitude() + COORDINATEPADDING;
|
||||
|
||||
mapTopLeft = new GPSCoordinate(minLatitude, minLongitude);
|
||||
mapBottomRight = new GPSCoordinate(maxLatitude, maxLongitude);
|
||||
}
|
||||
|
||||
public List<GPSCoordinate> getBoundary() {
|
||||
return boundary;
|
||||
}
|
||||
|
||||
public GPSCoordinate getMapTopLeft() {
|
||||
return mapTopLeft;
|
||||
}
|
||||
|
||||
public GPSCoordinate getMapBottomRight() {
|
||||
return mapBottomRight;
|
||||
}
|
||||
|
||||
public List<Leg> getLegs() {
|
||||
return legs;
|
||||
}
|
||||
|
||||
public Double getPadding() {
|
||||
return COORDINATEPADDING;
|
||||
}
|
||||
|
||||
public Date getCreationTimeDate() {
|
||||
return creationTimeDate;
|
||||
}
|
||||
|
||||
public Date getRaceStartTime() {
|
||||
return raceStartTime;
|
||||
}
|
||||
|
||||
public int getRaceID() {
|
||||
return raceID;
|
||||
}
|
||||
|
||||
public String getRaceType() {
|
||||
return raceType;
|
||||
}
|
||||
|
||||
public boolean isPostpone() {
|
||||
return postpone;
|
||||
}
|
||||
|
||||
public Map<Integer, StreamedBoat> getParticipants() {
|
||||
return participants;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import seng302.Controllers.RaceController;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.Race;
|
||||
import seng302.RaceDataSource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 21/04/17.
|
||||
*/
|
||||
public class StreamedRace extends Race {
|
||||
private RaceDataSource raceData;
|
||||
|
||||
public StreamedRace(RaceDataSource raceData, RaceController controller, int scaleFactor) {
|
||||
super(raceData.getBoats(), raceData.getLegs(), controller, scaleFactor);
|
||||
this.raceData = raceData;
|
||||
}
|
||||
|
||||
public void initialiseBoats() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the boat cannot finish the race
|
||||
* @return True if boat cannot finish the race
|
||||
*/
|
||||
protected boolean doNotFinish() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the position of the boat, this updates the boats current position.
|
||||
*
|
||||
* @param boat Boat that the postion is to be updated for.
|
||||
* @param timeElapsed Time that has elapse since the start of the the race.
|
||||
* @see BoatInRace
|
||||
*/
|
||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the boat's gps coordinates
|
||||
*
|
||||
* @param boat to be updated
|
||||
* @param millisecondsElapsed time since last update
|
||||
*/
|
||||
protected void updatePosition(BoatInRace boat, int millisecondsElapsed) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,17 @@ public class Boat {
|
||||
this.name = new SimpleStringProperty(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Boat initialiser which keeps all of the information of the boat.
|
||||
*
|
||||
* @param name Name of the Boat.
|
||||
* @param abbrev nam abbreviation
|
||||
*/
|
||||
public Boat(String name, String abbrev) {
|
||||
this.abbrev = abbrev;
|
||||
this.name = new SimpleStringProperty(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name of the boat
|
||||
*/
|
||||
|
||||
@@ -17,25 +17,25 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
*/
|
||||
public class BoatInRace extends Boat {
|
||||
|
||||
private Leg currentLeg;
|
||||
protected Leg currentLeg;
|
||||
private double scaledVelocity;
|
||||
private double distanceTravelledInLeg;
|
||||
private GPSCoordinate currentPosition;
|
||||
private long timeFinished;
|
||||
private Color colour;
|
||||
private boolean finished = false;
|
||||
private StringProperty currentLegName;
|
||||
private boolean started = false;
|
||||
private StringProperty position;
|
||||
private double heading;
|
||||
protected double distanceTravelledInLeg;
|
||||
protected GPSCoordinate currentPosition;
|
||||
protected long timeFinished;
|
||||
protected Color colour;
|
||||
protected boolean finished = false;
|
||||
protected StringProperty currentLegName;
|
||||
protected boolean started = false;
|
||||
protected StringProperty position;
|
||||
protected double heading;
|
||||
|
||||
private Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
|
||||
private long nextValidTime = 0;
|
||||
protected Queue<TrackPoint> track = new ConcurrentLinkedQueue<>();
|
||||
protected long nextValidTime = 0;
|
||||
|
||||
private static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000;
|
||||
private static float trackPointTimeInterval = 5000; // every 1 seconds
|
||||
private final int TRACK_POINT_LIMIT = 10;
|
||||
private boolean trackVisible = true;
|
||||
protected static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000;
|
||||
protected static float trackPointTimeInterval = 5000; // every 1 seconds
|
||||
protected final int TRACK_POINT_LIMIT = 10;
|
||||
protected boolean trackVisible = true;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
@@ -52,6 +52,20 @@ public class BoatInRace extends Boat {
|
||||
position = new SimpleStringProperty("-");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
*
|
||||
* @param name Name of the boat.
|
||||
* @param colour Colour the boat will be displayed as on the map
|
||||
* @param abbrev of boat
|
||||
*/
|
||||
public BoatInRace(String name, Color colour, String abbrev) {
|
||||
super(name, abbrev);
|
||||
setColour(colour);
|
||||
currentLegName = new SimpleStringProperty("");
|
||||
position = new SimpleStringProperty("-");
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the azimuth of the travel via map coordinates of the raceMarkers
|
||||
*
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.awt.geom.Point2D;
|
||||
* Created by esa46 on 29/03/17.
|
||||
*/
|
||||
public class Marker {
|
||||
|
||||
private GPSCoordinate averageGPSCoordinate;
|
||||
private GPSCoordinate mark1;
|
||||
private GPSCoordinate mark2;
|
||||
|
||||
@@ -65,8 +65,8 @@ public abstract class Race implements Runnable {
|
||||
public abstract void initialiseBoats();
|
||||
|
||||
/**
|
||||
* Randomly generate number to see if boat fails
|
||||
* @return True if number lower than dnfChance else false
|
||||
* Checks if the boat cannot finish the race
|
||||
* @return True if boat cannot finish the race
|
||||
*/
|
||||
protected abstract boolean doNotFinish();
|
||||
|
||||
@@ -80,7 +80,7 @@ public abstract class Race implements Runnable {
|
||||
protected abstract void checkPosition(BoatInRace boat, long timeElapsed);
|
||||
|
||||
/**
|
||||
* Updates the boat's gps coordinates depending on time elapsed
|
||||
* Updates the boat's gps coordinates
|
||||
*
|
||||
* @param boat to be updated
|
||||
* @param millisecondsElapsed time since last update
|
||||
|
||||
@@ -6,48 +6,61 @@ import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalAmount;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 19/04/2017.
|
||||
*/
|
||||
public class RaceClock {
|
||||
private StringProperty time;
|
||||
private DateTimeFormatter dateTimeFormatter;
|
||||
private String timeZone;
|
||||
private long lastTime;
|
||||
private ZoneId zoneId;
|
||||
private ZonedDateTime time;
|
||||
private StringProperty timeString;
|
||||
|
||||
public RaceClock(GPSCoordinate gpsCoordinate){
|
||||
public RaceClock(ZonedDateTime zonedDateTime) {
|
||||
this.zoneId = zonedDateTime.getZone();
|
||||
this.timeString = new SimpleStringProperty();
|
||||
this.time = zonedDateTime;
|
||||
setTime(time);
|
||||
}
|
||||
|
||||
public static ZonedDateTime getCurrentZonedDateTime(GPSCoordinate gpsCoordinate) {
|
||||
TimeZoneLookup timeZoneLookup = new TimeZoneLookup();
|
||||
TimeZoneResult timeZoneResult = timeZoneLookup.getTimeZone(gpsCoordinate.getLatitude(), gpsCoordinate.getLongitude());
|
||||
zoneId = ZoneId.of(timeZoneResult.getResult());
|
||||
LocalDateTime localDateTime = LocalDateTime.now(zoneId);
|
||||
ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
|
||||
dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM HH:mm:ss z");
|
||||
// System.out.println(dateTimeFormatter.format(zonedDateTime));
|
||||
time = new SimpleStringProperty(dateTimeFormatter.format(zonedDateTime));
|
||||
DateTimeFormatter timeZoneFormatter = DateTimeFormatter.ofPattern("z");
|
||||
timeZone = timeZoneFormatter.format(zonedDateTime);
|
||||
ZoneId zone = ZoneId.of(timeZoneResult.getResult());
|
||||
return LocalDateTime.now(zone).atZone(zone);
|
||||
}
|
||||
|
||||
public void updateTime(){
|
||||
LocalDateTime localDateTime = LocalDateTime.now(zoneId);
|
||||
ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
|
||||
time.setValue(dateTimeFormatter.format(zonedDateTime));
|
||||
/**
|
||||
* Sets time to arbitrary zoned time.
|
||||
* @param time arbitrary time with timezone.
|
||||
*/
|
||||
public void setTime(ZonedDateTime time) {
|
||||
this.time = time;
|
||||
this.timeString.set(DateTimeFormatter.ofPattern("dd-MM HH:mm:ss z").format(time));
|
||||
this.lastTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time.get();
|
||||
}
|
||||
|
||||
public StringProperty timeProperty() {
|
||||
return time;
|
||||
/**
|
||||
* Updates time by duration elapsed since last update.
|
||||
*/
|
||||
public void updateTime() {
|
||||
this.time = this.time.plus(Duration.of(System.currentTimeMillis() - this.lastTime, ChronoUnit.MILLIS));
|
||||
this.lastTime = System.currentTimeMillis();
|
||||
setTime(time);
|
||||
}
|
||||
|
||||
public String getTimeZone() {
|
||||
return timeZone;
|
||||
return zoneId.toString();
|
||||
}
|
||||
|
||||
public StringProperty timeStringProperty() {
|
||||
return timeString;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,6 +318,8 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
* Draws boats while race in progress, when leg heading is set.
|
||||
*/
|
||||
public void updateBoats() {
|
||||
// TODO Remove null when boats are ready
|
||||
boats = null;
|
||||
if (boats != null) {
|
||||
for (BoatInRace boat : boats) {
|
||||
boolean finished = boat.getCurrentLeg().getName().equals("Finish") || boat.getCurrentLeg().getName().equals("DNF");
|
||||
|
||||
@@ -3,6 +3,7 @@ package seng302;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.Model.Leg;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -13,7 +14,7 @@ public interface RaceDataSource {
|
||||
List<Leg> getLegs();
|
||||
List<GPSCoordinate> getBoundary();
|
||||
|
||||
GPSCoordinate getMark();
|
||||
ZonedDateTime getZonedDateTime();
|
||||
GPSCoordinate getMapTopLeft();
|
||||
GPSCoordinate getMapBottomRight();
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ import javafx.scene.paint.Color;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.Marker;
|
||||
import seng302.Model.*;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -272,8 +271,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
return legs;
|
||||
}
|
||||
|
||||
public GPSCoordinate getMark() {
|
||||
return mark;
|
||||
public ZonedDateTime getZonedDateTime() {
|
||||
return RaceClock.getCurrentZonedDateTime(mark);
|
||||
}
|
||||
|
||||
public GPSCoordinate getStartPt1() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package seng302;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
@@ -33,6 +34,10 @@ public abstract class XMLReader {
|
||||
return n.getElementsByTagName(tagName).item(0).getTextContent();
|
||||
}
|
||||
|
||||
public boolean exists(Node node, String attribute) {
|
||||
return node.getAttributes().getNamedItem(attribute) != null;
|
||||
}
|
||||
|
||||
public String getAttribute(Element n, String attr) {
|
||||
return n.getAttribute(attr);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<BoatConfig>
|
||||
|
||||
<Modified>2012-05-17T07:49:40+0200</Modified>
|
||||
|
||||
<Version>12</Version>
|
||||
|
||||
<Settings>
|
||||
|
||||
<RaceBoatType Type="AC45" />
|
||||
|
||||
<BoatDimension BoatLength="14.019" HullLength="13.449" />
|
||||
|
||||
<ZoneSize MarkZoneSize="40.347" CourseZoneSize="40.347" />
|
||||
|
||||
<ZoneLimits Limit1="200" Limit2="100" Limit3="40.347" Limit4="0" Limit5="-100" />
|
||||
|
||||
</Settings>
|
||||
|
||||
<BoatShapes>
|
||||
|
||||
<BoatShape ShapeID="0">
|
||||
|
||||
<Vertices>
|
||||
|
||||
<Vtx Seq="1" Y="0" X="-2.659" />
|
||||
|
||||
<Vtx Seq="2" Y="18.359" X="-2.659" />
|
||||
|
||||
<Vtx Seq="3" Y="18.359" X="2.659" />
|
||||
|
||||
<Vtx Seq="4" Y="0" X="2.659" />
|
||||
|
||||
</Vertices>
|
||||
|
||||
</BoatShape>
|
||||
|
||||
<BoatShape ShapeID="1">
|
||||
|
||||
<Vertices>
|
||||
|
||||
<Vtx Seq="1" Y="0" X="-1.278" />
|
||||
|
||||
<Vtx Seq="2" Y="8.876" X="-1.278" />
|
||||
|
||||
<Vtx Seq="3" Y="8.876" X="1.278" />
|
||||
|
||||
<Vtx Seq="4" Y="0" X="1.278" />
|
||||
|
||||
</Vertices>
|
||||
|
||||
</BoatShape>
|
||||
|
||||
<BoatShape ShapeID="2">
|
||||
|
||||
<Vertices>
|
||||
|
||||
<Vtx Seq="1" Y="0" X="-1.1" />
|
||||
|
||||
<Vtx Seq="2" Y="8.3" X="-1.1" />
|
||||
|
||||
<Vtx Seq="3" Y="8.3" X="1.1" />
|
||||
|
||||
<Vtx Seq="4" Y="0" X="1.1" />
|
||||
|
||||
</Vertices>
|
||||
|
||||
</BoatShape>
|
||||
|
||||
<BoatShape ShapeID="3">
|
||||
|
||||
<Vertices>
|
||||
|
||||
<Vtx Seq="1" Y="0" X="-0.75" />
|
||||
|
||||
<Vtx Seq="2" Y="3" X="-0.75" />
|
||||
|
||||
<Vtx Seq="3" Y="3" X="0.75" />
|
||||
|
||||
<Vtx Seq="4" Y="0" X="0.75" />
|
||||
|
||||
</Vertices>
|
||||
|
||||
</BoatShape>
|
||||
|
||||
<BoatShape ShapeID="4">
|
||||
|
||||
<Vertices>
|
||||
|
||||
<Vtx Seq="1" Y="0" X="-3.46" />
|
||||
|
||||
<Vtx Seq="2" Y="13.449" X="-3.46" />
|
||||
|
||||
<Vtx Seq="3" Y="14.019" X="0" />
|
||||
|
||||
<Vtx Seq="4" Y="13.449" X="3.46" />
|
||||
|
||||
<Vtx Seq="5" Y="0" X="3.46" />
|
||||
|
||||
</Vertices>
|
||||
|
||||
<Catamaran>
|
||||
|
||||
<Vtx Seq="1" Y="1.769" X="-2.752" />
|
||||
|
||||
<Vtx Seq="2" Y="0" X="-2.813" />
|
||||
|
||||
<Vtx Seq="3" Y="0" X="-3.34" />
|
||||
|
||||
<Vtx Seq="4" Y="5.351" X="-3.46" />
|
||||
|
||||
<Vtx Seq="5" Y="10.544" X="-3.387" />
|
||||
|
||||
<Vtx Seq="6" Y="13.449" X="-3.075" />
|
||||
|
||||
<Vtx Seq="7" Y="10.851" X="-2.793" />
|
||||
|
||||
<Vtx Seq="8" Y="6.669" X="-2.699" />
|
||||
|
||||
<Vtx Seq="9" Y="6.669" X="2.699" />
|
||||
|
||||
<Vtx Seq="10" Y="10.851" X="2.793" />
|
||||
|
||||
<Vtx Seq="11" Y="13.449" X="3.075" />
|
||||
|
||||
<Vtx Seq="12" Y="10.544" X="3.387" />
|
||||
|
||||
<Vtx Seq="13" Y="5.351" X="3.46" />
|
||||
|
||||
<Vtx Seq="14" Y="0" X="3.34" />
|
||||
|
||||
<Vtx Seq="15" Y="0" X="2.813" />
|
||||
|
||||
<Vtx Seq="16" Y="1.769" X="2.752" />
|
||||
|
||||
</Catamaran>
|
||||
|
||||
<Bowsprit>
|
||||
|
||||
<Vtx Seq="1" Y="6.669" X="-0.2" />
|
||||
|
||||
<Vtx Seq="2" Y="11.377" X="-0.2" />
|
||||
|
||||
<Vtx Seq="3" Y="14.019" X="0" />
|
||||
|
||||
<Vtx Seq="4" Y="11.377" X="0.2" />
|
||||
|
||||
<Vtx Seq="5" Y="6.669" X="0.2" />
|
||||
|
||||
</Bowsprit>
|
||||
|
||||
<Trampoline>
|
||||
|
||||
<Vtx Seq="1" Y="2" X="-2.699" />
|
||||
|
||||
<Vtx Seq="2" Y="6.438" X="-2.699" />
|
||||
|
||||
<Vtx Seq="3" Y="6.438" X="2.699" />
|
||||
|
||||
<Vtx Seq="4" Y="2" X="2.699" />
|
||||
|
||||
</Trampoline>
|
||||
|
||||
</BoatShape>
|
||||
|
||||
<BoatShape ShapeID="5" />
|
||||
|
||||
</BoatShapes>
|
||||
|
||||
<Boats>
|
||||
|
||||
<Boat Type="RC" SourceID="121" ShapeID="0" HullNum="RG01" StoweName="PRO" ShortName="PRO"
|
||||
|
||||
BoatName="Regardless">
|
||||
|
||||
<GPSposition Z="6.840" Y="7.800" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="7.800" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Mark" SourceID="122" ShapeID="1" HullNum="LC05" StoweName="CON" ShortName="Constellation"
|
||||
|
||||
BoatName="Constellation">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Mark" SourceID="123" ShapeID="1" HullNum="LC04" StoweName="MIS" ShortName="Mischief"
|
||||
|
||||
BoatName="Mischief">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Mark" SourceID="124" ShapeID="1" HullNum="LC03" ShortName="Atalanta" BoatName="Atalanta">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat SourceID="125" ShapeID="1" StoweName="VOL" HullNum="LC01" ShortName="Volunteer"
|
||||
|
||||
BoatName="Volunteer">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Mark" SourceID="126" ShapeID="1" HullNum="LC13" StoweName="MS2" ShortName="Defender"
|
||||
|
||||
BoatName="Defender">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Mark" SourceID="128" ShapeID="1" HullNum="LC01" ShortName="Shamrock" BoatName="Shamrock">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Yacht" SourceID="101" ShapeID="4" HullNum="AC4501" StoweName="KOR" ShortName="TEAM KOREA"
|
||||
|
||||
BoatName="TEAM KOREA" Country="KOR">
|
||||
|
||||
<GPSposition Z="1.738" Y="0.625" X="0.001" />
|
||||
|
||||
<MastTop Z="21.496" Y="4.233" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
</Boats>
|
||||
|
||||
</BoatConfig>
|
||||
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<Race>
|
||||
|
||||
<RaceID>11080703</RaceID>
|
||||
|
||||
<RaceType>Match</RaceType>
|
||||
|
||||
<CreationTimeDate>2011-08-06T13:25:00-0000</CreationTimeDate >
|
||||
|
||||
<RaceStartTime Time="2011-08-06T13:30:00-0700" Postpone="false" />
|
||||
|
||||
<Participants>
|
||||
|
||||
<Yacht SourceID="101" Entry="Port" />
|
||||
|
||||
<Yacht SourceID="108" Entry="Stbd" />
|
||||
|
||||
</Participants>
|
||||
|
||||
<Course>
|
||||
|
||||
<CompoundMark CompoundMarkID="1" Name="StartLine">
|
||||
|
||||
<Mark SeqID="1" Name="PRO" TargetLat="-36.83" TargetLng="174.83" SourceID="101" />
|
||||
|
||||
<Mark SeqID="2" Name="PIN" TargetLat="-36.84" TargetLng="174.81" SourceID="102" />
|
||||
|
||||
</CompoundMark>
|
||||
|
||||
<CompoundMark CompoundMarkID="2" Name="M1">
|
||||
|
||||
<Mark Name="M1" TargetLat="-36.63566590" TargetLng="174.88543944" SourceID="103" />
|
||||
|
||||
</CompoundMark>
|
||||
|
||||
<CompoundMark CompoundMarkID="3" Name="M2">
|
||||
|
||||
<Mark Name="M2" TargetLat="-36.83" TargetLng="174.80" SourceID="102" />
|
||||
|
||||
</CompoundMark>
|
||||
|
||||
<CompoundMark CompoundMarkID="4" Name="Gate">
|
||||
|
||||
<Mark SeqID="1" Name="G1" TargetLat="-36.63566590" TargetLng="174.97205159" SourceID="104" />
|
||||
|
||||
<Mark SeqID="2" Name="G2" TargetLat="-36.64566590" TargetLng="174.98205159" SourceID="105" />
|
||||
|
||||
</CompoundMark>
|
||||
|
||||
</Course>
|
||||
|
||||
<CompoundMarkSequence>
|
||||
|
||||
<Corner SeqID="1" CompoundMarkID="1" Rounding="SP" ZoneSize="3" />
|
||||
|
||||
<Corner SeqID="2" CompoundMarkID="2" Rounding="Port" ZoneSize="3" />
|
||||
|
||||
<Corner SeqID="3" CompoundMarkID="3" Rounding="Stbd" ZoneSize="6" />
|
||||
|
||||
<Corner SeqID="4" CompoundMarkID="4" Rounding="PS" ZoneSize="6" />
|
||||
|
||||
<Corner SeqID="5" CompoundMarkID="1" Rounding="SP" ZoneSize="3"/>
|
||||
|
||||
</CompoundMarkSequence>
|
||||
|
||||
<CourseLimit>
|
||||
|
||||
<Limit SeqID="1" Lat="-36.8325" Lon="174.8325"/>
|
||||
|
||||
<Limit SeqID="2" Lat="-36.82883" Lon="174.81983"/>
|
||||
|
||||
<Limit SeqID="3" Lat="-36.82067" Lon="174.81983"/>
|
||||
|
||||
<Limit SeqID="4" Lat="-36.811" Lon="174.8265"/>
|
||||
|
||||
<Limit SeqID="5" Lat="-36.81033" Lon="174.83833"/>
|
||||
|
||||
<Limit SeqID="6" Lat="-36.81533" Lon="174.8525"/>
|
||||
|
||||
<Limit SeqID="7" Lat="-36.81533" Lon="174.86733"/>
|
||||
|
||||
<Limit SeqID="8" Lat="-36.81633" Lon="174.88217"/>
|
||||
|
||||
<Limit SeqID="9" Lat="-36.83383" Lon="174.87117"/>
|
||||
|
||||
<Limit SeqID="10" Lat="-36.83417" Lon="174.84767"/>
|
||||
|
||||
</CourseLimit>
|
||||
|
||||
</Race>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RegattaConfig>
|
||||
|
||||
<RegattaID>3</RegattaID>
|
||||
|
||||
<RegattaName>New Zealand Test</RegattaName>
|
||||
|
||||
<CourseName>North Head</CourseName>
|
||||
|
||||
<CentralLatitude>-36.82791529</CentralLatitude>
|
||||
|
||||
<CentralLongitude>174.81218919</CentralLongitude>
|
||||
|
||||
<CentralAltitude>0.00</CentralAltitude>
|
||||
|
||||
<UtcOffset>12</UtcOffset>
|
||||
|
||||
<MagneticVariation>14.1</MagneticVariation>
|
||||
|
||||
</RegattaConfig>
|
||||
@@ -0,0 +1,49 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 21/04/17.
|
||||
*/
|
||||
public class BoatsXMLTest {
|
||||
BoatXMLReader boatXMLReader;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
try {
|
||||
boatXMLReader = new BoatXMLReader("mockXML/boatXML/boatTest.xml", false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//fail("Cannot find mockXML/raceXML/raceTest.xml in the resources folder");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidParticipant() {
|
||||
Map<Integer, StreamedBoat> inputParticipants = new HashMap<>();
|
||||
inputParticipants.put(420, new StreamedBoat(420));
|
||||
boatXMLReader.setParticipants(inputParticipants);
|
||||
boatXMLReader.read();
|
||||
assertEquals(boatXMLReader.getStreamedBoatMap().size(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidParticipant() {
|
||||
Map<Integer, StreamedBoat> inputParticipants = new HashMap<>();
|
||||
inputParticipants.put(101, new StreamedBoat(101));
|
||||
boatXMLReader.setParticipants(inputParticipants);
|
||||
boatXMLReader.read();
|
||||
assertTrue(boatXMLReader.getStreamedBoatMap().containsKey(101));
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class RegattaXMLTest {
|
||||
@Before
|
||||
public void findFile(){
|
||||
try {
|
||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml", false);
|
||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml");
|
||||
} catch (Exception e) {
|
||||
fail("Cannot find mockXML/regattaXML/regattaTest.xml in the resources folder");
|
||||
}
|
||||
@@ -24,29 +24,19 @@ public class RegattaXMLTest {
|
||||
|
||||
@Test
|
||||
public void makeRegattaTest() {
|
||||
try {
|
||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml");
|
||||
assertNotEquals(regattaXMLReader.getRegatta(), null);
|
||||
} catch (Exception e) {
|
||||
fail("Did not make a Regatta object");
|
||||
}
|
||||
assertNotEquals(regattaXMLReader.getRegatta(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctValuesTest() {
|
||||
try {
|
||||
regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml");
|
||||
Regatta regatta = regattaXMLReader.getRegatta();
|
||||
assertEquals(regatta.getRegattaID(), 3);
|
||||
assertEquals(regatta.getRegattaName(), "New Zealand Test");
|
||||
assertEquals(regatta.getCourseName(), "North Head");
|
||||
assertEquals(regatta.getCentralLatitude(), -36.82791529, 0.00000001);
|
||||
assertEquals(regatta.getCentralLongitude(), 174.81218919, 0.00000001);
|
||||
assertEquals(regatta.getCentralAltitude(), 0.00, 0.00000001);
|
||||
assertEquals(regatta.getUtcOffset(), 12.0, 0.001);
|
||||
assertEquals(regatta.getMagneticVariation(), 14.1, 0.001);
|
||||
} catch (Exception e) {
|
||||
fail("Did not have the correct values");
|
||||
}
|
||||
Regatta regatta = regattaXMLReader.getRegatta();
|
||||
assertEquals(regatta.getRegattaID(), 3);
|
||||
assertEquals(regatta.getRegattaName(), "New Zealand Test");
|
||||
assertEquals(regatta.getCourseName(), "North Head");
|
||||
assertEquals(regatta.getCentralLatitude(), -36.82791529, 0.00000001);
|
||||
assertEquals(regatta.getCentralLongitude(), 174.81218919, 0.00000001);
|
||||
assertEquals(regatta.getCentralAltitude(), 0.00, 0.00000001);
|
||||
assertEquals(regatta.getUtcOffset(), 12.0, 0.001);
|
||||
assertEquals(regatta.getMagneticVariation(), 14.1, 0.001);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package seng302.Mock;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.Model.Leg;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests only work on the current version of mockXML/raceXML/raceTest.xml
|
||||
*/
|
||||
public class StreamedRaceTest {
|
||||
StreamedCourseXMLReader streamedCourseXMLReader;
|
||||
List<GPSCoordinate> boundary;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
try {
|
||||
streamedCourseXMLReader = new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml", true);
|
||||
boundary = streamedCourseXMLReader.getBoundary();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//fail("Cannot find mockXML/raceXML/raceTest.xml in the resources folder");
|
||||
} catch (StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllBoundaryPointsRead() {
|
||||
assertEquals(boundary.size(), 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundaryPointData() {
|
||||
// First point
|
||||
assertEquals(boundary.get(0).getLatitude(), -36.8325, 1e-6);
|
||||
assertEquals(boundary.get(0).getLongitude(), 174.8325, 1e-6);
|
||||
|
||||
// Last point
|
||||
assertEquals(boundary.get(boundary.size() - 1).getLatitude(), -36.83417, 1e-6);
|
||||
assertEquals(boundary.get(boundary.size() - 1).getLongitude(), 174.84767, 1e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapEdges() {
|
||||
double maxLatitude = streamedCourseXMLReader.getMapBottomRight().getLatitude() - streamedCourseXMLReader.getPadding();
|
||||
double maxLongitude = streamedCourseXMLReader.getMapBottomRight().getLongitude() - streamedCourseXMLReader.getPadding();
|
||||
double minLatitude = streamedCourseXMLReader.getMapTopLeft().getLatitude() - streamedCourseXMLReader.getPadding();
|
||||
double minLongitude = streamedCourseXMLReader.getMapTopLeft().getLongitude() - streamedCourseXMLReader.getPadding();
|
||||
|
||||
assertEquals(maxLatitude, -36.81033, 1e-6);
|
||||
assertEquals(maxLongitude, 174.88217, 1e-6);
|
||||
assertEquals(minLatitude, -36.83417, 1e-6);
|
||||
assertEquals(minLongitude, 174.81983, 1e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRaceSettings() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctLegSequence() {
|
||||
List<Leg> legs = streamedCourseXMLReader.getLegs();
|
||||
String[] expectedNames = {
|
||||
"StartLine",
|
||||
"M1",
|
||||
"M2",
|
||||
"Gate"
|
||||
};
|
||||
for(int i = 0; i < legs.size(); i++) assertEquals(expectedNames[i], legs.get(i).getName());
|
||||
}
|
||||
}
|
||||
@@ -1,173 +1,18 @@
|
||||
package seng302.Model;
|
||||
|
||||
import javafx.scene.paint.Color;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import org.mockito.Mock;
|
||||
import seng302.RaceDataSource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Created by esa46 on 15/03/17.
|
||||
*/
|
||||
public class RaceTest {
|
||||
|
||||
Leg START_LEG = new Leg("Start", new Marker(new GPSCoordinate(0, 0)), new Marker(new GPSCoordinate(1, 1)), 0);
|
||||
Leg FINISH_LEG = new Leg("Finish", new Marker(new GPSCoordinate(1, 1)), new Marker(new GPSCoordinate(2, 2)), 0);
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void timerCanBeDisabled() {
|
||||
BoatInRace boat1 = new BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1");
|
||||
BoatInRace boat2 = new BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2");
|
||||
BoatInRace[] boats = new BoatInRace[]{boat1, boat2};
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG); legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 5);
|
||||
race.disableTimer();
|
||||
race.setDnfChance(0);
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
race.run();
|
||||
|
||||
assertTrue(System.currentTimeMillis() - timeStarted < 4000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkPositionUpdatesNumberFinishedBoats() {
|
||||
|
||||
BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt");
|
||||
finishedBoat.setDistanceTravelledInLeg(500);
|
||||
|
||||
finishedBoat.setCurrentLeg(FINISH_LEG);
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
|
||||
race.checkPosition(finishedBoat, 100000);
|
||||
assertEquals(race.boatsFinished, 1);
|
||||
assertEquals(finishedBoat.getTimeFinished(), 100000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkPositionDoesntUpdateNumberFinishedBoats() {
|
||||
|
||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
unFinishedBoat.setDistanceTravelledInLeg(0);
|
||||
|
||||
unFinishedBoat.setCurrentLeg(FINISH_LEG);
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
|
||||
race.checkPosition(unFinishedBoat, 100);
|
||||
assertEquals(race.boatsFinished, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceTravelledBeforeUpdatingLegIsRetained() {
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
|
||||
|
||||
legs.add(START_LEG);
|
||||
legs.add(FINISH_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.setDnfChance(0);
|
||||
|
||||
BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||
unFinishedBoat.setDistanceTravelledInLeg(100);
|
||||
unFinishedBoat.setCurrentLeg(START_LEG);
|
||||
|
||||
race.checkPosition(unFinishedBoat, 100);
|
||||
assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish");
|
||||
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0);
|
||||
assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100);
|
||||
|
||||
}
|
||||
|
||||
/*@Test
|
||||
|
||||
//Test temporarily removed as countdown timer now uses animation timer
|
||||
|
||||
public void timerDelaysByHalfSecond() {
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1);
|
||||
race.PRERACE_TIME = 500;
|
||||
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
race.countdownTimer();
|
||||
|
||||
//assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
||||
System.out.println(System.currentTimeMillis() - timeStarted);
|
||||
|
||||
}*/
|
||||
|
||||
@Test
|
||||
public void scalerScalesVelocityCorrectly() {
|
||||
|
||||
int scaleFactor = 3;
|
||||
float vel1 = 0;
|
||||
float vel2 = (float) 1.999;
|
||||
float vel3 = (float) 32.5;
|
||||
float vel4 = 500;
|
||||
BoatInRace boat1 = new BoatInRace("test", vel1, Color.ALICEBLUE, "tt");
|
||||
BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt");
|
||||
BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt");
|
||||
BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt");
|
||||
BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4};
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor);
|
||||
race.setDnfChance(0);
|
||||
|
||||
assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6);
|
||||
assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalerScalesRaceClockTo1MinCorrectly() {
|
||||
int scaleFactor = 10;
|
||||
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
|
||||
race.totalTimeElapsed = 6000; //6 seconds
|
||||
assertTrue(race.calcTimer().equals("Race clock: 00:01:00"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() {
|
||||
int scaleFactor = 3;
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(START_LEG);
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor);
|
||||
race.totalTimeElapsed = 3213000;
|
||||
assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,6 @@ public class RaceXMLTest {
|
||||
assertTrue(raceXMLReader.getLeewardPt2() != null);
|
||||
assertTrue(raceXMLReader.getWindwardPt1() != null);
|
||||
assertTrue(raceXMLReader.getWindwardPt2() != null);
|
||||
assertTrue(raceXMLReader.getMark() != null);
|
||||
assertTrue(raceXMLReader.getBoundary().size() == 11);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<BoatConfig>
|
||||
|
||||
<Modified>2012-05-17T07:49:40+0200</Modified>
|
||||
|
||||
<Version>12</Version>
|
||||
|
||||
<Settings>
|
||||
|
||||
<RaceBoatType Type="AC45" />
|
||||
|
||||
<BoatDimension BoatLength="14.019" HullLength="13.449" />
|
||||
|
||||
<ZoneSize MarkZoneSize="40.347" CourseZoneSize="40.347" />
|
||||
|
||||
<ZoneLimits Limit1="200" Limit2="100" Limit3="40.347" Limit4="0" Limit5="-100" />
|
||||
|
||||
</Settings>
|
||||
|
||||
<BoatShapes>
|
||||
|
||||
<BoatShape ShapeID="0">
|
||||
|
||||
<Vertices>
|
||||
|
||||
<Vtx Seq="1" Y="0" X="-2.659" />
|
||||
|
||||
<Vtx Seq="2" Y="18.359" X="-2.659" />
|
||||
|
||||
<Vtx Seq="3" Y="18.359" X="2.659" />
|
||||
|
||||
<Vtx Seq="4" Y="0" X="2.659" />
|
||||
|
||||
</Vertices>
|
||||
|
||||
</BoatShape>
|
||||
|
||||
<BoatShape ShapeID="1">
|
||||
|
||||
<Vertices>
|
||||
|
||||
<Vtx Seq="1" Y="0" X="-1.278" />
|
||||
|
||||
<Vtx Seq="2" Y="8.876" X="-1.278" />
|
||||
|
||||
<Vtx Seq="3" Y="8.876" X="1.278" />
|
||||
|
||||
<Vtx Seq="4" Y="0" X="1.278" />
|
||||
|
||||
</Vertices>
|
||||
|
||||
</BoatShape>
|
||||
|
||||
<BoatShape ShapeID="2">
|
||||
|
||||
<Vertices>
|
||||
|
||||
<Vtx Seq="1" Y="0" X="-1.1" />
|
||||
|
||||
<Vtx Seq="2" Y="8.3" X="-1.1" />
|
||||
|
||||
<Vtx Seq="3" Y="8.3" X="1.1" />
|
||||
|
||||
<Vtx Seq="4" Y="0" X="1.1" />
|
||||
|
||||
</Vertices>
|
||||
|
||||
</BoatShape>
|
||||
|
||||
<BoatShape ShapeID="3">
|
||||
|
||||
<Vertices>
|
||||
|
||||
<Vtx Seq="1" Y="0" X="-0.75" />
|
||||
|
||||
<Vtx Seq="2" Y="3" X="-0.75" />
|
||||
|
||||
<Vtx Seq="3" Y="3" X="0.75" />
|
||||
|
||||
<Vtx Seq="4" Y="0" X="0.75" />
|
||||
|
||||
</Vertices>
|
||||
|
||||
</BoatShape>
|
||||
|
||||
<BoatShape ShapeID="4">
|
||||
|
||||
<Vertices>
|
||||
|
||||
<Vtx Seq="1" Y="0" X="-3.46" />
|
||||
|
||||
<Vtx Seq="2" Y="13.449" X="-3.46" />
|
||||
|
||||
<Vtx Seq="3" Y="14.019" X="0" />
|
||||
|
||||
<Vtx Seq="4" Y="13.449" X="3.46" />
|
||||
|
||||
<Vtx Seq="5" Y="0" X="3.46" />
|
||||
|
||||
</Vertices>
|
||||
|
||||
<Catamaran>
|
||||
|
||||
<Vtx Seq="1" Y="1.769" X="-2.752" />
|
||||
|
||||
<Vtx Seq="2" Y="0" X="-2.813" />
|
||||
|
||||
<Vtx Seq="3" Y="0" X="-3.34" />
|
||||
|
||||
<Vtx Seq="4" Y="5.351" X="-3.46" />
|
||||
|
||||
<Vtx Seq="5" Y="10.544" X="-3.387" />
|
||||
|
||||
<Vtx Seq="6" Y="13.449" X="-3.075" />
|
||||
|
||||
<Vtx Seq="7" Y="10.851" X="-2.793" />
|
||||
|
||||
<Vtx Seq="8" Y="6.669" X="-2.699" />
|
||||
|
||||
<Vtx Seq="9" Y="6.669" X="2.699" />
|
||||
|
||||
<Vtx Seq="10" Y="10.851" X="2.793" />
|
||||
|
||||
<Vtx Seq="11" Y="13.449" X="3.075" />
|
||||
|
||||
<Vtx Seq="12" Y="10.544" X="3.387" />
|
||||
|
||||
<Vtx Seq="13" Y="5.351" X="3.46" />
|
||||
|
||||
<Vtx Seq="14" Y="0" X="3.34" />
|
||||
|
||||
<Vtx Seq="15" Y="0" X="2.813" />
|
||||
|
||||
<Vtx Seq="16" Y="1.769" X="2.752" />
|
||||
|
||||
</Catamaran>
|
||||
|
||||
<Bowsprit>
|
||||
|
||||
<Vtx Seq="1" Y="6.669" X="-0.2" />
|
||||
|
||||
<Vtx Seq="2" Y="11.377" X="-0.2" />
|
||||
|
||||
<Vtx Seq="3" Y="14.019" X="0" />
|
||||
|
||||
<Vtx Seq="4" Y="11.377" X="0.2" />
|
||||
|
||||
<Vtx Seq="5" Y="6.669" X="0.2" />
|
||||
|
||||
</Bowsprit>
|
||||
|
||||
<Trampoline>
|
||||
|
||||
<Vtx Seq="1" Y="2" X="-2.699" />
|
||||
|
||||
<Vtx Seq="2" Y="6.438" X="-2.699" />
|
||||
|
||||
<Vtx Seq="3" Y="6.438" X="2.699" />
|
||||
|
||||
<Vtx Seq="4" Y="2" X="2.699" />
|
||||
|
||||
</Trampoline>
|
||||
|
||||
</BoatShape>
|
||||
|
||||
<BoatShape ShapeID="5" />
|
||||
|
||||
</BoatShapes>
|
||||
|
||||
<Boats>
|
||||
|
||||
<Boat Type="RC" SourceID="121" ShapeID="0" HullNum="RG01" StoweName="PRO" ShortName="PRO"
|
||||
|
||||
BoatName="Regardless">
|
||||
|
||||
<GPSposition Z="6.840" Y="7.800" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="7.800" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Mark" SourceID="122" ShapeID="1" HullNum="LC05" StoweName="CON" ShortName="Constellation"
|
||||
|
||||
BoatName="Constellation">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Mark" SourceID="123" ShapeID="1" HullNum="LC04" StoweName="MIS" ShortName="Mischief"
|
||||
|
||||
BoatName="Mischief">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Mark" SourceID="124" ShapeID="1" HullNum="LC03" ShortName="Atalanta" BoatName="Atalanta">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat SourceID="125" ShapeID="1" StoweName="VOL" HullNum="LC01" ShortName="Volunteer"
|
||||
|
||||
BoatName="Volunteer">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Mark" SourceID="126" ShapeID="1" HullNum="LC13" StoweName="MS2" ShortName="Defender"
|
||||
|
||||
BoatName="Defender">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Mark" SourceID="128" ShapeID="1" HullNum="LC01" ShortName="Shamrock" BoatName="Shamrock">
|
||||
|
||||
<GPSposition Z="5.334" Y="3.804" X="0.000" />
|
||||
|
||||
<FlagPosition Z="0.000" Y="3.426" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
<Boat Type="Yacht" SourceID="101" ShapeID="4" HullNum="AC4501" StoweName="KOR" ShortName="TEAM KOREA"
|
||||
|
||||
BoatName="TEAM KOREA" Country="KOR">
|
||||
|
||||
<GPSposition Z="1.738" Y="0.625" X="0.001" />
|
||||
|
||||
<MastTop Z="21.496" Y="4.233" X="0.000" />
|
||||
|
||||
</Boat>
|
||||
|
||||
</Boats>
|
||||
|
||||
</BoatConfig>
|
||||
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<Race>
|
||||
|
||||
<RaceID>11080703</RaceID>
|
||||
|
||||
<RaceType>Match</RaceType>
|
||||
|
||||
<CreationTimeDate>2011-08-06T13:25:00-0000</CreationTimeDate >
|
||||
|
||||
<RaceStartTime Time="2011-08-06T13:30:00-0700" Postpone="false" />
|
||||
|
||||
<Participants>
|
||||
|
||||
<Yacht SourceID="107" Entry="Port" />
|
||||
|
||||
<Yacht SourceID="108" Entry="Stbd" />
|
||||
|
||||
</Participants>
|
||||
|
||||
<Course>
|
||||
|
||||
<CompoundMark CompoundMarkID="1" Name="StartLine">
|
||||
|
||||
<Mark SeqID="1" Name="PRO" TargetLat="-36.83" TargetLng="174.83" SourceID="101" />
|
||||
|
||||
<Mark SeqID="2" Name="PIN" TargetLat="-36.84" TargetLng="174.81" SourceID="102" />
|
||||
|
||||
</CompoundMark>
|
||||
|
||||
<CompoundMark CompoundMarkID="2" Name="M1">
|
||||
|
||||
<Mark Name="M1" TargetLat="-36.63566590" TargetLng="174.88543944" SourceID="103" />
|
||||
|
||||
</CompoundMark>
|
||||
|
||||
<CompoundMark CompoundMarkID="3" Name="M2">
|
||||
|
||||
<Mark Name="M2" TargetLat="-36.83" TargetLng="174.80" SourceID="102" />
|
||||
|
||||
</CompoundMark>
|
||||
|
||||
<CompoundMark CompoundMarkID="4" Name="Gate">
|
||||
|
||||
<Mark SeqID="1" Name="G1" TargetLat="-36.63566590" TargetLng="174.97205159" SourceID="104" />
|
||||
|
||||
<Mark SeqID="2" Name="G2" TargetLat="-36.64566590" TargetLng="174.98205159" SourceID="105" />
|
||||
|
||||
</CompoundMark>
|
||||
|
||||
</Course>
|
||||
|
||||
<CompoundMarkSequence>
|
||||
|
||||
<Corner SeqID="1" CompoundMarkID="1" Rounding="SP" ZoneSize="3" />
|
||||
|
||||
<Corner SeqID="2" CompoundMarkID="2" Rounding="Port" ZoneSize="3" />
|
||||
|
||||
<Corner SeqID="3" CompoundMarkID="3" Rounding="Stbd" ZoneSize="6" />
|
||||
|
||||
<Corner SeqID="4" CompoundMarkID="4" Rounding="PS" ZoneSize="6" />
|
||||
|
||||
<Corner SeqID="5" CompoundMarkID="1" Rounding="SP" ZoneSize="3"/>
|
||||
|
||||
</CompoundMarkSequence>
|
||||
|
||||
<CourseLimit>
|
||||
|
||||
<Limit SeqID="1" Lat="-36.8325" Lon="174.8325"/>
|
||||
|
||||
<Limit SeqID="2" Lat="-36.82883" Lon="174.81983"/>
|
||||
|
||||
<Limit SeqID="3" Lat="-36.82067" Lon="174.81983"/>
|
||||
|
||||
<Limit SeqID="4" Lat="-36.811" Lon="174.8265"/>
|
||||
|
||||
<Limit SeqID="5" Lat="-36.81033" Lon="174.83833"/>
|
||||
|
||||
<Limit SeqID="6" Lat="-36.81533" Lon="174.8525"/>
|
||||
|
||||
<Limit SeqID="7" Lat="-36.81533" Lon="174.86733"/>
|
||||
|
||||
<Limit SeqID="8" Lat="-36.81633" Lon="174.88217"/>
|
||||
|
||||
<Limit SeqID="9" Lat="-36.83383" Lon="174.87117"/>
|
||||
|
||||
<Limit SeqID="10" Lat="-36.83417" Lon="174.84767"/>
|
||||
|
||||
</CourseLimit>
|
||||
|
||||
</Race>
|
||||
Reference in New Issue
Block a user