16
16
*/
17
17
package org .grahamkirby .race_timing .individual_race ;
18
18
19
- import org .grahamkirby .race_timing .common .CompletionStatus ;
20
- import org .grahamkirby .race_timing .common .Normalisation ;
21
- import org .grahamkirby .race_timing .common .RaceInput ;
22
- import org .grahamkirby .race_timing .common .RaceResult ;
19
+ import org .grahamkirby .race_timing .common .*;
23
20
import org .grahamkirby .race_timing .common .categories .EntryCategory ;
24
21
import org .grahamkirby .race_timing .common .categories .PrizeCategory ;
25
22
import org .grahamkirby .race_timing .common .output .RaceOutputCSV ;
@@ -74,6 +71,39 @@ public EntryCategory findCategory(final int bib_number) {
74
71
return getEntryWithBibNumber (bib_number ).runner .category ;
75
72
}
76
73
74
+ public Duration getRunnerTime (final Runner runner ) {
75
+
76
+ final List <RaceResult > results = getOverallResults ();
77
+
78
+ for (final RaceResult result : results ) {
79
+
80
+ final IndividualRaceResult individual_result = (IndividualRaceResult ) result ;
81
+ if (individual_result .entry .runner .equals (runner ))
82
+ return individual_result .duration ();
83
+ }
84
+
85
+ return null ;
86
+ }
87
+
88
+ public Duration getMedianTime () {
89
+
90
+ if (median_time_string != null ) return Normalisation .parseTime (median_time_string );
91
+
92
+ final List <RaceResult > results = getOverallResults ();
93
+
94
+ if (results .size () % 2 == 0 ) {
95
+
96
+ final IndividualRaceResult median_result1 = (IndividualRaceResult ) results .get (results .size () / 2 );
97
+ final IndividualRaceResult median_result2 = (IndividualRaceResult ) results .get (results .size () / 2 + 1 );
98
+
99
+ return median_result1 .finish_time .plus (median_result2 .finish_time ).dividedBy (2 );
100
+ }
101
+ else {
102
+ final IndividualRaceResult median_result = (IndividualRaceResult ) results .get (results .size () / 2 );
103
+ return median_result .finish_time ;
104
+ }
105
+ }
106
+
77
107
//////////////////////////////////////////////////////////////////////////////////////////////////
78
108
79
109
private int compareRecordedPosition (final RaceResult r1 , final RaceResult r2 ) {
@@ -101,8 +131,6 @@ protected void readProperties() throws IOException {
101
131
102
132
super .readProperties ();
103
133
104
- // Specifies all the bib numbers for runners who did have a finish
105
- // time recorded but were declared DNF.
106
134
median_time_string = getProperty (KEY_MEDIAN_TIME );
107
135
}
108
136
@@ -134,11 +162,10 @@ protected RaceOutputPDF getOutputPDF() {
134
162
@ Override
135
163
protected void initialiseResults () {
136
164
137
- if (entries != null )
138
- entries .stream ().
139
- map (entry -> (IndividualRaceEntry ) entry ).
140
- map (entry -> new IndividualRaceResult (this , entry )).
141
- forEachOrdered (overall_results ::add );
165
+ entries .stream ().
166
+ map (entry -> (IndividualRaceEntry ) entry ).
167
+ map (entry -> new IndividualRaceResult (this , entry )).
168
+ forEachOrdered (overall_results ::add );
142
169
}
143
170
144
171
@ Override
@@ -166,12 +193,11 @@ public List<Comparator<RaceResult>> getDNFComparators() {
166
193
@ Override
167
194
protected boolean entryCategoryIsEligibleForPrizeCategoryByGender (final EntryCategory entry_category , final PrizeCategory prize_category ) {
168
195
169
- if (entry_category == null ) return true ;
170
- return entry_category .getGender ().equals (prize_category .getGender ());
196
+ return entry_category == null || entry_category .getGender ().equals (prize_category .getGender ());
171
197
}
172
198
173
199
@ Override
174
- protected EntryCategory getEntryCategory (RaceResult result ) {
200
+ protected EntryCategory getEntryCategory (final RaceResult result ) {
175
201
176
202
return ((IndividualRaceResult ) result ).entry .runner .category ;
177
203
}
@@ -192,37 +218,17 @@ protected void fillDNF(final String dnf_string) {
192
218
193
219
//////////////////////////////////////////////////////////////////////////////////////////////////
194
220
195
- public Duration getMedianTime () {
196
-
197
- if (median_time_string != null ) return Normalisation .parseTime (median_time_string );
198
-
199
- final List <RaceResult > results = getOverallResults ();
200
-
201
- if (results .size () % 2 == 0 ) {
202
-
203
- final IndividualRaceResult median_result1 = (IndividualRaceResult ) results .get (results .size () / 2 );
204
- final IndividualRaceResult median_result2 = (IndividualRaceResult ) results .get (results .size () / 2 + 1 );
205
-
206
- return median_result1 .finish_time .plus (median_result2 .finish_time ).dividedBy (2 );
207
- }
208
- else {
209
- final IndividualRaceResult median_result = (IndividualRaceResult ) results .get (results .size () / 2 );
210
- return median_result .finish_time ;
211
- }
212
- }
213
-
214
221
private void fillFinishTimes () {
215
222
216
- if (raw_results != null )
217
- raw_results .forEach (raw_result -> {
223
+ raw_results .forEach (raw_result -> {
218
224
219
- final IndividualRaceResult result = getResultWithBibNumber (raw_result .getBibNumber ());
220
- result .finish_time = raw_result .getRecordedFinishTime ();
225
+ final IndividualRaceResult result = getResultWithBibNumber (raw_result .getBibNumber ());
226
+ result .finish_time = raw_result .getRecordedFinishTime ();
221
227
222
- // Provisionally this result is not DNF since a finish time was recorded.
223
- // However, it might still be set to DNF in fillDNF() if the runner didn't complete the course.
224
- result .completion_status = CompletionStatus .COMPLETED ;
225
- });
228
+ // Provisionally this result is not DNF since a finish time was recorded.
229
+ // However, it might still be set to DNF in fillDNF() if the runner didn't complete the course.
230
+ result .completion_status = CompletionStatus .COMPLETED ;
231
+ });
226
232
}
227
233
228
234
private IndividualRaceResult getResultWithBibNumber (final int bib_number ) {
0 commit comments