final changes

This commit is contained in:
Finn Huelsbusch committed 2022-10-31 10:23:28 +01:00
1 parent 0b3142a727
commit 6149a22fa3
6 files changed
+48 -49

No files matched your search

@@ -96,7 +96,7 @@ public interface Leaderboard extends LeaderboardBase, HasRaceColumns {
* @author I518097
*
*/
public class RankComparableRank implements RankComparable{
public class RankComparableRank implements RankComparable {
private final Integer rank;
public RankComparableRank(Integer rank) {
@@ -106,25 +106,21 @@ public interface Leaderboard extends LeaderboardBase, HasRaceColumns {
}
this.rank = rank;
}
@Override
public int compareTo(RankComparable o) {
if (o instanceof RankComparableRank) {
RankComparableRank otherRankComparableRank = (RankComparableRank) o;
if (rank == 0) {
return 1; // the other RankComparable is better because this RankComparable has not started
RankComparableRank otherRankComparableRank = (RankComparableRank) o;
final int result;
if (rank == 0) {
result = 1; // the other RankComparable is better because this RankComparable has not started
} else {
if (otherRankComparableRank.rank == 0) {
result =-1; // this RankComparable is better (lower rank) than the other one because the other one
// has not started
} else {
if (otherRankComparableRank.rank == 0) {
return -1; // this RankComparable is better (lower rank) than the other one because the other one
// has not started
} else {
return rank - otherRankComparableRank.rank; // normal integer compare
}
result = rank - otherRankComparableRank.rank; // normal integer compare
}
}else {
// error handling needed
return 0;
}
return result;
}
}
@@ -1,9 +1,7 @@
package com.sap.sailing.domain.leaderboard.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -154,20 +152,18 @@ public abstract class AbstractLeaderboardImpl extends AbstractSimpleLeaderboardI
// if on the other hand the flag is set, we first need to order the competitors after their rankComparables.
// After that we can assign scores.
if (race.hasCrossFleetMergedRanking()) {
// group fleets by their ordering in order to check if the hasCrossFleetMergedRanking has an effect or
// is irrelevant.
HashMap<Integer, List<Fleet>> fleetsByRank = new HashMap<>();
// get Fleets that are of the same order as the fleet of the competitor
List<Fleet> fleetsOfSameOrderAsCompetitorsFleet = new ArrayList<>();
int rankOfCompetitorsFleet = race.getFleetOfCompetitor(competitor).getOrdering();
for (Fleet fleet : race.getFleets()) {
if (fleetsByRank.get(fleet.getOrdering()) == null) {
fleetsByRank.put(fleet.getOrdering(), Arrays.asList(fleet));
} else {
fleetsByRank.get(fleet.getOrdering()).add(fleet);
if (fleet.getOrdering() == rankOfCompetitorsFleet) {
fleetsOfSameOrderAsCompetitorsFleet.add(fleet);
}
}
if (fleetsByRank.get(race.getFleetOfCompetitor(competitor).getOrdering()).size() > 1) {
if (fleetsOfSameOrderAsCompetitorsFleet.size() > 1) {
// more than one fleet of the same rank -> need to merge these fleets
List<CompetitorAndRankComparable> competitorsFromBestToWorstAndRankComparable = new ArrayList<>();
for (Fleet fleet : fleetsByRank.get(race.getFleetOfCompetitor(competitor).getOrdering())) {
for (Fleet fleet : fleetsOfSameOrderAsCompetitorsFleet) {
List<CompetitorAndRankComparable> currentCompetitorsAndRankcomparables = race
.getTrackedRace(fleet).getCompetitorsFromBestToWorstAndRankComparable(timePoint);
competitorsFromBestToWorstAndRankComparable.addAll(currentCompetitorsAndRankcomparables);
@@ -177,20 +173,19 @@ public abstract class AbstractLeaderboardImpl extends AbstractSimpleLeaderboardI
Collections.sort(competitorsFromBestToWorstAndRankComparable);
Iterator<Competitor> competitorsIterator = competitorsFromBestToWorstAndRankComparable.stream()
.map(v -> v.getCompetitor()).iterator();
trackedRank = improveByDisqualificationsOfBetterRankedCompetitors(competitor, race, timePoint,
competitorsIterator);
trackedRank = getRankImprovedByDisqualificationsOfBetterRankedCompetitors(competitor, race,
timePoint, competitorsIterator);
} else {
// just one fleet for the given rank -> no merge needed just use the normal behavior
trackedRank = improveByDisqualificationsOfBetterRankedCompetitors(competitor, race, timePoint,
trackedRace.getCompetitorsFromBestToWorst(timePoint, cache).iterator());
trackedRank = getRankImprovedByDisqualificationsOfBetterRankedCompetitors(competitor, race,
timePoint, trackedRace.getCompetitorsFromBestToWorst(timePoint, cache).iterator());
}
} else {
trackedRank = improveByDisqualificationsOfBetterRankedCompetitors(competitor, race, timePoint,
trackedRank = getRankImprovedByDisqualificationsOfBetterRankedCompetitors(competitor, race, timePoint,
trackedRace.getCompetitorsFromBestToWorst(timePoint, cache).iterator());
}
}
return trackedRank;
}
/**
@@ -201,25 +196,25 @@ public abstract class AbstractLeaderboardImpl extends AbstractSimpleLeaderboardI
*
* @param competitor
* the competitor whose rank is to be improved
* @param race
* @param race
* raceColumn that is used to check if a competitor is disqualified
* @param timePoint
* time point at which to consider disqualifications (not used yet because currently we don't remember
* <em>when</em> a competitor was disqualified)
* @param competitorsFromBestToWorst
* An iterator that contains all competitors through which the rank of the given competitor can be improved.
* An iterator that contains all competitors through which the rank of the given competitor can be improved.
*
* @return the unmodified <code>Pair(Rank, {@link RankComparable}</code> if no disqualifications for better-ranked competitors exist for
* <code>race</code>, or otherwise a <code>Pair(Rank, {@link RankComparable}</code> where the Rank is improved (lowered) by the number of disqualifications of
* competitors whose tracked rank is better (lower) than <code>rank</code> while the {@link RankComparable} is consistent with the new Rank.
*/
private int improveByDisqualificationsOfBetterRankedCompetitors( Competitor competitor, RaceColumn race,
private int getRankImprovedByDisqualificationsOfBetterRankedCompetitors(Competitor competitor, RaceColumn race,
TimePoint timePoint, Iterator<Competitor> competitorsFromBestToWorst) {
int rank = 1;
int numberOfDisqualificationsOfBetterRankedCompetitors = 0;
while(competitorsFromBestToWorst.hasNext()) {
int rank = 1;
int numberOfDisqualificationsOfBetterRankedCompetitors = 0;
while (competitorsFromBestToWorst.hasNext()) {
Competitor currentCompetitor = competitorsFromBestToWorst.next();
if(competitor.equals(currentCompetitor)) {
if (competitor.equals(currentCompetitor)) {
break;
}
MaxPointsReason maxPointsReasonForBetterCompetitor = getScoreCorrection()
@@ -227,11 +222,11 @@ public abstract class AbstractLeaderboardImpl extends AbstractSimpleLeaderboardI
if (isSuppressed(currentCompetitor) || (maxPointsReasonForBetterCompetitor != null
&& maxPointsReasonForBetterCompetitor != MaxPointsReason.NONE
&& maxPointsReasonForBetterCompetitor.isAdvanceCompetitorsTrackedWorse())) {
numberOfDisqualificationsOfBetterRankedCompetitors ++;
numberOfDisqualificationsOfBetterRankedCompetitors++;
}
rank++;
rank++;
}
return rank - numberOfDisqualificationsOfBetterRankedCompetitors;
return rank - numberOfDisqualificationsOfBetterRankedCompetitors;
}
// Note: no need to redefine isMedalRaceChanged because that doesn't affect the competitorsCache
@@ -22,6 +22,7 @@ public class CompetitorAndRankComparable implements Comparable<CompetitorAndRank
public RankComparable getRankComparable() {
return rankComparable;
}
public Competitor getCompetitor() {
return competitor;
}
@@ -484,7 +484,6 @@ public class DelegatingRegattaLeaderboardWithCompetitorElimination extends Abstr
/**
* Before being serialized, ensure that the leaderboard supplier has been used
* to resolve the leaderboard.
* @throws IOException
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
getDelegateLeaderboard();
@@ -803,7 +803,7 @@ public interface TrackedRace
Competitor getCompetitorOfBoat(Boat boat);
/**
* Returns the competitors of this tracked race, according to their ranking (iteration order). Competitors whose
* Returns the competitors of this tracked race, according to their ranking within in this Race (iteration order). Competitors whose
* {@link #getRank} is 0 will be sorted "worst".
*
* @return If no ranking can be computed for the given {@link TimePoint} an empty LinkeHashMap is returned not null.
@@ -811,7 +811,7 @@ public interface TrackedRace
LinkedHashMap<Competitor, RankAndRankComparable> getCompetitorsFromBestToWorstAndRankAndRankComparable(TimePoint timePoint);
/**
* Same as {@link #getCompetitorsFromBestToWorstAndRankComparable(TimePoint)}, using a cache for wind, leg type and leg
* Same as {@link #getCompetitorsFromBestToWorstAndRankAndRankComparable(TimePoint)}, using a cache for wind, leg type and leg
* bearing values.
*
* @return If no ranking can be computed for the given {@link TimePoint} an empty {@link LinkedHashMap} is returned not null.
@@ -819,7 +819,7 @@ public interface TrackedRace
LinkedHashMap<Competitor, RankAndRankComparable> getCompetitorsFromBestToWorstAndRankAndRankComparable(TimePoint timePoint, WindLegTypeAndLegBearingAndORCPerformanceCurveCache cache);
/**
* Returns the competitors of this tracked race, according to their ranking (iteration order) and their RankComparables.
* Returns the competitors and their RankComparables of this tracked race, according to their ranking within in this Race (iteration order).
*
* @return If no ranking can be computed for the given {@link TimePoint} an empty {@link List} is returned not null.
*/
@@ -1601,7 +1601,12 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
// no mark passing at or before timePoint; competitor has not started / participated yet
result = 0;
} else {
result = getCompetitorsFromBestToWorstAndRankAndRankComparable(timePoint, cache).get(competitor).getRank();
RankAndRankComparable rankAndRankComparable = getCompetitorsFromBestToWorstAndRankAndRankComparable(timePoint, cache).get(competitor);
if(competitor == null) {
result = 0;
}else {
result = rankAndRankComparable.getRank();
}
}
}
return result;
@@ -1630,6 +1635,8 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
return getCompetitorsFromBestToWorst(timePoint, new LeaderboardDTOCalculationReuseCache(timePoint));
}
// defaults im interface anschauen
@Override
public Iterable<Competitor> getCompetitorsFromBestToWorst(TimePoint timePoint,
WindLegTypeAndLegBearingAndORCPerformanceCurveCache cache) {
@@ -1689,6 +1696,7 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
getRace().getCourse().lockForRead();
try {
// here the rankingmetrics need to return the RankComparables so that they could be ranked accordingly.
// encapsulate sorting providing etc. in a method of the Ranking metric. To Update this cache
Comparator<Competitor> comparator = getRankingMetric().getRaceRankingComparator(timePoint, cache);
List<Competitor> tempList = new ArrayList<Competitor>();
for (Competitor c : getRace().getCompetitors()) {
@@ -1696,9 +1704,9 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
}
Collections.sort(tempList, comparator);
final Iterator<Competitor> it = tempList.iterator();
rankedCompetitors = new LinkedHashMap<Competitor, RankAndRankComparable>();
rankedCompetitors = new LinkedHashMap<>();
for (int i = 1; it.hasNext(); i++) {
rankedCompetitors.put(it.next(), new RankAndRankComparable(i, new RankComparableRank(i)));
rankedCompetitors.put(it.next(), new RankAndRankComparable(i, /* TODO*/ new RankComparableRank(i)));
}
} finally {
getRace().getCourse().unlockAfterRead();