mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 03:13:49 +00:00
fix for bug 1091: getWins() and related methods now additionally get the RaceColumns so they can consider the factor of the column
This commit is contained in:
1 parent
957d4e771e
commit
b01809ff25
5 files changed
+34
-21
No files matched your search
+4
-2
@@ -10,6 +10,7 @@ import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.common.MaxPointsReason;
|
||||
import com.sap.sailing.domain.common.ScoringSchemeType;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
|
||||
/**
|
||||
* A leaderboard has a scoring scheme that decides how race ranks map to scores, how penalties are to be scored,
|
||||
@@ -67,7 +68,8 @@ public interface ScoringScheme extends Serializable {
|
||||
* @param competitor1Scores scores of the first competitor, in the order of race columns in the leaderboard
|
||||
* @param competitor2Scores scores of the second competitor, in the order of race columns in the leaderboard
|
||||
*/
|
||||
int compareByBetterScore(List<Double> competitor1Scores, List<Double> competitor2Scores, boolean nullScoresAreBetter);
|
||||
int compareByBetterScore(List<Pair<RaceColumn, Double>> competitor1Scores,
|
||||
List<Pair<RaceColumn, Double>> competitor2Scores, boolean nullScoresAreBetter);
|
||||
|
||||
/**
|
||||
* In case two competitors scored in different numbers of races, this scoring scheme decides whether this
|
||||
@@ -81,7 +83,7 @@ public interface ScoringScheme extends Serializable {
|
||||
/**
|
||||
* Usually, when all other sorting criteria end up in a tie, the last race sailed is used to decide.
|
||||
*/
|
||||
int compareByLastRace(List<Double> o1Scores, List<Double> o2Scores, boolean nullScoresAreBetter);
|
||||
int compareByLastRace(List<Pair<RaceColumn, Double>> o1Scores, List<Pair<RaceColumn, Double>> o2Scores, boolean nullScoresAreBetter);
|
||||
|
||||
/**
|
||||
* Under certain circumstances, a scoring scheme may decide that the scores of a column are not (yet) to be used
|
||||
|
||||
+16
-8
@@ -15,6 +15,7 @@ import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.common.NoWindException;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.ScoringScheme;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
@@ -120,16 +121,22 @@ public abstract class AbstractScoringSchemeImpl implements ScoringScheme {
|
||||
* Assuming both competitors scored in the same number of races, compares the sorted scores.
|
||||
*/
|
||||
@Override
|
||||
public int compareByBetterScore(List<Double> o1Scores, List<Double> o2Scores, boolean nullScoresAreBetter) {
|
||||
public int compareByBetterScore(List<Pair<RaceColumn, Double>> o1Scores, List<Pair<RaceColumn, Double>> o2Scores, boolean nullScoresAreBetter) {
|
||||
assert o1Scores.size() == o2Scores.size();
|
||||
Comparator<Double> scoreComparator = getScoreComparator(nullScoresAreBetter);
|
||||
List<Double> o1ScoresCopy = new ArrayList<Double>(o1Scores);
|
||||
List<Double> o2ScoresCopy = new ArrayList<Double>(o2Scores);
|
||||
final Comparator<Double> pureScoreComparator = getScoreComparator(nullScoresAreBetter);
|
||||
Comparator<Pair<RaceColumn, Double>> scoreComparator = new Comparator<Pair<RaceColumn, Double>>() {
|
||||
@Override
|
||||
public int compare(Pair<RaceColumn, Double> o1, Pair<RaceColumn, Double> o2) {
|
||||
return pureScoreComparator.compare(o1.getB(), o2.getB());
|
||||
}
|
||||
};
|
||||
List<Pair<RaceColumn, Double>> o1ScoresCopy = new ArrayList<Pair<RaceColumn, Double>>(o1Scores);
|
||||
List<Pair<RaceColumn, Double>> o2ScoresCopy = new ArrayList<Pair<RaceColumn, Double>>(o2Scores);
|
||||
Collections.sort(o1ScoresCopy, scoreComparator);
|
||||
Collections.sort(o2ScoresCopy, scoreComparator);
|
||||
// now both lists are sorted from best to worst score
|
||||
Iterator<Double> o1Iter = o1ScoresCopy.iterator();
|
||||
Iterator<Double> o2Iter = o2ScoresCopy.iterator();
|
||||
Iterator<Pair<RaceColumn, Double>> o1Iter = o1ScoresCopy.iterator();
|
||||
Iterator<Pair<RaceColumn, Double>> o2Iter = o2ScoresCopy.iterator();
|
||||
int result = 0;
|
||||
while (result == 0 && o1Iter.hasNext() && o2Iter.hasNext()) {
|
||||
result = scoreComparator.compare(o1Iter.next(), o2Iter.next());
|
||||
@@ -147,10 +154,11 @@ public abstract class AbstractScoringSchemeImpl implements ScoringScheme {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareByLastRace(List<Double> o1Scores, List<Double> o2Scores, boolean nullScoresAreBetter) {
|
||||
public int compareByLastRace(List<Pair<RaceColumn, Double>> o1Scores, List<Pair<RaceColumn, Double>> o2Scores, boolean nullScoresAreBetter) {
|
||||
int result = 0;
|
||||
if (!o1Scores.isEmpty() && !o2Scores.isEmpty()) {
|
||||
result = getScoreComparator(nullScoresAreBetter).compare(o1Scores.get(o1Scores.size()-1), o2Scores.get(o2Scores.size()-1));
|
||||
result = getScoreComparator(nullScoresAreBetter).compare(o1Scores.get(o1Scores.size()-1).getB(),
|
||||
o2Scores.get(o2Scores.size()-1).getB());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+6
-5
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.common.ScoringSchemeType;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
|
||||
/**
|
||||
* A variant of the {@link HighPoint} scoring scheme which breaks ties differently and which assigns a score of 10 to
|
||||
@@ -42,13 +43,13 @@ public class HighPointExtremeSailingSeriesOverall extends HighPoint {
|
||||
* Implements rule 13.5 of the Extreme Sailing Series notice of race as of August 2012.
|
||||
*/
|
||||
@Override
|
||||
public int compareByBetterScore(List<Double> o1Scores, List<Double> o2Scores, boolean nullScoresAreBetter) {
|
||||
public int compareByBetterScore(List<Pair<RaceColumn, Double>> o1Scores, List<Pair<RaceColumn, Double>> o2Scores, boolean nullScoresAreBetter) {
|
||||
assert o1Scores.size() == o2Scores.size();
|
||||
int o1Wins = getWins(o1Scores);
|
||||
int o2Wins = getWins(o2Scores);
|
||||
int result = o1Wins - o2Wins;
|
||||
if (result == 0 && o1Scores.size() >= 1 && o2Scores.size() >= 1) {
|
||||
result = o1Scores.get(o1Scores.size()-1).compareTo(o2Scores.get(o2Scores.size()-1));
|
||||
result = o1Scores.get(o1Scores.size()-1).getB().compareTo(o2Scores.get(o2Scores.size()-1).getB());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -57,10 +58,10 @@ public class HighPointExtremeSailingSeriesOverall extends HighPoint {
|
||||
* Counts a competitor's wins by comparing the scores to {@link #MAX_POINTS} which is the score attributed to a race
|
||||
* won
|
||||
*/
|
||||
private int getWins(List<Double> scores) {
|
||||
private int getWins(List<Pair<RaceColumn, Double>> scores) {
|
||||
int wins = 0;
|
||||
for (Double score : scores) {
|
||||
if (score == MAX_POINTS) {
|
||||
for (Pair<RaceColumn, Double> score : scores) {
|
||||
if (score.getB() == MAX_POINTS * score.getA().getFactor()) {
|
||||
wins++;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -2,7 +2,9 @@ package com.sap.sailing.domain.leaderboard.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.common.ScoringSchemeType;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
|
||||
/**
|
||||
* In this variant of the {@link HighPoint} scoring scheme, scoring by "better race" (sometimes referred to as a
|
||||
@@ -16,7 +18,7 @@ public class HighPointLastBreaksTie extends HighPoint {
|
||||
private static final long serialVersionUID = -5338636946886101669L;
|
||||
|
||||
@Override
|
||||
public int compareByBetterScore(List<Double> o1Scores, List<Double> o2Scores, boolean nullScoresAreBetter) {
|
||||
public int compareByBetterScore(List<Pair<RaceColumn, Double>> o1Scores, List<Pair<RaceColumn, Double>> o2Scores, boolean nullScoresAreBetter) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -93,8 +93,8 @@ public class LeaderboardTotalRankComparator implements Comparator<Competitor> {
|
||||
|
||||
@Override
|
||||
public int compare(Competitor o1, Competitor o2) {
|
||||
List<Double> o1Scores = new ArrayList<Double>();
|
||||
List<Double> o2Scores = new ArrayList<Double>();
|
||||
List<Pair<RaceColumn, Double>> o1Scores = new ArrayList<Pair<RaceColumn, Double>>();
|
||||
List<Pair<RaceColumn, Double>> o2Scores = new ArrayList<Pair<RaceColumn, Double>>();
|
||||
double o1ScoreSum = getLeaderboard().getCarriedPoints(o1);
|
||||
double o2ScoreSum = getLeaderboard().getCarriedPoints(o2);
|
||||
Double o1MedalRaceScore = 0.0;
|
||||
@@ -104,12 +104,12 @@ public class LeaderboardTotalRankComparator implements Comparator<Competitor> {
|
||||
int preemptiveColumnResult = 0;
|
||||
final Double o1Score = totalPointsCache.get(new Pair<Competitor, RaceColumn>(o1, raceColumn));
|
||||
if (o1Score != null) {
|
||||
o1Scores.add(o1Score);
|
||||
o1Scores.add(new Pair<RaceColumn, Double>(raceColumn, o1Score));
|
||||
o1ScoreSum += o1Score;
|
||||
}
|
||||
final Double o2Score = totalPointsCache.get(new Pair<Competitor, RaceColumn>(o2, raceColumn));
|
||||
if (o2Score != null) {
|
||||
o2Scores.add(o2Score);
|
||||
o2Scores.add(new Pair<RaceColumn, Double>(raceColumn, o2Score));
|
||||
o2ScoreSum += o2Score;
|
||||
}
|
||||
if (raceColumn.isMedalRace()) {
|
||||
@@ -237,7 +237,7 @@ public class LeaderboardTotalRankComparator implements Comparator<Competitor> {
|
||||
*
|
||||
* @see ScoringScheme#compareByBetterScore(List, List, boolean)
|
||||
*/
|
||||
protected int compareByBetterScore(List<Double> o1Scores, List<Double> o2Scores) {
|
||||
protected int compareByBetterScore(List<Pair<RaceColumn, Double>> o1Scores, List<Pair<RaceColumn, Double>> o2Scores) {
|
||||
return scoringScheme.compareByBetterScore(o1Scores, o2Scores, nullScoresAreBetter);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user