Standings page ok
This commit is contained in:
@@ -15,6 +15,7 @@ import kotlin.math.max
|
|||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
import org.jeudego.pairgoth.model.Criterion.*
|
import org.jeudego.pairgoth.model.Criterion.*
|
||||||
|
import org.jeudego.pairgoth.model.Game.Result.*
|
||||||
import org.jeudego.pairgoth.model.ID
|
import org.jeudego.pairgoth.model.ID
|
||||||
import org.jeudego.pairgoth.model.getID
|
import org.jeudego.pairgoth.model.getID
|
||||||
|
|
||||||
@@ -36,7 +37,9 @@ object StandingsHandler: PairgothApiHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val criteria = tournament.pairing.placementParams.criteria.map { crit ->
|
val neededCriteria = ArrayList(tournament.pairing.placementParams.criteria)
|
||||||
|
if (!neededCriteria.contains(NBW)) neededCriteria.add(NBW)
|
||||||
|
val criteria = neededCriteria.map { crit ->
|
||||||
crit.name to when (crit) {
|
crit.name to when (crit) {
|
||||||
NONE -> nullMap
|
NONE -> nullMap
|
||||||
CATEGORY -> nullMap
|
CATEGORY -> nullMap
|
||||||
@@ -70,13 +73,13 @@ object StandingsHandler: PairgothApiHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val pairables = tournament.pairables.values.map { it.toMutableJson() }
|
val pairables = tournament.pairables.values.map { it.toMutableJson() }
|
||||||
pairables.forEach { it ->
|
pairables.forEach { player ->
|
||||||
val player = it as Json.MutableObject
|
|
||||||
for (crit in criteria) {
|
for (crit in criteria) {
|
||||||
player[crit.first] = crit.second[player.getID()]
|
player[crit.first] = crit.second[player.getID()] ?: 0.0
|
||||||
}
|
}
|
||||||
|
player["results"] = Json.MutableArray(List(round) { "=0" })
|
||||||
}
|
}
|
||||||
return pairables.sortedWith { left, right ->
|
val sortedPairables = pairables.sortedWith { left, right ->
|
||||||
for (crit in criteria) {
|
for (crit in criteria) {
|
||||||
val lval = left.getDouble(crit.first) ?: 0.0
|
val lval = left.getDouble(crit.first) ?: 0.0
|
||||||
val rval = right.getDouble(crit.first) ?: 0.0
|
val rval = right.getDouble(crit.first) ?: 0.0
|
||||||
@@ -84,8 +87,58 @@ object StandingsHandler: PairgothApiHandler {
|
|||||||
if (cmp != 0) return@sortedWith -cmp
|
if (cmp != 0) return@sortedWith -cmp
|
||||||
}
|
}
|
||||||
return@sortedWith 0
|
return@sortedWith 0
|
||||||
|
}.mapIndexed() { i, obj ->
|
||||||
}.toJsonArray()
|
obj.set("num", i+1)
|
||||||
|
}
|
||||||
|
val sortedMap = sortedPairables.associateBy {
|
||||||
|
it.getID()!!
|
||||||
|
}
|
||||||
|
var place = 1
|
||||||
|
sortedPairables.groupBy { p ->
|
||||||
|
Triple(p.getDouble(criteria[0].first) ?: 0.0, p.getDouble(criteria[1].first) ?: 0.0, p.getDouble(criteria[2].first) ?: 0.0)
|
||||||
|
}.forEach {
|
||||||
|
it.value.forEach { p -> p["place"] = place }
|
||||||
|
place += it.value.size
|
||||||
|
}
|
||||||
|
for (r in 1..round) {
|
||||||
|
tournament.games(r).values.forEach { game ->
|
||||||
|
val white = if (game.white != 0) sortedMap[game.white] else null
|
||||||
|
val black = if (game.black != 0) sortedMap[game.black] else null
|
||||||
|
val whiteNum = white?.getInt("num") ?: 0
|
||||||
|
val blackNum = black?.getInt("num") ?: 0
|
||||||
|
val whiteColor = if (black == null) "" else "w"
|
||||||
|
val blackColor = if (white == null) "" else "b"
|
||||||
|
val handicap = if (game.handicap == 0) "" else "/h${game.handicap}"
|
||||||
|
assert(white != null || black != null)
|
||||||
|
if (white != null) {
|
||||||
|
val mark = when (game.result) {
|
||||||
|
UNKNOWN -> "?"
|
||||||
|
BLACK -> "-"
|
||||||
|
WHITE -> "+"
|
||||||
|
JIGO -> "="
|
||||||
|
CANCELLED -> "X"
|
||||||
|
BOTHWIN -> "++"
|
||||||
|
BOTHLOOSE -> "--"
|
||||||
|
}
|
||||||
|
val results = white.getArray("results") as Json.MutableArray
|
||||||
|
results[r - 1] = "$whiteColor$mark$blackNum$handicap"
|
||||||
|
}
|
||||||
|
if (black != null) {
|
||||||
|
val mark = when (game.result) {
|
||||||
|
UNKNOWN -> "?"
|
||||||
|
BLACK -> "+"
|
||||||
|
WHITE -> "-"
|
||||||
|
JIGO -> "="
|
||||||
|
CANCELLED -> "X"
|
||||||
|
BOTHWIN -> "++"
|
||||||
|
BOTHLOOSE -> "--"
|
||||||
|
}
|
||||||
|
val results = black.getArray("results") as Json.MutableArray
|
||||||
|
results[r - 1] = "$blackColor$mark$whiteNum$handicap"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sortedPairables.toJsonArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
val nullMap = mapOf<ID, Double>()
|
val nullMap = mapOf<ID, Double>()
|
||||||
|
2
pom.xml
2
pom.xml
@@ -92,7 +92,7 @@
|
|||||||
<slf4j.version>2.0.7</slf4j.version>
|
<slf4j.version>2.0.7</slf4j.version>
|
||||||
|
|
||||||
<!-- kotlin -->
|
<!-- kotlin -->
|
||||||
<kotlin.version>1.8.21</kotlin.version>
|
<kotlin.version>1.9.22</kotlin.version>
|
||||||
<kotlin.code.style>official</kotlin.code.style>
|
<kotlin.code.style>official</kotlin.code.style>
|
||||||
<kotlin.compiler.jvmTarget>10</kotlin.compiler.jvmTarget>
|
<kotlin.compiler.jvmTarget>10</kotlin.compiler.jvmTarget>
|
||||||
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
|
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
#end
|
#end
|
||||||
<div class="tab-content" id="pairing">
|
<div class="tab-content" id="pairing">
|
||||||
<div id="pairing-content">
|
<div id="pairing-content">
|
||||||
<div id="pairing-round" class="active-round"-box>
|
<div id="pairing-round" class="active-round-box">
|
||||||
Pairings for round
|
Pairings for round
|
||||||
<button class="ui floating choose-round prev-round button">«</button>
|
<button class="ui floating choose-round prev-round button">«</button>
|
||||||
<span class="active-round">$round</span>
|
<span class="active-round">$round</span>
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
#foreach($game in $games)
|
#foreach($game in $games)
|
||||||
#set($white = $pmap[$game.w])
|
#set($white = $pmap[$game.w])
|
||||||
#set($black = $pmap[$game.b])
|
#set($black = $pmap[$game.b])
|
||||||
<div class="listitem game" data-id="$game.id"><span class="table">#$game.t</span><span class="white">#if($white)$white.name $white.firstname #rank($white.rank)#{else}BIP#end</span><span> </span><span class="black">#if($black)$black.name $black.firstname #rank($black.rank)#{else}BIP#end</span><span class="handicap">$game.h</span></div>
|
<div class="listitem game" data-id="$game.id"><span class="table">#$game.t</span><span class="white">#if($white)$white.name $white.firstname #rank($white.rank)#{else}BIP#end</span><span> </span><span class="black">#if($black)$black.name $black.firstname #rank($black.rank)#{else}BIP#end</span>#if($game.h)<span class="handicap">h$game.h</span>#end</div>
|
||||||
#end
|
#end
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -5,13 +5,13 @@
|
|||||||
#set($pmap = $utils.toMap($parts))
|
#set($pmap = $utils.toMap($parts))
|
||||||
<table id="players" class="ui celled selectable striped table">
|
<table id="players" class="ui celled selectable striped table">
|
||||||
<thead>
|
<thead>
|
||||||
<th>name</th>
|
<th>Name</th>
|
||||||
<th>first name</th>
|
<th>First name</th>
|
||||||
<th>country</th>
|
<th>Country</th>
|
||||||
<th>club</th>
|
<th>Club</th>
|
||||||
<th>rank</th>
|
<th>Rank</th>
|
||||||
<th>rating</th>
|
<th>Rating</th>
|
||||||
<th>participation</th>
|
<th>Participation</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
#foreach($part in $parts)
|
#foreach($part in $parts)
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
#foreach($placement in $tour.pairing.placement)
|
#foreach($placement in $tour.pairing.placement)
|
||||||
<div class="criterium field">
|
<div class="criterium field">
|
||||||
#set($num = $foreach.index + 1)
|
#set($num = $foreach.index + 1)
|
||||||
<label>Criterium #$num</label>
|
<label>Crit #$num</label>
|
||||||
#placement($num $placement)
|
#placement($num $placement)
|
||||||
</div>
|
</div>
|
||||||
#end
|
#end
|
||||||
@@ -45,8 +45,40 @@
|
|||||||
</script>
|
</script>
|
||||||
#set($standings = [])
|
#set($standings = [])
|
||||||
#end
|
#end
|
||||||
#foreach($line in $standings)
|
<table id="standings-table" class="ui striped table">
|
||||||
<div class="standings-line">$line</div>
|
<thead>
|
||||||
|
<th>Num</th>
|
||||||
|
<th>Plc</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Rank</th>
|
||||||
|
<th>Cntry</th>
|
||||||
|
<th>Nbw</th>
|
||||||
|
#foreach($r in [1..$round])
|
||||||
|
<th>R$r</th>
|
||||||
#end
|
#end
|
||||||
|
#foreach($crit in $tour.pairing.placement)
|
||||||
|
<th>$crit</th>
|
||||||
|
#end
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
#foreach($part in $standings)
|
||||||
|
<tr>
|
||||||
|
<td>$part.num</td>
|
||||||
|
<td>$part.place</td>
|
||||||
|
<td>$part.name $part.firstname</td>
|
||||||
|
<td>$part.rank</td>
|
||||||
|
<td>$part.country</td>
|
||||||
|
<td>$part.NBW</td>
|
||||||
|
#set($mx = $round - 1)
|
||||||
|
#foreach($r in [0..$mx])
|
||||||
|
<td class="nobreak">$part.results[$r]</td>
|
||||||
|
#end
|
||||||
|
#foreach($crit in $tour.pairing.placement)
|
||||||
|
<td>$number.format('0.#', $part[$crit])</td>
|
||||||
|
#end
|
||||||
|
</tr>
|
||||||
|
#end
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user