mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-08 05:11:04 +00:00
working towards a solution for bug 2923 by centralizing the fetching of competitors for the ranking metric; however, we don't have the leaderboard available where we need it
This commit is contained in:
1 parent
d7a3fca6eb
commit
65776efe1d
2 files changed
+15
-8
No files matched your search
+14
-7
@@ -285,7 +285,7 @@ public abstract class AbstractRankingMetric implements RankingMetric {
|
||||
*/
|
||||
private Comparator<Competitor> getWindwardDistanceTraveledComparator(final TimePoint timePoint, final WindLegTypeAndLegBearingCache cache) {
|
||||
final Map<Competitor, Distance> windwardDistanceTraveledPerCompetitor = new HashMap<>();
|
||||
for (final Competitor competitor : getTrackedRace().getRace().getCompetitors()) {
|
||||
for (final Competitor competitor : getCompetitors()) {
|
||||
windwardDistanceTraveledPerCompetitor.put(competitor, getWindwardDistanceTraveled(competitor, timePoint, cache));
|
||||
}
|
||||
final Comparator<Distance> nullsFirstDistanceComparator = Comparator.nullsFirst(Comparator.naturalOrder());
|
||||
@@ -293,12 +293,19 @@ public abstract class AbstractRankingMetric implements RankingMetric {
|
||||
windwardDistanceTraveledPerCompetitor.get(c2),
|
||||
windwardDistanceTraveledPerCompetitor.get(c1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the competitors to consider for this ranking
|
||||
*/
|
||||
protected Iterable<Competitor> getCompetitors() {
|
||||
return getTrackedRace().getRace().getCompetitors();
|
||||
}
|
||||
|
||||
public RankingMetric.RankingInfo getRankingInfo(TimePoint timePoint, WindLegTypeAndLegBearingCache cache) {
|
||||
Map<Competitor, RankingMetric.CompetitorRankingInfo> result = new HashMap<>();
|
||||
Comparator<Competitor> oneDesignComparator = getWindwardDistanceTraveledComparator(timePoint, cache);
|
||||
Competitor competitorFarthestAhead = StreamSupport
|
||||
.stream(getTrackedRace().getRace().getCompetitors().spliterator(), /* parallel */true).
|
||||
.stream(getCompetitors().spliterator(), /* parallel */true).
|
||||
sorted(oneDesignComparator).findFirst().get();
|
||||
final Distance totalWindwardDistanceTraveled = getWindwardDistanceTraveled(competitorFarthestAhead, timePoint, cache);
|
||||
final TimePoint startOfRace = getTrackedRace().getStartOfRace();
|
||||
@@ -307,12 +314,12 @@ public abstract class AbstractRankingMetric implements RankingMetric {
|
||||
actualRaceDuration = null;
|
||||
} else {
|
||||
actualRaceDuration = startOfRace.until(timePoint);
|
||||
for (Competitor competitor : getTrackedRace().getRace().getCompetitors()) {
|
||||
for (Competitor competitor : getCompetitors()) {
|
||||
final Duration predictedDurationToReachWindwardPositionOfCompetitorFarthestAhead = getPredictedDurationToReachWindwardPositionOf(
|
||||
competitor, competitorFarthestAhead, timePoint, cache);
|
||||
final Duration totalEstimatedDurationSinceRaceStartToCompetitorFarthestAhead = predictedDurationToReachWindwardPositionOfCompetitorFarthestAhead == null ? null
|
||||
: actualRaceDuration.plus(predictedDurationToReachWindwardPositionOfCompetitorFarthestAhead);
|
||||
final Duration correctedEstimatedTimeWhenReachingCompetitorFarthestAhead = totalEstimatedDurationSinceRaceStartToCompetitorFarthestAhead == null ? null
|
||||
final Duration calculatedEstimatedTimeWhenReachingCompetitorFarthestAhead = totalEstimatedDurationSinceRaceStartToCompetitorFarthestAhead == null ? null
|
||||
: getCalculatedTime(
|
||||
competitor,
|
||||
() -> getTrackedRace().getTrackedLeg(competitorFarthestAhead, timePoint).getLeg(),
|
||||
@@ -320,14 +327,14 @@ public abstract class AbstractRankingMetric implements RankingMetric {
|
||||
timePoint, /* extrapolate */true),
|
||||
totalEstimatedDurationSinceRaceStartToCompetitorFarthestAhead,
|
||||
totalWindwardDistanceTraveled);
|
||||
final Duration correctedTime = getCalculatedTime(competitor,
|
||||
final Duration calculatedTime = getCalculatedTime(competitor,
|
||||
() -> getTrackedRace().getCurrentLeg(competitor, timePoint).getLeg(), () -> getTrackedRace()
|
||||
.getTrack(competitor).getEstimatedPosition(timePoint, /* extrapolated */true),
|
||||
actualRaceDuration, totalWindwardDistanceTraveled);
|
||||
RankingMetric.CompetitorRankingInfo rankingInfo = new CompetitorRankingInfoImpl(timePoint, competitor,
|
||||
getWindwardDistanceTraveled(competitor, timePoint, cache), actualRaceDuration, correctedTime,
|
||||
getWindwardDistanceTraveled(competitor, timePoint, cache), actualRaceDuration, calculatedTime,
|
||||
predictedDurationToReachWindwardPositionOfCompetitorFarthestAhead,
|
||||
correctedEstimatedTimeWhenReachingCompetitorFarthestAhead);
|
||||
calculatedEstimatedTimeWhenReachingCompetitorFarthestAhead);
|
||||
result.put(competitor, rankingInfo);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -137,7 +137,7 @@ public class TimeOnTimeAndDistanceRankingMetric extends AbstractRankingMetric {
|
||||
totalWindwardDistanceLegLeaderTraveledUpToTimePointOrLegEnd = getWindwardDistanceTraveled(
|
||||
fastestCompetitorInLeg, timePoint, cache);
|
||||
}
|
||||
for (Competitor competitor : getTrackedRace().getRace().getCompetitors()) {
|
||||
for (Competitor competitor : getCompetitors()) {
|
||||
final TrackedLegOfCompetitor competitorLeg = trackedLeg.getTrackedLeg(competitor);
|
||||
final Duration correctedTime;
|
||||
if (competitorLeg != null && competitorLeg.hasStartedLeg(timePoint)) {
|
||||
|
||||
Reference in new issue
Block a user