diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/StandingsHandler.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/StandingsHandler.kt index 4e3a586..38bb876 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/StandingsHandler.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/StandingsHandler.kt @@ -15,6 +15,7 @@ import kotlin.math.max import kotlin.math.min import org.jeudego.pairgoth.model.Criterion.* +import org.jeudego.pairgoth.model.Game.Result.* import org.jeudego.pairgoth.model.ID 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) { NONE -> nullMap CATEGORY -> nullMap @@ -70,13 +73,13 @@ object StandingsHandler: PairgothApiHandler { } } val pairables = tournament.pairables.values.map { it.toMutableJson() } - pairables.forEach { it -> - val player = it as Json.MutableObject + pairables.forEach { player -> 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) { val lval = left.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 } return@sortedWith 0 - - }.toJsonArray() + }.mapIndexed() { i, obj -> + 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() diff --git a/pom.xml b/pom.xml index d794366..33557d5 100644 --- a/pom.xml +++ b/pom.xml @@ -92,7 +92,7 @@ 2.0.7 - 1.8.21 + 1.9.22 official 10 true diff --git a/view-webapp/src/main/webapp/tour-pairing.inc.html b/view-webapp/src/main/webapp/tour-pairing.inc.html index 41c641a..1f52090 100644 --- a/view-webapp/src/main/webapp/tour-pairing.inc.html +++ b/view-webapp/src/main/webapp/tour-pairing.inc.html @@ -15,7 +15,7 @@ #end
-
+
Pairings for round $round @@ -42,7 +42,7 @@ #foreach($game in $games) #set($white = $pmap[$game.w]) #set($black = $pmap[$game.b]) -
#$game.t#if($white)$white.name $white.firstname #rank($white.rank)#{else}BIP#end #if($black)$black.name $black.firstname #rank($black.rank)#{else}BIP#end$game.h
+
#$game.t#if($white)$white.name $white.firstname #rank($white.rank)#{else}BIP#end #if($black)$black.name $black.firstname #rank($black.rank)#{else}BIP#end#if($game.h)h$game.h#end
#end
diff --git a/view-webapp/src/main/webapp/tour-registration.inc.html b/view-webapp/src/main/webapp/tour-registration.inc.html index 4d2aa49..b3926cd 100644 --- a/view-webapp/src/main/webapp/tour-registration.inc.html +++ b/view-webapp/src/main/webapp/tour-registration.inc.html @@ -5,13 +5,13 @@ #set($pmap = $utils.toMap($parts)) - - - - - - - + + + + + + + #foreach($part in $parts) diff --git a/view-webapp/src/main/webapp/tour-standings.inc.html b/view-webapp/src/main/webapp/tour-standings.inc.html index 9af4f5f..b2d3b23 100644 --- a/view-webapp/src/main/webapp/tour-standings.inc.html +++ b/view-webapp/src/main/webapp/tour-standings.inc.html @@ -19,7 +19,7 @@ #foreach($placement in $tour.pairing.placement)
#set($num = $foreach.index + 1) - + #placement($num $placement)
#end @@ -45,8 +45,40 @@ #set($standings = []) #end -#foreach($line in $standings) -
$line
+
namefirst namecountryclubrankratingparticipationNameFirst nameCountryClubRankRatingParticipation
+ + + + + + + +#foreach($r in [1..$round]) + #end +#foreach($crit in $tour.pairing.placement) + +#end + + +#foreach($part in $standings) + + + + + + + + #set($mx = $round - 1) + #foreach($r in [0..$mx]) + + #end + #foreach($crit in $tour.pairing.placement) + + #end + +#end + +
NumPlcNameRankCntryNbwR$r$crit
$part.num$part.place$part.name $part.firstname$part.rank$part.country$part.NBW$part.results[$r]$number.format('0.#', $part[$crit])