default time-on-time and time-on-distance values to 1.0 / 0.0, respectively, in BaseRegattaLinkImpl

This commit is contained in:
Axel Uhl committed 2015-05-28 11:41:45 +02:00
1 parent 82757a685c
commit 30a3b66c53
3 files changed
+27 -5

No files matched your search

@@ -5,6 +5,7 @@ import java.util.Comparator;
import java.util.function.Function; import java.util.function.Function;
import com.sap.sailing.domain.base.Competitor; import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.Leg;
import com.sap.sailing.domain.common.Distance; import com.sap.sailing.domain.common.Distance;
import com.sap.sailing.domain.leaderboard.caching.LeaderboardDTOCalculationReuseCache; import com.sap.sailing.domain.leaderboard.caching.LeaderboardDTOCalculationReuseCache;
import com.sap.sailing.domain.tracking.TrackedLeg; import com.sap.sailing.domain.tracking.TrackedLeg;
@@ -112,6 +113,16 @@ public interface RankingMetric extends Serializable {
* position at {@link #timePoint}. * position at {@link #timePoint}.
*/ */
Competitor getLeaderByCorrectedEstimatedTimeToCompetitorFarthestAhead(); Competitor getLeaderByCorrectedEstimatedTimeToCompetitorFarthestAhead();
/**
* Similar to {@link #getLeaderByCorrectedEstimatedTimeToCompetitorFarthestAhead()}, but relative to a
* {@link Leg}. This will not consider any progress or position beyond the finishing of that <code>leg</code>.
* Instead, for those competitors who have already finished the leg, their
* {@link TrackedLegOfCompetitor#getFinishTime() finishing time} for the leg is used, and the distance traveled
* is normalized to the {@link TrackedLeg#getWindwardDistance() windward distance of the leg} at the
* {@link TrackedLeg#getReferenceTimePoint() reference time point}.
*/
Competitor getLeaderInLegByCalculatedTime(Leg leg);
} }
public interface LegRankingInfo extends Timed, Serializable { public interface LegRankingInfo extends Timed, Serializable {
@@ -414,11 +414,12 @@ public class TimeOnTimeAndDistanceRankingMetric extends AbstractRankingMetric {
} }
// leader in the leg is now the competitor with the least corrected time to reach the competitor farthest ahead in the leg // leader in the leg is now the competitor with the least corrected time to reach the competitor farthest ahead in the leg
Comparator<Duration> durationComparatorNullsLast = Comparator.nullsLast(Comparator.naturalOrder()); Comparator<Duration> durationComparatorNullsLast = Comparator.nullsLast(Comparator.naturalOrder());
final Competitor leader = correctedTimeToReachFarthestAheadInLeg.entrySet().stream() final Competitor legLeader = rankingInfo.getLeaderInLegByCalculatedTime(trackedLegOfCompetitor.getTrackedLeg().getLeg());
final Competitor legLeader = correctedTimeToReachFarthestAheadInLeg.entrySet().stream()
.sorted((e1, e2) -> durationComparatorNullsLast.compare(e1.getValue(), e2.getValue())).findFirst().get().getKey(); .sorted((e1, e2) -> durationComparatorNullsLast.compare(e1.getValue(), e2.getValue())).findFirst().get().getKey();
result = getGapToCompetitorInOwnTime(trackedLegOfCompetitor.getCompetitor(), leader, result = getGapToCompetitorInOwnTime(trackedLegOfCompetitor.getCompetitor(), legLeader,
actualTimeFromRaceStartToReachFarthestAheadInLeg.get(trackedLegOfCompetitor.getCompetitor()), actualTimeFromRaceStartToReachFarthestAheadInLeg.get(trackedLegOfCompetitor.getCompetitor()),
actualTimeFromRaceStartToReachFarthestAheadInLeg.get(leader), actualTimeFromRaceStartToReachFarthestAheadInLeg.get(legLeader),
windwardDistanceFarthestTraveledUntilFinishingLeg); windwardDistanceFarthestTraveledUntilFinishingLeg);
} }
return result; return result;
@@ -64,7 +64,12 @@ public class BaseRegattaLikeImpl implements IsRegattaLike {
final Double timeOnTimeFactorFromRegattaLog = getTimeOnTimeFactorFromRegattaLog(competitor); final Double timeOnTimeFactorFromRegattaLog = getTimeOnTimeFactorFromRegattaLog(competitor);
final Double result; final Double result;
if (timeOnTimeFactorFromRegattaLog == null) { if (timeOnTimeFactorFromRegattaLog == null) {
result = competitor.getTimeOnTimeFactor(); final Double competitorTimeOnTimeFactorDefault = competitor.getTimeOnTimeFactor();
if (competitorTimeOnTimeFactorDefault == null) {
result = 1.0;
} else {
result = competitorTimeOnTimeFactorDefault;
}
} else { } else {
result = timeOnTimeFactorFromRegattaLog; result = timeOnTimeFactorFromRegattaLog;
} }
@@ -76,7 +81,12 @@ public class BaseRegattaLikeImpl implements IsRegattaLike {
final Duration timeOnDistanceAllowancePerNauticalMileFromRegattaLog = getTimeOnDistanceAllowancePerNauticalMileFromRegattaLog(competitor); final Duration timeOnDistanceAllowancePerNauticalMileFromRegattaLog = getTimeOnDistanceAllowancePerNauticalMileFromRegattaLog(competitor);
final Duration result; final Duration result;
if (timeOnDistanceAllowancePerNauticalMileFromRegattaLog == null) { if (timeOnDistanceAllowancePerNauticalMileFromRegattaLog == null) {
result = competitor.getTimeOnDistanceAllowancePerNauticalMile(); final Duration competitorAllowanceDefault = competitor.getTimeOnDistanceAllowancePerNauticalMile();
if (competitorAllowanceDefault == null) {
result = Duration.NULL;
} else {
result = competitorAllowanceDefault;
}
} else { } else {
result = timeOnDistanceAllowancePerNauticalMileFromRegattaLog; result = timeOnDistanceAllowancePerNauticalMileFromRegattaLog;
} }