Worked on XML reader to read a given race.xml in the format for the AC35. Added the ability to read the course limit and race settings #Pair[jjg64, cbt24] #Story[782]
This commit is contained in:
@@ -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<GPSCoordinate> boundary = new ArrayList<>();
|
||||
|
||||
public StreamedCourse(XMLReader xmlReader) {
|
||||
this.xmlReader = xmlReader;
|
||||
public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) {
|
||||
this.streamedCourseXMLReader = streamedCourseXMLReader;
|
||||
}
|
||||
|
||||
public List<BoatInRace> getBoats() {
|
||||
@@ -47,4 +45,5 @@ public class StreamedCourse implements RaceDataSource {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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<GPSCoordinate> 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<GPSCoordinate> 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user