Fixed date time parsing problem
#story[778]
This commit is contained in:
@@ -17,7 +17,9 @@ import javax.xml.transform.TransformerFactory;
|
|||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by esa46 on 21/04/17.
|
* Created by esa46 on 21/04/17.
|
||||||
@@ -27,11 +29,11 @@ public class RaceData {
|
|||||||
private RaceDataSource dataSource;
|
private RaceDataSource dataSource;
|
||||||
private Document doc;
|
private Document doc;
|
||||||
private Element rootElement;
|
private Element rootElement;
|
||||||
private OffsetDateTime creationTimeDate;
|
private ZonedDateTime creationTimeDate;
|
||||||
|
|
||||||
public RaceData(RaceDataSource dataSource) {
|
public RaceData(RaceDataSource dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
creationTimeDate = OffsetDateTime.now();
|
creationTimeDate = ZonedDateTime.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,7 +111,9 @@ public class RaceData {
|
|||||||
*/
|
*/
|
||||||
private void appendCreationTimeDate() {
|
private void appendCreationTimeDate() {
|
||||||
Element creationTimeElement = doc.createElement("CreationTimeDate");
|
Element creationTimeElement = doc.createElement("CreationTimeDate");
|
||||||
creationTimeElement.appendChild(doc.createTextNode(creationTimeDate.toString()));
|
|
||||||
|
|
||||||
|
creationTimeElement.appendChild(doc.createTextNode(toTruncatedString(creationTimeDate)));
|
||||||
rootElement.appendChild(creationTimeElement);
|
rootElement.appendChild(creationTimeElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +122,7 @@ public class RaceData {
|
|||||||
*/
|
*/
|
||||||
private void appendRaceStartTime() {
|
private void appendRaceStartTime() {
|
||||||
Element startTimeElement = doc.createElement("RaceStartTime");
|
Element startTimeElement = doc.createElement("RaceStartTime");
|
||||||
startTimeElement.setAttribute("Time", (creationTimeDate.plusMinutes(3)).toString());
|
startTimeElement.setAttribute("Time", (toTruncatedString(creationTimeDate.plusMinutes(0))));
|
||||||
startTimeElement.setAttribute("Postpone", "false");
|
startTimeElement.setAttribute("Postpone", "false");
|
||||||
rootElement.appendChild(startTimeElement);
|
rootElement.appendChild(startTimeElement);
|
||||||
}
|
}
|
||||||
@@ -179,7 +183,6 @@ public class RaceData {
|
|||||||
*/
|
*/
|
||||||
private Element createCompoundMarker(Marker marker, int i) {
|
private Element createCompoundMarker(Marker marker, int i) {
|
||||||
Element compoundMarkElement = doc.createElement("CompoundMark");
|
Element compoundMarkElement = doc.createElement("CompoundMark");
|
||||||
System.out.println("CompoundMark, " + i);
|
|
||||||
compoundMarkElement.setAttribute("CompoundMarkID", i + "");
|
compoundMarkElement.setAttribute("CompoundMarkID", i + "");
|
||||||
compoundMarkElement.setAttribute("Name", marker.getName());
|
compoundMarkElement.setAttribute("Name", marker.getName());
|
||||||
|
|
||||||
@@ -227,5 +230,15 @@ public class RaceData {
|
|||||||
rootElement.appendChild(courseLimitElement);
|
rootElement.appendChild(courseLimitElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String toTruncatedString(ZonedDateTime time) {
|
||||||
|
|
||||||
|
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||||
|
dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||||
|
String text = dateFormat.format(time);
|
||||||
|
System.out.println(text);
|
||||||
|
return text;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ public class MockOutput implements Runnable
|
|||||||
|
|
||||||
public MockOutput() throws IOException {
|
public MockOutput() throws IOException {
|
||||||
lastHeartbeatTime = System.currentTimeMillis();
|
lastHeartbeatTime = System.currentTimeMillis();
|
||||||
serverSocket = new ServerSocket(4943);
|
serverSocket = new ServerSocket(4942);
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* calculates the time since last heartbeat
|
* calculates the time since last heartbeat
|
||||||
@@ -132,6 +133,7 @@ public class MockOutput implements Runnable
|
|||||||
try {
|
try {
|
||||||
while (true){
|
while (true){
|
||||||
mockSocket = serverSocket.accept();
|
mockSocket = serverSocket.accept();
|
||||||
|
|
||||||
outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
|
||||||
|
|
||||||
/*******************************Test********************************/
|
/*******************************Test********************************/
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class Event {
|
|||||||
System.out.println("Sending Boat");
|
System.out.println("Sending Boat");
|
||||||
sendBoatData();
|
sendBoatData();
|
||||||
|
|
||||||
Race newRace = new Race(raceDataSource, 15, mockOutput);
|
Race newRace = new Race(raceDataSource, 3, mockOutput);
|
||||||
new Thread((newRace)).start();
|
new Thread((newRace)).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,8 @@ public class StartController extends Controller implements Observer {
|
|||||||
raceData = new StreamedCourse();
|
raceData = new StreamedCourse();
|
||||||
raceData.addObserver(this);
|
raceData.addObserver(this);
|
||||||
// visualiserInput = new VisualiserInput(new Socket("livedata.americascup.com", 4941), raceData);
|
// visualiserInput = new VisualiserInput(new Socket("livedata.americascup.com", 4941), raceData);
|
||||||
visualiserInput = new VisualiserInput(new Socket(InetAddress.getLocalHost(), 4943), raceData);
|
// visualiserInput = new VisualiserInput(new Socket("132.181.15.116", 8085), raceData);
|
||||||
|
visualiserInput = new VisualiserInput(new Socket(InetAddress.getLocalHost(), 4942), raceData);
|
||||||
new Thread(visualiserInput).start();
|
new Thread(visualiserInput).start();
|
||||||
// StreamedCourse streamedCourse = new StreamedCourse(new BoatXMLReader("mockXML/boatXML/boatTest.xml"));
|
// StreamedCourse streamedCourse = new StreamedCourse(new BoatXMLReader("mockXML/boatXML/boatTest.xml"));
|
||||||
// streamedCourse.setStreamedCourseXMLReader(new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml"));
|
// streamedCourse.setStreamedCourseXMLReader(new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml"));
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public class StreamedCourse extends Observable implements RaceDataSource {
|
|||||||
this.boatXMLReader = boatXMLReader;
|
this.boatXMLReader = boatXMLReader;
|
||||||
if (streamedCourseXMLReader != null && boatXMLReader != null) {
|
if (streamedCourseXMLReader != null && boatXMLReader != null) {
|
||||||
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
|
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
|
||||||
|
System.out.println("Participant size: " + streamedCourseXMLReader.getParticipants().size());
|
||||||
|
|
||||||
boatXMLReader.read();
|
boatXMLReader.read();
|
||||||
}
|
}
|
||||||
setChanged();
|
setChanged();
|
||||||
|
|||||||
@@ -87,10 +87,10 @@ public class StreamedCourseXMLReader extends XMLReader {
|
|||||||
|
|
||||||
raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID"));
|
raceID = Integer.parseInt(getTextValueOfNode(settings, "RaceID"));
|
||||||
raceType = getTextValueOfNode(settings, "RaceType");
|
raceType = getTextValueOfNode(settings, "RaceType");
|
||||||
//creationTimeDate = ZonedDateTime.parse(getTextValueOfNode(settings, "CreationTimeDate"), dateFormat);
|
|
||||||
|
|
||||||
// creationTimeDate = ZonedDateTime.now();
|
creationTimeDate = ZonedDateTime.parse(getTextValueOfNode(settings, "CreationTimeDate"), dateFormat);
|
||||||
// raceStartTime = ZonedDateTime.now();
|
// System.out.println(getTextValueOfNode(settings, "CreationTimeDate"));
|
||||||
|
|
||||||
if (raceTimeTag.getNamedItem("Time") != null) raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Time").getTextContent(), dateFormat);
|
if (raceTimeTag.getNamedItem("Time") != null) raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Time").getTextContent(), dateFormat);
|
||||||
else raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Start").getTextContent(), dateFormat);
|
else raceStartTime = ZonedDateTime.parse(raceTimeTag.getNamedItem("Start").getTextContent(), dateFormat);
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ public class StreamedRace extends Race {
|
|||||||
protected void checkPosition(Boat boat, long timeElapsed) {
|
protected void checkPosition(Boat boat, long timeElapsed) {
|
||||||
StreamedCourse raceData = visualiserInput.getCourse();
|
StreamedCourse raceData = visualiserInput.getCourse();
|
||||||
BoatStatusMessage boatStatusMessage = visualiserInput.getBoatStatus().get(boat.getSourceID());
|
BoatStatusMessage boatStatusMessage = visualiserInput.getBoatStatus().get(boat.getSourceID());
|
||||||
|
if (boatStatusMessage != null) {
|
||||||
BoatStatus boatStatus = BoatStatus.valueOf(boatStatusMessage.getBoatStatus());
|
BoatStatus boatStatus = BoatStatus.valueOf(boatStatusMessage.getBoatStatus());
|
||||||
|
|
||||||
int legNumber = boatStatusMessage.getLegNumber();
|
int legNumber = boatStatusMessage.getLegNumber();
|
||||||
|
|
||||||
if (boatStatus == BoatStatus.DNF) {
|
if (boatStatus == BoatStatus.DNF) {
|
||||||
@@ -70,6 +72,7 @@ public class StreamedRace extends Race {
|
|||||||
boat.setTimeFinished(timeElapsed);
|
boat.setTimeFinished(timeElapsed);
|
||||||
boat.setFinished(true);
|
boat.setFinished(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//Update the boat display table in the GUI to reflect the leg change
|
//Update the boat display table in the GUI to reflect the leg change
|
||||||
updatePositions();
|
updatePositions();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
|
||||||
import javafx.animation.AnimationTimer;
|
import javafx.animation.AnimationTimer;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
|
|||||||
@@ -214,6 +214,7 @@ public class VisualiserInput implements Runnable
|
|||||||
} else if (xml.getXmlMsgSubType() == xml.XMLTypeBoat){
|
} else if (xml.getXmlMsgSubType() == xml.XMLTypeBoat){
|
||||||
System.out.println("Setting Boats");
|
System.out.println("Setting Boats");
|
||||||
course.setBoatXMLReader(new BoatXMLReader(xml.getXmlMessage()));
|
course.setBoatXMLReader(new BoatXMLReader(xml.getXmlMessage()));
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -287,7 +288,8 @@ public class VisualiserInput implements Runnable
|
|||||||
|
|
||||||
public static void main(String argv[]) throws Exception
|
public static void main(String argv[]) throws Exception
|
||||||
{
|
{
|
||||||
Socket socket = new Socket(InetAddress.getLocalHost(), 4943);
|
Socket socket = new Socket("livedata.americascup.com", 4941);
|
||||||
|
// Socket socket = new Socket(InetAddress.getLocalHost(), 4942);
|
||||||
VisualiserInput receiver = new VisualiserInput(socket, new StreamedCourse());
|
VisualiserInput receiver = new VisualiserInput(socket, new StreamedCourse());
|
||||||
receiver.run();
|
receiver.run();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user