Skip to content

Commit

Permalink
more record classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbusche committed Dec 26, 2024
1 parent 5501b25 commit 8d6618c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 60 deletions.
54 changes: 25 additions & 29 deletions src/main/java/trap/model/RoundScore.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
package trap.model;

import lombok.AllArgsConstructor;
import lombok.Data;
public record RoundScore(
int eventId,
String event,
int locationId,
String location,
String eventDate,
String squadName,
String team,
String athlete,
String classification,
String gender,
int round1,
int round2,
int round3,
int round4,
int round5,
int round6,
int round7,
int round8,
String type
) {

@AllArgsConstructor
@Data
public class RoundScore {
int eventId;
String event;
int locationId;
String location;
String eventDate;
String squadName;
String team;
String athlete;
String classification;
String gender;
int round1;
int round2;
int round3;
int round4;
int round5;
int round6;
int round7;
int round8;
String type;

public String getUniqueName() {
return this.getAthlete() + " " + this.getTeam() + " " + this.getClassification() + " " + this.getType();
public String uniqueName() {
return athlete + " " + team + " " + classification + " " + type;
}

public String getTeamClassification() {
public String teamClassification() {
return switch (classification) {
case "Senior/Varsity" -> "Varsity";
case "Senior/Jr. Varsity" -> "Senior Varsity";
Expand All @@ -39,4 +35,4 @@ public String getTeamClassification() {
default -> classification;
};
}
}
}
38 changes: 19 additions & 19 deletions src/main/java/trap/report/ExcelHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,25 @@ private static String generateFilename() {
}

public static void addCleanData(Row row, RoundScore rowData) {
row.createCell(0).setCellValue(rowData.getEventId());
row.createCell(1).setCellValue(rowData.getEvent());
row.createCell(2).setCellValue(rowData.getLocationId());
row.createCell(3).setCellValue(rowData.getLocation());
row.createCell(4).setCellValue(rowData.getEventDate());
row.createCell(5).setCellValue(rowData.getSquadName());
row.createCell(6).setCellValue(rowData.getTeam());
row.createCell(7).setCellValue(rowData.getAthlete());
row.createCell(8).setCellValue(rowData.getClassification());
row.createCell(9).setCellValue(rowData.getGender());
row.createCell(10).setCellValue(rowData.getRound1());
row.createCell(11).setCellValue(rowData.getRound2());
row.createCell(12).setCellValue(rowData.getRound3());
row.createCell(13).setCellValue(rowData.getRound4());
row.createCell(14).setCellValue(rowData.getRound5());
row.createCell(15).setCellValue(rowData.getRound6());
row.createCell(16).setCellValue(rowData.getRound7());
row.createCell(17).setCellValue(rowData.getRound8());
row.createCell(18).setCellValue(rowData.getType());
row.createCell(0).setCellValue(rowData.eventId());
row.createCell(1).setCellValue(rowData.event());
row.createCell(2).setCellValue(rowData.locationId());
row.createCell(3).setCellValue(rowData.location());
row.createCell(4).setCellValue(rowData.eventDate());
row.createCell(5).setCellValue(rowData.squadName());
row.createCell(6).setCellValue(rowData.team());
row.createCell(7).setCellValue(rowData.athlete());
row.createCell(8).setCellValue(rowData.classification());
row.createCell(9).setCellValue(rowData.gender());
row.createCell(10).setCellValue(rowData.round1());
row.createCell(11).setCellValue(rowData.round2());
row.createCell(12).setCellValue(rowData.round3());
row.createCell(13).setCellValue(rowData.round4());
row.createCell(14).setCellValue(rowData.round5());
row.createCell(15).setCellValue(rowData.round6());
row.createCell(16).setCellValue(rowData.round7());
row.createCell(17).setCellValue(rowData.round8());
row.createCell(18).setCellValue(rowData.type());
}

public static void addTeamData(Row row, int startColumn, String team, int total, CellStyle mainTextStyle) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/trap/report/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void populateCleanData(Sheet sheet, List<RoundScore> allRoundScores) {

for (var type : trapTypes) {
var typeStart = System.currentTimeMillis();
var typeRoundScores = allRoundScores.stream().filter(t -> t.getType().equals(type)).toList();
var typeRoundScores = allRoundScores.stream().filter(t -> t.type().equals(type)).toList();
for (var score : typeRoundScores) {
var row = sheet.createRow(++rows);
ExcelHelper.addCleanData(row, score);
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/trap/report/TrapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ public Map<String, List<RoundTotal>> calculatePlayerRoundTotals(List<RoundScore>
Map<String, List<RoundTotal>> playerRoundTotals = new HashMap<>();

// Initialize map with empty lists for each unique player
roundScores.forEach(r -> playerRoundTotals.put(r.getUniqueName(), new ArrayList<>()));
roundScores.forEach(r -> playerRoundTotals.put(r.uniqueName(), new ArrayList<>()));

// Process each round score
for (RoundScore r : roundScores) {
List<RoundTotal> currentPlayerRoundTotal = playerRoundTotals.get(r.getUniqueName());
List<RoundTotal> currentPlayerRoundTotal = playerRoundTotals.get(r.uniqueName());

// If it's a single round, process round 1 and optionally round 2
if (singleRound(r.getType())) {
addRound(currentPlayerRoundTotal, r, r.getRound1());
if (r.getRound2() > 0) {
addRound(currentPlayerRoundTotal, r, r.getRound2());
if (singleRound(r.type())) {
addRound(currentPlayerRoundTotal, r, r.round1());
if (r.round2() > 0) {
addRound(currentPlayerRoundTotal, r, r.round2());
}
} else {
addRound(currentPlayerRoundTotal, r, r.getRound1() + r.getRound2());
addRound(currentPlayerRoundTotal, r, r.round1() + r.round2());
addMultipleRounds(currentPlayerRoundTotal, r);
}
}
Expand All @@ -100,13 +100,13 @@ public Map<String, List<RoundTotal>> calculatePlayerRoundTotals(List<RoundScore>

// Helper method to add individual rounds
private void addRound(List<RoundTotal> totals, RoundScore r, int total) {
totals.add(new RoundTotal(r.getEventId(), r.getLocationId(), r.getTeam(), r.getAthlete(),
r.getClassification(), r.getGender(), total, r.getType()));
totals.add(new RoundTotal(r.eventId(), r.locationId(), r.team(), r.athlete(),
r.classification(), r.gender(), total, r.type()));
}

// Helper method to add rounds 3 to 8 if applicable
private void addMultipleRounds(List<RoundTotal> totals, RoundScore r) {
int[] additionalRounds = {r.getRound3() + r.getRound4(), r.getRound5() + r.getRound6(), r.getRound7() + r.getRound8()};
int[] additionalRounds = {r.round3() + r.round4(), r.round5() + r.round6(), r.round7() + r.round8()};

for (int round : additionalRounds) {
if (round > 0) {
Expand All @@ -121,7 +121,7 @@ public Map<String, List<IndividualTotal>> calculatePlayerIndividualTotal(List<Ro
Map<String, List<IndividualTotal>> playerIndividualTotal = new HashMap<>();

// Initialize scores with empty lists
roundScores.forEach(r -> playerIndividualTotal.put(r.getUniqueName(), new ArrayList<>()));
roundScores.forEach(r -> playerIndividualTotal.put(r.uniqueName(), new ArrayList<>()));

for (List<RoundTotal> playerRoundTotal : playerRoundTotals.values()) {
if (playerRoundTotal.isEmpty()) continue;
Expand Down

0 comments on commit 8d6618c

Please sign in to comment.