From 47c729e61a1b33fcb1d545068bc9500d61dc5d46 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Sun, 26 Jan 2025 18:21:59 +0100 Subject: [PATCH] Team of individuals: initial display of results page ok --- .../jeudego/pairgoth/api/PairingHandler.kt | 6 ++++- .../org/jeudego/pairgoth/model/Tournament.kt | 25 ++++++++++++++++++- .../src/main/webapp/tour-pairing.inc.html | 7 ++++++ .../main/webapp/tour-registration.inc.html | 2 ++ .../src/main/webapp/tour-results.inc.html | 8 +++--- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt index c4d080c..544814e 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/PairingHandler.kt @@ -31,11 +31,15 @@ object PairingHandler: PairgothApiHandler { val games = tournament.games(round).values.sortedBy { if (it.table == 0) Int.MAX_VALUE else it.table } - return Json.Object( + val ret = Json.MutableObject( "games" to games.map { it.toJson() }.toCollection(Json.MutableArray()), "pairables" to pairables, "unpairables" to unpairables ) + if (tournament is TeamTournament) { + ret["individualGames"] = tournament.individualGames(round).map { it.toJson() }.toJsonArray() + } + return ret } override fun post(request: HttpServletRequest, response: HttpServletResponse): Json? { diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt index 5452804..29402e6 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt @@ -7,6 +7,7 @@ import com.republicate.kson.toJsonArray import java.time.LocalDate import org.jeudego.pairgoth.api.ApiHandler.Companion.badRequest import org.jeudego.pairgoth.api.ApiHandler.Companion.logger +import org.jeudego.pairgoth.store.nextGameId import org.jeudego.pairgoth.store.nextPlayerId import org.jeudego.pairgoth.store.nextTournamentId import kotlin.math.max @@ -241,6 +242,26 @@ class TeamTournament( override val players = mutableMapOf() val teams: MutableMap = _pairables + // For teams of individual players, map from a team game id to the list of individual games + // (filled on demand - it is merely a cache) + private val individualGames = mutableMapOf>() + + fun individualGames(round: Int): List { + val teamGames = games(round).values.toList() + return teamGames.flatMap { game -> + if (game.white == 0 || game.black ==0 ) listOf() + else { + individualGames.computeIfAbsent(game.id) { id -> + val whitePlayers = teams[game.white]!!.activePlayers(round) + val blackPlayers = teams[game.black]!!.activePlayers(round) + whitePlayers.zip(blackPlayers).map { + Game(nextGameId, game.table, it.first.id, it.second.id) + } + } + } + } + } + fun pairedTeams() = super.pairedPlayers() fun pairedTeams(round: Int) = super.pairedPlayers(round) @@ -271,7 +292,9 @@ class TeamTournament( } val teamOfIndividuals: Boolean get() = type.individual - override fun canPlay(round: Int) = teamPlayers.filter { it.canPlay(round) }.size == type.playersNumber + fun activePlayers(round: Int) = teamPlayers.filter { it.canPlay(round) }.sortedByDescending { it.rating } + + override fun canPlay(round: Int) = activePlayers(round).size == type.playersNumber } fun getPlayerTeam(playerId: ID) = teams.values.filter { it.playerIds.contains(playerId) }.firstOrNull() diff --git a/view-webapp/src/main/webapp/tour-pairing.inc.html b/view-webapp/src/main/webapp/tour-pairing.inc.html index aaceec9..4fb2aac 100644 --- a/view-webapp/src/main/webapp/tour-pairing.inc.html +++ b/view-webapp/src/main/webapp/tour-pairing.inc.html @@ -12,6 +12,11 @@ #set($pairables = $roundPairing.pairables) #set($games = $roundPairing.games) #set($unpairables = $roundPairing.unpairables) + #if($tour.type.startsWith('TEAM')) + #set($individualGames = $roundPairing.individualGames) + #else + #set($individualGames = $games) + #end #end
@@ -77,7 +82,9 @@
#end
+#if(!$tour.type.startsWith('TEAM')) +#end diff --git a/view-webapp/src/main/webapp/tour-registration.inc.html b/view-webapp/src/main/webapp/tour-registration.inc.html index a3475ea..178b8d7 100644 --- a/view-webapp/src/main/webapp/tour-registration.inc.html +++ b/view-webapp/src/main/webapp/tour-registration.inc.html @@ -2,10 +2,12 @@ #if($tour.type == 'INDIVIDUAL') ## Standard tournament #set($pmap = $utils.toMap($parts)) + #set($plmap = $pmap) #else ## Pairgo, rengo and teams of individuals #set($teams = $api.get("tour/${params.id}/team")) #set($pmap = $utils.toMap($teams)) + #set($plmap = $utils.toMap($parts)) #set($tmap = $utils.getTeamMap($teams)) #end diff --git a/view-webapp/src/main/webapp/tour-results.inc.html b/view-webapp/src/main/webapp/tour-results.inc.html index 12bca17..4bdfd15 100644 --- a/view-webapp/src/main/webapp/tour-results.inc.html +++ b/view-webapp/src/main/webapp/tour-results.inc.html @@ -4,7 +4,7 @@ $round -#set($stats = $utils.getResultsStats($games)) +#set($stats = $utils.getResultsStats($individualGames)) ( $stats.known / $stats.total )
@@ -25,9 +25,9 @@ #set($dispRst = {'?':'?', 'w':'1-0', 'b':'0-1', '=':'½-½', 'X':'X', '#':'1-1', '0':'0-0'}) -#foreach($game in $games) - #set($white = $pmap[$game.w]) - #set($black = $pmap[$game.b]) +#foreach($game in $individualGames) + #set($white = $plmap[$game.w]) + #set($black = $plmap[$game.b]) #if($black && $white) ${game.t}.