Team of individuals: initial display of results page ok
This commit is contained in:
@@ -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? {
|
||||
|
@@ -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<ID, Player>()
|
||||
val teams: MutableMap<ID, Team> = _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<ID, List<Game>>()
|
||||
|
||||
fun individualGames(round: Int): List<Game> {
|
||||
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()
|
||||
|
@@ -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
|
||||
<div class="tab-content" id="pairing-tab">
|
||||
<div id="pairing-content">
|
||||
@@ -77,7 +82,9 @@
|
||||
</div>
|
||||
#end
|
||||
</div>
|
||||
#if(!$tour.type.startsWith('TEAM'))
|
||||
<div class="result-sheets"><a href="result-sheets?id=${tour.id}&round=${round}" target="_blank" class="ui mini floating icon button">result sheets <i class="fa fa-external-link"></i></a></div>
|
||||
#end
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
<button class="ui floating choose-round prev-round button">«</button>
|
||||
<span class="active-round">$round</span>
|
||||
<button class="ui floating choose-round next-round button">»</button>
|
||||
#set($stats = $utils.getResultsStats($games))
|
||||
#set($stats = $utils.getResultsStats($individualGames))
|
||||
<span class="norbeak">( <span id="known">$stats.known</span> / $stats.total )</span>
|
||||
<div id="results-filter" class="toggle">
|
||||
<input type="checkbox" value="true"/>
|
||||
@@ -25,9 +25,9 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
#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)
|
||||
<tr id="result-$game.id" data-id="$game.id">
|
||||
<td data-sort="$game.t">${game.t}.</td>
|
||||
|
Reference in New Issue
Block a user