show tournament opponents rating average on podium
This commit is contained in:
parent
6126920a26
commit
42f77bee24
|
@ -86,7 +86,7 @@ object Tournament extends LilaController {
|
|||
OptionResult(repo byId id) { tour =>
|
||||
env.api.withdraw(tour, me.id)
|
||||
if (HTTPRequest.isXhr(ctx.req)) Ok(Json.obj("ok" -> true)) as JSON
|
||||
else Redirect(routes.Tournament.show(tour.id).url)
|
||||
else Redirect(routes.Tournament.show(tour.id))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ final class JsonView(
|
|||
"private" -> tour.`private`,
|
||||
"schedule" -> tour.schedule.map(scheduleJson),
|
||||
"variant" -> tour.variant.key,
|
||||
"players" -> tour.rankedPlayers.map(playerJson(sheets)),
|
||||
"players" -> tour.rankedPlayers.map(playerJson(sheets, tour)),
|
||||
"winner" -> tour.winner.map(_.id),
|
||||
"pairings" -> tour.pairings.take(50).map(pairingJson),
|
||||
"isOpen" -> tour.isOpen,
|
||||
|
@ -85,7 +85,7 @@ final class JsonView(
|
|||
"neustadtl" -> s.neustadtlRepr)
|
||||
}
|
||||
|
||||
private def playerJson(sheets: Map[String, ScoreSheet])(rankedPlayer: RankedPlayer) = {
|
||||
private def playerJson(sheets: Map[String, ScoreSheet], tour: Tournament)(rankedPlayer: RankedPlayer) = {
|
||||
val p = rankedPlayer.player
|
||||
val light = getLightUser(p.id)
|
||||
Json.obj(
|
||||
|
@ -97,9 +97,21 @@ final class JsonView(
|
|||
"withdraw" -> p.withdraw.option(true),
|
||||
"score" -> p.score,
|
||||
"perf" -> p.perf,
|
||||
"opposition" -> tour.isFinished.option(opposition(tour, p)),
|
||||
"sheet" -> sheets.get(p.id).map(sheetJson)).noNull
|
||||
}
|
||||
|
||||
private def opposition(tour: Tournament, p: Player): Int =
|
||||
tour.userPairings(p.id).foldLeft((0, 0)) {
|
||||
case ((count, sum), pairing) => (
|
||||
count + 1,
|
||||
(pairing opponentOf p.id flatMap tour.playerByUserId).fold(sum)(_.rating + sum)
|
||||
)
|
||||
} match {
|
||||
case (0, _) => 0
|
||||
case (count, sum) => sum / count
|
||||
}
|
||||
|
||||
private def pairingUserJson(userId: String) = {
|
||||
val name = getLightUser(userId).fold(userId)(_.name)
|
||||
if (name == userId) Json.arr(userId)
|
||||
|
|
|
@ -106,7 +106,17 @@ ol.scheduled_tournaments a:hover {
|
|||
font-size: 0.8em;
|
||||
}
|
||||
#tournament .podium .stats {
|
||||
margin-top: 8px;
|
||||
margin: 0.5em auto 0 auto;
|
||||
font-size: 0.7em;
|
||||
}
|
||||
#tournament .podium .stats th {
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
#tournament .podium .stats td {
|
||||
font-weight: bold;
|
||||
padding-left: 5px;
|
||||
}
|
||||
#tournament .podium .third .stats {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
#tournament div.tournament_show {
|
||||
|
|
|
@ -79,10 +79,11 @@ function podiumStats(p, data) {
|
|||
p.rating,
|
||||
perf
|
||||
]),
|
||||
m('div.stats', [
|
||||
m('p', ['Win: ', m('strong', winP + '%')]),
|
||||
berserkP > 0 ? m('p', ['Berserk: ', m('strong', berserkP + '%')]) : null
|
||||
])
|
||||
m('table.stats', m('tbody', [
|
||||
m('tr', [m('th', 'Win rate'), m('td', winP + '%')]),
|
||||
p.opposition ? m('tr', [m('th', 'Opponents rating'), m('td', p.opposition)]) : null,
|
||||
berserkP > 0 ? m('tr', [m('th', 'Berserk rate'), m('td', berserkP + '%')]) : null
|
||||
]))
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue