Reads BoatDataSource into StreamedCourseXMLReader so the latter can function as a single source of static information for the race.

- Mock.StreamedCourseXMLReader populates participant and mark list from BoatDataSource
- Added CompoundMarker class to accommodate Mark data from Boat XML
- Had to check for Yacht type in Visualiser.BoatXMLReader
- Added a missing coordinate value to raceTest.xml
- Marker class still exists due to large number of tests, which should be transitioned to CompoundMark
- IMPORTANT: race is no longer functional

#story[881]
main
cbt24 9 years ago
parent 9902cec688
commit f31a987787

@ -6,6 +6,8 @@ import javafx.stage.Stage;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import seng302.DataInput.*; import seng302.DataInput.*;
import seng302.Model.Event; import seng302.Model.Event;
import seng302.Model.StreamedCourseXMLException;
import seng302.Model.StreamedCourseXMLReader;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
@ -13,6 +15,7 @@ import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.ParseException;
public class App extends Application { public class App extends Application {
@ -35,9 +38,9 @@ public class App extends Application {
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
try { try {
RaceDataSource raceData = new RaceXMLReader("mockXML/raceTest.xml");
RegattaDataSource regattaData = new RegattaXMLReader("mockXML/regattaTest.xml"); RegattaDataSource regattaData = new RegattaXMLReader("mockXML/regattaTest.xml");
BoatDataSource boatData = new BoatXMLReader("mockXML/boatTest.xml"); BoatDataSource boatData = new BoatXMLReader("mockXML/boatTest.xml");
RaceDataSource raceData = new StreamedCourseXMLReader("mockXML/raceTest.xml", boatData);
Event raceEvent = new Event(raceData, regattaData, boatData); Event raceEvent = new Event(raceData, regattaData, boatData);
raceEvent.start(); raceEvent.start();
} catch (IOException e) { } catch (IOException e) {
@ -46,6 +49,10 @@ public class App extends Application {
e.printStackTrace(); e.printStackTrace();
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (StreamedCourseXMLException e) {
e.printStackTrace();
} }
} }
} }

@ -5,7 +5,7 @@ import org.w3c.dom.Element;
import seng302.DataInput.RaceDataSource; import seng302.DataInput.RaceDataSource;
import seng302.Exceptions.InvalidRaceDataException; import seng302.Exceptions.InvalidRaceDataException;
import seng302.Model.Boat; import seng302.Model.Boat;
import seng302.Model.CompoundMarker; import seng302.Model.CompoundMark;
import seng302.Model.GPSCoordinate; import seng302.Model.GPSCoordinate;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@ -151,9 +151,9 @@ public class RaceData {
Element compoundMarkSeqElement = doc.createElement("CompoundMarkSequence"); Element compoundMarkSeqElement = doc.createElement("CompoundMarkSequence");
int i = 1; int i = 1;
for (CompoundMarker compoundMarker : dataSource.getCompoundMarkers()) { for (CompoundMark compoundMark : dataSource.getCompoundMarks()) {
courseElement.appendChild(createCompoundMarker(compoundMarker, i)); courseElement.appendChild(createCompoundMarker(compoundMark, i));
compoundMarkSeqElement.appendChild(createCornerElement(i)); compoundMarkSeqElement.appendChild(createCornerElement(i));
i++; i++;
} }
@ -177,21 +177,21 @@ public class RaceData {
} }
/** /**
* Creates a compound compoundMarker holding one or two marks,and a sequence number * Creates a compound compoundMark holding one or two marks,and a sequence number
* *
* @param compoundMarker compoundMarker * @param compoundMark compoundMark
* @param i sequence number * @param i sequence number
* @return Element compound mark element * @return Element compound mark element
*/ */
private Element createCompoundMarker(CompoundMarker compoundMarker, int i) { private Element createCompoundMarker(CompoundMark compoundMark, int i) {
Element compoundMarkElement = doc.createElement("CompoundMark"); Element compoundMarkElement = doc.createElement("CompoundMark");
compoundMarkElement.setAttribute("CompoundMarkID", i + ""); compoundMarkElement.setAttribute("CompoundMarkID", i + "");
compoundMarkElement.setAttribute("Name", compoundMarker.getName()); compoundMarkElement.setAttribute("Name", compoundMark.getName());
compoundMarkElement.appendChild(createMark(compoundMarker.getMark1())); compoundMarkElement.appendChild(createMark(compoundMark.getMark1()));
if (!(compoundMarker.getMark1().equals(compoundMarker.getMark2()))) { if (!(compoundMark.getMark1().equals(compoundMark.getMark2()))) {
compoundMarkElement.appendChild(createMark(compoundMarker.getMark2())); compoundMarkElement.appendChild(createMark(compoundMark.getMark2()));
} }
return compoundMarkElement; return compoundMarkElement;

@ -3,12 +3,12 @@ package seng302.DataInput;
import seng302.Model.Boat; import seng302.Model.Boat;
import seng302.Model.Mark; import seng302.Model.Mark;
import java.util.List; import java.util.Map;
/** /**
* Created by cbt24 on 10/05/17. * Created by cbt24 on 10/05/17.
*/ */
public interface BoatDataSource { public interface BoatDataSource {
List<Boat> getBoats(); Map<Integer, Boat> getBoats();
List<Mark> getMarkerBoats(); Map<Integer, Mark> getMarkerBoats();
} }

@ -4,13 +4,12 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import seng302.Model.Boat; import seng302.Model.Boat;
import seng302.Model.GPSCoordinate;
import seng302.Model.Mark; import seng302.Model.Mark;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -51,7 +50,7 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
for (int i = 0; i < nBoats.getChildNodes().getLength(); i++) { for (int i = 0; i < nBoats.getChildNodes().getLength(); i++) {
Node boat = nBoats.getChildNodes().item(i); Node boat = nBoats.getChildNodes().item(i);
if (boat.getNodeName().equals("Boat")) { if (boat.getNodeName().equals("Boat")) {
readSingleBoat(boat); readBoatNode(boat);
} }
} }
} }
@ -78,34 +77,39 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
* Reads the information about one boat * Reads the information about one boat
* Ignored values: ShapeID, StoweName, HullNum, Skipper, Type * Ignored values: ShapeID, StoweName, HullNum, Skipper, Type
*/ */
private void readSingleBoat(Node boatNode) { private void readBoatNode(Node boatNode) {
Boat boat;
int sourceID = Integer.parseInt(boatNode.getAttributes().getNamedItem("SourceID").getTextContent()); int sourceID = Integer.parseInt(boatNode.getAttributes().getNamedItem("SourceID").getTextContent());
String name = boatNode.getAttributes().getNamedItem("BoatName").getTextContent(); String name = boatNode.getAttributes().getNamedItem("BoatName").getTextContent();
if (isYachtNode(boatNode)) { if (isYachtNode(boatNode)) readYacht(boatNode, sourceID, name);
String shortName = boatNode.getAttributes().getNamedItem("ShortName").getTextContent(); else readMark(boatNode, sourceID, name);
if (exists(boatNode, "Country")) { }
String country = boatNode.getAttributes().getNamedItem("Country").getTextContent();
boat = new Boat(sourceID, name, country); private void readYacht(Node boatNode, int sourceID, String name) {
} else { String shortName = boatNode.getAttributes().getNamedItem("ShortName").getTextContent();
boat = new Boat(sourceID, name, shortName); if (exists(boatNode, "Country")) {
} String country = boatNode.getAttributes().getNamedItem("Country").getTextContent();
boatMap.put(sourceID, boat); boatMap.put(sourceID, new Boat(sourceID, name, country));
} else { } else {
Mark mark = new Mark(name); boatMap.put(sourceID, new Boat(sourceID, name, shortName));
markerMap.put(sourceID, mark);
} }
} }
private void readMark(Node boatNode, int sourceID, String name) {
Node nCoord = ((Element)boatNode).getElementsByTagName("GPSposition").item(0);
double x = Double.parseDouble(nCoord.getAttributes().getNamedItem("X").getTextContent());
double y = Double.parseDouble(nCoord.getAttributes().getNamedItem("Y").getTextContent());
Mark mark = new Mark(sourceID, name, new GPSCoordinate(x,y));
markerMap.put(sourceID, mark);
}
@Override @Override
public List<Boat> getBoats() { public Map<Integer, Boat> getBoats() {
return new ArrayList<>(boatMap.values()); return boatMap;
} }
@Override @Override
public List<Mark> getMarkerBoats() { public Map<Integer, Mark> getMarkerBoats() {
return new ArrayList<>(markerMap.values()); return markerMap;
} }
} }

@ -2,10 +2,11 @@ package seng302.DataInput;
; ;
import seng302.Model.Boat; import seng302.Model.Boat;
import seng302.Model.CompoundMark;
import seng302.Model.GPSCoordinate; import seng302.Model.GPSCoordinate;
import seng302.Model.Leg; import seng302.Model.Leg;
import seng302.Model.CompoundMarker;
import java.time.ZonedDateTime;
import java.util.List; import java.util.List;
/** /**
@ -18,13 +19,13 @@ public interface RaceDataSource {
List<GPSCoordinate> getBoundary(); List<GPSCoordinate> getBoundary();
List<CompoundMarker> getCompoundMarkers(); List<CompoundMark> getCompoundMarks();
int getRaceId(); int getRaceId();
String getRaceType(); String getRaceType();
GPSCoordinate getMark(); ZonedDateTime getZonedDateTime();
GPSCoordinate getMapTopLeft(); GPSCoordinate getMapTopLeft();

@ -5,18 +5,17 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import seng302.Model.Boat; import seng302.Model.*;
import seng302.Model.CompoundMarker;
import seng302.Model.GPSCoordinate;
import seng302.Model.Leg;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException; import java.io.IOException;
import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Created by fwy13 on 26/03/2017. * Created by fwy13 on 26/03/2017.
* @deprecated please use {@link seng302.Model.StreamedCourseXMLReader}
*/ */
public class RaceXMLReader extends XMLReader implements RaceDataSource { public class RaceXMLReader extends XMLReader implements RaceDataSource {
private static double COORDINATEPADDING = 0.0005; private static double COORDINATEPADDING = 0.0005;
@ -27,7 +26,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
private GPSCoordinate mark, startPt1, startPt2, finishPt1, finishPt2, leewardPt1, leewardPt2, windwardPt1, windwardPt2; private GPSCoordinate mark, startPt1, startPt2, finishPt1, finishPt2, leewardPt1, leewardPt2, windwardPt1, windwardPt2;
private GPSCoordinate mapTopLeft, mapBottomRight; private GPSCoordinate mapTopLeft, mapBottomRight;
private List<GPSCoordinate> boundary = new ArrayList<>(); private List<GPSCoordinate> boundary = new ArrayList<>();
private List<CompoundMarker> compoundMarkers = new ArrayList<>(); private List<CompoundMark> compoundMarks = new ArrayList<>();
/** /**
* Constractor for Race XML * Constractor for Race XML
@ -106,8 +105,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
NodeList nMarkers = doc.getElementsByTagName("marker"); NodeList nMarkers = doc.getElementsByTagName("marker");
for (int i = 0; i < nMarkers.getLength(); i++) { for (int i = 0; i < nMarkers.getLength(); i++) {
CompoundMarker compoundMarker = getMarker((Element) nMarkers.item(i)); CompoundMark compoundMark = getMarker((Element) nMarkers.item(i));
if (compoundMarker.getName() != null) compoundMarkers.add(compoundMarker); if (compoundMark.getName() != null) compoundMarks.add(compoundMark);
} }
} }
@ -121,10 +120,10 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
for (int i = 0; i < nLegs.getLength(); i++) { for (int i = 0; i < nLegs.getLength(); i++) {
String label = getTextValueOfNode((Element) nLegs.item(i), "name"); String label = getTextValueOfNode((Element) nLegs.item(i), "name");
NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start"); NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start");
CompoundMarker startCompoundMarker = getMarker(start); CompoundMark startCompoundMark = getMarker(start);
NodeList finish = ((Element) nLegs.item(i)).getElementsByTagName("finish"); NodeList finish = ((Element) nLegs.item(i)).getElementsByTagName("finish");
CompoundMarker finishCompoundMarker = getMarker(finish); CompoundMark finishCompoundMark = getMarker(finish);
legs.add(new Leg(label, startCompoundMarker, finishCompoundMarker, i)); legs.add(new Leg(label, startCompoundMark, finishCompoundMark, i));
} }
} }
@ -204,7 +203,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
* @param start base nodelist this should be the tag that contains <coordinate></coordinate> * @param start base nodelist this should be the tag that contains <coordinate></coordinate>
* @return * @return
*/ */
private CompoundMarker getMarker(NodeList start) { private CompoundMark getMarker(NodeList start) {
return getMarker(start, 0); return getMarker(start, 0);
} }
@ -215,7 +214,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
* @param startIndex index in the node that has the coordinate tag * @param startIndex index in the node that has the coordinate tag
* @return * @return
*/ */
private CompoundMarker getMarker(NodeList start, int startIndex) { private CompoundMark getMarker(NodeList start, int startIndex) {
return getMarker(start, startIndex, 0); return getMarker(start, startIndex, 0);
} }
@ -227,7 +226,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
* @param nodeIndex coordinate index * @param nodeIndex coordinate index
* @return * @return
*/ */
private CompoundMarker getMarker(NodeList start, int startIndex, int nodeIndex) { private CompoundMark getMarker(NodeList start, int startIndex, int nodeIndex) {
NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("marker"); NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("marker");
Element marker = (Element) nodeList.item(nodeIndex); Element marker = (Element) nodeList.item(nodeIndex);
return getMarker(marker); return getMarker(marker);
@ -239,7 +238,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
* @param markerNode marker to turn into coordinates * @param markerNode marker to turn into coordinates
* @return * @return
*/ */
private CompoundMarker getMarker(Element markerNode) { private CompoundMark getMarker(Element markerNode) {
NodeList nCoordinates = markerNode.getElementsByTagName("coordinate"); NodeList nCoordinates = markerNode.getElementsByTagName("coordinate");
@ -251,7 +250,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
side2 = side1; side2 = side1;
} }
NodeList name = markerNode.getElementsByTagName("name"); NodeList name = markerNode.getElementsByTagName("name");
return name.getLength() == 1 ? new CompoundMarker(getTextValueOfNode((Element) markerNode, "name"), side1, side2) : new CompoundMarker(side1, side2); return null;//name.getLength() == 1 ? new CompoundMark(getTextValueOfNode((Element) markerNode, "name"), side1, side2) : new CompoundMark(side1, side2);
} }
/** /**
@ -362,11 +361,16 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
return raceID; return raceID;
} }
public List<CompoundMarker> getCompoundMarkers() { public List<CompoundMark> getCompoundMarks() {
return compoundMarkers; return compoundMarks;
} }
public String getRaceType() { public String getRaceType() {
return "FLEET"; return "FLEET";
} }
@Override
public ZonedDateTime getZonedDateTime() {
return null;
}
} }

@ -41,8 +41,8 @@ public class Boat {
public double calculateAzimuth() { public double calculateAzimuth() {
GeodeticCalculator calc = new GeodeticCalculator(); GeodeticCalculator calc = new GeodeticCalculator();
GPSCoordinate start = currentLeg.getStartCompoundMarker().getAverageGPSCoordinate(); GPSCoordinate start = currentLeg.getStartCompoundMark().getAverageGPSCoordinate();
GPSCoordinate end = currentLeg.getEndCompoundMarker().getAverageGPSCoordinate(); GPSCoordinate end = currentLeg.getEndCompoundMark().getAverageGPSCoordinate();
calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude()); calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude()); calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());

@ -0,0 +1,71 @@
package seng302.Model;
import org.geotools.referencing.GeodeticCalculator;
import java.awt.geom.Point2D;
/**
* Created by esa46 on 29/03/17.
*/
public class CompoundMark extends Marker{
private GPSCoordinate averageGPSCoordinate;
private Mark mark1;
private Mark mark2 = null;
private String name;
public CompoundMark(Mark mark1) {
super(mark1.getPosition());
this.mark1 = mark1;
this.averageGPSCoordinate = calculateAverage();
}
public CompoundMark(Mark mark1, Mark mark2) {
super(mark1.getPosition(), mark2.getPosition());
this.mark1 = mark1;
this.mark2 = mark2;
this.averageGPSCoordinate = calculateAverage();
}
public CompoundMark(String name, Mark mark1, Mark mark2) {
super(name, mark1.getPosition(), mark2.getPosition());
this.name = name;
this.mark1 = mark1;
this.mark2 = mark2;
this.averageGPSCoordinate = calculateAverage();
}
public GPSCoordinate getMark1() {
return mark1.getPosition();
}
public GPSCoordinate getMark2() {
return mark2.getPosition();
}
public GPSCoordinate getAverageGPSCoordinate() {
return averageGPSCoordinate;
}
public String getName() {
return name;
}
private GPSCoordinate calculateAverage() {
if(mark2 != null) {
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(mark1.getPosition().getLongitude(), mark1.getPosition().getLatitude());
calc.setDestinationGeographicPoint(mark2.getPosition().getLongitude(), mark2.getPosition().getLatitude());
double azimuth = calc.getAzimuth();
double distance = calc.getOrthodromicDistance();
GeodeticCalculator middleCalc = new GeodeticCalculator();
middleCalc.setStartingGeographicPoint(mark1.getPosition().getLongitude(), mark1.getPosition().getLatitude());
middleCalc.setDirection(azimuth, distance / 2);
Point2D middlePoint = middleCalc.getDestinationGeographicPoint();
return new GPSCoordinate(middlePoint.getY(), middlePoint.getX());
} else return mark1.getPosition();
}
}

@ -62,7 +62,7 @@ public class Event {
mockOutput.parseXMLString(regattaData, 26); mockOutput.parseXMLString(regattaData, 26);
System.out.println("Sending Race"); System.out.println("Sending Race");
String raceData = readFile("mock/src/main/resources//mockXML/raceTest.xml", StandardCharsets.UTF_8); String raceData = readFile("mock/src/main/resources/mockXML/raceTest.xml", StandardCharsets.UTF_8);
mockOutput.setRaceXml(raceData); mockOutput.setRaceXml(raceData);
mockOutput.parseXMLString(raceData, 26); mockOutput.parseXMLString(raceData, 26);

@ -10,8 +10,8 @@ import seng302.Constants;
public class Leg { public class Leg {
private String name; //nautical miles private String name; //nautical miles
private double distance; private double distance;
private CompoundMarker startCompoundMarker; private Marker startCompoundMark;
private CompoundMarker endCompoundMarker; private Marker endCompoundMark;
private int legNumber; private int legNumber;
/** /**
@ -22,10 +22,10 @@ public class Leg {
* @param end marker * @param end marker
* @param number Leg's position in race * @param number Leg's position in race
*/ */
public Leg(String name, CompoundMarker start, CompoundMarker end, int number) { public Leg(String name, Marker start, Marker end, int number) {
this.name = name; this.name = name;
this.startCompoundMarker = start; this.startCompoundMark = start;
this.endCompoundMarker = end; this.endCompoundMark = end;
this.legNumber = number; this.legNumber = number;
calculateDistance(); calculateDistance();
} }
@ -69,20 +69,20 @@ public class Leg {
} }
public CompoundMarker getStartCompoundMarker() { public Marker getStartCompoundMark() {
return startCompoundMarker; return startCompoundMark;
} }
public void setStartCompoundMarker(CompoundMarker startCompoundMarker) { public void setStartCompoundMark(Marker startCompoundMark) {
this.startCompoundMarker = startCompoundMarker; this.startCompoundMark = startCompoundMark;
} }
public CompoundMarker getEndCompoundMarker() { public Marker getEndCompoundMark() {
return endCompoundMarker; return endCompoundMark;
} }
public void setEndCompoundMarker(CompoundMarker endCompoundMarker) { public void setEndCompoundMark(Marker endCompoundMark) {
this.endCompoundMarker = endCompoundMarker; this.endCompoundMark = endCompoundMark;
} }
/** /**
@ -92,8 +92,8 @@ public class Leg {
GeodeticCalculator calc = new GeodeticCalculator(); GeodeticCalculator calc = new GeodeticCalculator();
//Load start and end of leg //Load start and end of leg
GPSCoordinate startMarker = this.startCompoundMarker.getAverageGPSCoordinate(); GPSCoordinate startMarker = this.startCompoundMark.getAverageGPSCoordinate();
GPSCoordinate endMarker = this.endCompoundMarker.getAverageGPSCoordinate(); GPSCoordinate endMarker = this.endCompoundMark.getAverageGPSCoordinate();
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude()); calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude()); calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion; this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion;

@ -4,13 +4,25 @@ package seng302.Model;
* Created by cbt24 on 10/05/17. * Created by cbt24 on 10/05/17.
*/ */
public class Mark { public class Mark {
private int sourceID;
private String name; private String name;
private GPSCoordinate position;
public Mark(String name) { public Mark(int sourceID, String name, GPSCoordinate position) {
this.sourceID = sourceID;
this.name = name; this.name = name;
this.position = position;
} }
public String getName() { public String getName() {
return name; return name;
} }
public int getSourceID() {
return sourceID;
}
public GPSCoordinate getPosition() {
return position;
}
} }

@ -6,7 +6,7 @@ import java.awt.geom.Point2D;
/** /**
* Created by esa46 on 29/03/17. * Created by esa46 on 29/03/17.
*/ */
public class CompoundMarker { public class Marker {
private GPSCoordinate averageGPSCoordinate; private GPSCoordinate averageGPSCoordinate;
private GPSCoordinate mark1; private GPSCoordinate mark1;
@ -14,7 +14,7 @@ public class CompoundMarker {
private String name; private String name;
private boolean doubleMarker = false; private boolean doubleMarker = false;
public CompoundMarker(GPSCoordinate mark1) { public Marker(GPSCoordinate mark1) {
this.mark1 = mark1; this.mark1 = mark1;
this.mark2 = mark1; this.mark2 = mark1;
@ -22,7 +22,7 @@ public class CompoundMarker {
} }
public CompoundMarker(GPSCoordinate mark1, GPSCoordinate mark2) { public Marker(GPSCoordinate mark1, GPSCoordinate mark2) {
this.mark1 = mark1; this.mark1 = mark1;
this.mark2 = mark2; this.mark2 = mark2;
@ -30,7 +30,7 @@ public class CompoundMarker {
} }
public CompoundMarker(String name, GPSCoordinate mark1, GPSCoordinate mark2) { public Marker(String name, GPSCoordinate mark1, GPSCoordinate mark2) {
this.name = name; this.name = name;
this.mark1 = mark1; this.mark1 = mark1;
@ -71,4 +71,4 @@ public class CompoundMarker {
} }
} }

@ -216,19 +216,14 @@ public class Race implements Runnable {
public void initialiseBoats() { public void initialiseBoats() {
Leg officialStart = legs.get(0); Leg officialStart = legs.get(0);
String name = officialStart.getName(); String name = officialStart.getName();
CompoundMarker endCompoundMarker = officialStart.getEndCompoundMarker();
ArrayList<CompoundMarker> startCompoundMarkers = getSpreadStartingPositions(); ArrayList<GPSCoordinate> startingPositions = getSpreadStartingPositions();
for (int i = 0; i < startingBoats.size(); i++) { for (int i = 0; i < startingBoats.size(); i++) {
Boat boat = startingBoats.get(i); Boat boat = startingBoats.get(i);
if (boat != null) { if (boat != null) {
boat.setScaledVelocity(boat.getVelocity() * scaleFactor); boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
Leg startLeg = new Leg(name, 0); boat.setCurrentPosition(startingPositions.get(i));
boat.setCurrentPosition(startCompoundMarkers.get(i).getAverageGPSCoordinate()); boat.setCurrentLeg(officialStart);
startLeg.setStartCompoundMarker(startCompoundMarkers.get(i));
startLeg.setEndCompoundMarker(endCompoundMarker);
startLeg.calculateDistance();
boat.setCurrentLeg(startLeg);
boat.setHeading(boat.calculateHeading()); boat.setHeading(boat.calculateHeading());
} }
} }
@ -239,27 +234,27 @@ public class Race implements Runnable {
* *
* @return list of starting positions * @return list of starting positions
*/ */
public ArrayList<CompoundMarker> getSpreadStartingPositions() { public ArrayList<GPSCoordinate> getSpreadStartingPositions() {
int nBoats = startingBoats.size(); int nBoats = startingBoats.size();
CompoundMarker compoundMarker = legs.get(0).getStartCompoundMarker(); Marker compoundMark = legs.get(0).getStartCompoundMark();
GeodeticCalculator initialCalc = new GeodeticCalculator(); GeodeticCalculator initialCalc = new GeodeticCalculator();
initialCalc.setStartingGeographicPoint(compoundMarker.getMark1().getLongitude(), compoundMarker.getMark1().getLatitude()); initialCalc.setStartingGeographicPoint(compoundMark.getMark1().getLongitude(), compoundMark.getMark1().getLatitude());
initialCalc.setDestinationGeographicPoint(compoundMarker.getMark2().getLongitude(), compoundMarker.getMark2().getLatitude()); initialCalc.setDestinationGeographicPoint(compoundMark.getMark2().getLongitude(), compoundMark.getMark2().getLatitude());
double azimuth = initialCalc.getAzimuth(); double azimuth = initialCalc.getAzimuth();
double distanceBetweenMarkers = initialCalc.getOrthodromicDistance(); double distanceBetweenMarkers = initialCalc.getOrthodromicDistance();
double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1); double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1);
GeodeticCalculator positionCalc = new GeodeticCalculator(); GeodeticCalculator positionCalc = new GeodeticCalculator();
positionCalc.setStartingGeographicPoint(compoundMarker.getMark1().getLongitude(), compoundMarker.getMark1().getLatitude()); positionCalc.setStartingGeographicPoint(compoundMark.getMark1().getLongitude(), compoundMark.getMark1().getLatitude());
ArrayList<CompoundMarker> positions = new ArrayList<>(); ArrayList<GPSCoordinate> positions = new ArrayList<>();
for (int i = 0; i < nBoats; i++) { for (int i = 0; i < nBoats; i++) {
positionCalc.setDirection(azimuth, distanceBetweenBoats); positionCalc.setDirection(azimuth, distanceBetweenBoats);
Point2D position = positionCalc.getDestinationGeographicPoint(); Point2D position = positionCalc.getDestinationGeographicPoint();
positions.add(new CompoundMarker(new GPSCoordinate(position.getY(), position.getX()))); positions.add(new GPSCoordinate(position.getY(), position.getX()));
positionCalc = new GeodeticCalculator(); positionCalc = new GeodeticCalculator();
positionCalc.setStartingGeographicPoint(position); positionCalc.setStartingGeographicPoint(position);
@ -302,7 +297,7 @@ public class Race implements Runnable {
//update boat's distance travelled //update boat's distance travelled
boat.setDistanceTravelledInLeg(totalDistanceTravelled); boat.setDistanceTravelledInLeg(totalDistanceTravelled);
//Calculate boat's new position by adding the distance travelled onto the start point of the leg //Calculate boat's new position by adding the distance travelled onto the start point of the leg
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartCompoundMarker().getAverageGPSCoordinate(), boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartCompoundMark().getAverageGPSCoordinate(),
totalDistanceTravelled, boat.calculateAzimuth())); totalDistanceTravelled, boat.calculateAzimuth()));
} }
} }

@ -0,0 +1,7 @@
package seng302.Model;
/**
* Created by cbt24 on 25/04/17.
*/
public class StreamedCourseXMLException extends Throwable {
}

@ -0,0 +1,274 @@
package seng302.Model;
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.DataInput.BoatDataSource;
import seng302.DataInput.RaceDataSource;
import seng302.DataInput.XMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.text.ParseException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
* Created by jjg64 on 21/04/17.
*/
public class StreamedCourseXMLReader extends XMLReader implements RaceDataSource {
private static final double COORDINATEPADDING = 0.000;
private GPSCoordinate mapTopLeft, mapBottomRight;
private final List<GPSCoordinate> boundary = new ArrayList<>();
private final Map<Integer,Element> compoundMarkMap = new HashMap<>();
private final Map<Integer, Boat> participants = new HashMap<>();
private final List<Leg> legs = new ArrayList<>();
private final List<CompoundMark> compoundMarks = new ArrayList<>();
private ZonedDateTime creationTimeDate;
private ZonedDateTime raceStartTime;
private int raceID;
private String raceType;
private boolean postpone;
private Map<Integer, Boat> boats;
private Map<Integer, Mark> marks;
/**
* Constructor for Streamed Race XML
* @param filePath path of the file
* @throws IOException error
* @throws SAXException error
* @throws ParserConfigurationException error
* @throws ParseException error
* @throws StreamedCourseXMLException error
*/
public StreamedCourseXMLReader(String filePath, BoatDataSource boatData) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException {
this(filePath, boatData, 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
* @throws ParseException error
* @throws StreamedCourseXMLException error
*/
public StreamedCourseXMLReader(String filePath, BoatDataSource boatData, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException {
super(filePath);
this.boats = boatData.getBoats();
this.marks = boatData.getMarkerBoats();
if (read) {
read();
}
}
/**
* reads
* @throws StreamedCourseXMLException error
*/
private void read() throws StreamedCourseXMLException {
readRace();
readParticipants();
readCourse();
}
/**
* reads a race
*/
private void readRace() {
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
Element settings = (Element) doc.getElementsByTagName("Race").item(0);
NamedNodeMap raceTimeTag = doc.getElementsByTagName("RaceStartTime").item(0).getAttributes();
if (raceTimeTag.getNamedItem("Time") != null) dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID"));
raceType = getTextValueOfNode(settings, "RaceType");
creationTimeDate = ZonedDateTime.parse(getTextValueOfNode(settings, "CreationTimeDate"), dateFormat);
if (raceTimeTag.getNamedItem("Time") != null) raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Time").getTextContent(), dateFormat);
else raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Start").getTextContent(), dateFormat);
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
}
private void readParticipants() {
Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0);
nParticipants.getChildNodes().getLength();
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, boats.get(sourceID));
}
}
}
}
/**
* reads a course
* @throws StreamedCourseXMLException error
*/
private void readCourse() throws StreamedCourseXMLException {
readCompoundMarks();
readCompoundMarkSequence();
readCourseLimit();
}
/**
* Indexes CompoundMark elements by their ID for use in generating the course, and populates list of Markers.
* @see CompoundMark
*/
private void readCompoundMarks() throws StreamedCourseXMLException {
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")) {
int compoundMarkID = getCompoundMarkID((Element) compoundMark);
compoundMarkMap.put(compoundMarkID, (Element)compoundMark);
compoundMarks.add(getCompoundMark(compoundMarkID));
}
}
}
/**
* Generates a CompoundMark from the CompoundMark element with given ID.
* @param compoundMarkID index of required CompoundMark element
* @return generated CompoundMark
* @throws StreamedCourseXMLException if CompoundMark element contains unhandled number of compoundMarks
* @see CompoundMark
*/
private CompoundMark getCompoundMark(int compoundMarkID) throws StreamedCourseXMLException {
Element compoundMark = compoundMarkMap.get(compoundMarkID);
NodeList nMarks = compoundMark.getElementsByTagName("Mark");
CompoundMark marker;
switch(nMarks.getLength()) {
case 1: marker = new CompoundMark(getMark((Element)nMarks.item(0))); break;
case 2: marker = new CompoundMark(getMark((Element)nMarks.item(0)), getMark((Element)nMarks.item(1))); break;
default: throw new StreamedCourseXMLException();
}
return marker;
}
private Mark getMark(Element mark) {
int sourceID = Integer.parseInt(mark.getAttribute("SourceID"));
System.out.println(marks.get(sourceID).getPosition());
return marks.get(sourceID);
}
/**
* 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 compoundMarkMap.get(compoundMarkID).getAttribute("Name");
}
/**
* Populates list of legs given CompoundMarkSequence element and referenced CompoundMark elements.
* @throws StreamedCourseXMLException if compoundMarks cannot be resolved from CompoundMark
*/
private void readCompoundMarkSequence() throws StreamedCourseXMLException {
Element nCompoundMarkSequence = (Element) doc.getElementsByTagName("CompoundMarkSequence").item(0);
NodeList nCorners = nCompoundMarkSequence.getElementsByTagName("Corner");
Element markXML = (Element)nCorners.item(0);
CompoundMark lastCompoundMark = getCompoundMark(getCompoundMarkID(markXML));
String legName = getCompoundMarkName(getCompoundMarkID(markXML));
for(int i = 1; i < nCorners.getLength(); i++) {
markXML = (Element)nCorners.item(i);
CompoundMark currentCompoundMark = getCompoundMark(getCompoundMarkID(markXML));
legs.add(new Leg(legName, lastCompoundMark, currentCompoundMark, i-1));
lastCompoundMark = currentCompoundMark;
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 List<CompoundMark> getCompoundMarks() { return compoundMarks; }
public Double getPadding() {
return COORDINATEPADDING;
}
public ZonedDateTime getCreationTimeDate() {
return creationTimeDate;
}
public ZonedDateTime getZonedDateTime() {
return raceStartTime;
}
public int getRaceId() {
return raceID;
}
public String getRaceType() {
return raceType;
}
public boolean isPostpone() {
return postpone;
}
public List<Boat> getBoats() {
return new ArrayList<>(participants.values());
}
}

@ -29,7 +29,7 @@
<Mark Name="Marker1" TargetLat="32.293039" TargetLng="-64.843983" SourceID="103"/> <Mark Name="Marker1" TargetLat="32.293039" TargetLng="-64.843983" SourceID="103"/>
</CompoundMark> </CompoundMark>
<CompoundMark CompoundMarkID="3" Name="Windward Gate"> <CompoundMark CompoundMarkID="3" Name="Windward Gate">
<Mark Name="WGL" SeqId="1" TargetLat="32.28468" TargetLng="" SourceID="104"/> <Mark Name="WGL" SeqId="1" TargetLat="32.28468" TargetLng="-64.850045" SourceID="104"/>
<Mark Name="WGR" SeqId="2" TargetLat="32.280164" TargetLng="-64.847591" SourceID="105"/> <Mark Name="WGR" SeqId="2" TargetLat="32.280164" TargetLng="-64.847591" SourceID="105"/>
</CompoundMark> </CompoundMark>
<CompoundMark CompoundMarkID="4" Name="Leeward Gate"> <CompoundMark CompoundMarkID="4" Name="Leeward Gate">

@ -8,6 +8,7 @@ import seng302.Model.Mark;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.testng.Assert.*; import static org.testng.Assert.*;
@ -24,8 +25,8 @@ public class BoatXMLReaderTest {
public void setUp() { public void setUp() {
try { try {
boatData = new BoatXMLReader("mockXML/boatTest.xml"); boatData = new BoatXMLReader("mockXML/boatTest.xml");
boats = boatData.getBoats(); boats = new ArrayList<>(boatData.getBoats().values());
marks = boatData.getMarkerBoats(); marks = new ArrayList<>(boatData.getMarkerBoats().values());
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
e.printStackTrace(); e.printStackTrace();
} catch (SAXException e) { } catch (SAXException e) {

@ -18,18 +18,18 @@ public class BoatTest {
@Test @Test
public void calculateDueNorthAzimuthReturns0() { public void calculateDueNorthAzimuthReturns0() {
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); Marker startMarker = new Marker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(50, 0)); Marker endMarker = new Marker(new GPSCoordinate(50, 0));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8); assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
} }
@Test @Test
public void calculateDueSouthAzimuthReturns180() { public void calculateDueSouthAzimuthReturns180() {
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); Marker startMarker = new Marker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(-50, 0)); Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8); assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
} }
@ -38,9 +38,9 @@ public class BoatTest {
@Test @Test
public void calculateDueEastAzimuthReturns90() { public void calculateDueEastAzimuthReturns90() {
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); Marker startMarker = new Marker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, 50)); Marker endMarker = new Marker(new GPSCoordinate(0, 50));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8); assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
} }
@ -48,9 +48,9 @@ public class BoatTest {
@Test @Test
public void calculateDueWestAzimuthReturnsNegative90() { public void calculateDueWestAzimuthReturnsNegative90() {
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); Marker startMarker = new Marker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, -50)); Marker endMarker = new Marker(new GPSCoordinate(0, -50));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8); assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
@ -59,9 +59,9 @@ public class BoatTest {
@Test @Test
public void calculateDueNorthHeadingReturns0() { public void calculateDueNorthHeadingReturns0() {
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); Marker startMarker = new Marker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(50, 0)); Marker endMarker = new Marker(new GPSCoordinate(50, 0));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8); assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
} }
@ -69,27 +69,27 @@ public class BoatTest {
@Test @Test
public void calculateDueEastHeadingReturns90() { public void calculateDueEastHeadingReturns90() {
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); Marker startMarker = new Marker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, 50)); Marker endMarker = new Marker(new GPSCoordinate(0, 50));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8); assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
} }
@Test @Test
public void calculateDueSouthHeadingReturns180() { public void calculateDueSouthHeadingReturns180() {
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); Marker startMarker = new Marker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(-50, 0)); Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8); assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
} }
@Test @Test
public void calculateDueWestHeadingReturns270() { public void calculateDueWestHeadingReturns270() {
CompoundMarker startCompoundMarker = new CompoundMarker(ORIGIN_COORDS); Marker startMarker = new Marker(ORIGIN_COORDS);
CompoundMarker endCompoundMarker = new CompoundMarker(new GPSCoordinate(0, -50)); Marker endMarker = new Marker(new GPSCoordinate(0, -50));
Leg start = new Leg("Start", startCompoundMarker, endCompoundMarker, 0); Leg start = new Leg("Start", startMarker, endMarker, 0);
TEST_BOAT.setCurrentLeg(start); TEST_BOAT.setCurrentLeg(start);
assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8); assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
} }

@ -8,14 +8,14 @@ import static org.junit.Assert.assertTrue;
/** /**
* Created by esa46 on 29/03/17. * Created by esa46 on 29/03/17.
*/ */
public class CompoundMarkerTest { public class CompoundMarkTest {
GPSCoordinate ORIGIN_COORD = new GPSCoordinate(0, 0); GPSCoordinate ORIGIN_COORD = new GPSCoordinate(0, 0);
@Test @Test
public void averageOfSingleMarkAtOriginIsSingleMark() { public void averageOfSingleMarkAtOriginIsSingleMark() {
CompoundMarker testMark = new CompoundMarker(ORIGIN_COORD); Marker testMark = new Marker(ORIGIN_COORD);
assertTrue(testMark.getAverageGPSCoordinate().equals(ORIGIN_COORD)); assertTrue(testMark.getAverageGPSCoordinate().equals(ORIGIN_COORD));
} }
@ -24,7 +24,7 @@ public class CompoundMarkerTest {
public void averageOfSingleMarkIsSingleMark() { public void averageOfSingleMarkIsSingleMark() {
GPSCoordinate testCoord = new GPSCoordinate(20, 25); GPSCoordinate testCoord = new GPSCoordinate(20, 25);
CompoundMarker testMark = new CompoundMarker(testCoord); Marker testMark = new Marker(testCoord);
assertTrue(testMark.getAverageGPSCoordinate().equals(testCoord)); assertTrue(testMark.getAverageGPSCoordinate().equals(testCoord));
} }
@ -34,7 +34,7 @@ public class CompoundMarkerTest {
public void averageLatOfTwoMarksIsAccurate() { public void averageLatOfTwoMarksIsAccurate() {
GPSCoordinate testCoord = new GPSCoordinate(10, 0); GPSCoordinate testCoord = new GPSCoordinate(10, 0);
CompoundMarker testMark = new CompoundMarker(ORIGIN_COORD, testCoord); Marker testMark = new Marker(ORIGIN_COORD, testCoord);
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(5, 0))); assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(5, 0)));
} }
@ -42,7 +42,7 @@ public class CompoundMarkerTest {
public void averageLongOfTwoMarksIsAccurate() { public void averageLongOfTwoMarksIsAccurate() {
GPSCoordinate testCoord = new GPSCoordinate(0, 10); GPSCoordinate testCoord = new GPSCoordinate(0, 10);
CompoundMarker testMark = new CompoundMarker(ORIGIN_COORD, testCoord); Marker testMark = new Marker(ORIGIN_COORD, testCoord);
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(0, 5))); assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(0, 5)));
} }
@ -52,7 +52,7 @@ public class CompoundMarkerTest {
GPSCoordinate testCoord1 = new GPSCoordinate(10, 30); GPSCoordinate testCoord1 = new GPSCoordinate(10, 30);
GPSCoordinate testCoord2 = new GPSCoordinate(30, 60); GPSCoordinate testCoord2 = new GPSCoordinate(30, 60);
CompoundMarker testMark = new CompoundMarker(testCoord1, testCoord2); Marker testMark = new Marker(testCoord1, testCoord2);
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(020.644102, 44.014817))); assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(020.644102, 44.014817)));
} }

@ -14,7 +14,7 @@ import static junit.framework.TestCase.assertEquals;
*/ */
public class LegTest { public class LegTest {
private CompoundMarker ORIGIN_Compound_MARKER = new CompoundMarker(new GPSCoordinate(0, 0)); private Marker ORIGIN_Compound_MARKER = new Marker(new GPSCoordinate(0, 0));
@Test @Test
public void calculateDistanceHandles5nmNorth() { public void calculateDistanceHandles5nmNorth() {
@ -22,8 +22,8 @@ public class LegTest {
calc.setStartingGeographicPoint(0, 0); calc.setStartingGeographicPoint(0, 0);
calc.setDirection(0, 5 * Constants.NMToMetersConversion); calc.setDirection(0, 5 * Constants.NMToMetersConversion);
CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint()); Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0); Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0);
assertEquals(test.getDistance(), 5, 1e-8); assertEquals(test.getDistance(), 5, 1e-8);
} }
@ -33,8 +33,8 @@ public class LegTest {
calc.setStartingGeographicPoint(0, 0); calc.setStartingGeographicPoint(0, 0);
calc.setDirection(90, 12 * Constants.NMToMetersConversion); calc.setDirection(90, 12 * Constants.NMToMetersConversion);
CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint()); Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0); Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0);
assertEquals(test.getDistance(), 12, 1e-8); assertEquals(test.getDistance(), 12, 1e-8);
} }
@ -44,8 +44,8 @@ public class LegTest {
calc.setStartingGeographicPoint(0, 0); calc.setStartingGeographicPoint(0, 0);
calc.setDirection(180, 0.5 * Constants.NMToMetersConversion); calc.setDirection(180, 0.5 * Constants.NMToMetersConversion);
CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint()); Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0); Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0);
assertEquals(test.getDistance(), 0.5, 1e-8); assertEquals(test.getDistance(), 0.5, 1e-8);
} }
@ -55,8 +55,8 @@ public class LegTest {
calc.setStartingGeographicPoint(0, 0); calc.setStartingGeographicPoint(0, 0);
calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion); calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion);
CompoundMarker endCompoundMarker = getEndMarker(calc.getDestinationGeographicPoint()); Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endCompoundMarker, 0); Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0);
assertEquals(test.getDistance(), 0.1, 1e-8); assertEquals(test.getDistance(), 0.1, 1e-8);
} }
@ -67,11 +67,11 @@ public class LegTest {
assertEquals(test.getDistance(), 0, 1e-8); assertEquals(test.getDistance(), 0, 1e-8);
} }
private CompoundMarker getEndMarker(Point2D point) { private Marker getEndMarker(Point2D point) {
GPSCoordinate coords = new GPSCoordinate(point.getY(), point.getX()); GPSCoordinate coords = new GPSCoordinate(point.getY(), point.getX());
return new CompoundMarker(coords); return new Marker(coords);
} }
} }

@ -28,8 +28,8 @@
//public class RaceTest{ //public class RaceTest{
// //
// private static MockOutput mockOutput; // private static MockOutput mockOutput;
// SharedModel.Leg START_LEG = new SharedModel.Leg("Start", new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(0, 0)), new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(1, 1)), 0); // SharedModel.Leg START_LEG = new SharedModel.Leg("Start", new SharedModel.Marker(new SharedModel.GPSCoordinate(0, 0)), new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), 0);
// SharedModel.Leg FINISH_LEG = new SharedModel.Leg("Finish", new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(1, 1)), new SharedModel.CompoundMarker(new SharedModel.GPSCoordinate(2, 2)), 0); // SharedModel.Leg FINISH_LEG = new SharedModel.Leg("Finish", new SharedModel.Marker(new SharedModel.GPSCoordinate(1, 1)), new SharedModel.Marker(new SharedModel.GPSCoordinate(2, 2)), 0);
// //
//// @Override //// @Override
//// public void start(Stage primaryStage) throws Exception{} //// public void start(Stage primaryStage) throws Exception{}

@ -88,7 +88,7 @@ public class BoatXMLReader extends XMLReader {
Element nBoats = (Element) doc.getElementsByTagName("Boats").item(0); Element nBoats = (Element) doc.getElementsByTagName("Boats").item(0);
for (int i = 0; i < nBoats.getChildNodes().getLength(); i++) { for (int i = 0; i < nBoats.getChildNodes().getLength(); i++) {
Node boat = nBoats.getChildNodes().item(i); Node boat = nBoats.getChildNodes().item(i);
if (boat.getNodeName().equals("Boat")) { if (boat.getNodeName().equals("Boat") && boat.getAttributes().getNamedItem("Type").getTextContent().equals("Yacht")) {
readSingleBoat(boat); readSingleBoat(boat);
} }
} }

Loading…
Cancel
Save