More code cleaning

This commit is contained in:
Claude Brisson
2024-08-13 15:24:58 +02:00
parent dd4ac87995
commit b039a549e3
3 changed files with 7 additions and 21 deletions

View File

@@ -34,9 +34,7 @@ fun Tournament<*>.getSortedPairables(round: Int, includePreliminary: Boolean = f
else ceil(score - epsilon) else ceil(score - epsilon)
} }
val historyHelper = HistoryHelper( val historyHelper = HistoryHelper(historyBefore(round + 1)) {
historyBefore(round + 1),
scoresGetter = {
if (pairing.type == PairingType.SWISS) wins.mapValues { Pair(0.0, it.value) } if (pairing.type == PairingType.SWISS) wins.mapValues { Pair(0.0, it.value) }
else pairables.mapValues { else pairables.mapValues {
it.value.let { pairable -> it.value.let { pairable ->
@@ -53,16 +51,7 @@ fun Tournament<*>.getSortedPairables(round: Int, includePreliminary: Boolean = f
) )
} }
} }
},
scoresXGetter = {
if (pairing.type == PairingType.SWISS) wins.mapValues { it.value }
else pairables.mapValues {
it.value.let { pairable ->
roundScore(pairable.mmBase() + (nbW(pairable) ?: 0.0))
} }
}
}
)
val neededCriteria = ArrayList(pairing.placementParams.criteria) val neededCriteria = ArrayList(pairing.placementParams.criteria)
if (!neededCriteria.contains(Criterion.NBW)) neededCriteria.add(Criterion.NBW) if (!neededCriteria.contains(Criterion.NBW)) neededCriteria.add(Criterion.NBW)
if (!neededCriteria.contains(Criterion.RATING)) neededCriteria.add(Criterion.RATING) if (!neededCriteria.contains(Criterion.RATING)) neededCriteria.add(Criterion.RATING)

View File

@@ -18,7 +18,7 @@ abstract class BasePairingHelper(
if (pairables.first().let { it is TeamTournament.Team && it.teamOfIndividuals }) TeamOfIndividualsHistoryHelper( if (pairables.first().let { it is TeamTournament.Team && it.teamOfIndividuals }) TeamOfIndividualsHistoryHelper(
history history
) { scores } ) { scores }
else HistoryHelper(history, scoresGetter = { scores }, scoresXGetter = { scoresX }) else HistoryHelper(history) { scores }
// Extend pairables with members from all rounds // Extend pairables with members from all rounds

View File

@@ -6,12 +6,7 @@ import org.jeudego.pairgoth.model.Game.Result.*
open class HistoryHelper( open class HistoryHelper(
protected val history: List<List<Game>>, protected val history: List<List<Game>>,
// scoresGetter() returns Pair(absentSosValueForOthers, score) where score is nbw for Swiss, mms for MM, ... // scoresGetter() returns Pair(absentSosValueForOthers, score) where score is nbw for Swiss, mms for MM, ...
scoresGetter: HistoryHelper.()-> Map<ID, Pair<Double, Double>>, scoresGetter: HistoryHelper.()-> Map<ID, Pair<Double, Double>>) {
// scoresXGetter(), defined by default as score
scoresXGetter: HistoryHelper.()-> Map<ID, Double> = {
scoresGetter().mapValues { entry -> entry.value.second
}
}) {
// List of all the pairables ID present in the history // List of all the pairables ID present in the history
val allPairables = history.flatten() val allPairables = history.flatten()
@@ -33,7 +28,9 @@ open class HistoryHelper(
} }
val scoresX by lazy { val scoresX by lazy {
scoresXGetter() scoresGetter().mapValues { entry ->
entry.value.first + (wins[entry.key] ?: 0.0)
}
} }
// Generic helper functions // Generic helper functions