-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/fog_cup_calculation'
- Loading branch information
Showing
11 changed files
with
107 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,5 @@ src/main/.DS_Store | |
/node_modules/** | ||
/build-with-act.sh | ||
/build-images-with-act.sh | ||
/testdb.mv.db | ||
/testdb.trace.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 38 additions & 6 deletions
44
src/main/java/de/jobst/resulter/domain/scoring/NebelCalculationStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,63 @@ | ||
package de.jobst.resulter.domain.scoring; | ||
|
||
import de.jobst.resulter.domain.*; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.*; | ||
|
||
@Slf4j | ||
public class NebelCalculationStrategy implements CupTypeCalculationStrategy { | ||
|
||
private final Map<OrganisationId, Organisation> organisationById; | ||
|
||
Set<String> classesToSkip = Set.of("BK", "BL", "Beg", "Trim", "Beginner", "OffK", "OffL", "D/H-12 Be"); | ||
Set<String> organisationsToSkip = Set.of("ohne", "Volkssport"); | ||
|
||
public NebelCalculationStrategy(Map<OrganisationId, Organisation> organisationById) { | ||
this.organisationById = organisationById; | ||
} | ||
|
||
@Override | ||
public boolean valid(ClassResult classResult) { | ||
return false; | ||
return classesToSkip.stream().noneMatch(it -> classResult.classResultShortName().value().equals(it)); | ||
} | ||
|
||
@Override | ||
public boolean valid(PersonResult personResult) { | ||
return false; | ||
if (personResult.organisationId() != null && (personResult.organisationId().value () == 131)) { | ||
var org = organisationById.get(personResult.organisationId()); | ||
log.debug(org.toString()); | ||
} | ||
Boolean result = Optional.ofNullable(organisationById.get(personResult.organisationId())) | ||
.map(v -> { | ||
boolean contains = organisationsToSkip.contains(v.getShortName().value()); | ||
return !contains; | ||
}) | ||
.orElse(false); | ||
return result; | ||
} | ||
|
||
@Override | ||
public List<CupScore> calculate(Cup cup, List<PersonRaceResult> personRaceResults) { | ||
public List<CupScore> calculate(Cup cup, List<PersonRaceResult> personRaceResults, | ||
Map<PersonId, OrganisationId> organisationByPerson) { | ||
if (personRaceResults.isEmpty()) { | ||
return List.of(); | ||
} | ||
|
||
PunchTime fastestTime = personRaceResults.getFirst().getRuntime(); | ||
Set<OrganisationId> organisationWithScore = new HashSet<>(); | ||
var personRaceResultsWithScore = personRaceResults.stream() | ||
.filter(x -> Optional.ofNullable(organisationByPerson.get(x.getPersonId())) | ||
.filter(organisationWithScore::add) // predicate will be applied only if Optional is not empty | ||
.isPresent()) | ||
.toList(); | ||
|
||
return personRaceResultsWithScore.stream().map(x -> calculateScore(x, fastestTime)).toList(); | ||
} | ||
|
||
return null; | ||
private CupScore calculateScore(PersonRaceResult personRaceResult, PunchTime fastestTime) { | ||
return CupScore.of(personRaceResult.getPersonId(), | ||
personRaceResult.getClassResultShortName(), | ||
NORCalculationStrategy.calculateNorPoints(fastestTime.value(), personRaceResult.getRuntime().value())); | ||
} | ||
} |