diff --git a/visualiser/.idea/uiDesigner.xml b/visualiser/.idea/uiDesigner.xml
new file mode 100644
index 00000000..e96534fb
--- /dev/null
+++ b/visualiser/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/visualiser/.idea/workspace.xml b/visualiser/.idea/workspace.xml
index a973e7f6..58b5f16d 100644
--- a/visualiser/.idea/workspace.xml
+++ b/visualiser/.idea/workspace.xml
@@ -13,127 +13,153 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -148,6 +174,11 @@
+
+
+ legs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -393,6 +488,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -413,7 +538,7 @@
-
+
@@ -440,6 +565,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -813,12 +964,14 @@
-
+
+
-
-
+
+
+
@@ -832,17 +985,44 @@
1492733921956
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -857,7 +1037,7 @@
-
+
@@ -865,6 +1045,7 @@
+
@@ -875,7 +1056,6 @@
-
@@ -910,198 +1090,271 @@
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java
index 0f76a4da..221138e7 100644
--- a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java
+++ b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java
@@ -4,22 +4,20 @@ import seng302.GPSCoordinate;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.RaceDataSource;
-import seng302.XMLReader;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
+import java.util.Date;
import java.util.List;
/**
* Created by jjg64 on 21/04/17.
*/
public class StreamedCourse implements RaceDataSource {
- XMLReader xmlReader;
+ StreamedCourseXMLReader streamedCourseXMLReader;
List boundary = new ArrayList<>();
- public StreamedCourse(XMLReader xmlReader) {
- this.xmlReader = xmlReader;
+ public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) {
+ this.streamedCourseXMLReader = streamedCourseXMLReader;
}
public List getBoats() {
@@ -47,4 +45,5 @@ public class StreamedCourse implements RaceDataSource {
}
+
}
diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java
new file mode 100644
index 00000000..46af3ef2
--- /dev/null
+++ b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java
@@ -0,0 +1,149 @@
+package seng302.Mock;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+import seng302.GPSCoordinate;
+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 boundary = 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 {
+ 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 {
+ super(filePath);
+ if (read) {
+ read();
+ }
+ }
+
+ private void read() throws ParseException {
+ 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() {
+ //TODO Modify BoatInRace to take in a sourceID
+ //TODO Produce list of BoatInRace
+ }
+
+ private void readCourse() {
+ readCompoundMarks();
+ readCompoundMarkSequence();
+ readCourseLimit();
+ }
+
+ private void readCompoundMarks() {
+ // TODO Produce map of sequence id to compound mark nodes (in xml)
+ // TODO Populate list of markers
+ }
+
+ private void readCompoundMarkSequence() {
+ // TODO Produce list of legs according to mark sequence ids
+ }
+
+ 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 getBoundary() {
+ return boundary;
+ }
+
+ public GPSCoordinate getMapTopLeft() {
+ return mapTopLeft;
+ }
+
+ public GPSCoordinate getMapBottomRight() {
+ return mapBottomRight;
+ }
+
+ 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;
+ }
+}
diff --git a/visualiser/src/main/java/seng302/Model/Marker.java b/visualiser/src/main/java/seng302/Model/Marker.java
index 2b7cafbe..118219f1 100644
--- a/visualiser/src/main/java/seng302/Model/Marker.java
+++ b/visualiser/src/main/java/seng302/Model/Marker.java
@@ -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;
diff --git a/visualiser/src/main/java/seng302/Model/RaceClock.java b/visualiser/src/main/java/seng302/Model/RaceClock.java
index 6ea62bd3..d9815cde 100644
--- a/visualiser/src/main/java/seng302/Model/RaceClock.java
+++ b/visualiser/src/main/java/seng302/Model/RaceClock.java
@@ -20,7 +20,7 @@ public class RaceClock {
private String timeZone;
private ZoneId zoneId;
- public RaceClock(GPSCoordinate gpsCoordinate){
+ public RaceClock(GPSCoordinate gpsCoordinate) {
TimeZoneLookup timeZoneLookup = new TimeZoneLookup();
TimeZoneResult timeZoneResult = timeZoneLookup.getTimeZone(gpsCoordinate.getLatitude(), gpsCoordinate.getLongitude());
zoneId = ZoneId.of(timeZoneResult.getResult());
@@ -33,7 +33,7 @@ public class RaceClock {
timeZone = timeZoneFormatter.format(zonedDateTime);
}
- public void updateTime(){
+ public void updateTime() {
LocalDateTime localDateTime = LocalDateTime.now(zoneId);
ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
time.setValue(dateTimeFormatter.format(zonedDateTime));
diff --git a/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java b/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java
index 821e476b..efc54a09 100644
--- a/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java
+++ b/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java
@@ -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);
}
}
diff --git a/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java b/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java
index dca6d1db..772c606e 100644
--- a/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java
+++ b/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java
@@ -1,8 +1,63 @@
package seng302.Mock;
+import org.junit.Before;
+import org.junit.Test;
+import seng302.GPSCoordinate;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
/**
- * Created by jjg64 on 21/04/17.
+ * Tests only work on the current version of mockXML/raceXML/raceTest.xml
*/
public class StreamedRaceTest {
+ StreamedCourseXMLReader streamedCourseXMLReader;
+ List 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");
+ }
+ }
+
+ @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() {
+ }
}