User win chart
parent
0e7b4512b9
commit
39cf289225
|
@ -6,6 +6,7 @@ import DbGame._
|
|||
import chess.{ Color, Variant, Status }
|
||||
import chess.format.Forsyth
|
||||
import round.Progress
|
||||
import user.User
|
||||
|
||||
import com.novus.salat._
|
||||
import com.novus.salat.dao._
|
||||
|
@ -146,6 +147,25 @@ class GameRepo(collection: MongoCollection)
|
|||
count(DBObject("status" -> Status.Mate.id)).toInt
|
||||
}
|
||||
|
||||
def countWinBy(user: User): IO[Int] = io {
|
||||
count(DBObject("winnerUserId" -> user.id.toString)).toInt
|
||||
}
|
||||
|
||||
def countDrawBy(user: User): IO[Int] = io {
|
||||
count(
|
||||
("status" $in List(Status.Draw.id, Status.Stalemate.id)) ++
|
||||
("userIds" -> user.id.toString)
|
||||
).toInt
|
||||
}
|
||||
|
||||
def countLossBy(user: User): IO[Int] = io {
|
||||
count(
|
||||
("status" $in List(Status.Mate.id, Status.Resign.id, Status.Outoftime.id, Status.Timeout.id)) ++
|
||||
("userIds" -> user.id.toString) ++
|
||||
("winnerUserId" $ne user.id.toString)
|
||||
).toInt
|
||||
}
|
||||
|
||||
def recentGames(limit: Int): IO[List[DbGame]] = io {
|
||||
find(DBObject("status" -> Status.Started.id))
|
||||
.sort(DBObject("updatedAt" -> -1))
|
||||
|
|
|
@ -10,8 +10,12 @@ import scalaz.effects._
|
|||
case class UserInfo(
|
||||
user: User,
|
||||
rank: Option[(Int, Int)],
|
||||
nbWin: Int,
|
||||
nbDraw: Int,
|
||||
nbLoss: Int,
|
||||
eloWithMe: Option[List[(String, Int)]],
|
||||
eloChart: Option[EloChart]) {
|
||||
eloChart: Option[EloChart],
|
||||
winChart: Option[WinChart]) {
|
||||
}
|
||||
|
||||
object UserInfo {
|
||||
|
@ -30,7 +34,13 @@ object UserInfo {
|
|||
}
|
||||
},
|
||||
io(None))
|
||||
nbWin ← gameRepo countWinBy user
|
||||
nbDraw ← gameRepo countDrawBy user
|
||||
nbLoss ← gameRepo countLossBy user
|
||||
eloChart ← eloChartBuilder(user)
|
||||
winChart = (user.nbGames > 0) option {
|
||||
new WinChart(nbWin, nbDraw, nbLoss)
|
||||
}
|
||||
eloWithMe = ctx.me.filter(user!=) map { me ⇒
|
||||
List(
|
||||
"win" -> eloCalculator.diff(me, user, Color.White.some),
|
||||
|
@ -40,6 +50,10 @@ object UserInfo {
|
|||
} yield new UserInfo(
|
||||
user = user,
|
||||
rank = rank,
|
||||
nbWin = nbWin,
|
||||
nbDraw = nbDraw,
|
||||
nbLoss = nbLoss,
|
||||
eloWithMe = eloWithMe,
|
||||
eloChart = eloChart)
|
||||
eloChart = eloChart,
|
||||
winChart = winChart)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package lila
|
||||
package user
|
||||
|
||||
import http.Context
|
||||
|
||||
import scala.math.round
|
||||
import scalaz.effects._
|
||||
import com.codahale.jerkson.Json
|
||||
import i18n.I18nKeys
|
||||
|
||||
final class WinChart(nbWin: Int, nbDraw: Int, nbLoss: Int) {
|
||||
|
||||
val columns = Json generate List(
|
||||
"string" :: "Result" :: Nil,
|
||||
"number" :: "Games" :: Nil)
|
||||
|
||||
def rows(trans: I18nKeys)(implicit ctx: Context) = Json generate {
|
||||
List(
|
||||
List(trans.nbWins.str(nbWin), nbWin),
|
||||
List(trans.nbLosses.str(nbLoss), nbLoss),
|
||||
List(trans.nbDraws.str(nbDraw), nbDraw))
|
||||
}
|
||||
}
|
|
@ -41,5 +41,10 @@ evenMoreJs = evenMoreJs) {
|
|||
@e._1.capitalize: <strong>@showNumber(e._2)</strong>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
<div class="stats">
|
||||
@info.winChart.map { winChart =>
|
||||
<div class="win_stats" title="@trans.gamesPlayed(): @u.nbGames" data-columns="@winChart.columns" data-rows="@winChart.rows(trans)"></div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue