added the forwarding of the StopTracking event from TracTrac

added a new property to the TrackedRace to keep the StopTracking timepoint
This commit is contained in:
fmittag
2012-03-27 13:54:20 +02:00
parent 61d0c68a61
commit a9f9a728fe
10 changed files with 104 additions and 36 deletions
@@ -508,7 +508,25 @@ public class MockedTrackedRace implements DynamicTrackedRace {
}
@Override
public void setStartOfTracking(TimePoint startOfTracking) {
public TimePoint getEndOfTracking() {
// TODO Auto-generated method stub
return null;
}
@Override
public TimePoint getTimePointOfOldestEvent() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setStartOfTrackingReceived(TimePoint startOfTrackingReceived) {
// TODO Auto-generated method stub
}
@Override
public void setEndOfTrackingReceived(TimePoint endOfTrackingReceived) {
// TODO Auto-generated method stub
}
@@ -61,11 +61,17 @@ public class RaceStartedAndFinishedReceiver extends AbstractReceiverWithQueue<Ra
System.out.print("StartStop");
DynamicTrackedRace trackedRace = getTrackedRace(event.getA());
if (trackedRace != null) {
MillisecondsTimePoint start = new MillisecondsTimePoint(event.getB().getStartTime());
if (trackedRace.getStart() == null || !trackedRace.getStart().equals(start)) {
trackedRace.setStartOfTracking(start);
StartStopTimesData startStopTimesData = event.getB();
if(startStopTimesData != null) {
if(startStopTimesData.getStartTime() > 0) {
MillisecondsTimePoint startOfTracking = new MillisecondsTimePoint(startStopTimesData.getStartTime());
trackedRace.setStartOfTrackingReceived(startOfTracking);
}
if(startStopTimesData.getStopTime() > 0) {
MillisecondsTimePoint endOfTracking = new MillisecondsTimePoint(startStopTimesData.getStopTime());
trackedRace.setEndOfTrackingReceived(endOfTracking);
}
}
// TODO forward race stop time, event.getB().getStopTime()
} else {
logger.warning("Couldn't find tracked race for race " + event.getA().getName()
+ ". Dropping start/stop event " + event);
@@ -39,7 +39,9 @@ public interface DynamicTrackedRace extends TrackedRace {
*/
void setStartTimeReceived(TimePoint start);
void setStartOfTracking(TimePoint startOfTracking);
void setStartOfTrackingReceived(TimePoint startOfTrackingReceived);
void setEndOfTrackingReceived(TimePoint endOfTrackingReceived);
void setMillisecondsOverWhichToAverageSpeed(long millisecondsOverWhichToAverageSpeed);
@@ -215,12 +215,20 @@ public interface TrackedRace {
TimePoint getStartOfTracking();
TimePoint getEndOfTracking();
/**
* Regardless of the order in which events were received, this method returns the latest time point contained by any of
* the events received and processed.
*/
TimePoint getTimePointOfNewestEvent();
/**
* Regardless of the order in which events were received, this method returns the oldest time point contained by any of
* the events received and processed.
*/
TimePoint getTimePointOfOldestEvent();
/**
* @return the mark passings for <code>competitor</code> in this race received so far; the mark passing objects are
* returned such that their {@link MarkPassing#getWaypoint() waypoints} are ordered in the same way they are ordered
@@ -299,8 +299,13 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
}
@Override
public void setStartOfTracking(TimePoint startOfTracking) {
super.setStartOfTracking(startOfTracking);
public void setStartOfTrackingReceived(TimePoint startOfTrackingReceived) {
super.setStartOfTrackingReceived(startOfTrackingReceived);
}
@Override
public void setEndOfTrackingReceived(TimePoint endOfTrackingReceived) {
super.setEndOfTrackingReceived(endOfTrackingReceived);
}
/**
@@ -106,7 +106,17 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
* Keeps the oldest timestamp that is fed into this tracked race, either from a boat fix, a buoy fix, a race
* start/finish or a coarse definition.
*/
private TimePoint startOfTracking;
private TimePoint timePointOfOldestEvent;
/**
* The start of tracking time as announced by the tracking infrastructure.
*/
private TimePoint startOfTrackingReceived;
/**
* The end of tracking time as announced by the tracking infrastructure.
*/
private TimePoint endOfTrackingReceived;
/**
* Race start time as announced by the tracking infrastructure
@@ -252,7 +262,12 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
@Override
public TimePoint getStartOfTracking() {
return startOfTracking;
return startOfTrackingReceived;
}
@Override
public TimePoint getEndOfTracking() {
return endOfTrackingReceived;
}
@Override
@@ -712,6 +727,11 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
return result;
}
@Override
public TimePoint getTimePointOfOldestEvent() {
return timePointOfOldestEvent;
}
@Override
public TimePoint getTimePointOfNewestEvent() {
return timePointOfNewestEvent;
@@ -733,18 +753,22 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
if (timePointOfNewestEvent == null || timePointOfNewestEvent.compareTo(timeOfEvent) < 0) {
timePointOfNewestEvent = timeOfEvent;
}
if (getStartOfTracking() == null || getStartOfTracking().compareTo(timeOfEvent) > 0) {
setStartOfTracking(timeOfEvent);
if (timePointOfOldestEvent == null || timePointOfOldestEvent.compareTo(timeOfEvent) > 0) {
timePointOfOldestEvent = timeOfEvent;
}
timePointOfLastEvent = timeOfEvent;
}
notifyAll();
}
protected void setStartOfTracking(TimePoint startOfTracking) {
this.startOfTracking = startOfTracking;
protected void setStartOfTrackingReceived(TimePoint startOfTracking) {
this.startOfTrackingReceived = startOfTracking;
}
protected void setEndOfTrackingReceived(TimePoint endOfTracking) {
this.endOfTrackingReceived = endOfTracking;
}
/**
* Schedules the clearing of the caches. If a cache clearing is already scheduled, this is a no-op.
*/
@@ -132,9 +132,7 @@ public class RaceTimePanel extends TimePanel<RaceTimePanelSettings> implements R
}
break;
case Replay:
//TODO Merge with Franks branch for better end of race calculation
Date tempEndOfRace = newRaceTimesInfo.getLastLegTimes() != null ? newRaceTimesInfo.getLastLegTimes().firstPassingDate : newRaceTimesInfo.endOfRace;
long extensionTime = calculateRaceExtensionTime(newRaceTimesInfo.startOfRace, tempEndOfRace);
long extensionTime = calculateRaceExtensionTime(newRaceTimesInfo.startOfRace, newRaceTimesInfo.endOfRace);
if (newRaceTimesInfo.startOfRace != null) {
min = new Date(newRaceTimesInfo.startOfRace.getTime() - extensionTime);
@@ -143,7 +141,7 @@ public class RaceTimePanel extends TimePanel<RaceTimePanelSettings> implements R
}
if (newRaceTimesInfo.endOfRace != null) {
max = new Date(tempEndOfRace.getTime() + extensionTime);
max = new Date(newRaceTimesInfo.endOfRace.getTime() + extensionTime);
} else if (newRaceTimesInfo.timePointOfNewestEvent != null) {
max = newRaceTimesInfo.timePointOfNewestEvent;
}
@@ -213,10 +211,6 @@ public class RaceTimePanel extends TimePanel<RaceTimePanelSettings> implements R
}
sliderBar.redraw();
}
// the marker information is complete if we have a time for the start, the end, and all legs
// TODO: Implement this later on
// TODO (from Axel Uhl) I think the above may not be correct. The data may change at all times, even after the race. isTimeInfoComplete removed. Frank, please review.
// isTimeInfoComplete = false;
}
@Override
@@ -914,41 +914,49 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
raceTimesInfo.startOfTracking = trackedRace.getStartOfTracking() == null ? null : trackedRace.getStartOfTracking().asDate();
raceTimesInfo.timePointOfLastEvent = trackedRace.getTimePointOfLastEvent() == null ? null : trackedRace.getTimePointOfLastEvent().asDate();
raceTimesInfo.timePointOfNewestEvent = trackedRace.getTimePointOfNewestEvent() == null ? null : trackedRace.getTimePointOfNewestEvent().asDate();
raceTimesInfo.endOfTracking = trackedRace.getEndOfTracking() == null ? null : trackedRace.getEndOfTracking().asDate();
raceTimesInfo.endOfRace = trackedRace.getAssumedEnd() == null ? null : trackedRace.getAssumedEnd().asDate();
List<LegTimesInfoDTO> legTimes = new ArrayList<LegTimesInfoDTO>();
raceTimesInfo.setLegTimes(legTimes);
Iterable<TrackedLeg> trackedLegs = trackedRace.getTrackedLegs();
Date lastLegPassingTime = null;
int i = 1;
// Remark: sometimes it can happen that a mark passing with a wrong time stamp breaks the right time order of the leg times
Date lastLegPassingTime = null;
for (TrackedLeg trackedLeg : trackedLegs) {
if (i == 1) {
if (raceTimesInfo.startOfRace != null) {
// For the race start, we'd like to show the race start date as provided by TrackedRace.getStart().
// Therefore, the use of "firstPassingDate" is not exactly correct for the race start.
LegTimesInfoDTO legTimepointDTO = new LegTimesInfoDTO("S");
legTimepointDTO.firstPassingDate = raceTimesInfo.getStartOfRace();
legTimepointDTO.firstPassingDate = raceTimesInfo.startOfRace;
legTimepointDTO.lastPassingDate = raceTimesInfo.startOfRace;
legTimes.add(legTimepointDTO);
lastLegPassingTime = raceTimesInfo.getStartOfRace();
lastLegPassingTime = raceTimesInfo.startOfRace;
}
}
Waypoint to = trackedLeg.getLeg().getTo();
Iterable<MarkPassing> markPassings = trackedRace.getMarkPassingsInOrder(to);
if (markPassings != null) {
if (markPassings != null && Util.size(markPassings) > 0) {
// ensure the passing date is in the right time order; there may perhaps be left-overs for marks to be reached later that
// claim it has been passed in the past which may have been an accidental tracker read-out;
// the results of getMarkPassingsInOrder(to) has by definition an ascending time-point ordering
synchronized (markPassings) {
boolean isFirstValidPassing = true;
LegTimesInfoDTO legTimepointDTO = new LegTimesInfoDTO("L" + i++);
for (MarkPassing currentMarkPassing : markPassings) {
Date currentPassingDate = currentMarkPassing.getTimePoint().asDate();
if (lastLegPassingTime == null) {
lastLegPassingTime = currentPassingDate;
}
if (currentPassingDate.after(lastLegPassingTime)) {
LegTimesInfoDTO legTimepointDTO = new LegTimesInfoDTO("L" + i++);
legTimepointDTO.firstPassingDate = currentPassingDate;
legTimes.add(legTimepointDTO);
lastLegPassingTime = currentPassingDate;
break;
if(lastLegPassingTime == null || currentPassingDate.after(lastLegPassingTime)) {
if(isFirstValidPassing) {
legTimes.add(legTimepointDTO);
legTimepointDTO.firstPassingDate = currentPassingDate;
legTimepointDTO.lastPassingDate = currentPassingDate;
lastLegPassingTime = currentPassingDate;
isFirstValidPassing = false;
} else {
if (currentPassingDate.after(legTimepointDTO.lastPassingDate)) {
legTimepointDTO.lastPassingDate = currentPassingDate;
}
}
}
}
}
@@ -12,6 +12,8 @@ public class LegTimesInfoDTO extends NamedDTO implements IsSerializable {
*/
public Date firstPassingDate;
public Date lastPassingDate;
public LegTimesInfoDTO() {}
public LegTimesInfoDTO(String name) {
@@ -14,6 +14,7 @@ public class RaceTimesInfoDTO implements IsSerializable {
public Date startOfRace;
public Date startOfTracking;
public Date endOfTracking;
public Date endOfRace;
public Date timePointOfLastEvent;