Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring to prep for changes #428

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/main/java/trap/report/TrapHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ public Map<String, ArrayList<IndividualTotal>> calculatePlayerIndividualTotal(Li
playerIndividualTotal.put(r.getUniqueName(), new ArrayList<>());
}
for (var playerRoundTotal : playerRoundTotals.values()) {
// clays, skeet, and fivestand are top 3 scores only, minimum 2 locations
var subtractScores = subtractScores(playerRoundTotal.getFirst().getType());
var roundsToCount = getRoundsToCount(playerRoundTotal.getFirst().getType());
var indTotal = new ArrayList<IndividualTotal>();
playerRoundTotal.sort(Comparator.comparingInt(RoundTotal::getTotal).reversed());
for (var t : playerRoundTotal) {
if (indTotal.size() < (3 - subtractScores)) {
if (indTotal.size() < (roundsToCount - 1)) {
indTotal.add(new IndividualTotal(t.getLocationId(), t.getTeam(), t.getAthlete(), t.getClassification(), t.getGender(), t.getTotal(), t.getType()));
} else {
var locationIds = new HashSet<Integer>();
Expand Down Expand Up @@ -94,11 +93,23 @@ public Map<String, IndividualTotal> calculatePlayerFinalTotal(Map<String, ArrayL
return playerFinalTotal;
}

private int subtractScores(String roundType) {
return roundType.equals("clays") || roundType.equals("skeet") || roundType.equals("fivestand") || roundType.equals("doublesskeet") ? 1 : 0;
}

private boolean singleRound(String roundType) {
return roundType.equals("clays") || roundType.equals("doubles") || roundType.equals("doublesskeet");
}

private static HashMap determineRoundsToCount() {
var roundCounts = new HashMap<>();
roundCounts.put("singles", 4);
roundCounts.put("doubles", 4);
roundCounts.put("handicap", 4);
roundCounts.put("skeet", 3);
roundCounts.put("clays", 3);
roundCounts.put("fivestand", 3);
roundCounts.put("doublesskeet", 3);
return roundCounts;
}

public static int getRoundsToCount(String type) {
return Integer.parseInt(determineRoundsToCount().get(type).toString());
}
}
11 changes: 11 additions & 0 deletions src/test/java/trap/report/TrapHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,15 @@ void fivestandScoring3LocationsWithHigherScoresInOneLocation() {
assertEquals("fivestand", playerFinalTotal.get(player1.getUniqueName()).getType());
}

@Test
void roundsToCount() {
assertEquals(4, trapHelper.getRoundsToCount("singles"));
assertEquals(4, trapHelper.getRoundsToCount("doubles"));
assertEquals(4, trapHelper.getRoundsToCount("handicap"));

assertEquals(3, trapHelper.getRoundsToCount("skeet"));
assertEquals(3, trapHelper.getRoundsToCount("clays"));
assertEquals(3, trapHelper.getRoundsToCount("fivestand"));
assertEquals(3, trapHelper.getRoundsToCount("doublesskeet"));
}
}