fixed live time for getQuickRanks(); added several null checks for cases where competitors haven't started their legs yet

This commit is contained in:
Axel Uhl committed 2015-05-29 14:17:58 +02:00
1 parent 1a6663af45
commit 0dbfaba524
4 files changed
+32 -23

No files matched your search

@@ -161,13 +161,17 @@ public abstract class AbstractRankingMetric implements RankingMetric {
final Duration result;
final TrackedLegOfCompetitor tloc = getTrackedRace().getTrackedLeg(competitor, getTimePoint());
final Duration raceDurationAtTimePoint = getTrackedRace().getStartOfRace().until(getTimePoint());
if (tloc.hasStartedLeg(getTimePoint())) {
if (tloc != null && tloc.hasStartedLeg(getTimePoint())) {
final Competitor competitorFarthestAheadInLeg = getCompetitorFarthestAheadInLeg(leg, getTimePoint(), cache);
final TrackedLegOfCompetitor tlocOfCompetitorFarthestAheadInLeg = tloc.getTrackedLeg().getTrackedLeg(competitorFarthestAheadInLeg);
final Duration predictedDurationFromTimePointToReachFarthestAheadInLeg = getPredictedDurationToReachWindwardPositionOf(
tloc, tlocOfCompetitorFarthestAheadInLeg, getTimePoint(), cache);
final Duration cDurationFromRaceStartToReachFarthestInLeg = raceDurationAtTimePoint.plus(predictedDurationFromTimePointToReachFarthestAheadInLeg);
result = cDurationFromRaceStartToReachFarthestInLeg;
if (predictedDurationFromTimePointToReachFarthestAheadInLeg == null) {
result = null;
} else {
final Duration cDurationFromRaceStartToReachFarthestInLeg = raceDurationAtTimePoint.plus(predictedDurationFromTimePointToReachFarthestAheadInLeg);
result = cDurationFromRaceStartToReachFarthestInLeg;
}
} else {
result = null;
}
@@ -325,19 +325,23 @@ public class TimeOnTimeAndDistanceRankingMetric extends AbstractRankingMetric {
result = null;
} else {
final Competitor farthestAheadOrEarliestLegFinisher = getCompetitorFarthestAheadInLeg(trackedLegOfCompetitor.getTrackedLeg(), timePoint, cache);
final TrackedLegOfCompetitor tlocOfFarthestAhead = trackedLegOfCompetitor.getTrackedLeg().getTrackedLeg(farthestAheadOrEarliestLegFinisher);
final boolean farthestAheadAlreadyFinishedLeg = tlocOfFarthestAhead.hasFinishedLeg(timePoint);
final Distance windwardDistanceFarthestTraveledUntilFinishingLeg = getWindwardDistanceTraveled(farthestAheadOrEarliestLegFinisher,
farthestAheadAlreadyFinishedLeg ? tlocOfFarthestAhead.getFinishTime() : timePoint, cache);
// Consider all competitors, regardless of whether they have started the leg or not; a competitor in a previous
// leg may well be the race leader. However, if a competitor has finished the leg already, use the finishing time
// point for that competitor.
// leader in the leg is now the competitor with the least corrected time to reach the competitor farthest ahead in the leg
final Competitor legLeader = rankingInfo.getLeaderInLegByCalculatedTime(trackedLegOfCompetitor.getTrackedLeg().getLeg(), cache);
result = getGapToCompetitorInOwnTime(trackedLegOfCompetitor.getCompetitor(), legLeader,
rankingInfo.getActualTimeFromRaceStartToReachFarthestAheadInLeg(trackedLegOfCompetitor.getCompetitor(), leg, cache),
rankingInfo.getActualTimeFromRaceStartToReachFarthestAheadInLeg(legLeader, leg, cache),
windwardDistanceFarthestTraveledUntilFinishingLeg);
if (farthestAheadOrEarliestLegFinisher == null) {
result = null;
} else {
final TrackedLegOfCompetitor tlocOfFarthestAhead = trackedLegOfCompetitor.getTrackedLeg().getTrackedLeg(farthestAheadOrEarliestLegFinisher);
final boolean farthestAheadAlreadyFinishedLeg = tlocOfFarthestAhead.hasFinishedLeg(timePoint);
final Distance windwardDistanceFarthestTraveledUntilFinishingLeg = getWindwardDistanceTraveled(farthestAheadOrEarliestLegFinisher,
farthestAheadAlreadyFinishedLeg ? tlocOfFarthestAhead.getFinishTime() : timePoint, cache);
// Consider all competitors, regardless of whether they have started the leg or not; a competitor in a previous
// leg may well be the race leader. However, if a competitor has finished the leg already, use the finishing time
// point for that competitor.
// leader in the leg is now the competitor with the least corrected time to reach the competitor farthest ahead in the leg
final Competitor legLeader = rankingInfo.getLeaderInLegByCalculatedTime(trackedLegOfCompetitor.getTrackedLeg().getLeg(), cache);
result = getGapToCompetitorInOwnTime(trackedLegOfCompetitor.getCompetitor(), legLeader,
rankingInfo.getActualTimeFromRaceStartToReachFarthestAheadInLeg(trackedLegOfCompetitor.getCompetitor(), leg, cache),
rankingInfo.getActualTimeFromRaceStartToReachFarthestAheadInLeg(legLeader, leg, cache),
windwardDistanceFarthestTraveledUntilFinishingLeg);
}
}
return result;
}
@@ -2055,7 +2055,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
rank++;
}
final Iterable<Competitor> competitorsInOrderOfWindwardDistanceTraveledFarthestFirst = getService().getCompetitorInOrderOfWindwardDistanceTraveledFarthestFirst(trackedRace, timePoint);
final Iterable<Competitor> competitorsInOrderOfWindwardDistanceTraveledFarthestFirst = getService()
.getCompetitorInOrderOfWindwardDistanceTraveledFarthestFirst(trackedRace, actualTimePoint);
competitorDTOsInOrderOfWindwardDistanceTraveledFarthestFirst = convertToCompetitorDTOs(competitorsInOrderOfWindwardDistanceTraveledFarthestFirst);
} else {
competitorDTOsInOrderOfWindwardDistanceTraveledFarthestFirst = Collections.emptyList();
@@ -39,6 +39,7 @@ public class CompactRaceMapDataDTO implements IsSerializable {
this.boatPositionsByCompetitorIdAsString.put(e.getKey().getIdAsString(), e.getValue());
}
this.quickRanks = new ArrayList<CompactQuickRankDTO>(quickRanks == null ? 0 : Util.size(quickRanks.getQuickRanks()));
this.competitorsInOrderOfWindwardDistanceTraveledFarthestFirstIdAsStringAndOneBasedLegNumber = new LinkedHashMap<>();
Map<String, Integer> competitorIdAsStringToOneBasedLegNumber = new HashMap<>();
if (quickRanks != null) {
for (QuickRankDTO quickRank : quickRanks.getQuickRanks()) {
@@ -46,12 +47,11 @@ public class CompactRaceMapDataDTO implements IsSerializable {
quickRank.legNumberOneBased));
competitorIdAsStringToOneBasedLegNumber.put(quickRank.competitor.getIdAsString(), quickRank.legNumberOneBased);
}
}
this.competitorsInOrderOfWindwardDistanceTraveledFarthestFirstIdAsStringAndOneBasedLegNumber = new LinkedHashMap<>();
for (CompetitorDTO competitorInOrderOfWindwardDistanceTraveled : quickRanks.getCompetitorsInOrderOfWindwardDistanceTraveledFarthestFirst()) {
this.competitorsInOrderOfWindwardDistanceTraveledFarthestFirstIdAsStringAndOneBasedLegNumber.put(
competitorInOrderOfWindwardDistanceTraveled.getIdAsString(),
competitorIdAsStringToOneBasedLegNumber.get(competitorInOrderOfWindwardDistanceTraveled.getIdAsString()));
for (CompetitorDTO competitorInOrderOfWindwardDistanceTraveled : quickRanks.getCompetitorsInOrderOfWindwardDistanceTraveledFarthestFirst()) {
this.competitorsInOrderOfWindwardDistanceTraveledFarthestFirstIdAsStringAndOneBasedLegNumber.put(
competitorInOrderOfWindwardDistanceTraveled.getIdAsString(),
competitorIdAsStringToOneBasedLegNumber.get(competitorInOrderOfWindwardDistanceTraveled.getIdAsString()));
}
}
this.courseSidelines = courseSidelines;
this.coursePositions = coursePositions;