all marks displaying except currently gate marks are displaying as a single dot

#story[923] #pair[ajm412, ptg19]
This commit is contained in:
Alistair McIntyre
2017-05-18 18:02:25 +12:00
parent 08057edb28
commit 5d6b356602
6 changed files with 83 additions and 39 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ public class App extends Application {
//Change the StreamReceiver in this else block to change the default data source. //Change the StreamReceiver in this else block to change the default data source.
else{ else{
// sr = new StreamReceiver("localhost", 4949, "RaceStream"); // sr = new StreamReceiver("localhost", 4949, "RaceStream");
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
} }
sr.start(); sr.start();
@@ -1,6 +1,11 @@
package seng302.controllers; package seng302.controllers;
import javafx.animation.*; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.PriorityBlockingQueue;
import javafx.animation.AnimationTimer;
import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleDoubleProperty;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
@@ -10,15 +15,18 @@ import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import seng302.models.*; import seng302.models.BoatGroup;
import seng302.models.mark.*; import seng302.models.Colors;
import seng302.models.Yacht;
import seng302.models.mark.GateMark;
import seng302.models.mark.Mark;
import seng302.models.mark.MarkGroup;
import seng302.models.mark.MarkType;
import seng302.models.mark.SingleMark;
import seng302.models.stream.StreamParser; import seng302.models.stream.StreamParser;
import seng302.models.stream.packets.BoatPositionPacket;
import seng302.models.stream.XMLParser; import seng302.models.stream.XMLParser;
import seng302.models.stream.XMLParser.RaceXMLObject.Limit; import seng302.models.stream.XMLParser.RaceXMLObject.Limit;
import seng302.models.mark.Mark; import seng302.models.stream.packets.BoatPositionPacket;
import java.util.*;
import java.util.concurrent.PriorityBlockingQueue;
/** /**
* Created by ptg19 on 15/03/17. * Created by ptg19 on 15/03/17.
@@ -96,6 +104,7 @@ public class CanvasController {
// TODO: 1/05/17 wmu16 - Change this call to now draw the marks as from the xml // TODO: 1/05/17 wmu16 - Change this call to now draw the marks as from the xml
initializeBoats(); initializeBoats();
initializeMarks();
timer = new AnimationTimer() { timer = new AnimationTimer() {
@Override @Override
@@ -179,8 +188,8 @@ public class CanvasController {
boatGroup.move(); boatGroup.move();
} }
for (MarkGroup markGroup : markGroups) { for (MarkGroup markGroup : markGroups) {
for (int id : markGroup.getRaceIds()) { for (long id : markGroup.getRaceIds()) {
if (StreamParser.boatPositions.containsKey(id)) { if (StreamParser.markPositions.containsKey(id)) {
UpdateMarkGroup(id, markGroup); UpdateMarkGroup(id, markGroup);
} }
} }
@@ -214,8 +223,8 @@ public class CanvasController {
} }
} }
void UpdateMarkGroup (int raceId, MarkGroup markGroup) { void UpdateMarkGroup (long raceId, MarkGroup markGroup) {
PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.boatPositions.get(raceId); PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.markPositions.get(raceId);
if (movementQueue.size() > 0){ if (movementQueue.size() > 0){
try { try {
BoatPositionPacket positionPacket = movementQueue.take(); BoatPositionPacket positionPacket = movementQueue.take();
@@ -244,6 +253,26 @@ public class CanvasController {
group.getChildren().addAll(boatGroups); group.getChildren().addAll(boatGroups);
} }
private void initializeMarks() {
Map<Integer, Mark> allMarks = StreamParser.getXmlObject().getRaceXML().getCompoundMarks();
for (Mark mark : allMarks.values()) {
if (mark.getMarkType() == MarkType.SINGLE_MARK) {
SingleMark sMark = (SingleMark) mark;
MarkGroup markGroup = new MarkGroup(mark, findScaledXY(sMark));
markGroups.add(markGroup);
} else {
GateMark gMark = (GateMark) mark;
MarkGroup markGroup = new MarkGroup(mark, findScaledXY(gMark.getSingleMark1()),
findScaledXY(gMark.getSingleMark2())); //should be 2 objects in the list.
markGroups.add(markGroup);
}
}
group.getChildren().addAll(markGroups);
}
class ResizableCanvas extends Canvas { class ResizableCanvas extends Canvas {
ResizableCanvas() { ResizableCanvas() {
+2 -2
View File
@@ -10,7 +10,7 @@ public abstract class Mark {
private MarkType markType; private MarkType markType;
private double latitude; private double latitude;
private double longitude; private double longitude;
private int id; private long id;
/** /**
* Create a mark instance by passing its name and type * Create a mark instance by passing its name and type
@@ -125,7 +125,7 @@ public abstract class Mark {
return longitude; return longitude;
} }
public int getId() { public long getId() {
return id; return id;
} }
@@ -1,14 +1,12 @@
package seng302.models.mark; package seng302.models.mark;
import java.util.ArrayList;
import java.util.List;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.scene.shape.Line; import javafx.scene.shape.Line;
import javafx.scene.transform.Rotate;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by CJIRWIN on 26/04/2017. * Created by CJIRWIN on 26/04/2017.
@@ -72,7 +70,7 @@ public class MarkGroup extends Group {
} }
} }
public void moveMarkTo (double x, double y, int raceId) public void moveMarkTo (double x, double y, long raceId)
{ {
if (mainMark.getMarkType() == MarkType.SINGLE_MARK) { if (mainMark.getMarkType() == MarkType.SINGLE_MARK) {
Circle markCircle = (Circle) super.getChildren().get(0); Circle markCircle = (Circle) super.getChildren().get(0);
@@ -104,8 +102,8 @@ public class MarkGroup extends Group {
return false; return false;
} }
public int[] getRaceIds () { public long[] getRaceIds () {
int[] idArray = new int[marks.size()]; long[] idArray = new long[marks.size()];
int i = 0; int i = 0;
for (Mark mark : marks) for (Mark mark : marks)
idArray[i++] = mark.getId(); idArray[i++] = mark.getId();
@@ -1,6 +1,23 @@
package seng302.models.stream; package seng302.models.stream;
import java.io.IOException;
import java.io.StringReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.PriorityBlockingQueue;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@@ -8,19 +25,6 @@ import seng302.models.Yacht;
import seng302.models.stream.packets.BoatPositionPacket; import seng302.models.stream.packets.BoatPositionPacket;
import seng302.models.stream.packets.StreamPacket; import seng302.models.stream.packets.StreamPacket;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.StringReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.PriorityBlockingQueue;
import seng302.models.stream.XMLParser;
/** /**
* The purpose of this class is to take in the stream of divided packets so they can be read * The purpose of this class is to take in the stream of divided packets so they can be read
* and parsed in by turning the byte arrays into useful data. There are two public static hashmaps * and parsed in by turning the byte arrays into useful data. There are two public static hashmaps
@@ -29,6 +33,7 @@ import seng302.models.stream.XMLParser;
*/ */
public class StreamParser extends Thread{ public class StreamParser extends Thread{
public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> markPositions = new ConcurrentHashMap<>();
public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> boatPositions = new ConcurrentHashMap<>(); public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> boatPositions = new ConcurrentHashMap<>();
private String threadName; private String threadName;
private Thread t; private Thread t;
@@ -400,6 +405,20 @@ public class StreamParser extends Thread{
})); }));
} }
boatPositions.get(boatId).put(boatPacket); boatPositions.get(boatId).put(boatPacket);
} else if (deviceType == 3){
BoatPositionPacket markPacket = new BoatPositionPacket(boatId, timeValid, lat, lon, heading, groundSpeed);
//add a new priority que to the boatPositions HashMap
if (!markPositions.containsKey(boatId)) {
markPositions.put(boatId,
new PriorityBlockingQueue<>(256, new Comparator<BoatPositionPacket>() {
@Override
public int compare(BoatPositionPacket p1, BoatPositionPacket p2) {
return (int) (p1.getTimeValid() - p2.getTimeValid());
}
}));
}
markPositions.get(boatId).put(markPacket);
} }
} }
@@ -1,6 +1,9 @@
package seng302.models.stream; package seng302.models.stream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@@ -9,10 +12,6 @@ import seng302.models.Yacht;
import seng302.models.mark.GateMark; import seng302.models.mark.GateMark;
import seng302.models.mark.Mark; import seng302.models.mark.Mark;
import seng302.models.mark.MarkType; import seng302.models.mark.MarkType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import seng302.models.mark.SingleMark; import seng302.models.mark.SingleMark;
/** /**
@@ -349,7 +348,6 @@ public class XMLParser {
} }
} }
System.out.println(marksList.size());
if (marksList.size() == 1) { if (marksList.size() == 1) {
return marksList.get(0); return marksList.get(0);
} else if (marksList.size() == 2) { } else if (marksList.size() == 2) {