Skip to content

Commit

Permalink
Tidying.
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamkirby committed Dec 13, 2024
1 parent 0af729c commit 6b7b763
Show file tree
Hide file tree
Showing 66 changed files with 774 additions and 675 deletions.
File renamed without changes.
31 changes: 31 additions & 0 deletions .github/workflows/maven-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B verify
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ public static Duration parseTime(String element) {
}
}


private static Duration parseTime(String element, String separator) {
private static Duration parseTime(String element, final String separator) {

element = element.strip();
if (element.startsWith(separator)) element = "0" + element;
Expand Down
48 changes: 26 additions & 22 deletions src/main/java/org/grahamkirby/race_timing/common/Race.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import java.util.*;
import java.util.function.Predicate;

import static org.grahamkirby.race_timing.common.categories.PrizeCategory.PRIZE_CATEGORY_GROUP_NAME_INDEX;
import static org.grahamkirby.race_timing.common.categories.PrizeCategory.makePrizeCategory;

public abstract class Race {

public static final String COMMENT_SYMBOL = "#";
Expand All @@ -44,43 +47,43 @@ public abstract class Race {
public static final String KEY_YEAR = "YEAR";
public static final String KEY_RACE_NAME_FOR_RESULTS = "RACE_NAME_FOR_RESULTS";
public static final String KEY_RACE_NAME_FOR_FILENAMES = "RACE_NAME_FOR_FILENAMES";
public static final String KEY_ENTRY_MAP_PATH = "ENTRY_MAP_PATH";
public static final String KEY_NORMALISED_CLUB_NAMES_PATH = "NORMALISED_CLUB_NAMES_PATH";
public static final String KEY_CAPITALISATION_STOP_WORDS_PATH = "CAPITALISATION_STOP_WORDS_PATH";
public static final String KEY_NORMALISED_HTML_ENTITIES_PATH = "NORMALISED_HTML_ENTITIES_PATH";
private static final String KEY_ENTRY_MAP_PATH = "ENTRY_MAP_PATH";
private static final String KEY_NORMALISED_CLUB_NAMES_PATH = "NORMALISED_CLUB_NAMES_PATH";
private static final String KEY_CAPITALISATION_STOP_WORDS_PATH = "CAPITALISATION_STOP_WORDS_PATH";
private static final String KEY_NORMALISED_HTML_ENTITIES_PATH = "NORMALISED_HTML_ENTITIES_PATH";

// Single race.
public static final String KEY_ENTRIES_PATH = "ENTRIES_PATH";
public static final String KEY_RAW_RESULTS_PATH = "RAW_RESULTS_PATH";
public static final String KEY_RESULTS_PATH = "RESULTS_PATH";
public static final String KEY_CATEGORIES_ENTRY_PATH = "CATEGORIES_ENTRY_PATH";
public static final String KEY_CATEGORIES_PRIZE_PATH = "CATEGORIES_PRIZE_PATH";
public static final String KEY_DNF_FINISHERS = "DNF_FINISHERS";
protected static final String KEY_DNF_FINISHERS = "DNF_FINISHERS";

// Individual race.
public static final String KEY_MEDIAN_TIME = "MEDIAN_TIME";
protected static final String KEY_MEDIAN_TIME = "MEDIAN_TIME";

// Relay race.
public static final String KEY_GENDER_ELIGIBILITY_MAP_PATH = "GENDER_ELIGIBILITY_MAP_PATH";
protected static final String KEY_GENDER_ELIGIBILITY_MAP_PATH = "GENDER_ELIGIBILITY_MAP_PATH";
public static final String KEY_ANNOTATIONS_PATH = "ANNOTATIONS_PATH";
public static final String KEY_PAPER_RESULTS_PATH = "PAPER_RESULTS_PATH";
public static final String KEY_NUMBER_OF_LEGS = "NUMBER_OF_LEGS";
public static final String KEY_PAIRED_LEGS = "PAIRED_LEGS";
public static final String KEY_INDIVIDUAL_LEG_STARTS = "INDIVIDUAL_LEG_STARTS";
public static final String KEY_MASS_START_ELAPSED_TIMES = "MASS_START_ELAPSED_TIMES";
public static final String KEY_START_OFFSET = "START_OFFSET";
protected static final String KEY_NUMBER_OF_LEGS = "NUMBER_OF_LEGS";
protected static final String KEY_PAIRED_LEGS = "PAIRED_LEGS";
protected static final String KEY_INDIVIDUAL_LEG_STARTS = "INDIVIDUAL_LEG_STARTS";
protected static final String KEY_MASS_START_ELAPSED_TIMES = "MASS_START_ELAPSED_TIMES";
protected static final String KEY_START_OFFSET = "START_OFFSET";

// Series race.
public static final String KEY_RACES = "RACES";
public static final String KEY_NUMBER_OF_RACES_IN_SERIES = "NUMBER_OF_RACES_IN_SERIES";
public static final String KEY_MINIMUM_NUMBER_OF_RACES = "MINIMUM_NUMBER_OF_RACES";
protected static final String KEY_NUMBER_OF_RACES_IN_SERIES = "NUMBER_OF_RACES_IN_SERIES";
protected static final String KEY_MINIMUM_NUMBER_OF_RACES = "MINIMUM_NUMBER_OF_RACES";

// Grand Prix race.
public static final String KEY_RACE_CATEGORIES_PATH = "RACE_CATEGORIES_PATH";
public static final String KEY_QUALIFYING_CLUBS = "QUALIFYING_CLUBS";
protected static final String KEY_RACE_CATEGORIES_PATH = "RACE_CATEGORIES_PATH";
protected static final String KEY_QUALIFYING_CLUBS = "QUALIFYING_CLUBS";

// Midweek race.
public static final String KEY_SCORE_FOR_FIRST_PLACE = "SCORE_FOR_FIRST_PLACE";
protected static final String KEY_SCORE_FOR_FIRST_PLACE = "SCORE_FOR_FIRST_PLACE";

// Minitour race.
public static final String KEY_WAVE_START_OFFSETS = "WAVE_START_OFFSETS";
Expand All @@ -91,12 +94,14 @@ public abstract class Race {

//////////////////////////////////////////////////////////////////////////////////////////////////

public static final String LINE_SEPARATOR = System.lineSeparator();

public static final String SUFFIX_CSV = ".csv";
public static final String SUFFIX_PDF = ".pdf";

public static final int UNKNOWN_BIB_NUMBER = 0;
public static final int UNKNOWN_LEG_NUMBER = 0;
public static final int UNKNOWN_RACE_POSITION = 0;
protected static final int UNKNOWN_RACE_POSITION = 0;

private static final String DEFAULT_ENTRY_MAP_PATH = "/src/main/resources/configuration/default_entry_map" + SUFFIX_CSV;
private static final String DEFAULT_NORMALISED_HTML_ENTITIES_PATH = "/src/main/resources/configuration/html_entities" + SUFFIX_CSV;
Expand Down Expand Up @@ -154,7 +159,6 @@ public Race(final Path config_file_path) throws IOException {

protected abstract void readProperties() throws IOException;
protected abstract void configureInputData() throws IOException;
protected abstract void initialiseResults();
protected abstract void outputResults() throws IOException;
protected abstract List<Comparator<RaceResult>> getComparators();
protected abstract List<Comparator<RaceResult>> getDNFComparators();
Expand Down Expand Up @@ -406,7 +410,7 @@ private void configureImportCategoryMap() throws IOException {

private void configureCategories() throws IOException {

entry_categories = Files.readAllLines(getPath(getProperty(KEY_CATEGORIES_ENTRY_PATH))).stream().map(EntryCategory::new).toList();
entry_categories = Files.readAllLines(getPath(getProperty(KEY_CATEGORIES_ENTRY_PATH))).stream().map(EntryCategory::makeEntryCategory).toList();
prize_category_groups = getPrizeCategoryGroups(getPath(getProperty(KEY_CATEGORIES_PRIZE_PATH)));
}

Expand Down Expand Up @@ -462,10 +466,10 @@ private List<PrizeCategoryGroup> getPrizeCategoryGroups(final Path prize_categor
Files.readAllLines(prize_categories_path).stream().
filter(line -> !line.startsWith(COMMENT_SYMBOL)).
forEachOrdered(line -> {
final String group_name = line.split(",")[5];
final String group_name = line.split(",")[PRIZE_CATEGORY_GROUP_NAME_INDEX];

addGroupIfAbsent(groups, group_name);
getGroupWithName(groups, group_name).categories().add(new PrizeCategory(line));
getGroupWithName(groups, group_name).categories().add(makePrizeCategory(line));
});

return groups;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@
*/
package org.grahamkirby.race_timing.common.categories;

/**
* Parent class for entry category and prize category,
* each including a gender and age range.
*/
public abstract class Category {

// E.g. "Men Senior", "Men 40-49".
private final String long_name;

// E.g. "MS", "M40".
private final String short_name;

// e.g "Women", "Female", "Mixed", "Open".
private final String gender;

// Both ages are inclusive.
private final int minimum_age;
private final int maximum_age;

Expand Down Expand Up @@ -54,17 +64,7 @@ public int getMaximumAge() {
return maximum_age;
}

public boolean equalGenderAndAgeCategory(final Category other) {
return gender.equals(other.gender) && minimum_age == other.minimum_age && maximum_age == other.maximum_age;
}

@Override
public boolean equals(final Object obj) {
return obj instanceof Category other && equalGenderAndAgeCategory(other);
}

@Override
public int hashCode() {
return short_name.hashCode();
public boolean equals(final Object o) {
return o instanceof Category other && gender.equals(other.gender) && minimum_age == other.minimum_age && maximum_age == other.maximum_age;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@
*/
package org.grahamkirby.race_timing.common.categories;

/**
* Category specific to a particular entry.
*/
public class EntryCategory extends Category {

public EntryCategory(final String long_name, final String short_name, final String gender, final int minimum_age, final int maximum_age) {

super(long_name, short_name, gender, minimum_age, maximum_age);
}

public EntryCategory(final String line) {
public static EntryCategory makeEntryCategory(final String line) {

final String[] parts = line.split(",");

final String long_name = parts[0];
final String short_name = parts[1];
final String gender = parts[2];
final int minimum_age = Integer.parseInt(parts[3]);
final int maximum_age = Integer.parseInt(parts[4]);

this(
line.split(",")[0],
line.split(",")[1],
line.split(",")[2],
Integer.parseInt(line.split(",")[3]),
Integer.parseInt(line.split(",")[4]));
return new EntryCategory(long_name, short_name, gender, minimum_age, maximum_age);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@
*/
package org.grahamkirby.race_timing.common.categories;

/**
* Category defining eligibility for a particular prize.
* This is separate from entry category since multiple entry categories
* may be eligible for a prize category e.g. an open prize category
* may include multiple age categories.
*/
public class PrizeCategory extends Category {

public static final int PRIZE_CATEGORY_GROUP_NAME_INDEX = 6;

private final int number_of_prizes;

public PrizeCategory(final String long_name, final String short_name, final String gender, final int minimum_age, final int maximum_age, final int number_of_prizes) {
Expand All @@ -26,15 +34,18 @@ public PrizeCategory(final String long_name, final String short_name, final Stri
this.number_of_prizes = number_of_prizes;
}

public PrizeCategory(final String line) {
public static PrizeCategory makePrizeCategory(final String line) {

final String[] parts = line.split(",");

final String long_name = parts[0];
final String short_name = parts[1];
final String gender = parts[2];
final int minimum_age = Integer.parseInt(parts[3]);
final int maximum_age = Integer.parseInt(parts[4]);
final int number_of_prizes = Integer.parseInt(parts[5]);

this(
line.split(",")[0],
line.split(",")[1],
line.split(",")[2],
Integer.parseInt(line.split(",")[3]),
Integer.parseInt(line.split(",")[4]),
Integer.parseInt(line.split(",")[6]));
return new PrizeCategory(long_name, short_name, gender, minimum_age, maximum_age, number_of_prizes);
}

public int numberOfPrizes() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.grahamkirby.race_timing.common.output;

public enum CreditLink {

INCLUDE_CREDIT_LINK, DONT_INCLUDE_CREDIT_LINK
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class RaceOutput {
//////////////////////////////////////////////////////////////////////////////////////////////////

protected abstract String getFileSuffix();
protected abstract String getResultsHeader() throws IOException;
protected abstract String getResultsHeader();
protected abstract String getPrizesSectionHeader();
protected abstract String getPrizesCategoryHeader(final PrizeCategory category) ;
protected abstract String getPrizesCategoryFooter();
Expand All @@ -71,7 +71,7 @@ public void printResults() throws IOException {
try (final OutputStreamWriter writer = new OutputStreamWriter(stream)) {

writer.append(getResultsHeader());
printResults(writer, getOverallResultPrinter(writer), false);
printResults(writer, getOverallResultPrinter(writer), CreditLink.DONT_INCLUDE_CREDIT_LINK);
}
}

Expand Down Expand Up @@ -111,7 +111,7 @@ protected void constructFilePaths() {

//////////////////////////////////////////////////////////////////////////////////////////////////

protected void printResults(final OutputStreamWriter writer, ResultPrinter printer, final boolean include_credit_link) throws IOException {
protected void printResults(final OutputStreamWriter writer, ResultPrinter printer, final CreditLink credit_link_option) throws IOException {

for (int i = 0; i < race.prize_category_groups.size(); i++) {

Expand All @@ -124,11 +124,11 @@ protected void printResults(final OutputStreamWriter writer, ResultPrinter print

final String sub_heading = only_one_group ? "" : "\n" + makeSubHeading(group_title);

printResults(writer, printer, prize_categories, sub_heading, include_credit_link && last_group);
printResults(writer, printer, prize_categories, sub_heading, (credit_link_option == CreditLink.INCLUDE_CREDIT_LINK && last_group) ? CreditLink.INCLUDE_CREDIT_LINK : CreditLink.DONT_INCLUDE_CREDIT_LINK);
}
}

protected void printResults(final OutputStreamWriter writer, ResultPrinter printer, final List<PrizeCategory> categories, final String sub_heading, final boolean include_credit_link) throws IOException {
protected void printResults(final OutputStreamWriter writer, ResultPrinter printer, final List<PrizeCategory> categories, final String sub_heading, final CreditLink include_credit_link) throws IOException {

writer.append(sub_heading);

Expand Down Expand Up @@ -172,7 +172,7 @@ private void printPrizes(final OutputStreamWriter writer, final PrizeCategory ca

final List<RaceResult> category_prize_winners = race.prizes.getPrizeWinners(category);

getPrizeResultPrinter(writer).print(category_prize_winners, false);
getPrizeResultPrinter(writer).print(category_prize_winners, CreditLink.DONT_INCLUDE_CREDIT_LINK);

writer.append(getPrizesCategoryFooter());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public RaceOutputCSV(final Race race) {

protected String getResultsHeader() { return ""; }

protected void printResults(final OutputStreamWriter writer, ResultPrinter printer, final List<PrizeCategory> categories, final String sub_heading, boolean include_credit_link) throws IOException {
super.printResults(writer, printer, categories, "", false);
protected void printResults(final OutputStreamWriter writer, ResultPrinter printer, final List<PrizeCategory> categories, final String sub_heading, final CreditLink credit_link_option) throws IOException {
super.printResults(writer, printer, categories, "", credit_link_option);
}

@Override
Expand All @@ -56,6 +56,6 @@ public String getPrizesCategoryFooter() {
}

protected static String encode(String s) {
return s.contains(",") ? "\"" + s + "\"" : s;
return s.contains(",") ? STR."\"\{s}\"" : s;
}
}
Loading

0 comments on commit 6b7b763

Please sign in to comment.