From a85bf292d56e4fc43578343a6456330604bdad81 Mon Sep 17 00:00:00 2001 From: Joseph Gardner Date: Fri, 21 Apr 2017 12:23:02 +1200 Subject: [PATCH 1/9] new branch for xml readers for the visuliser --- .../resources/mockXML/boatXML/boatTest.xml | 251 ++++++ visualiser/.idea/compiler.xml | 16 + .../Maven__com_beust_jcommander_1_64.xml | 13 + ...__com_github_bfsmith_geotimezone_1_0_3.xml | 13 + .../Maven__com_spatial4j_spatial4j_0_4_1.xml | 13 + ...Maven__commons_pool_commons_pool_1_5_4.xml | 13 + .../libraries/Maven__java3d_vecmath_1_3_2.xml | 13 + .../Maven__javax_media_jai_core_1_1_3.xml | 13 + .../Maven__jgridshift_jgridshift_1_0.xml | 13 + .../Maven__joda_time_joda_time_2_7.xml | 13 + .../libraries/Maven__junit_junit_4_12.xml | 13 + ...et_java_dev_jsr_275_jsr_275_1_0_beta_2.xml | 13 + .../Maven__org_geotools_gt_metadata_9_0.xml | 13 + .../Maven__org_geotools_gt_opengis_9_0.xml | 13 + ...Maven__org_geotools_gt_referencing_9_0.xml | 13 + .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 + .../Maven__org_mockito_mockito_all_1_9_5.xml | 13 + .../Maven__org_testng_testng_6_11.xml | 13 + .../Maven__org_yaml_snakeyaml_1_17.xml | 13 + visualiser/.idea/misc.xml | 43 + visualiser/.idea/modules.xml | 8 + visualiser/.idea/workspace.xml | 817 ++++++++++++++++++ .../resources/mockXML/boatXML/boatTest.xml | 251 ++++++ 23 files changed, 1607 insertions(+) create mode 100644 mock/src/test/resources/mockXML/boatXML/boatTest.xml create mode 100644 visualiser/.idea/compiler.xml create mode 100644 visualiser/.idea/libraries/Maven__com_beust_jcommander_1_64.xml create mode 100644 visualiser/.idea/libraries/Maven__com_github_bfsmith_geotimezone_1_0_3.xml create mode 100644 visualiser/.idea/libraries/Maven__com_spatial4j_spatial4j_0_4_1.xml create mode 100644 visualiser/.idea/libraries/Maven__commons_pool_commons_pool_1_5_4.xml create mode 100644 visualiser/.idea/libraries/Maven__java3d_vecmath_1_3_2.xml create mode 100644 visualiser/.idea/libraries/Maven__javax_media_jai_core_1_1_3.xml create mode 100644 visualiser/.idea/libraries/Maven__jgridshift_jgridshift_1_0.xml create mode 100644 visualiser/.idea/libraries/Maven__joda_time_joda_time_2_7.xml create mode 100644 visualiser/.idea/libraries/Maven__junit_junit_4_12.xml create mode 100644 visualiser/.idea/libraries/Maven__net_java_dev_jsr_275_jsr_275_1_0_beta_2.xml create mode 100644 visualiser/.idea/libraries/Maven__org_geotools_gt_metadata_9_0.xml create mode 100644 visualiser/.idea/libraries/Maven__org_geotools_gt_opengis_9_0.xml create mode 100644 visualiser/.idea/libraries/Maven__org_geotools_gt_referencing_9_0.xml create mode 100644 visualiser/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 visualiser/.idea/libraries/Maven__org_mockito_mockito_all_1_9_5.xml create mode 100644 visualiser/.idea/libraries/Maven__org_testng_testng_6_11.xml create mode 100644 visualiser/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml create mode 100644 visualiser/.idea/misc.xml create mode 100644 visualiser/.idea/modules.xml create mode 100644 visualiser/.idea/workspace.xml create mode 100644 visualiser/src/test/resources/mockXML/boatXML/boatTest.xml diff --git a/mock/src/test/resources/mockXML/boatXML/boatTest.xml b/mock/src/test/resources/mockXML/boatXML/boatTest.xml new file mode 100644 index 00000000..738502a5 --- /dev/null +++ b/mock/src/test/resources/mockXML/boatXML/boatTest.xml @@ -0,0 +1,251 @@ + + + + + 2012-05-17T07:49:40+0200 + + 12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/compiler.xml b/visualiser/.idea/compiler.xml new file mode 100644 index 00000000..4feb7dd4 --- /dev/null +++ b/visualiser/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__com_beust_jcommander_1_64.xml b/visualiser/.idea/libraries/Maven__com_beust_jcommander_1_64.xml new file mode 100644 index 00000000..e72647cc --- /dev/null +++ b/visualiser/.idea/libraries/Maven__com_beust_jcommander_1_64.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__com_github_bfsmith_geotimezone_1_0_3.xml b/visualiser/.idea/libraries/Maven__com_github_bfsmith_geotimezone_1_0_3.xml new file mode 100644 index 00000000..70fc370b --- /dev/null +++ b/visualiser/.idea/libraries/Maven__com_github_bfsmith_geotimezone_1_0_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__com_spatial4j_spatial4j_0_4_1.xml b/visualiser/.idea/libraries/Maven__com_spatial4j_spatial4j_0_4_1.xml new file mode 100644 index 00000000..e70d84d7 --- /dev/null +++ b/visualiser/.idea/libraries/Maven__com_spatial4j_spatial4j_0_4_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__commons_pool_commons_pool_1_5_4.xml b/visualiser/.idea/libraries/Maven__commons_pool_commons_pool_1_5_4.xml new file mode 100644 index 00000000..ab207212 --- /dev/null +++ b/visualiser/.idea/libraries/Maven__commons_pool_commons_pool_1_5_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__java3d_vecmath_1_3_2.xml b/visualiser/.idea/libraries/Maven__java3d_vecmath_1_3_2.xml new file mode 100644 index 00000000..1eebe0af --- /dev/null +++ b/visualiser/.idea/libraries/Maven__java3d_vecmath_1_3_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__javax_media_jai_core_1_1_3.xml b/visualiser/.idea/libraries/Maven__javax_media_jai_core_1_1_3.xml new file mode 100644 index 00000000..d8609e87 --- /dev/null +++ b/visualiser/.idea/libraries/Maven__javax_media_jai_core_1_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__jgridshift_jgridshift_1_0.xml b/visualiser/.idea/libraries/Maven__jgridshift_jgridshift_1_0.xml new file mode 100644 index 00000000..b7ad97c6 --- /dev/null +++ b/visualiser/.idea/libraries/Maven__jgridshift_jgridshift_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__joda_time_joda_time_2_7.xml b/visualiser/.idea/libraries/Maven__joda_time_joda_time_2_7.xml new file mode 100644 index 00000000..1259ecab --- /dev/null +++ b/visualiser/.idea/libraries/Maven__joda_time_joda_time_2_7.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__junit_junit_4_12.xml b/visualiser/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 00000000..d4110417 --- /dev/null +++ b/visualiser/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__net_java_dev_jsr_275_jsr_275_1_0_beta_2.xml b/visualiser/.idea/libraries/Maven__net_java_dev_jsr_275_jsr_275_1_0_beta_2.xml new file mode 100644 index 00000000..bf5f49be --- /dev/null +++ b/visualiser/.idea/libraries/Maven__net_java_dev_jsr_275_jsr_275_1_0_beta_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__org_geotools_gt_metadata_9_0.xml b/visualiser/.idea/libraries/Maven__org_geotools_gt_metadata_9_0.xml new file mode 100644 index 00000000..e872950f --- /dev/null +++ b/visualiser/.idea/libraries/Maven__org_geotools_gt_metadata_9_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__org_geotools_gt_opengis_9_0.xml b/visualiser/.idea/libraries/Maven__org_geotools_gt_opengis_9_0.xml new file mode 100644 index 00000000..01a5965e --- /dev/null +++ b/visualiser/.idea/libraries/Maven__org_geotools_gt_opengis_9_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__org_geotools_gt_referencing_9_0.xml b/visualiser/.idea/libraries/Maven__org_geotools_gt_referencing_9_0.xml new file mode 100644 index 00000000..36874c5c --- /dev/null +++ b/visualiser/.idea/libraries/Maven__org_geotools_gt_referencing_9_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/visualiser/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 00000000..f58bbc11 --- /dev/null +++ b/visualiser/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__org_mockito_mockito_all_1_9_5.xml b/visualiser/.idea/libraries/Maven__org_mockito_mockito_all_1_9_5.xml new file mode 100644 index 00000000..7797878d --- /dev/null +++ b/visualiser/.idea/libraries/Maven__org_mockito_mockito_all_1_9_5.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__org_testng_testng_6_11.xml b/visualiser/.idea/libraries/Maven__org_testng_testng_6_11.xml new file mode 100644 index 00000000..51052227 --- /dev/null +++ b/visualiser/.idea/libraries/Maven__org_testng_testng_6_11.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml b/visualiser/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml new file mode 100644 index 00000000..20e2920c --- /dev/null +++ b/visualiser/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/misc.xml b/visualiser/.idea/misc.xml new file mode 100644 index 00000000..a46856d3 --- /dev/null +++ b/visualiser/.idea/misc.xml @@ -0,0 +1,43 @@ + + + + + + + + + + $USER_HOME$/.subversion + + + + + + 1.8 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/modules.xml b/visualiser/.idea/modules.xml new file mode 100644 index 00000000..e9597707 --- /dev/null +++ b/visualiser/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/workspace.xml b/visualiser/.idea/workspace.xml new file mode 100644 index 00000000..8abce0df --- /dev/null +++ b/visualiser/.idea/workspace.xml @@ -0,0 +1,817 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1492733921956 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/src/test/resources/mockXML/boatXML/boatTest.xml b/visualiser/src/test/resources/mockXML/boatXML/boatTest.xml new file mode 100644 index 00000000..738502a5 --- /dev/null +++ b/visualiser/src/test/resources/mockXML/boatXML/boatTest.xml @@ -0,0 +1,251 @@ + + + + + 2012-05-17T07:49:40+0200 + + 12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 9e3ca68df8bf88e57dc80eb900b5c61d4f365bd1 Mon Sep 17 00:00:00 2001 From: Joseph Gardner Date: Fri, 21 Apr 2017 13:28:55 +1200 Subject: [PATCH 2/9] added skeleton for StreamedRace and StreamedCourse #Pair[jjg64, cbt24] #Story[782] --- visualiser/.idea/workspace.xml | 447 +++++++++++++++--- .../java/seng302/Mock/StreamedCourse.java | 50 ++ .../main/java/seng302/Mock/StreamedRace.java | 56 +++ .../src/main/java/seng302/Model/Race.java | 6 +- .../test/java/seng302/Mock/BoatsXMLTest.java | 7 + .../java/seng302/Mock/StreamedRaceTest.java | 8 + .../resources/mockXML/raceXML/raceTest.xml | 91 ++++ 7 files changed, 585 insertions(+), 80 deletions(-) create mode 100644 visualiser/src/main/java/seng302/Mock/StreamedCourse.java create mode 100644 visualiser/src/main/java/seng302/Mock/StreamedRace.java create mode 100644 visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java create mode 100644 visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java create mode 100644 visualiser/src/test/resources/mockXML/raceXML/raceTest.xml diff --git a/visualiser/.idea/workspace.xml b/visualiser/.idea/workspace.xml index 8abce0df..a973e7f6 100644 --- a/visualiser/.idea/workspace.xml +++ b/visualiser/.idea/workspace.xml @@ -19,21 +19,121 @@ - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + @@ -41,11 +141,34 @@ + + + + + + @@ -124,15 +247,15 @@ @@ -745,41 +842,41 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -797,6 +894,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -805,13 +950,161 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java new file mode 100644 index 00000000..0f76a4da --- /dev/null +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java @@ -0,0 +1,50 @@ +package seng302.Mock; + +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.List; + +/** + * Created by jjg64 on 21/04/17. + */ +public class StreamedCourse implements RaceDataSource { + XMLReader xmlReader; + List boundary = new ArrayList<>(); + + public StreamedCourse(XMLReader xmlReader) { + this.xmlReader = xmlReader; + } + + public List getBoats() { + return null; + } + + public List getLegs() { + return null; + } + + public List getBoundary() { + return null; + } + + public GPSCoordinate getMark() { + return null; + } + + public GPSCoordinate getMapTopLeft() { + return null; + } + + public GPSCoordinate getMapBottomRight() { + return null; + } + + +} diff --git a/visualiser/src/main/java/seng302/Mock/StreamedRace.java b/visualiser/src/main/java/seng302/Mock/StreamedRace.java new file mode 100644 index 00000000..3fa93dec --- /dev/null +++ b/visualiser/src/main/java/seng302/Mock/StreamedRace.java @@ -0,0 +1,56 @@ +package seng302.Mock; + +import javafx.collections.FXCollections; +import seng302.Controllers.RaceController; +import seng302.Model.BoatInRace; +import seng302.Model.Leg; +import seng302.Model.Race; +import seng302.RaceDataSource; + +import java.util.*; + +/** + * Created by jjg64 on 21/04/17. + */ +public class StreamedRace extends Race{ + private RaceDataSource raceData; + + public StreamedRace(RaceDataSource raceData, RaceController controller, int scaleFactor) { + super(raceData.getBoats(), raceData.getLegs(), controller, scaleFactor); + this.raceData = raceData; + } + + public void initialiseBoats() { + + } + + /** + * Checks if the boat cannot finish the race + * @return True if boat cannot finish the race + */ + protected boolean doNotFinish() { + return false; + } + + /** + * Checks the position of the boat, this updates the boats current position. + * + * @param boat Boat that the postion is to be updated for. + * @param timeElapsed Time that has elapse since the start of the the race. + * @see BoatInRace + */ + protected void checkPosition(BoatInRace boat, long timeElapsed) { + + } + + /** + * Updates the boat's gps coordinates + * + * @param boat to be updated + * @param millisecondsElapsed time since last update + */ + protected void updatePosition(BoatInRace boat, int millisecondsElapsed) { + + } + +} diff --git a/visualiser/src/main/java/seng302/Model/Race.java b/visualiser/src/main/java/seng302/Model/Race.java index bfc1d518..c033c8a3 100644 --- a/visualiser/src/main/java/seng302/Model/Race.java +++ b/visualiser/src/main/java/seng302/Model/Race.java @@ -65,8 +65,8 @@ public abstract class Race implements Runnable { public abstract void initialiseBoats(); /** - * Randomly generate number to see if boat fails - * @return True if number lower than dnfChance else false + * Checks if the boat cannot finish the race + * @return True if boat cannot finish the race */ protected abstract boolean doNotFinish(); @@ -80,7 +80,7 @@ public abstract class Race implements Runnable { protected abstract void checkPosition(BoatInRace boat, long timeElapsed); /** - * Updates the boat's gps coordinates depending on time elapsed + * Updates the boat's gps coordinates * * @param boat to be updated * @param millisecondsElapsed time since last update diff --git a/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java b/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java new file mode 100644 index 00000000..990e3a49 --- /dev/null +++ b/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java @@ -0,0 +1,7 @@ +package seng302.Mock; + +/** + * Created by jjg64 on 21/04/17. + */ +public class BoatsXMLTest { +} diff --git a/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java b/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java new file mode 100644 index 00000000..dca6d1db --- /dev/null +++ b/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java @@ -0,0 +1,8 @@ +package seng302.Mock; + +/** + * Created by jjg64 on 21/04/17. + */ +public class StreamedRaceTest { + +} diff --git a/visualiser/src/test/resources/mockXML/raceXML/raceTest.xml b/visualiser/src/test/resources/mockXML/raceXML/raceTest.xml new file mode 100644 index 00000000..8c19df9a --- /dev/null +++ b/visualiser/src/test/resources/mockXML/raceXML/raceTest.xml @@ -0,0 +1,91 @@ + + + + + 11080703 + + Match + + 2011-08-06T13:25:00-0000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 0d0b9e143f47036a720e3303d7174d942355f7cd Mon Sep 17 00:00:00 2001 From: Joseph Gardner Date: Fri, 21 Apr 2017 16:43:35 +1200 Subject: [PATCH 3/9] 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] --- visualiser/.idea/uiDesigner.xml | 124 ++++ visualiser/.idea/workspace.xml | 545 +++++++++++++----- .../java/seng302/Mock/StreamedCourse.java | 11 +- .../seng302/Mock/StreamedCourseXMLReader.java | 149 +++++ .../src/main/java/seng302/Model/Marker.java | 1 - .../main/java/seng302/Model/RaceClock.java | 4 +- .../java/seng302/Mock/RegattaXMLTest.java | 32 +- .../java/seng302/Mock/StreamedRaceTest.java | 57 +- 8 files changed, 746 insertions(+), 177 deletions(-) create mode 100644 visualiser/.idea/uiDesigner.xml create mode 100644 visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java diff --git a/visualiser/.idea/uiDesigner.xml b/visualiser/.idea/uiDesigner.xml new file mode 100644 index 00000000..e96534fb --- /dev/null +++ b/visualiser/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualiser/.idea/workspace.xml b/visualiser/.idea/workspace.xml index a973e7f6..58b5f16d 100644 --- a/visualiser/.idea/workspace.xml +++ b/visualiser/.idea/workspace.xml @@ -13,127 +13,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - - - + + - - - + + + + + + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - - - - - - - - - - - - - - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + @@ -148,6 +174,11 @@ + + + legs + + - + @@ -440,6 +565,32 @@ + + + + + + + + + + + @@ -832,17 +985,44 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -857,7 +1037,7 @@ - + @@ -865,6 +1045,7 @@ + @@ -875,7 +1056,6 @@ - @@ -910,198 +1090,271 @@ - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - + - - + + + + + + + + + + + + + - + - - + + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java index 0f76a4da..221138e7 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java @@ -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 boundary = new ArrayList<>(); - public StreamedCourse(XMLReader xmlReader) { - this.xmlReader = xmlReader; + public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) { + this.streamedCourseXMLReader = streamedCourseXMLReader; } public List getBoats() { @@ -47,4 +45,5 @@ public class StreamedCourse implements RaceDataSource { } + } diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java new file mode 100644 index 00000000..46af3ef2 --- /dev/null +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java @@ -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 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 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; + } +} diff --git a/visualiser/src/main/java/seng302/Model/Marker.java b/visualiser/src/main/java/seng302/Model/Marker.java index 2b7cafbe..118219f1 100644 --- a/visualiser/src/main/java/seng302/Model/Marker.java +++ b/visualiser/src/main/java/seng302/Model/Marker.java @@ -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; diff --git a/visualiser/src/main/java/seng302/Model/RaceClock.java b/visualiser/src/main/java/seng302/Model/RaceClock.java index 6ea62bd3..d9815cde 100644 --- a/visualiser/src/main/java/seng302/Model/RaceClock.java +++ b/visualiser/src/main/java/seng302/Model/RaceClock.java @@ -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)); diff --git a/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java b/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java index 821e476b..efc54a09 100644 --- a/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java +++ b/visualiser/src/test/java/seng302/Mock/RegattaXMLTest.java @@ -16,7 +16,7 @@ public class RegattaXMLTest { @Before public void findFile(){ try { - regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml", false); + regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml"); } catch (Exception e) { fail("Cannot find mockXML/regattaXML/regattaTest.xml in the resources folder"); } @@ -24,29 +24,19 @@ public class RegattaXMLTest { @Test public void makeRegattaTest() { - try { - regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml"); - assertNotEquals(regattaXMLReader.getRegatta(), null); - } catch (Exception e) { - fail("Did not make a Regatta object"); - } + assertNotEquals(regattaXMLReader.getRegatta(), null); } @Test public void correctValuesTest() { - try { - regattaXMLReader = new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml"); - Regatta regatta = regattaXMLReader.getRegatta(); - assertEquals(regatta.getRegattaID(), 3); - assertEquals(regatta.getRegattaName(), "New Zealand Test"); - assertEquals(regatta.getCourseName(), "North Head"); - assertEquals(regatta.getCentralLatitude(), -36.82791529, 0.00000001); - assertEquals(regatta.getCentralLongitude(), 174.81218919, 0.00000001); - assertEquals(regatta.getCentralAltitude(), 0.00, 0.00000001); - assertEquals(regatta.getUtcOffset(), 12.0, 0.001); - assertEquals(regatta.getMagneticVariation(), 14.1, 0.001); - } catch (Exception e) { - fail("Did not have the correct values"); - } + Regatta regatta = regattaXMLReader.getRegatta(); + assertEquals(regatta.getRegattaID(), 3); + assertEquals(regatta.getRegattaName(), "New Zealand Test"); + assertEquals(regatta.getCourseName(), "North Head"); + assertEquals(regatta.getCentralLatitude(), -36.82791529, 0.00000001); + assertEquals(regatta.getCentralLongitude(), 174.81218919, 0.00000001); + assertEquals(regatta.getCentralAltitude(), 0.00, 0.00000001); + assertEquals(regatta.getUtcOffset(), 12.0, 0.001); + assertEquals(regatta.getMagneticVariation(), 14.1, 0.001); } } diff --git a/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java b/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java index dca6d1db..772c606e 100644 --- a/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java +++ b/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java @@ -1,8 +1,63 @@ package seng302.Mock; +import org.junit.Before; +import org.junit.Test; +import seng302.GPSCoordinate; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + /** - * Created by jjg64 on 21/04/17. + * Tests only work on the current version of mockXML/raceXML/raceTest.xml */ public class StreamedRaceTest { + StreamedCourseXMLReader streamedCourseXMLReader; + List boundary; + + @Before + public void setup() { + try { + streamedCourseXMLReader = new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml", true); + boundary = streamedCourseXMLReader.getBoundary(); + } catch (Exception e) { + e.printStackTrace(); + //fail("Cannot find mockXML/raceXML/raceTest.xml in the resources folder"); + } + } + + @Test + public void testAllBoundaryPointsRead() { + assertEquals(boundary.size(), 10); + } + + @Test + public void testBoundaryPointData() { + // First point + assertEquals(boundary.get(0).getLatitude(), -36.8325, 1e-6); + assertEquals(boundary.get(0).getLongitude(), 174.8325, 1e-6); + + // Last point + assertEquals(boundary.get(boundary.size() - 1).getLatitude(), -36.83417, 1e-6); + assertEquals(boundary.get(boundary.size() - 1).getLongitude(), 174.84767, 1e-6); + } + + @Test + public void testMapEdges() { + double maxLatitude = streamedCourseXMLReader.getMapBottomRight().getLatitude() - streamedCourseXMLReader.getPadding(); + double maxLongitude = streamedCourseXMLReader.getMapBottomRight().getLongitude() - streamedCourseXMLReader.getPadding(); + double minLatitude = streamedCourseXMLReader.getMapTopLeft().getLatitude() - streamedCourseXMLReader.getPadding(); + double minLongitude = streamedCourseXMLReader.getMapTopLeft().getLongitude() - streamedCourseXMLReader.getPadding(); + + assertEquals(maxLatitude, -36.81033, 1e-6); + assertEquals(maxLongitude, 174.88217, 1e-6); + assertEquals(minLatitude, -36.83417, 1e-6); + assertEquals(minLongitude, 174.81983, 1e-6); + } + + @Test + public void testRaceSettings() { + } } From 22075ee415df51589c839f6d2cddb5656e536194 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 25 Apr 2017 02:13:57 +1200 Subject: [PATCH 4/9] Started on the boat XML parser, reads only boat data from the XML and makes a StreamedBoat for each boat in the XML. #story[861] --- .../main/java/seng302/Mock/BoatXMLReader.java | 126 ++++++++++++++++++ .../main/java/seng302/Mock/StreamedBoat.java | 37 +++++ .../main/java/seng302/Mock/StreamedRace.java | 2 +- .../src/main/java/seng302/Model/Boat.java | 11 ++ .../main/java/seng302/Model/BoatInRace.java | 50 ++++--- .../test/java/seng302/Mock/BoatsXMLTest.java | 13 ++ 6 files changed, 220 insertions(+), 19 deletions(-) create mode 100644 visualiser/src/main/java/seng302/Mock/BoatXMLReader.java create mode 100644 visualiser/src/main/java/seng302/Mock/StreamedBoat.java diff --git a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java new file mode 100644 index 00000000..5a9b8e4c --- /dev/null +++ b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java @@ -0,0 +1,126 @@ +package seng302.Mock; + +import javafx.scene.paint.Color; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; +import seng302.XMLReader; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.lang.annotation.ElementType; +import java.text.ParseException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by Joseph on 24/04/2017. + */ +public class BoatXMLReader extends XMLReader { + Map streamedBoatMap = new HashMap<>(); + private Color[] colours = {Color.BLUEVIOLET, Color.BLACK, Color.RED, Color.ORANGE, Color.DARKOLIVEGREEN, Color.LIMEGREEN}; + private int currentColourIndex = 0; + + /** + * Constructor for Boat XML Reader + * @param filePath path of the file + * @throws IOException error + * @throws SAXException error + * @throws ParserConfigurationException error + */ + public BoatXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException { + this(filePath, true); + } + + /** + * Constructor for Boat XML Reader + * @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 BoatXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException { + super(filePath); + if (read) { + read(); + } + } + + private void read() { + readSettings(); + readShapes(); + readBoats(); + } + + /** + * Reads boats settings. + * INFORMATION FROM HERE IS IGNORED FOR NOW + */ + private void readSettings() { + + } + + /** + * Reads different kinds of boat. + * INFORMATION FROM HERE IS IGNORED FOR NOW + */ + private void readShapes() { + + } + + /** + * Reads the boats in the race + */ + private void readBoats() { + Element nBoats = (Element) doc.getElementsByTagName("Boats").item(0); + for (int i = 0; i < nBoats.getChildNodes().getLength(); i++) { + Node boat = nBoats.getChildNodes().item(i); + if (boat.getNodeName().equals("Boat")) { + readSingleBoat(boat); + currentColourIndex++; + } + } + } + + /** + * Reads the information about one boat + * Ignored values: Type, ShapeID, StoweName, HullNum, Skipper + */ + private void readSingleBoat(Node boat) { + StreamedBoat streamedBoat; + String country = null; + int sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent()); + String boatName = boat.getAttributes().getNamedItem("BoatName").getTextContent(); + String shortName = boat.getAttributes().getNamedItem("ShortName").getTextContent(); + if (boat.getAttributes().getNamedItem("Country") != null) country = boat.getAttributes().getNamedItem("Country").getTextContent(); + + if (!streamedBoatMap.containsKey(sourceID)) { + if (country != null) { + streamedBoat = new StreamedBoat(sourceID, boatName, colours[currentColourIndex], country); + } else { + streamedBoat = new StreamedBoat(sourceID, boatName, colours[currentColourIndex], shortName); + } + streamedBoatMap.put(sourceID, streamedBoat); + } + + for (int i = 0; i < boat.getChildNodes().getLength(); i++) { + Node GPSPosition = boat.getChildNodes().item(i); + if (GPSPosition.getNodeName().equals("GPSposition")) readBoatPositionInformation(sourceID, GPSPosition); + } + } + + /** + * Reads the positional information about a boat + * Ignored values: FlagPosition, MastTop, Z value of GPSposition + */ + private void readBoatPositionInformation(int sourceID, Node GPSPosition) { + // TODO Get relative point before implementing. (GPSposition is based off a relative point). + } + + private Map getBoatMap() { + return streamedBoatMap; + } +} diff --git a/visualiser/src/main/java/seng302/Mock/StreamedBoat.java b/visualiser/src/main/java/seng302/Mock/StreamedBoat.java new file mode 100644 index 00000000..1f483d40 --- /dev/null +++ b/visualiser/src/main/java/seng302/Mock/StreamedBoat.java @@ -0,0 +1,37 @@ +package seng302.Mock; + +import javafx.scene.paint.Color; +import seng302.GPSCoordinate; +import seng302.Model.Boat; +import seng302.Model.BoatInRace; + +/** + * Created by Joseph on 24/04/2017. + */ +public class StreamedBoat extends BoatInRace { + private int sourceID; + + public StreamedBoat(int sourceID, String name, Color colour, String abbrev) { + super(name, colour, abbrev); + this.sourceID = sourceID; + } + + + /** + * Overridden to ignore this function + * @deprecated + * @return 0 + */ + public double getScaledVelocity() { + return 0; + } + + /** + * Overridden to ignore this function + * @deprecated + * @param velocity of boat + */ + public void setScaledVelocity(double velocity) { + + } +} diff --git a/visualiser/src/main/java/seng302/Mock/StreamedRace.java b/visualiser/src/main/java/seng302/Mock/StreamedRace.java index 3fa93dec..56b6a114 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedRace.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedRace.java @@ -12,7 +12,7 @@ import java.util.*; /** * Created by jjg64 on 21/04/17. */ -public class StreamedRace extends Race{ +public class StreamedRace extends Race { private RaceDataSource raceData; public StreamedRace(RaceDataSource raceData, RaceController controller, int scaleFactor) { diff --git a/visualiser/src/main/java/seng302/Model/Boat.java b/visualiser/src/main/java/seng302/Model/Boat.java index 49b5a0f9..a3e269d4 100644 --- a/visualiser/src/main/java/seng302/Model/Boat.java +++ b/visualiser/src/main/java/seng302/Model/Boat.java @@ -27,6 +27,17 @@ public class Boat { this.name = new SimpleStringProperty(name); } + /** + * Boat initialiser which keeps all of the information of the boat. + * + * @param name Name of the Boat. + * @param abbrev nam abbreviation + */ + public Boat(String name, String abbrev) { + this.abbrev = abbrev; + this.name = new SimpleStringProperty(name); + } + /** * @return Name of the boat */ diff --git a/visualiser/src/main/java/seng302/Model/BoatInRace.java b/visualiser/src/main/java/seng302/Model/BoatInRace.java index 520e7b06..6f835593 100644 --- a/visualiser/src/main/java/seng302/Model/BoatInRace.java +++ b/visualiser/src/main/java/seng302/Model/BoatInRace.java @@ -17,25 +17,25 @@ import java.util.concurrent.ConcurrentLinkedQueue; */ public class BoatInRace extends Boat { - private Leg currentLeg; + protected Leg currentLeg; private double scaledVelocity; - private double distanceTravelledInLeg; - private GPSCoordinate currentPosition; - private long timeFinished; - private Color colour; - private boolean finished = false; - private StringProperty currentLegName; - private boolean started = false; - private StringProperty position; - private double heading; - - private Queue track = new ConcurrentLinkedQueue<>(); - private long nextValidTime = 0; - - private static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000; - private static float trackPointTimeInterval = 5000; // every 1 seconds - private final int TRACK_POINT_LIMIT = 10; - private boolean trackVisible = true; + protected double distanceTravelledInLeg; + protected GPSCoordinate currentPosition; + protected long timeFinished; + protected Color colour; + protected boolean finished = false; + protected StringProperty currentLegName; + protected boolean started = false; + protected StringProperty position; + protected double heading; + + protected Queue track = new ConcurrentLinkedQueue<>(); + protected long nextValidTime = 0; + + protected static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000; + protected static float trackPointTimeInterval = 5000; // every 1 seconds + protected final int TRACK_POINT_LIMIT = 10; + protected boolean trackVisible = true; /** * Constructor method. @@ -52,6 +52,20 @@ public class BoatInRace extends Boat { position = new SimpleStringProperty("-"); } + /** + * Constructor method. + * + * @param name Name of the boat. + * @param colour Colour the boat will be displayed as on the map + * @param abbrev of boat + */ + public BoatInRace(String name, Color colour, String abbrev) { + super(name, abbrev); + setColour(colour); + currentLegName = new SimpleStringProperty(""); + position = new SimpleStringProperty("-"); + } + /** * Calculates the azimuth of the travel via map coordinates of the raceMarkers * diff --git a/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java b/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java index 990e3a49..507bf60e 100644 --- a/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java +++ b/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java @@ -1,7 +1,20 @@ package seng302.Mock; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.text.ParseException; + /** * Created by jjg64 on 21/04/17. */ public class BoatsXMLTest { + + @Test + public void test() throws SAXException, ParserConfigurationException, ParseException, IOException { + new BoatXMLReader("mockXML/boatXML/boatTest.xml"); + //new BoatXMLReader("mockXML/raceXML/raceTest.xml", true); + } } From a59342a668b7eb2403ac855a3a77289fa1789ff3 Mon Sep 17 00:00:00 2001 From: cbt24 Date: Tue, 25 Apr 2017 13:00:45 +1200 Subject: [PATCH 5/9] Modified RaceClock to support arbitrary start times - Amended RaceDataSource interface to require time instead of mark for calculating time. #story[758] --- .../seng302/Controllers/RaceController.java | 2 +- .../seng302/Controllers/StartController.java | 4 +- .../java/seng302/Mock/RegattaXMLReader.java | 1 + .../main/java/seng302/Model/RaceClock.java | 55 +++--- .../src/main/java/seng302/RaceDataSource.java | 3 +- .../src/main/java/seng302/RaceXMLReader.java | 9 +- .../src/test/java/seng302/Model/RaceTest.java | 163 +----------------- 7 files changed, 48 insertions(+), 189 deletions(-) diff --git a/visualiser/src/main/java/seng302/Controllers/RaceController.java b/visualiser/src/main/java/seng302/Controllers/RaceController.java index 6d4bdf8e..f6339d4f 100644 --- a/visualiser/src/main/java/seng302/Controllers/RaceController.java +++ b/visualiser/src/main/java/seng302/Controllers/RaceController.java @@ -133,7 +133,7 @@ public class RaceController extends Controller { //Initialize save annotation array, fps listener, and annotation listeners //timezone - RaceClock raceClock = new RaceClock(raceData.getMark()); + RaceClock raceClock = new RaceClock(raceData.getZonedDateTime()); timeZone.setText(raceClock.getTimeZone()); initializeFPS(); initializeAnnotations(); diff --git a/visualiser/src/main/java/seng302/Controllers/StartController.java b/visualiser/src/main/java/seng302/Controllers/StartController.java index f62fb6ea..f5662746 100644 --- a/visualiser/src/main/java/seng302/Controllers/StartController.java +++ b/visualiser/src/main/java/seng302/Controllers/StartController.java @@ -103,8 +103,8 @@ public class StartController extends Controller { boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); boatCodeColumn.setCellValueFactory(new PropertyValueFactory<>("abbrev")); //timezone - raceClock = new RaceClock(raceData.getMark()); - timeZoneTime.textProperty().bind(raceClock.timeProperty()); + raceClock = new RaceClock(raceData.getZonedDateTime()); + timeZoneTime.textProperty().bind(raceClock.timeStringProperty()); } diff --git a/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java b/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java index 6291825f..6c9cc5f6 100644 --- a/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java @@ -3,6 +3,7 @@ package seng302.Mock; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import seng302.RaceDataSource; import seng302.XMLReader; import javax.xml.parsers.ParserConfigurationException; diff --git a/visualiser/src/main/java/seng302/Model/RaceClock.java b/visualiser/src/main/java/seng302/Model/RaceClock.java index d9815cde..7ecda612 100644 --- a/visualiser/src/main/java/seng302/Model/RaceClock.java +++ b/visualiser/src/main/java/seng302/Model/RaceClock.java @@ -6,48 +6,61 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import seng302.GPSCoordinate; +import java.time.Duration; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; /** * Created by Gondr on 19/04/2017. */ public class RaceClock { - private StringProperty time; - private DateTimeFormatter dateTimeFormatter; - private String timeZone; + private long lastTime; private ZoneId zoneId; + private ZonedDateTime time; + private StringProperty timeString; - public RaceClock(GPSCoordinate gpsCoordinate) { + public RaceClock(ZonedDateTime zonedDateTime) { + this.zoneId = zonedDateTime.getZone(); + this.timeString = new SimpleStringProperty(); + } + + public static ZonedDateTime getCurrentZonedDateTime(GPSCoordinate gpsCoordinate) { TimeZoneLookup timeZoneLookup = new TimeZoneLookup(); TimeZoneResult timeZoneResult = timeZoneLookup.getTimeZone(gpsCoordinate.getLatitude(), gpsCoordinate.getLongitude()); - zoneId = ZoneId.of(timeZoneResult.getResult()); - LocalDateTime localDateTime = LocalDateTime.now(zoneId); - ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId); - dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM HH:mm:ss z"); - // System.out.println(dateTimeFormatter.format(zonedDateTime)); - time = new SimpleStringProperty(dateTimeFormatter.format(zonedDateTime)); - DateTimeFormatter timeZoneFormatter = DateTimeFormatter.ofPattern("z"); - timeZone = timeZoneFormatter.format(zonedDateTime); + ZoneId zone = ZoneId.of(timeZoneResult.getResult()); + return LocalDateTime.now(zone).atZone(zone); + } + + /** + * Sets time to arbitrary zoned time. + * @param time arbitrary time with timezone. + */ + public void setTime(ZonedDateTime time) { + this.time = time; + this.timeString.set(DateTimeFormatter.ofPattern("dd-MM HH:mm:ss z").format(time)); + this.lastTime = System.currentTimeMillis(); } + /** + * Updates time by duration elapsed since last update. + */ public void updateTime() { - LocalDateTime localDateTime = LocalDateTime.now(zoneId); - ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId); - time.setValue(dateTimeFormatter.format(zonedDateTime)); + this.time.plus(Duration.of(System.currentTimeMillis() - this.lastTime, ChronoUnit.MILLIS)); + this.lastTime = System.currentTimeMillis(); } - public String getTime() { - return time.get(); + public String getTimeZone() { + return zoneId.toString(); } - public StringProperty timeProperty() { - return time; + public String getTimeString() { + return timeString.get(); } - public String getTimeZone() { - return timeZone; + public StringProperty timeStringProperty() { + return timeString; } } diff --git a/visualiser/src/main/java/seng302/RaceDataSource.java b/visualiser/src/main/java/seng302/RaceDataSource.java index 2f562766..82d30b73 100644 --- a/visualiser/src/main/java/seng302/RaceDataSource.java +++ b/visualiser/src/main/java/seng302/RaceDataSource.java @@ -3,6 +3,7 @@ package seng302; import seng302.Model.BoatInRace; import seng302.Model.Leg; +import java.time.ZonedDateTime; import java.util.List; /** @@ -13,7 +14,7 @@ public interface RaceDataSource { List getLegs(); List getBoundary(); - GPSCoordinate getMark(); + ZonedDateTime getZonedDateTime(); GPSCoordinate getMapTopLeft(); GPSCoordinate getMapBottomRight(); } diff --git a/visualiser/src/main/java/seng302/RaceXMLReader.java b/visualiser/src/main/java/seng302/RaceXMLReader.java index f10da6ef..14244417 100644 --- a/visualiser/src/main/java/seng302/RaceXMLReader.java +++ b/visualiser/src/main/java/seng302/RaceXMLReader.java @@ -4,12 +4,11 @@ import javafx.scene.paint.Color; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import seng302.Model.BoatInRace; -import seng302.Model.Leg; -import seng302.Model.Marker; +import seng302.Model.*; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; @@ -272,8 +271,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource { return legs; } - public GPSCoordinate getMark() { - return mark; + public ZonedDateTime getZonedDateTime() { + return RaceClock.getCurrentZonedDateTime(mark); } public GPSCoordinate getStartPt1() { diff --git a/visualiser/src/test/java/seng302/Model/RaceTest.java b/visualiser/src/test/java/seng302/Model/RaceTest.java index 859e74e6..79024843 100644 --- a/visualiser/src/test/java/seng302/Model/RaceTest.java +++ b/visualiser/src/test/java/seng302/Model/RaceTest.java @@ -1,173 +1,18 @@ package seng302.Model; -import javafx.scene.paint.Color; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -import seng302.GPSCoordinate; - -import java.util.ArrayList; -import java.util.Arrays; +import org.mockito.Mock; +import seng302.RaceDataSource; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; /** * Created by esa46 on 15/03/17. */ public class RaceTest { - Leg START_LEG = new Leg("Start", new Marker(new GPSCoordinate(0, 0)), new Marker(new GPSCoordinate(1, 1)), 0); - Leg FINISH_LEG = new Leg("Finish", new Marker(new GPSCoordinate(1, 1)), new Marker(new GPSCoordinate(2, 2)), 0); - - @Ignore - @Test - public void timerCanBeDisabled() { - BoatInRace boat1 = new BoatInRace("Test 1", 10000, Color.ALICEBLUE, "t1"); - BoatInRace boat2 = new BoatInRace("Test 2", 10000, Color.BURLYWOOD, "t2"); - BoatInRace[] boats = new BoatInRace[]{boat1, boat2}; - - ArrayList legs = new ArrayList<>(); - legs.add(START_LEG); legs.add(FINISH_LEG); - - ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, 5); - race.disableTimer(); - race.setDnfChance(0); - long timeStarted = System.currentTimeMillis(); - race.run(); - - assertTrue(System.currentTimeMillis() - timeStarted < 4000); - } - - @Test - public void checkPositionUpdatesNumberFinishedBoats() { - - BoatInRace finishedBoat = new BoatInRace("Test", 1000, Color.ALICEBLUE, "tt"); - finishedBoat.setDistanceTravelledInLeg(500); - - finishedBoat.setCurrentLeg(FINISH_LEG); - - ArrayList legs = new ArrayList<>(); - legs.add(FINISH_LEG); - - ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1); - race.setDnfChance(0); - assertEquals(race.boatsFinished, 0); - - - race.checkPosition(finishedBoat, 100000); - assertEquals(race.boatsFinished, 1); - assertEquals(finishedBoat.getTimeFinished(), 100000); - } - - @Test - public void checkPositionDoesntUpdateNumberFinishedBoats() { - - BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt"); - unFinishedBoat.setDistanceTravelledInLeg(0); - - unFinishedBoat.setCurrentLeg(FINISH_LEG); - - ArrayList legs = new ArrayList<>(); - legs.add(FINISH_LEG); - - ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1); - race.setDnfChance(0); - assertEquals(race.boatsFinished, 0); - - race.checkPosition(unFinishedBoat, 100); - assertEquals(race.boatsFinished, 0); - } - - @Test - public void distanceTravelledBeforeUpdatingLegIsRetained() { - - ArrayList legs = new ArrayList<>(); - - - legs.add(START_LEG); - legs.add(FINISH_LEG); - - ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1); - race.setDnfChance(0); - - BoatInRace unFinishedBoat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt"); - unFinishedBoat.setDistanceTravelledInLeg(100); - unFinishedBoat.setCurrentLeg(START_LEG); - - race.checkPosition(unFinishedBoat, 100); - assertEquals(unFinishedBoat.getCurrentLeg().getName(), "Finish"); - assertTrue(unFinishedBoat.getDistanceTravelledInLeg() > 0); - assertTrue(unFinishedBoat.getDistanceTravelledInLeg() < 100); - - } - - /*@Test - - //Test temporarily removed as countdown timer now uses animation timer - - public void timerDelaysByHalfSecond() { - - ArrayList legs = new ArrayList<>(); - legs.add(START_LEG); - - ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[1], legs, null, 1); - race.PRERACE_TIME = 500; - - long timeStarted = System.currentTimeMillis(); - race.countdownTimer(); - - //assertTrue(System.currentTimeMillis() - timeStarted > 500); - System.out.println(System.currentTimeMillis() - timeStarted); - - }*/ - - @Test - public void scalerScalesVelocityCorrectly() { - - int scaleFactor = 3; - float vel1 = 0; - float vel2 = (float) 1.999; - float vel3 = (float) 32.5; - float vel4 = 500; - BoatInRace boat1 = new BoatInRace("test", vel1, Color.ALICEBLUE, "tt"); - BoatInRace boat2 = new BoatInRace("test", vel2, Color.ALICEBLUE, "tt"); - BoatInRace boat3 = new BoatInRace("test", vel3, Color.ALICEBLUE, "tt"); - BoatInRace boat4 = new BoatInRace("test", vel4, Color.ALICEBLUE, "tt"); - BoatInRace[] boats = new BoatInRace[]{boat1, boat2, boat3, boat4}; - - ArrayList legs = new ArrayList<>(); - legs.add(START_LEG); - - ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, null, scaleFactor); - race.setDnfChance(0); - - assertEquals(race.getStartingBoats().get(0).getScaledVelocity(), vel1 * scaleFactor, 1e-6); - assertEquals(race.getStartingBoats().get(1).getScaledVelocity(), vel2 * scaleFactor, 1e-6); - assertEquals(race.getStartingBoats().get(2).getScaledVelocity(), vel3 * scaleFactor, 1e-6); - assertEquals(race.getStartingBoats().get(3).getScaledVelocity(), vel4 * scaleFactor, 1e-6); - } - - @Test - public void scalerScalesRaceClockTo1MinCorrectly() { - int scaleFactor = 10; - - ArrayList legs = new ArrayList<>(); - legs.add(START_LEG); - - ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor); - race.totalTimeElapsed = 6000; //6 seconds - assertTrue(race.calcTimer().equals("Race clock: 00:01:00")); - } - - @Test - public void scalerScalesRaceClockHoursMinutesAndSecondsCorrectly() { - int scaleFactor = 3; - ArrayList legs = new ArrayList<>(); - legs.add(START_LEG); - - ConstantVelocityRace race = new ConstantVelocityRace(new BoatInRace[5], legs, null, scaleFactor); - race.totalTimeElapsed = 3213000; - assertTrue(race.calcTimer().equals("Race clock: 02:40:39")); - - } } From 858db3f45ee951609af118115ef9fa6fbb0fad17 Mon Sep 17 00:00:00 2001 From: cbt24 Date: Tue, 25 Apr 2017 13:08:57 +1200 Subject: [PATCH 6/9] Fixed interface implementation for StreamedCourse #story[758] --- visualiser/src/main/java/seng302/Mock/StreamedCourse.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java index 221138e7..6e27705e 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java @@ -5,6 +5,7 @@ import seng302.Model.BoatInRace; import seng302.Model.Leg; import seng302.RaceDataSource; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -32,7 +33,7 @@ public class StreamedCourse implements RaceDataSource { return null; } - public GPSCoordinate getMark() { + public ZonedDateTime getZonedDateTime() { return null; } From 3461a2c0b72b559405d543cc5486ecc4b605f3e3 Mon Sep 17 00:00:00 2001 From: Joseph Gardner Date: Tue, 25 Apr 2017 13:13:15 +1200 Subject: [PATCH 7/9] Added the ability to reads boats from both race.xml and boat.xml. Linked the two xmls via the StreamedCource class. #story[782] --- .../main/java/seng302/Mock/BoatXMLReader.java | 80 +++++++++++++------ .../main/java/seng302/Mock/StreamedBoat.java | 9 ++- .../java/seng302/Mock/StreamedCourse.java | 26 +++++- .../seng302/Mock/StreamedCourseXMLReader.java | 18 ++++- .../src/main/java/seng302/XMLReader.java | 5 ++ .../test/java/seng302/Mock/BoatsXMLTest.java | 35 +++++++- .../java/seng302/Mock/StreamedRaceTest.java | 8 +- 7 files changed, 144 insertions(+), 37 deletions(-) diff --git a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java index 5a9b8e4c..a7d429dc 100644 --- a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java @@ -11,17 +11,16 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.lang.annotation.ElementType; import java.text.ParseException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * Created by Joseph on 24/04/2017. */ public class BoatXMLReader extends XMLReader { Map streamedBoatMap = new HashMap<>(); - private Color[] colours = {Color.BLUEVIOLET, Color.BLACK, Color.RED, Color.ORANGE, Color.DARKOLIVEGREEN, Color.LIMEGREEN}; - private int currentColourIndex = 0; + Map participants = new HashMap<>(); + private List colours; + private static int currentColourIndex = 0; /** * Constructor for Boat XML Reader @@ -31,7 +30,8 @@ public class BoatXMLReader extends XMLReader { * @throws ParserConfigurationException error */ public BoatXMLReader(String filePath) throws IOException, SAXException, ParserConfigurationException, ParseException { - this(filePath, true); + this(filePath, false); + makeColours(); } /** @@ -44,12 +44,13 @@ public class BoatXMLReader extends XMLReader { */ public BoatXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException, ParseException { super(filePath); + makeColours(); if (read) { read(); } } - private void read() { + public void read() { readSettings(); readShapes(); readBoats(); @@ -80,35 +81,46 @@ public class BoatXMLReader extends XMLReader { Node boat = nBoats.getChildNodes().item(i); if (boat.getNodeName().equals("Boat")) { readSingleBoat(boat); - currentColourIndex++; + currentColourIndex = (currentColourIndex + 1) % colours.size(); } } } /** * Reads the information about one boat - * Ignored values: Type, ShapeID, StoweName, HullNum, Skipper + * Ignored values: ShapeID, StoweName, HullNum, Skipper */ private void readSingleBoat(Node boat) { StreamedBoat streamedBoat; + String type = "None"; + int sourceID = -1; + String boatName = null; + String shortName = null; String country = null; - int sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent()); - String boatName = boat.getAttributes().getNamedItem("BoatName").getTextContent(); - String shortName = boat.getAttributes().getNamedItem("ShortName").getTextContent(); - if (boat.getAttributes().getNamedItem("Country") != null) country = boat.getAttributes().getNamedItem("Country").getTextContent(); - - if (!streamedBoatMap.containsKey(sourceID)) { - if (country != null) { - streamedBoat = new StreamedBoat(sourceID, boatName, colours[currentColourIndex], country); - } else { - streamedBoat = new StreamedBoat(sourceID, boatName, colours[currentColourIndex], shortName); + if (exists(boat, "Type")) type = boat.getAttributes().getNamedItem("Type").getTextContent(); + if (exists(boat, "SourceID")) sourceID = Integer.parseInt(boat.getAttributes().getNamedItem("SourceID").getTextContent()); + if (exists(boat, "BoatName")) boatName = boat.getAttributes().getNamedItem("BoatName").getTextContent(); + if (exists(boat, "ShortName")) shortName = boat.getAttributes().getNamedItem("ShortName").getTextContent(); + if (exists(boat, "Country")) country = boat.getAttributes().getNamedItem("Country").getTextContent(); + + // Ignore all non participating boats + if (participants.containsKey(sourceID)) { + + if (!streamedBoatMap.containsKey(sourceID)) { + if (country != null) { + streamedBoat = new StreamedBoat(sourceID, boatName, colours.get(currentColourIndex), country); + } else { + streamedBoat = new StreamedBoat(sourceID, boatName, colours.get(currentColourIndex), shortName); + } + streamedBoatMap.put(sourceID, streamedBoat); + // Override boat with new boat + participants.put(sourceID, streamedBoat); } - streamedBoatMap.put(sourceID, streamedBoat); - } - for (int i = 0; i < boat.getChildNodes().getLength(); i++) { - Node GPSPosition = boat.getChildNodes().item(i); - if (GPSPosition.getNodeName().equals("GPSposition")) readBoatPositionInformation(sourceID, GPSPosition); + for (int i = 0; i < boat.getChildNodes().getLength(); i++) { + Node GPSPosition = boat.getChildNodes().item(i); + if (GPSPosition.getNodeName().equals("GPSposition")) readBoatPositionInformation(sourceID, GPSPosition); + } } } @@ -120,7 +132,25 @@ public class BoatXMLReader extends XMLReader { // TODO Get relative point before implementing. (GPSposition is based off a relative point). } - private Map getBoatMap() { + private void makeColours() { + colours = new ArrayList(Arrays.asList( + Color.BLUEVIOLET, + Color.BLACK, + Color.RED, + Color.ORANGE, + Color.DARKOLIVEGREEN, + Color.LIMEGREEN, + Color.PURPLE, + Color.DARKGRAY, + Color.YELLOW + )); + } + + public void setParticipants(Map participants) { + this.participants = participants; + } + + public Map getStreamedBoatMap() { return streamedBoatMap; } } diff --git a/visualiser/src/main/java/seng302/Mock/StreamedBoat.java b/visualiser/src/main/java/seng302/Mock/StreamedBoat.java index 1f483d40..0ff629a0 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedBoat.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedBoat.java @@ -10,10 +10,18 @@ import seng302.Model.BoatInRace; */ public class StreamedBoat extends BoatInRace { private int sourceID; + private boolean complete; public StreamedBoat(int sourceID, String name, Color colour, String abbrev) { super(name, colour, abbrev); this.sourceID = sourceID; + this.complete = true; + } + + public StreamedBoat(int sourceID) { + super("None", Color.BLACK, "None"); + this.sourceID = sourceID; + this.complete = false; } @@ -32,6 +40,5 @@ public class StreamedBoat extends BoatInRace { * @param velocity of boat */ public void setScaledVelocity(double velocity) { - } } diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java index 221138e7..f4bb83d2 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java @@ -13,13 +13,34 @@ import java.util.List; * Created by jjg64 on 21/04/17. */ public class StreamedCourse implements RaceDataSource { - StreamedCourseXMLReader streamedCourseXMLReader; + StreamedCourseXMLReader streamedCourseXMLReader = null; + BoatXMLReader boatXMLReader = null; List boundary = new ArrayList<>(); public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) { this.streamedCourseXMLReader = streamedCourseXMLReader; } + public StreamedCourse(BoatXMLReader boatXMLReader) { + this.boatXMLReader = boatXMLReader; + } + + public void setBoatXMLReader(BoatXMLReader boatXMLReader) { + this.boatXMLReader = boatXMLReader; + if (streamedCourseXMLReader != null) { + boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants()); + boatXMLReader.read(); + } + } + + public void setStreamedCourseXMLReader(StreamedCourseXMLReader streamedCourseXMLReader) { + this.streamedCourseXMLReader = streamedCourseXMLReader; + if (streamedCourseXMLReader != null) { + boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants()); + boatXMLReader.read(); + } + } + public List getBoats() { return null; } @@ -43,7 +64,4 @@ public class StreamedCourse implements RaceDataSource { public GPSCoordinate getMapBottomRight() { return null; } - - - } diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java index 46af3ef2..949be304 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java @@ -21,6 +21,7 @@ public class StreamedCourseXMLReader extends XMLReader { private static double COORDINATEPADDING = 0.0005; private GPSCoordinate mapTopLeft, mapBottomRight; private List boundary = new ArrayList<>(); + private Map participants = new HashMap<>(); Date creationTimeDate; Date raceStartTime; int raceID; @@ -72,8 +73,17 @@ public class StreamedCourseXMLReader extends XMLReader { } private void readParticipants() { - //TODO Modify BoatInRace to take in a sourceID - //TODO Produce list of BoatInRace + Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0); + for (int i = 0; i < nParticipants.getChildNodes().getLength(); i++) { + int sourceID; + Node yacht = nParticipants.getChildNodes().item(i); + if (yacht.getNodeName().equals("Yacht")) { + if (exists(yacht, "SourceID")) { + sourceID = Integer.parseInt(yacht.getAttributes().getNamedItem("SourceID").getTextContent()); + participants.put(sourceID, new StreamedBoat(sourceID)); + } + } + } } private void readCourse() { @@ -146,4 +156,8 @@ public class StreamedCourseXMLReader extends XMLReader { public boolean isPostpone() { return postpone; } + + public Map getParticipants() { + return participants; + } } diff --git a/visualiser/src/main/java/seng302/XMLReader.java b/visualiser/src/main/java/seng302/XMLReader.java index 810096d3..62aaea2b 100644 --- a/visualiser/src/main/java/seng302/XMLReader.java +++ b/visualiser/src/main/java/seng302/XMLReader.java @@ -2,6 +2,7 @@ package seng302; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.Node; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; @@ -33,6 +34,10 @@ public abstract class XMLReader { return n.getElementsByTagName(tagName).item(0).getTextContent(); } + public boolean exists(Node node, String attribute) { + return node.getAttributes().getNamedItem(attribute) != null; + } + public String getAttribute(Element n, String attr) { return n.getAttribute(attr); } diff --git a/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java b/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java index 507bf60e..af025e6d 100644 --- a/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java +++ b/visualiser/src/test/java/seng302/Mock/BoatsXMLTest.java @@ -1,20 +1,49 @@ package seng302.Mock; +import org.junit.Before; import org.junit.Test; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.text.ParseException; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Created by jjg64 on 21/04/17. */ public class BoatsXMLTest { + BoatXMLReader boatXMLReader; + + @Before + public void setup() { + try { + boatXMLReader = new BoatXMLReader("mockXML/boatXML/boatTest.xml", false); + } catch (Exception e) { + e.printStackTrace(); + //fail("Cannot find mockXML/raceXML/raceTest.xml in the resources folder"); + } + } + + @Test + public void testInvalidParticipant() { + Map inputParticipants = new HashMap<>(); + inputParticipants.put(420, new StreamedBoat(420)); + boatXMLReader.setParticipants(inputParticipants); + boatXMLReader.read(); + assertEquals(boatXMLReader.getStreamedBoatMap().size(), 0); + } @Test - public void test() throws SAXException, ParserConfigurationException, ParseException, IOException { - new BoatXMLReader("mockXML/boatXML/boatTest.xml"); - //new BoatXMLReader("mockXML/raceXML/raceTest.xml", true); + public void testValidParticipant() { + Map inputParticipants = new HashMap<>(); + inputParticipants.put(101, new StreamedBoat(101)); + boatXMLReader.setParticipants(inputParticipants); + boatXMLReader.read(); + assertTrue(boatXMLReader.getStreamedBoatMap().containsKey(101)); } } diff --git a/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java b/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java index 772c606e..1a475290 100644 --- a/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java +++ b/visualiser/src/test/java/seng302/Mock/StreamedRaceTest.java @@ -5,8 +5,10 @@ import org.junit.Test; import seng302.GPSCoordinate; import java.util.List; +import java.util.Map; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -57,7 +59,9 @@ public class StreamedRaceTest { } @Test - public void testRaceSettings() { - + public void testParticipants() { + Map participants = streamedCourseXMLReader.getParticipants(); + assertTrue(participants.containsKey(107)); + assertTrue(participants.containsKey(108)); } } From a3e87f2c61a261a9b17024850eb793749a2d2303 Mon Sep 17 00:00:00 2001 From: Joseph Gardner Date: Tue, 25 Apr 2017 13:20:10 +1200 Subject: [PATCH 8/9] Got rid of test using a deprecated method --- visualiser/src/test/java/seng302/Model/RaceXMLTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/visualiser/src/test/java/seng302/Model/RaceXMLTest.java b/visualiser/src/test/java/seng302/Model/RaceXMLTest.java index e53c9085..618f2ff4 100644 --- a/visualiser/src/test/java/seng302/Model/RaceXMLTest.java +++ b/visualiser/src/test/java/seng302/Model/RaceXMLTest.java @@ -86,7 +86,6 @@ public class RaceXMLTest { assertTrue(raceXMLReader.getLeewardPt2() != null); assertTrue(raceXMLReader.getWindwardPt1() != null); assertTrue(raceXMLReader.getWindwardPt2() != null); - assertTrue(raceXMLReader.getMark() != null); assertTrue(raceXMLReader.getBoundary().size() == 11); } catch (Exception e) { e.printStackTrace(); From e89a269565fc10d5df5ef4e331c1fdffe2812ebb Mon Sep 17 00:00:00 2001 From: Joseph Gardner Date: Tue, 25 Apr 2017 14:00:41 +1200 Subject: [PATCH 9/9] initialised time in raceclock (1 line) --- visualiser/src/main/java/seng302/Model/RaceClock.java | 1 + 1 file changed, 1 insertion(+) diff --git a/visualiser/src/main/java/seng302/Model/RaceClock.java b/visualiser/src/main/java/seng302/Model/RaceClock.java index 7ecda612..8cb4e0b2 100644 --- a/visualiser/src/main/java/seng302/Model/RaceClock.java +++ b/visualiser/src/main/java/seng302/Model/RaceClock.java @@ -25,6 +25,7 @@ public class RaceClock { public RaceClock(ZonedDateTime zonedDateTime) { this.zoneId = zonedDateTime.getZone(); this.timeString = new SimpleStringProperty(); + this.time = zonedDateTime; } public static ZonedDateTime getCurrentZonedDateTime(GPSCoordinate gpsCoordinate) {