fix tournament TV selector
This commit is contained in:
parent
2cedd9313c
commit
342a443b9f
|
@ -86,10 +86,14 @@ private[tournament] final class TournamentApi(
|
||||||
private def featureOneOf(tour: Tournament, pairings: Pairings, ranking: Ranking): Funit =
|
private def featureOneOf(tour: Tournament, pairings: Pairings, ranking: Ranking): Funit =
|
||||||
tour.featuredId.ifTrue(pairings.nonEmpty) ?? PairingRepo.byId map2
|
tour.featuredId.ifTrue(pairings.nonEmpty) ?? PairingRepo.byId map2
|
||||||
RankedPairing(ranking) map (_.flatten) flatMap { curOption =>
|
RankedPairing(ranking) map (_.flatten) flatMap { curOption =>
|
||||||
val candidates = pairings flatMap RankedPairing(ranking)
|
val bestCandidate = pairings.flatMap(RankedPairing(ranking)).sortBy(_.bestRank).headOption
|
||||||
if (curOption.exists(_.pairing.playing)) funit
|
def select(rp: RankedPairing) = TournamentRepo.setFeaturedGameId(tour.id, rp.pairing.gameId)
|
||||||
else candidates.sortBy(_.bestRank).headOption ?? { best =>
|
curOption.filter(_.pairing.playing) match {
|
||||||
TournamentRepo.setFeaturedGameId(tour.id, best.pairing.gameId)
|
case Some(current) =>
|
||||||
|
if (current.pairing.playing)
|
||||||
|
bestCandidate.filter(_.bestRank < current.bestRank) ?? select
|
||||||
|
else bestCandidate ?? select
|
||||||
|
case None => bestCandidate ?? select
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ case class TourAndRanks(
|
||||||
case class RankedPairing(pairing: Pairing, rank1: Int, rank2: Int) {
|
case class RankedPairing(pairing: Pairing, rank1: Int, rank2: Int) {
|
||||||
|
|
||||||
def bestRank = rank1 min rank2
|
def bestRank = rank1 min rank2
|
||||||
def rankSum = rank1 + rank2
|
// def rankSum = rank1 + rank2
|
||||||
|
|
||||||
def bestColor = chess.Color(rank1 < rank2)
|
def bestColor = chess.Color(rank1 < rank2)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue