Removed the rest of the shared model classes needed by mock

#story[778]
This commit is contained in:
Erika Savell
2017-05-01 15:49:07 +12:00
parent d34dfc537e
commit 9acd519d7b
22 changed files with 202 additions and 478 deletions
+16
View File
@@ -0,0 +1,16 @@
package seng302;
/**
* Constants that are used throughout the program
* Created by Erika on 19-Mar-17.
*/
public class Constants {
public static final int NMToMetersConversion = 1852; // 1 nautical mile = 1852 meters
//Knots x this = meters per second.
public static final double KnotsToMetersPerSecondConversionFactor = 0.514444;
public static final double wakeScale = 10;
}
@@ -4,9 +4,9 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import seng302.DataInput.RaceDataSource;
import seng302.Exceptions.InvalidRaceDataException;
import SharedModel.GPSCoordinate;
import SharedModel.Marker;
import seng302.Model.Boat;
import seng302.Model.GPSCoordinate;
import seng302.Model.Marker;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -1,9 +1,10 @@
package seng302.DataInput;
import SharedModel.GPSCoordinate;
import SharedModel.Leg;
import SharedModel.Marker;
;
import seng302.Model.Boat;
import seng302.Model.GPSCoordinate;
import seng302.Model.Leg;
import seng302.Model.Marker;
import java.util.List;
@@ -4,10 +4,11 @@ import javafx.scene.paint.Color;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import SharedModel.GPSCoordinate;
import SharedModel.Leg;
import SharedModel.Marker;
import seng302.Model.Boat;
import seng302.Model.GPSCoordinate;
import seng302.Model.Leg;
import seng302.Model.Marker;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
@@ -1,6 +1,7 @@
package seng302.DataInput;
import SharedModel.Regatta;
import seng302.Model.Regatta;
/**
* Created by zwu18 on 25/04/17.
@@ -3,7 +3,8 @@ package seng302.DataInput;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import SharedModel.Regatta;
import seng302.Model.Regatta;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
+1 -3
View File
@@ -1,7 +1,5 @@
package seng302.Model;
import SharedModel.*;
import SharedModel.Leg;
import org.geotools.referencing.GeodeticCalculator;
@@ -14,7 +12,7 @@ public class Boat {
private double scaledVelocity;
private String abbrev;
private int sourceID;
private SharedModel.Leg currentLeg;
private Leg currentLeg;
private double distanceTravelledInLeg;
private GPSCoordinate currentPosition;
private long timeFinished = -1;
@@ -0,0 +1,72 @@
package seng302.Model;
/**
* GPS Coordinate for the world map.
* Created by esa46 on 15/03/17.
*/
public class GPSCoordinate {
private double latitude;
private double longitude;
/**
* Constructor Method
*
* @param latitude latitude the coordinate is located at.
* @param longitude Longitude that the coordinate is located at.
*/
public GPSCoordinate(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
/**
* Gets the Latitude that the Coordinate is at.
*
* @return Returns the latitude of the Coordinate.
*/
public double getLatitude() {
return latitude;
}
/**
* Gets the Longitude that the Coordinate is at.
*
* @return Returns the longitude of the Coordinate.
*/
public double getLongitude() {
return longitude;
}
/**
* To String method of the Coordinate in the form Latitude: $f, Longitude: $f.
*
* @return A String representation of the GPSCoordinate Class.
*/
public String toString() {
return String.format("Latitude: %f, Longitude: %f", latitude, longitude);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GPSCoordinate that = (GPSCoordinate) o;
if (Math.abs(this.latitude - that.latitude) > 1e-7) return false;
return (Math.abs(this.longitude - that.longitude) < 1e-7);
}
@Override
public int hashCode() {
int result;
long temp;
temp = Double.doubleToLongBits(latitude);
result = (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(longitude);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
}
+103
View File
@@ -0,0 +1,103 @@
package seng302.Model;
import org.geotools.referencing.GeodeticCalculator;
import seng302.Constants;
/**
* Created by cbt24 on 6/03/17.
*/
public class Leg {
private String name; //nautical miles
private double distance;
private Marker startMarker;
private Marker endMarker;
private int legNumber;
/**
* Leg Initialiser
*
* @param name Name of the Leg
* @param start marker
* @param end marker
* @param number Leg's position in race
*/
public Leg(String name, Marker start, Marker end, int number) {
this.name = name;
this.startMarker = start;
this.endMarker = end;
this.legNumber = number;
calculateDistance();
}
/**
* Construction Method
*
* @param name Name of the Leg
* @param number leg number
*/
public Leg(String name, int number) {
this.name = name;
this.legNumber = number;
}
/**
* Returns the name of the Leg
*
* @return Returns the name of the Leg
*/
public String getName() {
return name;
}
/**
* Get the distance in nautical miles
*
* @return Returns the total distance of the leg.
*/
public double getDistance() {
return distance;
}
/**
* Returns the leg number that the leg exists in the Race
*
* @return Returns the Leg
*/
public int getLegNumber() {
return legNumber;
}
public Marker getStartMarker() {
return startMarker;
}
public void setStartMarker(Marker startMarker) {
this.startMarker = startMarker;
}
public Marker getEndMarker() {
return endMarker;
}
public void setEndMarker(Marker endMarker) {
this.endMarker = endMarker;
}
/**
* Calculates the distance that the legs are in nautical miles (1.852 km).
*/
public void calculateDistance() {
GeodeticCalculator calc = new GeodeticCalculator();
//Load start and end of leg
GPSCoordinate startMarker = this.startMarker.getAverageGPSCoordinate();
GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate();
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
}
}
@@ -0,0 +1,74 @@
package seng302.Model;
import org.geotools.referencing.GeodeticCalculator;
import java.awt.geom.Point2D;
/**
* Created by esa46 on 29/03/17.
*/
public class Marker {
private GPSCoordinate averageGPSCoordinate;
private GPSCoordinate mark1;
private GPSCoordinate mark2;
private String name;
private boolean doubleMarker = false;
public Marker(GPSCoordinate mark1) {
this.mark1 = mark1;
this.mark2 = mark1;
this.averageGPSCoordinate = calculateAverage();
}
public Marker(GPSCoordinate mark1, GPSCoordinate mark2) {
this.mark1 = mark1;
this.mark2 = mark2;
this.averageGPSCoordinate = calculateAverage();
}
public Marker(String name, GPSCoordinate mark1, GPSCoordinate mark2) {
this.name = name;
this.mark1 = mark1;
this.mark2 = mark2;
this.averageGPSCoordinate = calculateAverage();
}
public GPSCoordinate getMark1() {
return mark1;
}
public GPSCoordinate getMark2() {
return mark2;
}
public GPSCoordinate getAverageGPSCoordinate() {
return averageGPSCoordinate;
}
public String getName() {
return name;
}
private GPSCoordinate calculateAverage() {
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(mark1.getLongitude(), mark1.getLatitude());
calc.setDestinationGeographicPoint(mark2.getLongitude(), mark2.getLatitude());
double azimuth = calc.getAzimuth();
double distance = calc.getOrthodromicDistance();
GeodeticCalculator middleCalc = new GeodeticCalculator();
middleCalc.setStartingGeographicPoint(mark1.getLongitude(), mark1.getLatitude());
middleCalc.setDirection(azimuth, distance / 2);
Point2D middlePoint = middleCalc.getDestinationGeographicPoint();
return new GPSCoordinate(middlePoint.getY(), middlePoint.getX());
}
}
+25 -19
View File
@@ -7,6 +7,7 @@ import javafx.collections.ObservableList;
import org.geotools.referencing.GeodeticCalculator;
import seng302.Constants;
import seng302.DataInput.RaceDataSource;
import seng302.Networking.MockOutput;
import seng302.Networking.Utils.BoatStatusMessage;
@@ -26,7 +27,7 @@ import java.util.Random;
public class Race implements Runnable {
//protected Boat[] startingBoats;
protected ObservableList<Boat> startingBoats;
protected List<SharedModel.Leg> legs;
protected List<Leg> legs;
protected int boatsFinished = 0;
protected long totalTimeElapsed;
protected int scaleFactor;
@@ -44,11 +45,11 @@ public class Race implements Runnable {
* @param legs Number of marks in order that the boats pass in order to complete the race.
* @param scaleFactor for race
*/
public Race(List<Boat> boats, List<SharedModel.Leg> legs, int scaleFactor, MockOutput mockOutput) {
public Race(List<Boat> boats, List<Leg> legs, int scaleFactor, MockOutput mockOutput) {
this.startingBoats = FXCollections.observableArrayList(boats);
this.legs = legs;
this.legs.add(new SharedModel.Leg("Finish", this.legs.size()));
this.legs.add(new Leg("Finish", this.legs.size()));
this.scaleFactor = scaleFactor;
this.mockOutput = mockOutput;
@@ -68,14 +69,14 @@ public class Race implements Runnable {
this.raceId = raceId;
}
/**
* Calculates the boats next SharedModel.GPS position based on its distance travelled and heading
* Calculates the boats next GPS position based on its distance travelled and heading
*
* @param oldCoordinates SharedModel.GPS coordinates of the boat's starting position
* @param oldCoordinates GPS coordinates of the boat's starting position
* @param distanceTravelled distance in nautical miles
* @param azimuth boat's current direction. Value between -180 and 180
* @return The boat's new coordinate
*/
public static SharedModel.GPSCoordinate calculatePosition(SharedModel.GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) {
public static GPSCoordinate calculatePosition(GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) {
//Find new coordinate using current heading and distance
@@ -84,11 +85,11 @@ public class Race implements Runnable {
Point2D startPoint = new Point2D.Double(oldCoordinates.getLongitude(), oldCoordinates.getLatitude());
geodeticCalculator.setStartingGeographicPoint(startPoint);
//load direction and distance tranvelled into calculator
geodeticCalculator.setDirection(azimuth, distanceTravelled * SharedModel.Constants.NMToMetersConversion);
geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion);
//get new point
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
return new SharedModel.GPSCoordinate(endPoint.getY(), endPoint.getX());
return new GPSCoordinate(endPoint.getY(), endPoint.getX());
}
/**
@@ -96,6 +97,8 @@ public class Race implements Runnable {
*/
public void run() {
initialiseBoats();
System.out.println("Beginning");
countdownTimer();
}
@@ -118,6 +121,7 @@ public class Race implements Runnable {
@Override
public void handle(long arg0) {
timeLeft = startTime - currentTime;
System.out.println(timeLeft);
if (timeLeft <= 0) {
stop();
simulateRace();
@@ -140,6 +144,7 @@ public class Race implements Runnable {
*/
private void simulateRace() {
System.out.println("Running");
System.setProperty("javafx.animation.fullspeed", "true");
for (Boat boat : startingBoats) {
@@ -161,11 +166,12 @@ public class Race implements Runnable {
//For each boat, we update it's position, and generate a BoatLocationMessage.
for (Boat boat : startingBoats) {
if (boat != null && boat.getTimeFinished() > 0) {
if (boat != null && boat.getTimeFinished() < 0) {
//Update position.
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
checkPosition(boat, totalTimeElapsed);
mockOutput.parseBoatLocation(boat);
System.out.println("Sending boat status");
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
} else {
@@ -181,16 +187,16 @@ public class Race implements Runnable {
public void initialiseBoats() {
SharedModel.Leg officialStart = legs.get(0);
Leg officialStart = legs.get(0);
String name = officialStart.getName();
SharedModel.Marker endMarker = officialStart.getEndMarker();
Marker endMarker = officialStart.getEndMarker();
ArrayList<SharedModel.Marker> startMarkers = getSpreadStartingPositions();
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
for (int i = 0; i < startingBoats.size(); i++) {
Boat boat = startingBoats.get(i);
if (boat != null) {
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
SharedModel.Leg startLeg = new SharedModel.Leg(name, 0);
Leg startLeg = new Leg(name, 0);
boat.setCurrentPosition(startMarkers.get(i).getAverageGPSCoordinate());
startLeg.setStartMarker(startMarkers.get(i));
startLeg.setEndMarker(endMarker);
@@ -206,10 +212,10 @@ public class Race implements Runnable {
*
* @return list of starting positions
*/
public ArrayList<SharedModel.Marker> getSpreadStartingPositions() {
public ArrayList<Marker> getSpreadStartingPositions() {
int nBoats = startingBoats.size();
SharedModel.Marker marker = legs.get(0).getStartMarker();
Marker marker = legs.get(0).getStartMarker();
GeodeticCalculator initialCalc = new GeodeticCalculator();
initialCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
@@ -221,12 +227,12 @@ public class Race implements Runnable {
GeodeticCalculator positionCalc = new GeodeticCalculator();
positionCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
ArrayList<SharedModel.Marker> positions = new ArrayList<>();
ArrayList<Marker> positions = new ArrayList<>();
for (int i = 0; i < nBoats; i++) {
positionCalc.setDirection(azimuth, distanceBetweenBoats);
Point2D position = positionCalc.getDestinationGeographicPoint();
positions.add(new SharedModel.Marker(new SharedModel.GPSCoordinate(position.getY(), position.getX())));
positions.add(new Marker(new GPSCoordinate(position.getY(), position.getX())));
positionCalc = new GeodeticCalculator();
positionCalc.setStartingGeographicPoint(position);
@@ -285,14 +291,14 @@ public class Race implements Runnable {
} else if (doNotFinish()) {
boatsFinished++;
boat.setTimeFinished(timeElapsed);
boat.setCurrentLeg(new SharedModel.Leg("DNF", -1));
boat.setCurrentLeg(new Leg("DNF", -1));
boat.setVelocity(0);
boat.setScaledVelocity(0);
} else {
//Calculate how much the boat overshot the marker by
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
//Move boat on to next leg
SharedModel.Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
boat.setCurrentLeg(nextLeg);
//Add overshoot distance into the distance travelled for the next leg
@@ -4,7 +4,7 @@ import com.github.bfsmith.geotimezone.TimeZoneLookup;
import com.github.bfsmith.geotimezone.TimeZoneResult;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import SharedModel.GPSCoordinate;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -0,0 +1,99 @@
package seng302.Model;
/**
* Created by jjg64 on 19/04/17.
*/
public class Regatta {
int regattaID;
String RegattaName;
int raceID = 0;
String courseName;
double centralLatitude;
double centralLongitude;
double centralAltitude;
float utcOffset;
float magneticVariation;
public Regatta(int regattaID, String regattaName, String courseName, double centralLatitude, double centralLongitude, double centralAltitude, float utcOffset, float magneticVariation) {
this.regattaID = regattaID;
this.RegattaName = regattaName;
this.courseName = courseName;
this.centralLatitude = centralLatitude;
this.centralLongitude = centralLongitude;
this.centralAltitude = centralAltitude;
this.utcOffset = utcOffset;
this.magneticVariation = magneticVariation;
}
public int getRegattaID() {
return regattaID;
}
public void setRegattaID(int ID) {
this.regattaID = ID;
}
public String getRegattaName() {
return RegattaName;
}
public void setRegattaName(String regattaName) {
RegattaName = regattaName;
}
public int getRaceID() {
return raceID;
}
public void setRaceID(int raceID) {
this.raceID = raceID;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public double getCentralLatitude() {
return centralLatitude;
}
public void setCentralLatitude(double centralLatitude) {
this.centralLatitude = centralLatitude;
}
public double getCentralLongitude() {
return centralLongitude;
}
public void setCentralLongitude(double centralLongitude) {
this.centralLongitude = centralLongitude;
}
public double getCentralAltitude() {
return centralAltitude;
}
public void setCentralAltitude(double centralAltitude) {
this.centralAltitude = centralAltitude;
}
public float getUtcOffset() {
return utcOffset;
}
public void setUtcOffset(float utcOffset) {
this.utcOffset = utcOffset;
}
public float getMagneticVariation() {
return magneticVariation;
}
public void setMagneticVariation(float magneticVariation) {
this.magneticVariation = magneticVariation;
}
}