diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/ranking/RankingMetric.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/ranking/RankingMetric.java
index f011e15bf36..982742d03d5 100755
--- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/ranking/RankingMetric.java
+++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/ranking/RankingMetric.java
@@ -5,6 +5,7 @@ import java.util.Comparator;
import java.util.function.Function;
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.leaderboard.caching.LeaderboardDTOCalculationReuseCache;
import com.sap.sailing.domain.tracking.TrackedLeg;
@@ -112,6 +113,16 @@ public interface RankingMetric extends Serializable {
* position at {@link #timePoint}.
*/
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 leg.
+ * 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 {
diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/ranking/TimeOnTimeAndDistanceRankingMetric.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/ranking/TimeOnTimeAndDistanceRankingMetric.java
index f1af3d5cc29..909b01ee045 100755
--- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/ranking/TimeOnTimeAndDistanceRankingMetric.java
+++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/ranking/TimeOnTimeAndDistanceRankingMetric.java
@@ -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
Comparator 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();
- result = getGapToCompetitorInOwnTime(trackedLegOfCompetitor.getCompetitor(), leader,
+ result = getGapToCompetitorInOwnTime(trackedLegOfCompetitor.getCompetitor(), legLeader,
actualTimeFromRaceStartToReachFarthestAheadInLeg.get(trackedLegOfCompetitor.getCompetitor()),
- actualTimeFromRaceStartToReachFarthestAheadInLeg.get(leader),
+ actualTimeFromRaceStartToReachFarthestAheadInLeg.get(legLeader),
windwardDistanceFarthestTraveledUntilFinishingLeg);
}
return result;
diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalike/BaseRegattaLikeImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalike/BaseRegattaLikeImpl.java
index f5fb55a1948..7dbef9f0c15 100644
--- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalike/BaseRegattaLikeImpl.java
+++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalike/BaseRegattaLikeImpl.java
@@ -64,7 +64,12 @@ public class BaseRegattaLikeImpl implements IsRegattaLike {
final Double timeOnTimeFactorFromRegattaLog = getTimeOnTimeFactorFromRegattaLog(competitor);
final Double result;
if (timeOnTimeFactorFromRegattaLog == null) {
- result = competitor.getTimeOnTimeFactor();
+ final Double competitorTimeOnTimeFactorDefault = competitor.getTimeOnTimeFactor();
+ if (competitorTimeOnTimeFactorDefault == null) {
+ result = 1.0;
+ } else {
+ result = competitorTimeOnTimeFactorDefault;
+ }
} else {
result = timeOnTimeFactorFromRegattaLog;
}
@@ -76,7 +81,12 @@ public class BaseRegattaLikeImpl implements IsRegattaLike {
final Duration timeOnDistanceAllowancePerNauticalMileFromRegattaLog = getTimeOnDistanceAllowancePerNauticalMileFromRegattaLog(competitor);
final Duration result;
if (timeOnDistanceAllowancePerNauticalMileFromRegattaLog == null) {
- result = competitor.getTimeOnDistanceAllowancePerNauticalMile();
+ final Duration competitorAllowanceDefault = competitor.getTimeOnDistanceAllowancePerNauticalMile();
+ if (competitorAllowanceDefault == null) {
+ result = Duration.NULL;
+ } else {
+ result = competitorAllowanceDefault;
+ }
} else {
result = timeOnDistanceAllowancePerNauticalMileFromRegattaLog;
}