From 187acc6960b8f76372c2a35fa3d049502b97973b Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 10 May 2017 12:30:46 +1200 Subject: [PATCH 01/76] added an empty polarparser class to push a new branch #story[900] --- mock/src/main/java/seng302/DataInput/PolarParser.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 mock/src/main/java/seng302/DataInput/PolarParser.java diff --git a/mock/src/main/java/seng302/DataInput/PolarParser.java b/mock/src/main/java/seng302/DataInput/PolarParser.java new file mode 100644 index 00000000..e33612bb --- /dev/null +++ b/mock/src/main/java/seng302/DataInput/PolarParser.java @@ -0,0 +1,7 @@ +package seng302.DataInput; + +/** + * Created by hba56 on 10/05/17. + */ +public class PolarParser { +} From 5b010cad494051b777d0ac53fbe51a26daaa3865 Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 10 May 2017 13:45:09 +1200 Subject: [PATCH 02/76] added the polar class for storing polars #story[900] --- mock/src/main/java/seng302/Model/Polar.java | 330 ++++++++++++++++++ .../test/java/seng302/Model/PolarTest.java | 7 + 2 files changed, 337 insertions(+) create mode 100644 mock/src/main/java/seng302/Model/Polar.java create mode 100644 mock/src/test/java/seng302/Model/PolarTest.java diff --git a/mock/src/main/java/seng302/Model/Polar.java b/mock/src/main/java/seng302/Model/Polar.java new file mode 100644 index 00000000..805c1f78 --- /dev/null +++ b/mock/src/main/java/seng302/Model/Polar.java @@ -0,0 +1,330 @@ +package seng302.Model; + +import java.lang.reflect.Array; +import java.util.ArrayList; + +import static java.lang.Math.abs; +import static java.lang.Math.cos; + +/** + * Created by hba56 on 10/05/17. + */ +public class Polar { + private Integer trueWindSpeed; + + private Integer upTrueWindAngel; + private Integer upBoatSpeed; + + private Integer downTrueWindAngle; + private Integer downBoatSpeed; + + private Integer trueWindAngle0; + private Integer boatSpeed0; + private Integer trueWindAngle1; + private Integer boatSpeed1; + private Integer trueWindAngle2; + private Integer boatSpeed2; + private Integer trueWindAngle3; + private Integer boatSpeed3; + private Integer trueWindAngle4; + private Integer boatSpeed4; + private Integer trueWindAngle5; + private Integer boatSpeed5; + private Integer trueWindAngle6; + private Integer boatSpeed6; + private Integer trueWindAngle7; + private Integer boatSpeed7; + + private ArrayList trueWindAngles = new ArrayList(); + + /** + * constructor for a single boat polar + * @param trueWindSpeed the true wind angle to the boat + * @param upTrueWindAngel the true up wind angle + * @param upBoatSpeed the boat speed for up wind + * @param downTrueWindAngle the true down wind angle + * @param downBoatSpeed the boat speed for down wind + * @param trueWindAngle0 the true wind angle option 0 + * @param boatSpeed0 the boat speed for option 0 + * @param trueWindAngle1 the true wind angle option 0 + * @param boatSpeed1 the boat speed for option 0 + * @param trueWindAngle2 the true wind angle option 0 + * @param boatSpeed2 the boat speed for option 0 + * @param trueWindAngle3 the true wind angle option 0 + * @param boatSpeed3 the boat speed for option 0 + * @param trueWindAngle4 the true wind angle option 0 + * @param boatSpeed4 the boat speed for option 0 + * @param trueWindAngle5 the true wind angle option 0 + * @param boatSpeed5 the boat speed for option 0 + * @param trueWindAngle6 the true wind angle option 0 + * @param boatSpeed6 the boat speed for option 0 + * @param trueWindAngle7 the true wind angle option 0 + * @param boatSpeed7 the boat speed for option 0 + */ + public Polar(Integer trueWindSpeed, Integer upTrueWindAngel, Integer upBoatSpeed, Integer downTrueWindAngle, + Integer downBoatSpeed, Integer trueWindAngle0, Integer boatSpeed0, Integer trueWindAngle1, + Integer boatSpeed1, Integer trueWindAngle2, Integer boatSpeed2, Integer trueWindAngle3, + Integer boatSpeed3, Integer trueWindAngle4, Integer boatSpeed4, Integer trueWindAngle5, + Integer boatSpeed5, Integer trueWindAngle6, Integer boatSpeed6, Integer trueWindAngle7, + Integer boatSpeed7) { + this.trueWindSpeed = trueWindSpeed; + this.upTrueWindAngel = upTrueWindAngel; + this.upBoatSpeed = upBoatSpeed; + this.downTrueWindAngle = downTrueWindAngle; + this.downBoatSpeed = downBoatSpeed; + this.trueWindAngle0 = trueWindAngle0; + this.boatSpeed0 = boatSpeed0; + this.trueWindAngle1 = trueWindAngle1; + this.boatSpeed1 = boatSpeed1; + this.trueWindAngle2 = trueWindAngle2; + this.boatSpeed2 = boatSpeed2; + this.trueWindAngle3 = trueWindAngle3; + this.boatSpeed3 = boatSpeed3; + this.trueWindAngle4 = trueWindAngle4; + this.boatSpeed4 = boatSpeed4; + this.trueWindAngle5 = trueWindAngle5; + this.boatSpeed5 = boatSpeed5; + this.trueWindAngle6 = trueWindAngle6; + this.boatSpeed6 = boatSpeed6; + this.trueWindAngle7 = trueWindAngle7; + this.boatSpeed7 = boatSpeed7; + + double[] option0 = new double[2]; + option0[0] = trueWindAngle0; + option0[1] = boatSpeed0; + + double[] option1 = new double[2]; + option1[0] = trueWindAngle1; + option1[1] = boatSpeed1; + + double[] option2 = new double[2]; + option2[0] = trueWindAngle2; + option2[1] = boatSpeed2; + + double[] option3 = new double[2]; + option3[0] = trueWindAngle3; + option3[1] = boatSpeed3; + + double[] option4 = new double[2]; + option4[0] = trueWindAngle4; + option4[1] = boatSpeed4; + + double[] option5 = new double[2]; + option5[0] = trueWindAngle5; + option5[1] = boatSpeed5; + + double[] option6 = new double[2]; + option6[0] = trueWindAngle6; + option6[1] = boatSpeed6; + + double[] option7 = new double[2]; + option7[0] = trueWindAngle7; + option7[1] = boatSpeed7; + + + this.trueWindAngles.add(option0); + this.trueWindAngles.add(option1); + this.trueWindAngles.add(option2); + this.trueWindAngles.add(option3); + this.trueWindAngles.add(option4); + this.trueWindAngles.add(option5); + this.trueWindAngles.add(option6); + this.trueWindAngles.add(option7); + } + + /** + * + * @param angleToDestination + * @param angleOfWind + * @return + */ + public double getBestHeading(double angleToDestination, double angleOfWind){ + double vmg = 0; + double vmgTemp = 0; + + double[] bestOption = null; + + for(double[] option: this.trueWindAngles) { + double angle = option[0] - angleToDestination; + vmgTemp = cos(angle)*option[1]; + + if(bestOption == null){ + vmg = vmgTemp; + bestOption = option; + }else if (vmgTemp > vmg){ + vmg = vmgTemp; + bestOption = option; + } + } + + return bestOption[0]; + } + + public Integer getTrueWindSpeed() { + return trueWindSpeed; + } + + public void setTrueWindSpeed(Integer trueWindSpeed) { + this.trueWindSpeed = trueWindSpeed; + } + + public Integer getUpTrueWindAngel() { + return upTrueWindAngel; + } + + public void setUpTrueWindAngel(Integer upTrueWindAngel) { + this.upTrueWindAngel = upTrueWindAngel; + } + + public Integer getUpBoatSpeed() { + return upBoatSpeed; + } + + public void setUpBoatSpeed(Integer upBoatSpeed) { + this.upBoatSpeed = upBoatSpeed; + } + + public Integer getDownTrueWindAngle() { + return downTrueWindAngle; + } + + public void setDownTrueWindAngle(Integer downTrueWindAngle) { + this.downTrueWindAngle = downTrueWindAngle; + } + + public Integer getDownBoatSpeed() { + return downBoatSpeed; + } + + public void setDownBoatSpeed(Integer downBoatSpeed) { + this.downBoatSpeed = downBoatSpeed; + } + + public Integer getTrueWindAngle0() { + return trueWindAngle0; + } + + public void setTrueWindAngle0(Integer trueWindAngle0) { + this.trueWindAngle0 = trueWindAngle0; + } + + public Integer getBoatSpeed0() { + return boatSpeed0; + } + + public void setBoatSpeed0(Integer boatSpeed0) { + this.boatSpeed0 = boatSpeed0; + } + + public Integer getTrueWindAngle1() { + return trueWindAngle1; + } + + public void setTrueWindAngle1(Integer trueWindAngle1) { + this.trueWindAngle1 = trueWindAngle1; + } + + public Integer getBoatSpeed1() { + return boatSpeed1; + } + + public void setBoatSpeed1(Integer boatSpeed1) { + this.boatSpeed1 = boatSpeed1; + } + + public Integer getTrueWindAngle2() { + return trueWindAngle2; + } + + public void setTrueWindAngle2(Integer trueWindAngle2) { + this.trueWindAngle2 = trueWindAngle2; + } + + public Integer getBoatSpeed2() { + return boatSpeed2; + } + + public void setBoatSpeed2(Integer boatSpeed2) { + this.boatSpeed2 = boatSpeed2; + } + + public Integer getTrueWindAngle3() { + return trueWindAngle3; + } + + public void setTrueWindAngle3(Integer trueWindAngle3) { + this.trueWindAngle3 = trueWindAngle3; + } + + public Integer getBoatSpeed3() { + return boatSpeed3; + } + + public void setBoatSpeed3(Integer boatSpeed3) { + this.boatSpeed3 = boatSpeed3; + } + + public Integer getTrueWindAngle4() { + return trueWindAngle4; + } + + public void setTrueWindAngle4(Integer trueWindAngle4) { + this.trueWindAngle4 = trueWindAngle4; + } + + public Integer getBoatSpeed4() { + return boatSpeed4; + } + + public void setBoatSpeed4(Integer boatSpeed4) { + this.boatSpeed4 = boatSpeed4; + } + + public Integer getTrueWindAngle5() { + return trueWindAngle5; + } + + public void setTrueWindAngle5(Integer trueWindAngle5) { + this.trueWindAngle5 = trueWindAngle5; + } + + public Integer getBoatSpeed5() { + return boatSpeed5; + } + + public void setBoatSpeed5(Integer boatSpeed5) { + this.boatSpeed5 = boatSpeed5; + } + + public Integer getTrueWindAngle6() { + return trueWindAngle6; + } + + public void setTrueWindAngle6(Integer trueWindAngle6) { + this.trueWindAngle6 = trueWindAngle6; + } + + public Integer getBoatSpeed6() { + return boatSpeed6; + } + + public void setBoatSpeed6(Integer boatSpeed6) { + this.boatSpeed6 = boatSpeed6; + } + + public Integer getTrueWindAngle7() { + return trueWindAngle7; + } + + public void setTrueWindAngle7(Integer trueWindAngle7) { + this.trueWindAngle7 = trueWindAngle7; + } + + public Integer getBoatSpeed7() { + return boatSpeed7; + } + + public void setBoatSpeed7(Integer boatSpeed7) { + this.boatSpeed7 = boatSpeed7; + } +} diff --git a/mock/src/test/java/seng302/Model/PolarTest.java b/mock/src/test/java/seng302/Model/PolarTest.java new file mode 100644 index 00000000..c76d0bfb --- /dev/null +++ b/mock/src/test/java/seng302/Model/PolarTest.java @@ -0,0 +1,7 @@ +package seng302.Model; + +/** + * Created by hba56 on 10/05/17. + */ +public class PolarTest { +} From d7294f73a1dee74884d09cf8cc2cc612cd573942 Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 10 May 2017 14:23:26 +1200 Subject: [PATCH 03/76] boats now have polars stored in the -added getter and setter for a boats polars #story[900] --- mock/src/main/java/seng302/Model/Boat.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mock/src/main/java/seng302/Model/Boat.java b/mock/src/main/java/seng302/Model/Boat.java index 5ff47bd9..08931c28 100644 --- a/mock/src/main/java/seng302/Model/Boat.java +++ b/mock/src/main/java/seng302/Model/Boat.java @@ -2,6 +2,8 @@ package seng302.Model; import org.geotools.referencing.GeodeticCalculator; +import java.util.ArrayList; + /** * Created by esa46 on 1/05/17. @@ -18,6 +20,7 @@ public class Boat { private long timeFinished = -1; private boolean started = false; private double heading; + private ArrayList polars; /** * Boat initialiser which keeps all of the information of the boat. @@ -153,4 +156,12 @@ public class Boat { public void setHeading(double heading) { this.heading = heading; } + + public ArrayList getPolars() { + return polars; + } + + public void setPolars(ArrayList polars) { + this.polars = polars; + } } From a4480f3ccffbf37d1742510c511995b51d86f7a9 Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 10 May 2017 14:25:06 +1200 Subject: [PATCH 04/76] removed the get best heading method as it was incorrect and not related to this story #story[900] --- mock/src/main/java/seng302/Model/Polar.java | 28 ------------------- .../test/java/seng302/Model/PolarTest.java | 7 ----- 2 files changed, 35 deletions(-) delete mode 100644 mock/src/test/java/seng302/Model/PolarTest.java diff --git a/mock/src/main/java/seng302/Model/Polar.java b/mock/src/main/java/seng302/Model/Polar.java index 805c1f78..ffa9f3cb 100644 --- a/mock/src/main/java/seng302/Model/Polar.java +++ b/mock/src/main/java/seng302/Model/Polar.java @@ -132,34 +132,6 @@ public class Polar { this.trueWindAngles.add(option7); } - /** - * - * @param angleToDestination - * @param angleOfWind - * @return - */ - public double getBestHeading(double angleToDestination, double angleOfWind){ - double vmg = 0; - double vmgTemp = 0; - - double[] bestOption = null; - - for(double[] option: this.trueWindAngles) { - double angle = option[0] - angleToDestination; - vmgTemp = cos(angle)*option[1]; - - if(bestOption == null){ - vmg = vmgTemp; - bestOption = option; - }else if (vmgTemp > vmg){ - vmg = vmgTemp; - bestOption = option; - } - } - - return bestOption[0]; - } - public Integer getTrueWindSpeed() { return trueWindSpeed; } diff --git a/mock/src/test/java/seng302/Model/PolarTest.java b/mock/src/test/java/seng302/Model/PolarTest.java deleted file mode 100644 index c76d0bfb..00000000 --- a/mock/src/test/java/seng302/Model/PolarTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package seng302.Model; - -/** - * Created by hba56 on 10/05/17. - */ -public class PolarTest { -} From 1f554648ef19fbe23ce66c9cf97d612a32277a96 Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 10 May 2017 14:41:05 +1200 Subject: [PATCH 05/76] changed all polar values to doubles and added a empty constructor #story[900] --- mock/src/main/java/seng302/Model/Polar.java | 140 ++++++++++---------- 1 file changed, 72 insertions(+), 68 deletions(-) diff --git a/mock/src/main/java/seng302/Model/Polar.java b/mock/src/main/java/seng302/Model/Polar.java index ffa9f3cb..ef6d0853 100644 --- a/mock/src/main/java/seng302/Model/Polar.java +++ b/mock/src/main/java/seng302/Model/Polar.java @@ -1,42 +1,46 @@ package seng302.Model; -import java.lang.reflect.Array; import java.util.ArrayList; import static java.lang.Math.abs; -import static java.lang.Math.cos; /** * Created by hba56 on 10/05/17. */ public class Polar { - private Integer trueWindSpeed; - - private Integer upTrueWindAngel; - private Integer upBoatSpeed; - - private Integer downTrueWindAngle; - private Integer downBoatSpeed; - - private Integer trueWindAngle0; - private Integer boatSpeed0; - private Integer trueWindAngle1; - private Integer boatSpeed1; - private Integer trueWindAngle2; - private Integer boatSpeed2; - private Integer trueWindAngle3; - private Integer boatSpeed3; - private Integer trueWindAngle4; - private Integer boatSpeed4; - private Integer trueWindAngle5; - private Integer boatSpeed5; - private Integer trueWindAngle6; - private Integer boatSpeed6; - private Integer trueWindAngle7; - private Integer boatSpeed7; + private double trueWindSpeed; + + private double upTrueWindAngel; + private double upBoatSpeed; + + private double downTrueWindAngle; + private double downBoatSpeed; + + private double trueWindAngle0; + private double boatSpeed0; + private double trueWindAngle1; + private double boatSpeed1; + private double trueWindAngle2; + private double boatSpeed2; + private double trueWindAngle3; + private double boatSpeed3; + private double trueWindAngle4; + private double boatSpeed4; + private double trueWindAngle5; + private double boatSpeed5; + private double trueWindAngle6; + private double boatSpeed6; + private double trueWindAngle7; + private double boatSpeed7; private ArrayList trueWindAngles = new ArrayList(); + /** + * basic constructor + */ + public Polar() { + } + /** * constructor for a single boat polar * @param trueWindSpeed the true wind angle to the boat @@ -132,171 +136,171 @@ public class Polar { this.trueWindAngles.add(option7); } - public Integer getTrueWindSpeed() { + public double getTrueWindSpeed() { return trueWindSpeed; } - public void setTrueWindSpeed(Integer trueWindSpeed) { + public void setTrueWindSpeed(double trueWindSpeed) { this.trueWindSpeed = trueWindSpeed; } - public Integer getUpTrueWindAngel() { + public double getUpTrueWindAngel() { return upTrueWindAngel; } - public void setUpTrueWindAngel(Integer upTrueWindAngel) { + public void setUpTrueWindAngel(double upTrueWindAngel) { this.upTrueWindAngel = upTrueWindAngel; } - public Integer getUpBoatSpeed() { + public double getUpBoatSpeed() { return upBoatSpeed; } - public void setUpBoatSpeed(Integer upBoatSpeed) { + public void setUpBoatSpeed(double upBoatSpeed) { this.upBoatSpeed = upBoatSpeed; } - public Integer getDownTrueWindAngle() { + public double getDownTrueWindAngle() { return downTrueWindAngle; } - public void setDownTrueWindAngle(Integer downTrueWindAngle) { + public void setDownTrueWindAngle(double downTrueWindAngle) { this.downTrueWindAngle = downTrueWindAngle; } - public Integer getDownBoatSpeed() { + public double getDownBoatSpeed() { return downBoatSpeed; } - public void setDownBoatSpeed(Integer downBoatSpeed) { + public void setDownBoatSpeed(double downBoatSpeed) { this.downBoatSpeed = downBoatSpeed; } - public Integer getTrueWindAngle0() { + public double getTrueWindAngle0() { return trueWindAngle0; } - public void setTrueWindAngle0(Integer trueWindAngle0) { + public void setTrueWindAngle0(double trueWindAngle0) { this.trueWindAngle0 = trueWindAngle0; } - public Integer getBoatSpeed0() { + public double getBoatSpeed0() { return boatSpeed0; } - public void setBoatSpeed0(Integer boatSpeed0) { + public void setBoatSpeed0(double boatSpeed0) { this.boatSpeed0 = boatSpeed0; } - public Integer getTrueWindAngle1() { + public double getTrueWindAngle1() { return trueWindAngle1; } - public void setTrueWindAngle1(Integer trueWindAngle1) { + public void setTrueWindAngle1(double trueWindAngle1) { this.trueWindAngle1 = trueWindAngle1; } - public Integer getBoatSpeed1() { + public double getBoatSpeed1() { return boatSpeed1; } - public void setBoatSpeed1(Integer boatSpeed1) { + public void setBoatSpeed1(double boatSpeed1) { this.boatSpeed1 = boatSpeed1; } - public Integer getTrueWindAngle2() { + public double getTrueWindAngle2() { return trueWindAngle2; } - public void setTrueWindAngle2(Integer trueWindAngle2) { + public void setTrueWindAngle2(double trueWindAngle2) { this.trueWindAngle2 = trueWindAngle2; } - public Integer getBoatSpeed2() { + public double getBoatSpeed2() { return boatSpeed2; } - public void setBoatSpeed2(Integer boatSpeed2) { + public void setBoatSpeed2(double boatSpeed2) { this.boatSpeed2 = boatSpeed2; } - public Integer getTrueWindAngle3() { + public double getTrueWindAngle3() { return trueWindAngle3; } - public void setTrueWindAngle3(Integer trueWindAngle3) { + public void setTrueWindAngle3(double trueWindAngle3) { this.trueWindAngle3 = trueWindAngle3; } - public Integer getBoatSpeed3() { + public double getBoatSpeed3() { return boatSpeed3; } - public void setBoatSpeed3(Integer boatSpeed3) { + public void setBoatSpeed3(double boatSpeed3) { this.boatSpeed3 = boatSpeed3; } - public Integer getTrueWindAngle4() { + public double getTrueWindAngle4() { return trueWindAngle4; } - public void setTrueWindAngle4(Integer trueWindAngle4) { + public void setTrueWindAngle4(double trueWindAngle4) { this.trueWindAngle4 = trueWindAngle4; } - public Integer getBoatSpeed4() { + public double getBoatSpeed4() { return boatSpeed4; } - public void setBoatSpeed4(Integer boatSpeed4) { + public void setBoatSpeed4(double boatSpeed4) { this.boatSpeed4 = boatSpeed4; } - public Integer getTrueWindAngle5() { + public double getTrueWindAngle5() { return trueWindAngle5; } - public void setTrueWindAngle5(Integer trueWindAngle5) { + public void setTrueWindAngle5(double trueWindAngle5) { this.trueWindAngle5 = trueWindAngle5; } - public Integer getBoatSpeed5() { + public double getBoatSpeed5() { return boatSpeed5; } - public void setBoatSpeed5(Integer boatSpeed5) { + public void setBoatSpeed5(double boatSpeed5) { this.boatSpeed5 = boatSpeed5; } - public Integer getTrueWindAngle6() { + public double getTrueWindAngle6() { return trueWindAngle6; } - public void setTrueWindAngle6(Integer trueWindAngle6) { + public void setTrueWindAngle6(double trueWindAngle6) { this.trueWindAngle6 = trueWindAngle6; } - public Integer getBoatSpeed6() { + public double getBoatSpeed6() { return boatSpeed6; } - public void setBoatSpeed6(Integer boatSpeed6) { + public void setBoatSpeed6(double boatSpeed6) { this.boatSpeed6 = boatSpeed6; } - public Integer getTrueWindAngle7() { + public double getTrueWindAngle7() { return trueWindAngle7; } - public void setTrueWindAngle7(Integer trueWindAngle7) { + public void setTrueWindAngle7(double trueWindAngle7) { this.trueWindAngle7 = trueWindAngle7; } - public Integer getBoatSpeed7() { + public double getBoatSpeed7() { return boatSpeed7; } - public void setBoatSpeed7(Integer boatSpeed7) { + public void setBoatSpeed7(double boatSpeed7) { this.boatSpeed7 = boatSpeed7; } } From f518c52c7b1dab909d5a40932beae990ab2896d9 Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 10 May 2017 15:10:03 +1200 Subject: [PATCH 06/76] changed the way we store polars -removed polar class -added in new hasmap polars class -updated boat class to the changes #story[900] --- mock/src/main/java/seng302/Model/Boat.java | 7 +- mock/src/main/java/seng302/Model/Polar.java | 306 ------------------- mock/src/main/java/seng302/Model/Polars.java | 25 ++ 3 files changed, 29 insertions(+), 309 deletions(-) delete mode 100644 mock/src/main/java/seng302/Model/Polar.java create mode 100644 mock/src/main/java/seng302/Model/Polars.java diff --git a/mock/src/main/java/seng302/Model/Boat.java b/mock/src/main/java/seng302/Model/Boat.java index 08931c28..052bcda3 100644 --- a/mock/src/main/java/seng302/Model/Boat.java +++ b/mock/src/main/java/seng302/Model/Boat.java @@ -20,7 +20,7 @@ public class Boat { private long timeFinished = -1; private boolean started = false; private double heading; - private ArrayList polars; + private Polars polars; /** * Boat initialiser which keeps all of the information of the boat. @@ -157,11 +157,12 @@ public class Boat { this.heading = heading; } - public ArrayList getPolars() { + + public Polars getPolars() { return polars; } - public void setPolars(ArrayList polars) { + public void setPolars(Polars polars) { this.polars = polars; } } diff --git a/mock/src/main/java/seng302/Model/Polar.java b/mock/src/main/java/seng302/Model/Polar.java deleted file mode 100644 index ef6d0853..00000000 --- a/mock/src/main/java/seng302/Model/Polar.java +++ /dev/null @@ -1,306 +0,0 @@ -package seng302.Model; - -import java.util.ArrayList; - -import static java.lang.Math.abs; - -/** - * Created by hba56 on 10/05/17. - */ -public class Polar { - private double trueWindSpeed; - - private double upTrueWindAngel; - private double upBoatSpeed; - - private double downTrueWindAngle; - private double downBoatSpeed; - - private double trueWindAngle0; - private double boatSpeed0; - private double trueWindAngle1; - private double boatSpeed1; - private double trueWindAngle2; - private double boatSpeed2; - private double trueWindAngle3; - private double boatSpeed3; - private double trueWindAngle4; - private double boatSpeed4; - private double trueWindAngle5; - private double boatSpeed5; - private double trueWindAngle6; - private double boatSpeed6; - private double trueWindAngle7; - private double boatSpeed7; - - private ArrayList trueWindAngles = new ArrayList(); - - /** - * basic constructor - */ - public Polar() { - } - - /** - * constructor for a single boat polar - * @param trueWindSpeed the true wind angle to the boat - * @param upTrueWindAngel the true up wind angle - * @param upBoatSpeed the boat speed for up wind - * @param downTrueWindAngle the true down wind angle - * @param downBoatSpeed the boat speed for down wind - * @param trueWindAngle0 the true wind angle option 0 - * @param boatSpeed0 the boat speed for option 0 - * @param trueWindAngle1 the true wind angle option 0 - * @param boatSpeed1 the boat speed for option 0 - * @param trueWindAngle2 the true wind angle option 0 - * @param boatSpeed2 the boat speed for option 0 - * @param trueWindAngle3 the true wind angle option 0 - * @param boatSpeed3 the boat speed for option 0 - * @param trueWindAngle4 the true wind angle option 0 - * @param boatSpeed4 the boat speed for option 0 - * @param trueWindAngle5 the true wind angle option 0 - * @param boatSpeed5 the boat speed for option 0 - * @param trueWindAngle6 the true wind angle option 0 - * @param boatSpeed6 the boat speed for option 0 - * @param trueWindAngle7 the true wind angle option 0 - * @param boatSpeed7 the boat speed for option 0 - */ - public Polar(Integer trueWindSpeed, Integer upTrueWindAngel, Integer upBoatSpeed, Integer downTrueWindAngle, - Integer downBoatSpeed, Integer trueWindAngle0, Integer boatSpeed0, Integer trueWindAngle1, - Integer boatSpeed1, Integer trueWindAngle2, Integer boatSpeed2, Integer trueWindAngle3, - Integer boatSpeed3, Integer trueWindAngle4, Integer boatSpeed4, Integer trueWindAngle5, - Integer boatSpeed5, Integer trueWindAngle6, Integer boatSpeed6, Integer trueWindAngle7, - Integer boatSpeed7) { - this.trueWindSpeed = trueWindSpeed; - this.upTrueWindAngel = upTrueWindAngel; - this.upBoatSpeed = upBoatSpeed; - this.downTrueWindAngle = downTrueWindAngle; - this.downBoatSpeed = downBoatSpeed; - this.trueWindAngle0 = trueWindAngle0; - this.boatSpeed0 = boatSpeed0; - this.trueWindAngle1 = trueWindAngle1; - this.boatSpeed1 = boatSpeed1; - this.trueWindAngle2 = trueWindAngle2; - this.boatSpeed2 = boatSpeed2; - this.trueWindAngle3 = trueWindAngle3; - this.boatSpeed3 = boatSpeed3; - this.trueWindAngle4 = trueWindAngle4; - this.boatSpeed4 = boatSpeed4; - this.trueWindAngle5 = trueWindAngle5; - this.boatSpeed5 = boatSpeed5; - this.trueWindAngle6 = trueWindAngle6; - this.boatSpeed6 = boatSpeed6; - this.trueWindAngle7 = trueWindAngle7; - this.boatSpeed7 = boatSpeed7; - - double[] option0 = new double[2]; - option0[0] = trueWindAngle0; - option0[1] = boatSpeed0; - - double[] option1 = new double[2]; - option1[0] = trueWindAngle1; - option1[1] = boatSpeed1; - - double[] option2 = new double[2]; - option2[0] = trueWindAngle2; - option2[1] = boatSpeed2; - - double[] option3 = new double[2]; - option3[0] = trueWindAngle3; - option3[1] = boatSpeed3; - - double[] option4 = new double[2]; - option4[0] = trueWindAngle4; - option4[1] = boatSpeed4; - - double[] option5 = new double[2]; - option5[0] = trueWindAngle5; - option5[1] = boatSpeed5; - - double[] option6 = new double[2]; - option6[0] = trueWindAngle6; - option6[1] = boatSpeed6; - - double[] option7 = new double[2]; - option7[0] = trueWindAngle7; - option7[1] = boatSpeed7; - - - this.trueWindAngles.add(option0); - this.trueWindAngles.add(option1); - this.trueWindAngles.add(option2); - this.trueWindAngles.add(option3); - this.trueWindAngles.add(option4); - this.trueWindAngles.add(option5); - this.trueWindAngles.add(option6); - this.trueWindAngles.add(option7); - } - - public double getTrueWindSpeed() { - return trueWindSpeed; - } - - public void setTrueWindSpeed(double trueWindSpeed) { - this.trueWindSpeed = trueWindSpeed; - } - - public double getUpTrueWindAngel() { - return upTrueWindAngel; - } - - public void setUpTrueWindAngel(double upTrueWindAngel) { - this.upTrueWindAngel = upTrueWindAngel; - } - - public double getUpBoatSpeed() { - return upBoatSpeed; - } - - public void setUpBoatSpeed(double upBoatSpeed) { - this.upBoatSpeed = upBoatSpeed; - } - - public double getDownTrueWindAngle() { - return downTrueWindAngle; - } - - public void setDownTrueWindAngle(double downTrueWindAngle) { - this.downTrueWindAngle = downTrueWindAngle; - } - - public double getDownBoatSpeed() { - return downBoatSpeed; - } - - public void setDownBoatSpeed(double downBoatSpeed) { - this.downBoatSpeed = downBoatSpeed; - } - - public double getTrueWindAngle0() { - return trueWindAngle0; - } - - public void setTrueWindAngle0(double trueWindAngle0) { - this.trueWindAngle0 = trueWindAngle0; - } - - public double getBoatSpeed0() { - return boatSpeed0; - } - - public void setBoatSpeed0(double boatSpeed0) { - this.boatSpeed0 = boatSpeed0; - } - - public double getTrueWindAngle1() { - return trueWindAngle1; - } - - public void setTrueWindAngle1(double trueWindAngle1) { - this.trueWindAngle1 = trueWindAngle1; - } - - public double getBoatSpeed1() { - return boatSpeed1; - } - - public void setBoatSpeed1(double boatSpeed1) { - this.boatSpeed1 = boatSpeed1; - } - - public double getTrueWindAngle2() { - return trueWindAngle2; - } - - public void setTrueWindAngle2(double trueWindAngle2) { - this.trueWindAngle2 = trueWindAngle2; - } - - public double getBoatSpeed2() { - return boatSpeed2; - } - - public void setBoatSpeed2(double boatSpeed2) { - this.boatSpeed2 = boatSpeed2; - } - - public double getTrueWindAngle3() { - return trueWindAngle3; - } - - public void setTrueWindAngle3(double trueWindAngle3) { - this.trueWindAngle3 = trueWindAngle3; - } - - public double getBoatSpeed3() { - return boatSpeed3; - } - - public void setBoatSpeed3(double boatSpeed3) { - this.boatSpeed3 = boatSpeed3; - } - - public double getTrueWindAngle4() { - return trueWindAngle4; - } - - public void setTrueWindAngle4(double trueWindAngle4) { - this.trueWindAngle4 = trueWindAngle4; - } - - public double getBoatSpeed4() { - return boatSpeed4; - } - - public void setBoatSpeed4(double boatSpeed4) { - this.boatSpeed4 = boatSpeed4; - } - - public double getTrueWindAngle5() { - return trueWindAngle5; - } - - public void setTrueWindAngle5(double trueWindAngle5) { - this.trueWindAngle5 = trueWindAngle5; - } - - public double getBoatSpeed5() { - return boatSpeed5; - } - - public void setBoatSpeed5(double boatSpeed5) { - this.boatSpeed5 = boatSpeed5; - } - - public double getTrueWindAngle6() { - return trueWindAngle6; - } - - public void setTrueWindAngle6(double trueWindAngle6) { - this.trueWindAngle6 = trueWindAngle6; - } - - public double getBoatSpeed6() { - return boatSpeed6; - } - - public void setBoatSpeed6(double boatSpeed6) { - this.boatSpeed6 = boatSpeed6; - } - - public double getTrueWindAngle7() { - return trueWindAngle7; - } - - public void setTrueWindAngle7(double trueWindAngle7) { - this.trueWindAngle7 = trueWindAngle7; - } - - public double getBoatSpeed7() { - return boatSpeed7; - } - - public void setBoatSpeed7(double boatSpeed7) { - this.boatSpeed7 = boatSpeed7; - } -} diff --git a/mock/src/main/java/seng302/Model/Polars.java b/mock/src/main/java/seng302/Model/Polars.java new file mode 100644 index 00000000..d4609d49 --- /dev/null +++ b/mock/src/main/java/seng302/Model/Polars.java @@ -0,0 +1,25 @@ +package seng302.Model; + +import javafx.util.Pair; + +import java.util.HashMap; + +/** + * Created by hba56 on 10/05/17. + */ +public class Polars { + private HashMap polarValues; + + public Polars() { + polarValues = new HashMap(); + } + + public void addEstimate(double trueWindSpeed, double trueWindAngle, double boatSpeed){ + Pair newKey = new Pair(trueWindSpeed, trueWindAngle); + polarValues.put(newKey, boatSpeed); + } + + public HashMap getPolarValues() { + return polarValues; + } +} From aeee8ca7487aa9c85f11d706a53568742f038a14 Mon Sep 17 00:00:00 2001 From: fjc40 Date: Wed, 10 May 2017 15:11:51 +1200 Subject: [PATCH 07/76] Added polar data file. Added PolarParse class - currently commented out as it depends on polar table class. #story[900] --- .../java/seng302/DataInput/PolarParser.java | 170 ++++++++++++++++++ .../Exceptions/InvalidPolarFileException.java | 28 +++ mock/src/main/resources/polars/acc_polars.csv | 8 + .../seng302/DataInput/PolarParserTest.java | 26 +++ 4 files changed, 232 insertions(+) create mode 100644 mock/src/main/java/seng302/Exceptions/InvalidPolarFileException.java create mode 100644 mock/src/main/resources/polars/acc_polars.csv create mode 100644 mock/src/test/java/seng302/DataInput/PolarParserTest.java diff --git a/mock/src/main/java/seng302/DataInput/PolarParser.java b/mock/src/main/java/seng302/DataInput/PolarParser.java index e33612bb..475125a9 100644 --- a/mock/src/main/java/seng302/DataInput/PolarParser.java +++ b/mock/src/main/java/seng302/DataInput/PolarParser.java @@ -3,5 +3,175 @@ package seng302.DataInput; /** * Created by hba56 on 10/05/17. */ + +import seng302.Exceptions.InvalidPolarFileException; +import seng302.Model.Polar; + +import java.io.*; +import java.util.ArrayList; + + +/** + * Responsible for parsing a polar data file, and creating a polar data object. + */ public class PolarParser { + + + /** + * Given a filename, this function parses it and generates a PolarTable object, which can be queried for polar information. + * @param filename + * @return + */ + /* + ///TEMP PolarTable = ArrayList + public static ArrayList parse(String filename) throws InvalidPolarFileException { + //Temporary table to return later. + ArrayList polarTable = new ArrayList(); + + + //Open the file for reading. + InputStream fileStream = PolarParser.class.getClassLoader().getResourceAsStream(filename); + if (fileStream == null) { + throw new InvalidPolarFileException("Could not open polar data file: " + filename); + } + //Wrap it with buffered input stream to set encoding and buffer. + InputStreamReader in = null; + try { + in = new InputStreamReader(fileStream, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new InvalidPolarFileException("Unsupported encoding: UTF-8", e); + } + BufferedReader inputStream = new BufferedReader(in); + + + //We expect the polar data file to have the column headings: + // Tws, Twa0, Bsp0, Twa1, Bsp1, UpTwa, UpBsp, Twa2, Bsp2, Twa3, Bsp3, Twa4, Bsp4, Twa5, Bsp5, Twa6, Bsp6, DnTwa, DnBsp, Twa7, Bsp7 + //and to have 7 rows of data. + //Angles are expected to be in degrees, and velocities in knots. + + + //We read the heading and data rows, and split them into arrays of elements. + String[] headings; + ArrayList dataRows = new ArrayList<>(7); + try { + //Heading. + //Read heading row. + String headingRow = inputStream.readLine(); + + //Split it into individual headings. + headings = headingRow.split(","); + + + //Data rows. + while (inputStream.ready()) { + //Read line. + String dataRow = inputStream.readLine(); + + //Split line. + String[] dataElements = dataRow.split(","); + + //Add to collection. + dataRows.add(dataElements); + + } + + } catch (IOException e) { + throw new InvalidPolarFileException("Could not read from polar data file: " + filename, e); + } + + //Finished reading in data, now we need to construct polar rows and table from it. + //For each row... + int rowNumber = 0; + for (String[] row : dataRows) { + //Create Polar row object. + Polar polarRow = new Polar(); + + //For each column... + for (int i = 0; i < row.length; i++) { + + //Convert value to a double. + Double value; + try { + value = Double.parseDouble(row[i]); + } + catch (NumberFormatException e) { + throw new InvalidPolarFileException("Could not convert (Row,Col): (" + rowNumber + "," + i +") = " + row[i] + "to a double.", e); + } + + //Set the values of the row. + //For reference: + //Tws, Twa0, Bsp0, Twa1, Bsp1, UpTwa, UpBsp, Twa2, Bsp2, Twa3, Bsp3, Twa4, Bsp4, Twa5, Bsp5, Twa6, Bsp6, DnTwa, DnBsp, Twa7, Bsp7 + if (headings[i] == "Tws") { + polarRow.setTrueWindSpeed(value); + } + else if (headings[i] == "Twa0") { + polarRow.setTrueWindAngle0(value); + } + else if (headings[i] == "Bsp0") { + polarRow.setBoatSpeed0(value); + } + else if (headings[i] == "Twa1") { + polarRow.setTrueWindAngle1(value); + } + else if (headings[i] == "Bsp1") { + polarRow.setBoatSpeed1(value); + } + else if (headings[i] == "UpTwa") { + polarRow.setUpTrueWindAngel(value); + } + else if (headings[i] == "UpBsp") { + polarRow.setUpBoatSpeed(value); + } + else if (headings[i] == "Twa2") { + polarRow.setTrueWindAngle2(value); + } + else if (headings[i] == "Bsp2") { + polarRow.setBoatSpeed2(value); + } + else if (headings[i] == "Twa3") { + polarRow.setTrueWindAngle3(value); + } + else if (headings[i] == "Bsp3") { + polarRow.setBoatSpeed3(value); + } + else if (headings[i] == "Twa4") { + polarRow.setTrueWindAngle4(value); + } + else if (headings[i] == "Bsp4") { + polarRow.setBoatSpeed4(value); + } + else if (headings[i] == "Twa5") { + polarRow.setTrueWindAngle5(value); + } + else if (headings[i] == "Bsp5") { + polarRow.setBoatSpeed5(value); + } + else if (headings[i] == "Twa6") { + polarRow.setTrueWindAngle6(value); + } + else if (headings[i] == "Bsp6") { + polarRow.setBoatSpeed6(value); + } + else if (headings[i] == "Twa7") { + polarRow.setTrueWindAngle7(value); + } + else if (headings[i] == "Bsp7") { + polarRow.setBoatSpeed7(value); + } + + //Add the polar row to the polar table. + polarTable.add(polarRow); + + } + + //Increment row number. + rowNumber++; + + } + + + return polarTable; + } +*/ + } diff --git a/mock/src/main/java/seng302/Exceptions/InvalidPolarFileException.java b/mock/src/main/java/seng302/Exceptions/InvalidPolarFileException.java new file mode 100644 index 00000000..cc997c67 --- /dev/null +++ b/mock/src/main/java/seng302/Exceptions/InvalidPolarFileException.java @@ -0,0 +1,28 @@ +package seng302.Exceptions; + +/** + * Created by f123 on 10-May-17. + */ + +/** + * An exception thrown when we cannot parse a polar data file. + */ +public class InvalidPolarFileException extends RuntimeException { + + /** + * Constructs the exception with a given message. + * @param message Message to store. + */ + public InvalidPolarFileException(String message) { + super(message); + } + + /** + * Constructs the exception with a given message and cause. + * @param message Message to store. + * @param cause Cause to store. + */ + public InvalidPolarFileException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/mock/src/main/resources/polars/acc_polars.csv b/mock/src/main/resources/polars/acc_polars.csv new file mode 100644 index 00000000..ee7ea80e --- /dev/null +++ b/mock/src/main/resources/polars/acc_polars.csv @@ -0,0 +1,8 @@ +Tws,Twa0,Bsp0,Twa1,Bsp1,UpTwa,UpBsp,Twa2,Bsp2,Twa3,Bsp3,Twa4,Bsp4,Twa5,Bsp5,Twa6,Bsp6,DnTwa,DnBsp,Twa7,Bsp7 +4,0,0,30,4,45,8,60,9,75,10,90,10,115,10,145,10,155,10,175,4 +8,0,0,30,7,43,10,60,11,75,11,90,11,115,12,145,12,153,12,175,10 +12,0,0,30,11,43,14.4,60,16,75,20,90,23,115,24,145,23,153,21.6,175,14 +16,0,0,30,12,42,19.2,60,25,75,27,90,31,115,32,145,30,153,28.8,175,20 +20,0,0,30,13,41,24,60,29,75,37,90,39,115,40,145,38,153,36,175,24 +25,0,0,30,15,40,30,60,38,75,44,90,49,115,50,145,49,151,47,175,30 +30,0,0,30,15,42,30,60,37,75,42,90,48,115,49,145,48,150,46,175,32 diff --git a/mock/src/test/java/seng302/DataInput/PolarParserTest.java b/mock/src/test/java/seng302/DataInput/PolarParserTest.java new file mode 100644 index 00000000..0bb06326 --- /dev/null +++ b/mock/src/test/java/seng302/DataInput/PolarParserTest.java @@ -0,0 +1,26 @@ +package seng302.DataInput; + +import org.testng.annotations.Test; + +import java.io.File; + +import static org.testng.Assert.*; + +/** + * Created by f123 on 10-May-17. + */ +public class PolarParserTest { + + @Test + /** + * Tests if we can parse a polar data file (stored in a string), and create a polar table. + */ + public void testParse() throws Exception { + + + //Polars = PolarParser.parse("polars/acc_polars.csv"); + + + } + +} From e67f8fae4bed5d186f4ef012f785d8dc1774903b Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 10 May 2017 15:24:46 +1200 Subject: [PATCH 08/76] parser updated for the hashmap polars #pair[hba56, fjc40] #story[900] --- .../java/seng302/DataInput/PolarParser.java | 80 ++----------------- 1 file changed, 7 insertions(+), 73 deletions(-) diff --git a/mock/src/main/java/seng302/DataInput/PolarParser.java b/mock/src/main/java/seng302/DataInput/PolarParser.java index 475125a9..6b977483 100644 --- a/mock/src/main/java/seng302/DataInput/PolarParser.java +++ b/mock/src/main/java/seng302/DataInput/PolarParser.java @@ -5,7 +5,7 @@ package seng302.DataInput; */ import seng302.Exceptions.InvalidPolarFileException; -import seng302.Model.Polar; +import seng302.Model.Polars; import java.io.*; import java.util.ArrayList; @@ -22,11 +22,11 @@ public class PolarParser { * @param filename * @return */ - /* + ///TEMP PolarTable = ArrayList - public static ArrayList parse(String filename) throws InvalidPolarFileException { + public static Polars parse(String filename) throws InvalidPolarFileException { //Temporary table to return later. - ArrayList polarTable = new ArrayList(); + Polars polarTable = new Polars(); //Open the file for reading. @@ -84,84 +84,19 @@ public class PolarParser { int rowNumber = 0; for (String[] row : dataRows) { //Create Polar row object. - Polar polarRow = new Polar(); //For each column... - for (int i = 0; i < row.length; i++) { + for (int i = 0; i < row.length / 2; i += 2) { //Convert value to a double. Double value; try { - value = Double.parseDouble(row[i]); + //Add the polar value to the polar table + polarTable.addEstimate( Double.parseDouble(row[0]), Double.parseDouble(row[i]), Double.parseDouble(row[i + 1])); } catch (NumberFormatException e) { throw new InvalidPolarFileException("Could not convert (Row,Col): (" + rowNumber + "," + i +") = " + row[i] + "to a double.", e); } - - //Set the values of the row. - //For reference: - //Tws, Twa0, Bsp0, Twa1, Bsp1, UpTwa, UpBsp, Twa2, Bsp2, Twa3, Bsp3, Twa4, Bsp4, Twa5, Bsp5, Twa6, Bsp6, DnTwa, DnBsp, Twa7, Bsp7 - if (headings[i] == "Tws") { - polarRow.setTrueWindSpeed(value); - } - else if (headings[i] == "Twa0") { - polarRow.setTrueWindAngle0(value); - } - else if (headings[i] == "Bsp0") { - polarRow.setBoatSpeed0(value); - } - else if (headings[i] == "Twa1") { - polarRow.setTrueWindAngle1(value); - } - else if (headings[i] == "Bsp1") { - polarRow.setBoatSpeed1(value); - } - else if (headings[i] == "UpTwa") { - polarRow.setUpTrueWindAngel(value); - } - else if (headings[i] == "UpBsp") { - polarRow.setUpBoatSpeed(value); - } - else if (headings[i] == "Twa2") { - polarRow.setTrueWindAngle2(value); - } - else if (headings[i] == "Bsp2") { - polarRow.setBoatSpeed2(value); - } - else if (headings[i] == "Twa3") { - polarRow.setTrueWindAngle3(value); - } - else if (headings[i] == "Bsp3") { - polarRow.setBoatSpeed3(value); - } - else if (headings[i] == "Twa4") { - polarRow.setTrueWindAngle4(value); - } - else if (headings[i] == "Bsp4") { - polarRow.setBoatSpeed4(value); - } - else if (headings[i] == "Twa5") { - polarRow.setTrueWindAngle5(value); - } - else if (headings[i] == "Bsp5") { - polarRow.setBoatSpeed5(value); - } - else if (headings[i] == "Twa6") { - polarRow.setTrueWindAngle6(value); - } - else if (headings[i] == "Bsp6") { - polarRow.setBoatSpeed6(value); - } - else if (headings[i] == "Twa7") { - polarRow.setTrueWindAngle7(value); - } - else if (headings[i] == "Bsp7") { - polarRow.setBoatSpeed7(value); - } - - //Add the polar row to the polar table. - polarTable.add(polarRow); - } //Increment row number. @@ -172,6 +107,5 @@ public class PolarParser { return polarTable; } -*/ } From 245914a69ef3ce89b005509e58e1ab681fea72ce Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 10 May 2017 15:26:43 +1200 Subject: [PATCH 09/76] added the polars csv #story[900] --- mock/src/test/resources/acc_polars.csv | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 mock/src/test/resources/acc_polars.csv diff --git a/mock/src/test/resources/acc_polars.csv b/mock/src/test/resources/acc_polars.csv new file mode 100644 index 00000000..ee7ea80e --- /dev/null +++ b/mock/src/test/resources/acc_polars.csv @@ -0,0 +1,8 @@ +Tws,Twa0,Bsp0,Twa1,Bsp1,UpTwa,UpBsp,Twa2,Bsp2,Twa3,Bsp3,Twa4,Bsp4,Twa5,Bsp5,Twa6,Bsp6,DnTwa,DnBsp,Twa7,Bsp7 +4,0,0,30,4,45,8,60,9,75,10,90,10,115,10,145,10,155,10,175,4 +8,0,0,30,7,43,10,60,11,75,11,90,11,115,12,145,12,153,12,175,10 +12,0,0,30,11,43,14.4,60,16,75,20,90,23,115,24,145,23,153,21.6,175,14 +16,0,0,30,12,42,19.2,60,25,75,27,90,31,115,32,145,30,153,28.8,175,20 +20,0,0,30,13,41,24,60,29,75,37,90,39,115,40,145,38,153,36,175,24 +25,0,0,30,15,40,30,60,38,75,44,90,49,115,50,145,49,151,47,175,30 +30,0,0,30,15,42,30,60,37,75,42,90,48,115,49,145,48,150,46,175,32 From 4f8d6b14d4340eb4aacc79e0762f2d6847e4166d Mon Sep 17 00:00:00 2001 From: hba56 Date: Wed, 10 May 2017 15:46:01 +1200 Subject: [PATCH 10/76] updated app class to read the polar csv and pass it off to its parser #story[900] --- mock/src/main/java/seng302/App.java | 9 ++++----- .../java/seng302/DataInput/RaceXMLReader.java | 20 +++++++++++++++---- mock/src/test/resources/acc_polars.csv | 8 -------- 3 files changed, 20 insertions(+), 17 deletions(-) delete mode 100644 mock/src/test/resources/acc_polars.csv diff --git a/mock/src/main/java/seng302/App.java b/mock/src/main/java/seng302/App.java index c80b6432..0e6306bc 100644 --- a/mock/src/main/java/seng302/App.java +++ b/mock/src/main/java/seng302/App.java @@ -4,11 +4,9 @@ package seng302; import javafx.application.Application; import javafx.stage.Stage; import org.xml.sax.SAXException; -import seng302.DataInput.RaceDataSource; -import seng302.DataInput.RaceXMLReader; -import seng302.DataInput.RegattaDataSource; -import seng302.DataInput.RegattaXMLReader; +import seng302.DataInput.*; import seng302.Model.Event; +import seng302.Model.Polars; import javax.xml.parsers.ParserConfigurationException; @@ -28,7 +26,8 @@ public class App extends Application { @Override public void start(Stage primaryStage) { try { - RaceDataSource raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml"); + Polars boatPolars = PolarParser.parse("polars/acc_polars.csv"); + RaceDataSource raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml", boatPolars); RegattaDataSource regattaData = new RegattaXMLReader("mockXML/regattaTest.xml"); Event raceEvent = new Event(raceData, regattaData); raceEvent.start(); diff --git a/mock/src/main/java/seng302/DataInput/RaceXMLReader.java b/mock/src/main/java/seng302/DataInput/RaceXMLReader.java index 50bebb1c..00a14965 100644 --- a/mock/src/main/java/seng302/DataInput/RaceXMLReader.java +++ b/mock/src/main/java/seng302/DataInput/RaceXMLReader.java @@ -5,10 +5,7 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import seng302.Model.Boat; -import seng302.Model.GPSCoordinate; -import seng302.Model.Leg; -import seng302.Model.Marker; +import seng302.Model.*; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; @@ -28,6 +25,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { private GPSCoordinate mapTopLeft, mapBottomRight; private List boundary = new ArrayList<>(); private List markers = new ArrayList<>(); + private Polars boatPolars; /** * Constractor for Race XML @@ -41,6 +39,19 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { this(filePath, true); } + /** + * Constractor for Race XML + * + * @param filePath path of the file + * @throws IOException error + * @throws SAXException error + * @throws ParserConfigurationException error + */ + public RaceXMLReader(String filePath, Polars boatPolars) throws IOException, SAXException, ParserConfigurationException { + this(filePath, true); + this.boatPolars = boatPolars; + } + /** * COnstructor for Race XML * @@ -90,6 +101,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { double velo = Double.parseDouble(getTextValueOfNode((Element) nBoats.item(i), "speed")); int sourceID = Integer.parseInt(getTextValueOfNode((Element) nBoats.item(i), "sourceID")); Boat boat = new Boat(name, velo, abbrev, sourceID); + boat.setPolars(boatPolars); boat.setCurrentPosition(startPt1); if (legs.size() > 0) { boat.setCurrentLeg(legs.get(0)); diff --git a/mock/src/test/resources/acc_polars.csv b/mock/src/test/resources/acc_polars.csv deleted file mode 100644 index ee7ea80e..00000000 --- a/mock/src/test/resources/acc_polars.csv +++ /dev/null @@ -1,8 +0,0 @@ -Tws,Twa0,Bsp0,Twa1,Bsp1,UpTwa,UpBsp,Twa2,Bsp2,Twa3,Bsp3,Twa4,Bsp4,Twa5,Bsp5,Twa6,Bsp6,DnTwa,DnBsp,Twa7,Bsp7 -4,0,0,30,4,45,8,60,9,75,10,90,10,115,10,145,10,155,10,175,4 -8,0,0,30,7,43,10,60,11,75,11,90,11,115,12,145,12,153,12,175,10 -12,0,0,30,11,43,14.4,60,16,75,20,90,23,115,24,145,23,153,21.6,175,14 -16,0,0,30,12,42,19.2,60,25,75,27,90,31,115,32,145,30,153,28.8,175,20 -20,0,0,30,13,41,24,60,29,75,37,90,39,115,40,145,38,153,36,175,24 -25,0,0,30,15,40,30,60,38,75,44,90,49,115,50,145,49,151,47,175,30 -30,0,0,30,15,42,30,60,37,75,42,90,48,115,49,145,48,150,46,175,32 From 3bc8ad0a0762a7636f4cdfeb627fc46c0c7ecafe Mon Sep 17 00:00:00 2001 From: Joseph Gardner Date: Wed, 10 May 2017 16:30:32 +1200 Subject: [PATCH 11/76] Arrow is now displayed on screen more vividly, the arrow can be customised to a different colour scheme if needed. #story[882] --- .../Networking/Messages/RaceStatus.java | 2 +- visualiser/pom.xml | 6 ++ .../seng302/Controllers/RaceController.java | 57 +++++++++++++ .../seng302/Model/ResizableRaceCanvas.java | 19 ++++- .../main/java/seng302/VisualiserInput.java | 4 +- .../src/main/resources/scenes/race.fxml | 80 ++++++++----------- 6 files changed, 115 insertions(+), 53 deletions(-) diff --git a/network/src/main/java/seng302/Networking/Messages/RaceStatus.java b/network/src/main/java/seng302/Networking/Messages/RaceStatus.java index 097045ba..708dcd70 100644 --- a/network/src/main/java/seng302/Networking/Messages/RaceStatus.java +++ b/network/src/main/java/seng302/Networking/Messages/RaceStatus.java @@ -17,7 +17,7 @@ public class RaceStatus extends AC35Data { private int windSpeed; private int raceType; private ArrayList boatStatuses; - private static final double windDirectionScalar = 360.0 / 32768.0; // 0x8000 / 360 + private static final double windDirectionScalar = 360.0 / 49152; // 0xC000 / 360 public RaceStatus(long currentTime, int raceID, int raceStatus, long expectedStartTime, int windDirection, int windSpeed, int raceType, ArrayList boatStatuses){ super(MessageType.RACESTATUS); diff --git a/visualiser/pom.xml b/visualiser/pom.xml index fb7b17a8..8876c318 100644 --- a/visualiser/pom.xml +++ b/visualiser/pom.xml @@ -54,6 +54,12 @@ 1.0-SNAPSHOT + + eu.hansolo + Medusa + 7.9 + + diff --git a/visualiser/src/main/java/seng302/Controllers/RaceController.java b/visualiser/src/main/java/seng302/Controllers/RaceController.java index a108b592..8bb2e1a2 100644 --- a/visualiser/src/main/java/seng302/Controllers/RaceController.java +++ b/visualiser/src/main/java/seng302/Controllers/RaceController.java @@ -1,16 +1,27 @@ package seng302.Controllers; +import eu.hansolo.medusa.Fonts; +import eu.hansolo.medusa.Gauge; +import eu.hansolo.medusa.GaugeBuilder; +import eu.hansolo.medusa.skins.GaugeSkin; +import eu.hansolo.medusa.skins.GaugeSkinBase; import javafx.collections.ObservableList; import javafx.fxml.FXML; +import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; +import javafx.scene.layout.StackPane; +import javafx.scene.paint.Color; +import javafx.scene.paint.Paint; import seng302.Mock.StreamedRace; import seng302.Model.*; import seng302.VisualiserInput; import java.net.URL; import java.util.ArrayList; +import java.util.Locale; import java.util.ResourceBundle; /** @@ -24,7 +35,9 @@ public class RaceController extends Controller { private ResizableRaceCanvas raceMap; private ResizableRaceMap raceBoundaries; + private Gauge arrow; @FXML SplitPane race; + @FXML StackPane arrowPane; @FXML CheckBox showFPS; @FXML CheckBox showBoatPath; @FXML CheckBox showAnnotations; @@ -94,6 +107,8 @@ public class RaceController extends Controller { StreamedRace newRace = new StreamedRace(visualiserInput, this); //newRace.initialiseBoats(); + makeArrow(); + raceMap = new ResizableRaceCanvas(visualiserInput.getCourse()); raceMap.setMouseTransparent(true); raceMap.widthProperty().bind(canvasBase.widthProperty()); @@ -101,6 +116,7 @@ public class RaceController extends Controller { //raceMap.setBoats(newRace.getStartingBoats()); raceMap.draw(); raceMap.setVisible(true); + raceMap.setArrow(this.arrow); canvasBase.getChildren().add(0, raceMap); @@ -110,6 +126,7 @@ public class RaceController extends Controller { raceBoundaries.heightProperty().bind(canvasBase.heightProperty()); raceBoundaries.draw(); raceBoundaries.setVisible(true); + canvasBase.getChildren().add(0, raceBoundaries); race.setVisible(true); @@ -211,4 +228,44 @@ public class RaceController extends Controller { } }); } + + private void makeArrow() { + arrow = GaugeBuilder.create() + .minValue(0) + .maxValue(359) + .startAngle(180) + .angleRange(360) + .autoScale(false) + .customTickLabelsEnabled(true) + .customTickLabels("N", "", "", "", "", "", "", "", "", + "E", "", "", "", "", "", "", "", "", + "S", "", "", "", "", "", "", "", "", + "W", "", "", "", "", "", "", "", "") + .customTickLabelFontSize(72) + .needleBehavior(Gauge.NeedleBehavior.OPTIMIZED) + .borderPaint(Color.web("#1f1e23")) + .backgroundPaint(Color.web("#1f1e23")) + .needleColor(Color.web("#dad9db")) + .tickMarkColor(Color.web("#9f9fa1")) + .tickLabelColor(Color.web("#dad9db")) + .valueColor(Color.web("#dad9db")) + .title("Wind direction") + .titleColor(Color.web("#dad9db")) + .knobType(Gauge.KnobType.FLAT) + .knobColor(Gauge.BRIGHT_COLOR) + .prefSize(125, 125) + .maxWidth(125) + .maxHeight(125) + .build(); + + Label value = new Label("0°"); + value.setFont(Fonts.latoBold(72)); + value.setAlignment(Pos.CENTER); + + arrow.valueProperty().addListener(o -> { + value.setText(String.format("%f°", arrow.getValue())); + }); + arrow.setValue(0); + arrowPane.getChildren().add(arrow); + } } diff --git a/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java b/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java index 2b793da9..ead59846 100644 --- a/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -1,6 +1,9 @@ package seng302.Model; +import eu.hansolo.medusa.Gauge; +import eu.hansolo.medusa.GaugeBuilder; +import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.scene.transform.Rotate; @@ -31,6 +34,7 @@ public class ResizableRaceCanvas extends ResizableCanvas { private final List markers; double[] xpoints = {}, ypoints = {}; private final RaceDataSource raceData; + private Gauge arrow; public ResizableRaceCanvas(RaceDataSource raceData) { super(); @@ -146,6 +150,13 @@ public class ResizableRaceCanvas extends ResizableCanvas { gc.restore(); } + private void displayFancyArrow(GraphCoordinate coordinate, double angle) { + angle = angle % 360; + if (arrow != null && arrow.getValue() != angle) { + this.arrow.setValue(angle); + } + } + /** * Rotates things on the canvas Note: this must be called in between gc.save() and gc.restore() else they will rotate everything * @@ -240,9 +251,9 @@ public class ResizableRaceCanvas extends ResizableCanvas { //display wind direction arrow - specify origin point and angle - angle now set to random angle if (raceData instanceof StreamedCourse) { - displayArrow(new GraphCoordinate((int) getWidth() - 40, 40), ((StreamedCourse) raceData).getWindDirection()); + displayFancyArrow(new GraphCoordinate((int) getWidth() - 40, 40), ((StreamedCourse) raceData).getWindDirection()); } else { - displayArrow(new GraphCoordinate((int) getWidth() - 40, 40), 150); + displayFancyArrow(new GraphCoordinate((int) getWidth() - 40, 40), 150); } } @@ -349,4 +360,8 @@ public class ResizableRaceCanvas extends ResizableCanvas { )); } + public void setArrow(Gauge arrow) { + this.arrow = arrow; + } + } \ No newline at end of file diff --git a/visualiser/src/main/java/seng302/VisualiserInput.java b/visualiser/src/main/java/seng302/VisualiserInput.java index ffba53c3..87afeaed 100644 --- a/visualiser/src/main/java/seng302/VisualiserInput.java +++ b/visualiser/src/main/java/seng302/VisualiserInput.java @@ -219,7 +219,7 @@ public class VisualiserInput implements Runnable { //If no heartbeat has been received in more the heartbeat period //then the connection will need to be restarted. - System.out.println("time since last heartbeat: " + timeSinceHeartbeat());//TEMP REMOVE + //System.out.println("time since last heartbeat: " + timeSinceHeartbeat());//TEMP REMOVE long heartBeatPeriod = 10 * 1000; if (timeSinceHeartbeat() > heartBeatPeriod) { System.out.println("Connection has stopped, trying to reconnect."); @@ -285,7 +285,7 @@ public class VisualiserInput implements Runnable { for (BoatStatus boatStatus: this.raceStatus.getBoatStatuses()) { this.boatStatusMap.put(boatStatus.getSourceID(), boatStatus); } - setCourseWindDirection(raceStatus.getScaledWindDirection() + 180); + setCourseWindDirection(raceStatus.getScaledWindDirection()); } //DisplayTextMessage. /*else if (message instanceof DisplayTextMessage) { diff --git a/visualiser/src/main/resources/scenes/race.fxml b/visualiser/src/main/resources/scenes/race.fxml index 7ab63046..46d9c717 100644 --- a/visualiser/src/main/resources/scenes/race.fxml +++ b/visualiser/src/main/resources/scenes/race.fxml @@ -1,19 +1,21 @@ + + + - + + - + - + @@ -24,28 +26,13 @@ - - - - - -