Integrated changes from story33-estimateTime branch

- Used refactored bearing methods
- Sent accurate current time to visualiser

#story[875]
main
cbt24 9 years ago
parent 5f23f335e5
commit b58c3b98ed

@ -30,7 +30,7 @@ public class Constants {
/**
* The race pre-start time, in milliseconds. 3 minutes.
*/
public static final long RacePreStartTime = 3 * 60 * 1000;
public static final long RacePreStartTime = 1 * 60 * 1000;
/**

@ -109,9 +109,9 @@ public class MockOutput implements Runnable
* @param heading heading of boat
* @param speed speed of boat
*/
public synchronized void parseBoatLocation(int sourceID, double lat, double lon, double heading, double speed){
public synchronized void parseBoatLocation(int sourceID, double lat, double lon, double heading, double speed, long time){
BoatLocation boatLocation = new BoatLocation(sourceID, lat, lon, boatLocationSequenceNumber, heading, speed);
BoatLocation boatLocation = new BoatLocation(sourceID, lat, lon, boatLocationSequenceNumber, heading, speed, time);
//iterates the sequence number
boatLocationSequenceNumber++;

@ -81,6 +81,8 @@ public class Boat {
*/
private long timeSinceTackChange = 0;
private long estimatedTime = 0;
/**
* Constructs a boat object with a given sourceID, name, country/team abbreviation, and polars table.
@ -442,4 +444,11 @@ public class Boat {
return distanceTravelledMeters;
}
public long getEstimatedTime() {
return estimatedTime;
}
public void setEstimatedTime(long estimatedTime) {
this.estimatedTime = estimatedTime;
}
}

@ -18,6 +18,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Random;
import static java.lang.Math.cos;
/**
* Represents a yacht race.
@ -173,7 +175,7 @@ public class Race implements Runnable {
*/
private void parseIndividualMark(Mark mark) {
this.mockOutput.parseBoatLocation(mark.getSourceID(), mark.getPosition().getLatitude(), mark.getPosition().getLongitude(),0,0);
this.mockOutput.parseBoatLocation(mark.getSourceID(), mark.getPosition().getLatitude(), mark.getPosition().getLongitude(),0,0, totalTimeElapsed+startTime);
}
@ -202,7 +204,8 @@ public class Race implements Runnable {
boat.getCurrentPosition().getLatitude(),
boat.getCurrentPosition().getLongitude(),
boat.getBearing().degrees(),
boat.getCurrentSpeed()
boat.getCurrentSpeed(),
startTime + totalTimeElapsed
);
}
@ -253,7 +256,7 @@ public class Race implements Runnable {
//Add each boat status to the status list.
for (Boat boat : boats) {
BoatStatus boatStatus = new BoatStatus(boat.getSourceID(), boat.getStatus(), boat.getCurrentLeg().getLegNumber());
BoatStatus boatStatus = new BoatStatus(boat.getSourceID(), boat.getStatus(), boat.getCurrentLeg().getLegNumber(), boat.getEstimatedTime());
boatStatuses.add(boatStatus);
}
@ -625,7 +628,7 @@ public class Race implements Runnable {
//Check the boats position (update leg and stuff).
this.checkPosition(boat, totalTimeElapsed);
this.updateEstimatedTime(boat);
}
}
@ -899,4 +902,16 @@ public class Race implements Runnable {
protected int getWind(){
return windDir;
}
/**
* Updates the boat's estimated time to next mark if positive
* @param boat to estimate time given its velocity
*/
private void updateEstimatedTime(Boat boat) {
double velocityToMark = boat.getCurrentSpeed() * cos(boat.getBearing().radians() - boat.calculateBearingToNextMarker().radians()) / Constants.KnotsToMMPerSecond;
if (velocityToMark > 0) {
long timeFromNow = (long)(1000*boat.calculateDistanceToNextMarker()/velocityToMark);
boat.setEstimatedTime(startTime + totalTimeElapsed + timeFromNow);
}
}
}

@ -57,7 +57,7 @@ public class RaceTest{
Race testRace = new Race(raceDataSource, mockOutput);
testRace.initialiseBoats();
testRace.countdownTimer.handle(1);
verify(mockOutput, atLeast(boatDataSource.getBoats().size())).parseBoatLocation(anyInt(), anyDouble(), anyDouble(), anyDouble(), anyDouble());
verify(mockOutput, atLeast(boatDataSource.getBoats().size())).parseBoatLocation(anyInt(), anyDouble(), anyDouble(), anyDouble(), anyDouble(), anyLong());
} catch (ParserConfigurationException | IOException | SAXException | ParseException | StreamedCourseXMLException e) {
e.printStackTrace();

@ -152,11 +152,11 @@ public class BoatLocation extends AC35Data {
this.rudderAngle = rudderAngle;
}
public BoatLocation(int sourceID, double lat, double lon, long sequenceNumber, double heading, double boatSpeed) {
public BoatLocation(int sourceID, double lat, double lon, long sequenceNumber, double heading, double boatSpeed, long time) {
super(MessageType.BOATLOCATION);
this.messageVersionNumber = (byte) 1;
this.time = System.currentTimeMillis();
this.time = time;
this.sourceID = sourceID;
this.sequenceNumber = sequenceNumber;
this.deviceType = 1;

@ -27,14 +27,14 @@ public class BoatStatus {
}
public BoatStatus(int sourceID, BoatStatusEnum boatStatusEnum, int legNum) {
public BoatStatus(int sourceID, BoatStatusEnum boatStatusEnum, int legNum, long estTimeAtNextMark) {
this.sourceID = sourceID;
this.boatStatus = boatStatusEnum.getValue();
this.legNumber = ByteConverter.intToBytes(legNum)[0];
this.numPenaltiesAwarded = 0;
this.numPenaltiesServed = 0;
this.estTimeAtFinish = 0;
this.estTimeAtNextMark = 0;
this.estTimeAtNextMark = estTimeAtNextMark;
}

Loading…
Cancel
Save