added AbstractScoreCorrection to prepare for Mongo-based score corrections

This commit is contained in:
Axel Uhl committed 2011-07-29 17:07:00 +02:00
1 parent 70ac978a21
commit be6697850c
3 files changed
+84 -8

No files matched your search

@@ -19,7 +19,7 @@ import com.sap.sailing.domain.base.impl.NationalityImpl;
import com.sap.sailing.domain.base.impl.PersonImpl;
import com.sap.sailing.domain.base.impl.TeamImpl;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.ScoreCorrection;
import com.sap.sailing.domain.leaderboard.impl.AbstractScoreCorrection;
import com.sap.sailing.domain.leaderboard.impl.LeaderboardImpl;
import com.sap.sailing.domain.leaderboard.impl.ResultDiscardingRuleImpl;
import com.sap.sailing.domain.test.mock.MockedTrackedRace;
@@ -70,13 +70,8 @@ public class LeaderboardTests {
protected void testLeaderboard(int numberOfStartedRaces, int numberOfNotStartedRaces, int firstDiscardingThreshold,
int secondDiscardingThreshold) throws NoWindException {
setupRaces(numberOfStartedRaces, numberOfNotStartedRaces);
Leaderboard leaderboard = new LeaderboardImpl(new ScoreCorrection() {
@Override
public int getCorrectedScore(int uncorrectedScore, Competitor competitor, TrackedRace trackedRace,
TimePoint timePoint) {
return uncorrectedScore;
}
}, new ResultDiscardingRuleImpl(new int[] { firstDiscardingThreshold, secondDiscardingThreshold }));
Leaderboard leaderboard = new LeaderboardImpl(new AbstractScoreCorrection(), new ResultDiscardingRuleImpl(
new int[] { firstDiscardingThreshold, secondDiscardingThreshold }));
for (TrackedRace race : testRaces) {
leaderboard.addRace(race);
}
@@ -15,5 +15,23 @@ import com.sap.sailing.domain.tracking.TrackedRace;
*
*/
public interface ScoreCorrection {
/**
* The reasons why a competitor may get the maximum number of points, usually equaling the
* number of competitors enlisted for the regatta plus one.
*
* @author Axel Uhl (d043530)
*
*/
enum MaxPointsReason {
/** The competitor finished the race properly */
NONE,
/** Did Not Start */
DNS,
/** Did Not Finish */
DNF,
/** DiSQualified */
DSQ
};
int getCorrectedScore(int uncorrectedScore, Competitor competitor, TrackedRace trackedRace, TimePoint timePoint);
}
@@ -0,0 +1,63 @@
package com.sap.sailing.domain.leaderboard.impl;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.TimePoint;
import com.sap.sailing.domain.leaderboard.ScoreCorrection;
import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.util.Util;
/**
* Implements the basic logic of assigning a maximum score to a competitor in a race if that competitor was
* disqualified, did not start or did not finish. The maximum score is determined by counting the number of competitors
* listed in the event to which the race belongs.
* <p>
*
* Subclasses should consider redefining {@link #getMaxPointsReason(Competitor, TrackedRace)} and
* {@link #getCorrectedNonMaxedScore(Competitor, TrackedRace, int)} if they want to manage, e.g., disqualifications and
* jury overruling of tracking results.
* <p>
*
* To allow tests to use a trivial implementation of the {@link ScoreCorrection} interface, this class which carries
* "Abstract" in its name is non-abstract.
*
* @author Axel Uhl (d043530)
*
*/
public class AbstractScoreCorrection implements ScoreCorrection {
protected MaxPointsReason getMaxPointsReason(Competitor competitor, TrackedRace trackedRace) {
return MaxPointsReason.NONE;
}
/**
* If the {@link #getMaxPointsReason(Competitor, TrackedRace)} for the <code>competitor</code> for the
* <code>trackedRace</code> is not {@link MaxPointsReason#NONE}, the {@link #getMaxPoints(TrackedRace) maximum
* score} is computed for the competitor. Otherwise, the <code>uncorrectedScore</code> is returned.<p>
*/
@Override
public int getCorrectedScore(int uncorrectedScore, Competitor competitor, TrackedRace trackedRace,
TimePoint timePoint) {
int result;
if (getMaxPointsReason(competitor, trackedRace) == MaxPointsReason.NONE) {
result = getCorrectedNonMaxedScore(competitor, trackedRace, uncorrectedScore);
} else {
result = getMaxPoints(trackedRace);
}
return getCorrectedNonMaxedScore(competitor, trackedRace, result);
}
/**
* Under the assumption that the competitor is not assigned the maximum score due to disqualification or other
* reasons, computes the corrected score. This default implementation uses <code>uncorrectedScore</code> without
* changes. Subclasses may wish to allow for optionally overwriting this uncorrected score to handle, e.g.,
* differences between what the tracking results suggest and what the jury or race committee decided.
*/
protected int getCorrectedNonMaxedScore(Competitor competitor, TrackedRace trackedRace, int uncorrectedScore) {
return uncorrectedScore;
}
private int getMaxPoints(TrackedRace trackedRace) {
return Util.size(trackedRace.getRace().getCompetitors())+1;
}
}