Skip to content

Commit

Permalink
Minor clean ups (#408)
Browse files Browse the repository at this point in the history
* minor clean ups

* more logging

* download files
  • Loading branch information
mrbusche committed Jun 15, 2024
1 parent 344de8a commit 501fb86
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/java/trap/report/CommandLineAppStartupRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class CommandLineAppStartupRunner implements CommandLineRunner {

@Override
public void run(String... args) throws Exception {
reportHelper.doItAll();
reportHelper.generateExcelFile();
}
}
3 changes: 1 addition & 2 deletions src/main/java/trap/report/DownloadHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public void downloadFiles(String[] trapTypes) throws IOException {

logger.info("Replacing double spaces for {} file", type);
var path = Paths.get(type + ".csv");
var content = Files.readString(path, charset);
content = content.replaceAll(" {2}", " ");
var content = Files.readString(path, charset).replaceAll(" {2}", " ");
Files.writeString(path, content, charset);
logger.info("Finished replacing double spaces for {} file", type);
}
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/trap/report/ExcelHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,18 @@ public static void setCurrentDateHeader(Sheet sheet, String currentDate) {
}

public static void setCurrentSeasonHeader(Sheet sheet) {
var date = new Date();
var cal = Calendar.getInstance();
cal.setTime(date);
cal.setTime(new Date());
var month = cal.get(Calendar.MONTH);
var year = cal.get(Calendar.YEAR);
var currentSeason = month > 8 ? year + 1 : year;
sheet.getRow(8).getCell(1).setCellValue(currentSeason + " " + sheet.getRow(8).getCell(1).getStringCellValue());
}

public static void createFile(Workbook workbook) throws IOException {
long start;
start = System.currentTimeMillis();
var date = new Date();
long start = System.currentTimeMillis();
var formatter = new SimpleDateFormat("yyyyMMddHHmmss");
var currentDate = formatter.format(date);
var currentDate = formatter.format(new Date());
var filename = "league-data-" + currentDate + ".xlsx";
logger.info("Creating file");
FileOutputStream fileOutputStream = new FileOutputStream(filename);
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/trap/report/ReportHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ReportHelper {

Logger logger = LoggerFactory.getLogger(ReportHelper.class);

public void doItAll() throws Exception {
public void generateExcelFile() throws Exception {
downloadHelper.downloadFiles(trapTypes);

var workbook = getWorkbook();
Expand All @@ -71,6 +71,7 @@ public void doItAll() throws Exception {
var style = ExcelHelper.setFontForHeaders(workbook);

var allRoundScores = generateRoundScores();
logger.info("Generated round scores in {} ms", System.currentTimeMillis() - trueStart);
populateCleanData(workbook.getSheet("Clean Data"), allRoundScores);

var playerRoundTotals = trapHelper.calculatePlayerRoundTotals(allRoundScores);
Expand Down Expand Up @@ -128,21 +129,22 @@ private List<RoundScore> generateRoundScores(String type) throws IOException, Cs
private void populateCleanData(Sheet sheet, List<RoundScore> allRoundScores) {
var start = System.currentTimeMillis();

logger.info("Ran get all data for clean data population {} ms", System.currentTimeMillis() - start);
logger.info("Ran get all data for clean data population in {} ms", System.currentTimeMillis() - start);

var rows = sheet.getLastRowNum();
Row row;

for (var type : trapTypes) {
var typeStart = System.currentTimeMillis();
var typeRoundScores = allRoundScores.stream().filter(t -> t.getType().equals(type)).toList();
for (var score : typeRoundScores) {
row = sheet.createRow(++rows);
var row = sheet.createRow(++rows);
ExcelHelper.addCleanData(row, score);
}
logger.info("Clean data for {} {} scores populated in {} ms", typeRoundScores.size(), type, System.currentTimeMillis() - typeStart);
}

sheet.setAutoFilter(CellRangeAddress.valueOf("A1:S1"));
logger.info("Clean data populated in in {} ms", System.currentTimeMillis() - start);
logger.info("Clean data populated in {} ms", System.currentTimeMillis() - start);
}

private List<TeamScore> getTeamScores(List<Map.Entry<String, ArrayList<IndividualTotal>>> teamData) {
Expand Down Expand Up @@ -269,7 +271,7 @@ private void populateIndividualData(Workbook workbook, String sheetName, String
updateRow++;
start = System.currentTimeMillis();
individualData = justValues.stream().filter(f -> f.getGender().equals(gender) && f.getTeamClassification().equals(classification) && f.getType().equals(type)).toList();
logger.info("Ran query for {} by {} and {} in {} ms", type, gender, classification, System.currentTimeMillis() - start);
logger.info("Ran query for {} by {} and {} in {} ms", type, gender, classification, System.currentTimeMillis() - start);
for (IndividualTotal data : individualData) {
row = sheet.getRow(++updateRow);
ExcelHelper.addPlayerData(row, column, data.getAthlete(), data.getTotal(), data.getTeam(), mainTextStyle);
Expand Down Expand Up @@ -314,7 +316,6 @@ private void populateTeamIndividualData(Workbook workbook, String sheetName, Lis
logger.info("Ran query for team scores in {} ms", System.currentTimeMillis() - start);

var rows = sheet.getLastRowNum();

var teamScoresThatCount = calculateTeamScores(teamScoresByTotal);
for (var individualTotalList : teamScoresThatCount.values()) {
for (var rowData : individualTotalList) {
Expand Down

0 comments on commit 501fb86

Please sign in to comment.