diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index afcd3430..524b3d40 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -63,7 +63,8 @@ public class App extends Application { //Change the StreamReceiver in this else block to change the default data source. else{ //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 = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); } sr.start(); diff --git a/src/main/java/seng302/controllers/RaceViewController.java b/src/main/java/seng302/controllers/RaceViewController.java index 22c96f13..577f985f 100644 --- a/src/main/java/seng302/controllers/RaceViewController.java +++ b/src/main/java/seng302/controllers/RaceViewController.java @@ -1,5 +1,6 @@ package seng302.controllers; +import java.util.concurrent.ConcurrentLinkedQueue; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.collections.FXCollections; @@ -7,6 +8,10 @@ import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; +import javafx.scene.chart.LineChart; +import javafx.scene.chart.NumberAxis; +import javafx.scene.chart.XYChart; +import javafx.scene.chart.XYChart.Series; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ComboBox; @@ -36,6 +41,8 @@ import java.util.*; */ public class RaceViewController extends Thread implements ImportantAnnotationDelegate { + + public LineChart raceSparkLine; @FXML private VBox positionVbox; @FXML @@ -61,6 +68,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel private Race race; private Stage stage; + private int index = 0; + private ImportantAnnotationsState importantAnnotations; private Yacht selectedBoat; @@ -82,7 +91,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel initialiseAnnotationSlider(); initialiseBoatSelectionComboBox(); includedCanvasController.timer.start(); - + initializeSparkline(); selectAnnotationBtn.setOnAction(event -> { loadSelectAnnotationView(); }); @@ -173,6 +182,16 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel annotationSlider.setValue(2); } + private void initializeSparkline(){ + raceSparkLine.setTitle("Boat Positions"); + for (Yacht yacht: startingBoats){ + if (raceSparkLine.getData().contains(yacht.getSparklinePosition())) { + raceSparkLine.getData().remove(yacht.getSparklinePosition()); + } + raceSparkLine.getData().add(yacht.getSparklinePosition()); + System.out.println("Here"); + } + } /** * Initalises a timer which updates elements of the RaceView such as wind direction, boat diff --git a/src/main/java/seng302/models/Yacht.java b/src/main/java/seng302/models/Yacht.java index 23ba616a..2c2ff186 100644 --- a/src/main/java/seng302/models/Yacht.java +++ b/src/main/java/seng302/models/Yacht.java @@ -1,5 +1,9 @@ package seng302.models; +import java.util.concurrent.ConcurrentLinkedQueue; +import javafx.scene.chart.XYChart; +import javafx.scene.chart.XYChart.Data; +import javafx.scene.chart.XYChart.Series; import javafx.scene.paint.Color; import java.text.DateFormat; @@ -16,6 +20,9 @@ public class Yacht { private Color colour; private double velocity; + private int index; + private ConcurrentLinkedQueue dataQ1; + private String boatType; private Integer sourceID; private String hullID; //matches HullNum in the XML spec. @@ -33,6 +40,9 @@ public class Yacht { // Mark rounding private Long markRoundingTime; + // Used for sparkline + private XYChart.Series sparklinePosition; + /** * Used in EventTest and RaceTest. * @@ -54,6 +64,11 @@ public class Yacht { this.velocity = boatVelocity; this.shortName = shortName; this.sourceID = id; + this.sparklinePosition = new XYChart.Series<>(); + this.sparklinePosition.setName(boatName); + index = 0; + dataQ1 = new ConcurrentLinkedQueue<>(); + } public Yacht(String boatType, Integer sourceID, String hullID, String shortName, String boatName, String country) { @@ -63,6 +78,10 @@ public class Yacht { this.shortName = shortName; this.boatName = boatName; this.country = country; + this.sparklinePosition = new XYChart.Series<>(); + this.sparklinePosition.setName(boatName); + index = 0; + dataQ1 = new ConcurrentLinkedQueue<>(); } public String getBoatType() { @@ -140,6 +159,15 @@ public class Yacht { } public void setPosition(String position) { + try { + if (Integer.parseInt(position) != Integer.parseInt(this.position)){ + dataQ1.add(Integer.parseInt(position)); + sparklinePosition.getData().add(new XYChart.Data<>(index++, dataQ1.remove())); + System.out.println("new position found for " + boatName + " in position " + position + " old(" + this.position + ")"); + } + } catch (NumberFormatException e) { + System.out.println("No position found"); + } this.position = position; } @@ -167,6 +195,10 @@ public class Yacht { this.markRoundingTime = markRoundingTime; } + public Series getSparklinePosition() { + return sparklinePosition; + } + @Override public String toString() { return boatName; diff --git a/src/main/resources/views/RaceView.fxml b/src/main/resources/views/RaceView.fxml index 49c9d188..3260cec2 100644 --- a/src/main/resources/views/RaceView.fxml +++ b/src/main/resources/views/RaceView.fxml @@ -62,7 +62,12 @@