Skip to content

Commit

Permalink
Moved maximum race score for midweek series to config.
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamkirby committed Nov 27, 2024
1 parent e05a300 commit f5e731a
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/grahamkirby/race_timing/common/Race.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public abstract class Race {

// Midweek race.
public static final String KEY_MINIMUM_NUMBER_OF_RACES = "MINIMUM_NUMBER_OF_RACES";
public static final String KEY_MAX_RACE_SCORE = "MAX_RACE_SCORE";

// Minitour race.
public static final String KEY_WAVE_START_OFFSETS = "WAVE_START_OFFSETS";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private record ResultWithLegIndex(RelayRaceResult result, int leg_index) {}
// mass start. This allows e.g. for a leg 1 runner finishing after a leg 3 mass start - see configureMassStarts().
private List<Duration> start_times_for_mass_starts;

protected List<Boolean> paired_legs;
protected Set<Integer> paired_legs;
private List<IndividualLegStart> individual_leg_starts;
private Duration start_offset;
private Map<String, String> gender_eligibility_map;
Expand Down Expand Up @@ -206,7 +206,8 @@ protected boolean entryCategoryIsEligibleForPrizeCategoryByGender(final EntryCat

return gender_eligibility_map.keySet().stream().
filter(entry_gender -> entry_category.getGender().equals(entry_gender)).
anyMatch(entry_gender -> prize_category.getGender().equals(gender_eligibility_map.get(entry_gender)));
filter(entry_gender -> prize_category.getGender().equals(gender_eligibility_map.get(entry_gender))).
count() > 0;
}

@Override
Expand Down Expand Up @@ -408,12 +409,10 @@ private void configurePairedLegs() {

// Example: PAIRED_LEGS = 2,3

paired_legs = Stream.generate(() -> false).
limit(number_of_legs).
collect(Collectors.toList());
paired_legs = new HashSet<>();

for (final String leg_number_as_string : paired_legs_string.split(","))
paired_legs.set(Integer.parseInt(leg_number_as_string) - 1, true);
paired_legs.add(Integer.parseInt(leg_number_as_string));
}

private void configureIndividualLegStarts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public LegResultPrinter(final Race race, final OutputStreamWriter writer, final
@Override
public void printResultsHeader() throws IOException {

final String plural = ((RelayRace) race).paired_legs.get(leg - 1) ? "s" : "";
final String plural = ((RelayRace) race).paired_legs.contains(leg) ? "s" : "";
writer.append(STR."Pos,Runner\{plural},Time\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void printResultsHeader() throws IOException {
<thead>
<tr>
<th>Pos</th>
<th>Runner\{((RelayRace)race).paired_legs.get(leg - 1) ? "s" : ""}</th>
<th>Runner\{((RelayRace)race).paired_legs.contains(leg) ? "s" : ""}</th>
<th>Time</th>
</tr>
</thead>
Expand Down Expand Up @@ -271,7 +271,7 @@ public void printResultsHeader() throws IOException {
for (int leg_number = 1; leg_number <= ((RelayRace)race).number_of_legs; leg_number++) {

writer.append(STR."""
<th>Runner\{((RelayRace)race).paired_legs.get(leg_number - 1) ? "s" : ""} \{leg_number}</th>
<th>Runner\{((RelayRace)race).paired_legs.contains(leg_number) ? "s" : ""} \{leg_number}</th>
<th>Leg \{leg_number}</th>
<th>\{leg_number < ((RelayRace)race).number_of_legs ? STR."Split \{leg_number}" : "Total"}</th>
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

public class MidweekRace extends SeriesRace {

// TODO Move to config.
private static final int MAX_RACE_SCORE = 200;
private int max_race_score;

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

Expand All @@ -64,6 +64,7 @@ public static void main(final String[] args) throws IOException {
protected void readProperties() {

minimum_number_of_races = Integer.parseInt(getProperty(KEY_MINIMUM_NUMBER_OF_RACES));
max_race_score = Integer.parseInt(getProperty(KEY_MAX_RACE_SCORE));
}

@Override
Expand Down Expand Up @@ -203,24 +204,21 @@ private void recordDefinedClubForRunnerName(final String runner_name, final Stri

public int calculateRaceScore(final IndividualRace individual_race, final Runner runner) {

// TODO try writing as stream.
if (individual_race == null) return 0;

int score = MAX_RACE_SCORE;

final String gender = runner.category.getGender();
final AtomicInteger score = new AtomicInteger(max_race_score + 1);

// The first finisher of each gender gets the maximum score, the next finisher one less, and so on.
for (final RaceResult result : individual_race.getOverallResults()) {

IndividualRaceResult result1 = (IndividualRaceResult) result;
final Runner result_runner = result1.entry.runner;

if (result1.getCompletionStatus() == CompletionStatus.COMPLETED && result_runner.equals(runner)) return Math.max(score, 0);
if (gender.equals(result_runner.category.getGender())) score--;
}

// Runner didn't compete in this race.
return 0;
return individual_race.getOverallResults().stream().
map(result -> (IndividualRaceResult) result).
filter(result -> result.getCompletionStatus() == CompletionStatus.COMPLETED).
map(result -> result.entry.runner).
peek(result_runner -> { if (gender.equals(result_runner.category.getGender())) score.decrementAndGet(); }).
filter(result_runner -> result_runner.equals(runner)).
findFirst().
map(_ -> Math.max(score.get(), 0)).
orElse(0); // Runner didn't compete in this race.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,,,,
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to config file.
CATEGORIES_PRIZE_PATH = categories_prize_individual_senior.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,strath_blebo/input/config.txt,,,
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to config file.
CATEGORIES_PRIZE_PATH = categories_prize_individual_senior.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,strath_blebo/input/config.txt,hill_of_tarvit/input/config.txt,,
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to config file.
CATEGORIES_PRIZE_PATH = categories_prize_individual_senior.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,strath_blebo/input/config.txt,hill_of_tarvit/input/config.txt,dunnikier/input/config.txt,
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to config file.
CATEGORIES_PRIZE_PATH = categories_prize_individual_senior.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,strath_blebo/input/config.txt,hill_of_tarvit/input/config.txt,dunnikier/input/config.txt,balmullo/input/config.txt
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to config file.
CATEGORIES_PRIZE_PATH = categories_prize_individual_senior.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,strath_blebo/input/config.txt,hill_of_tarvit/input/config.txt,dunnikier/input/config.txt,balmullo/input/config.txt
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to config file.
CATEGORIES_PRIZE_PATH = categories_prize_individual_senior.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,strath_blebo/input/config.txt,tarvit/input/config.txt,dunnikier/input/config.txt,balmullo/input/config.txt
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to config file.
CATEGORIES_PRIZE_PATH = categories_prize_individual_senior.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,strath_blebo/input/config.txt,tarvit/input/config.txt,,
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to project root directory.
CATEGORIES_ENTRY_PATH = /src/main/resources/configuration/categories_entry_individual_senior.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,strath_blebo/input/config.txt,tarvit/input/config.txt,dunnikier/input/config.txt,balmullo/input/config.txt
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to project root directory.
CATEGORIES_ENTRY_PATH = /src/main/resources/configuration/categories_entry_individual_senior.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,strath_blebo/input/config.txt,tarvit/input/config.txt,,
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to project root directory.
CATEGORIES_ENTRY_PATH = /src/main/resources/configuration/categories_entry_individual_senior.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RACE_NAME_FOR_FILENAMES = midweek

RACES = st_andrews/input/config.txt,strath_blebo/input/config.txt,tarvit/input/config.txt,dunnikier/input/config.txt,balmullo/input/config.txt
MINIMUM_NUMBER_OF_RACES = 4
MAX_RACE_SCORE = 200

# Relative to config file.
CATEGORIES_PRIZE_PATH = categories_prize_individual_senior.csv
Expand Down

0 comments on commit f5e731a

Please sign in to comment.