more user nb games denormalization, fix filters and improve win chart

pull/83/head
Thibault Duplessis 2012-09-08 14:23:12 +02:00
parent 5bb6fc273f
commit de920db74a
7 changed files with 25 additions and 25 deletions

View File

@ -44,9 +44,9 @@ object GameFilterMenu extends NonEmptyLists {
val all = nel(All, List(
info.nbWithMe.fold(_ > 0, false) option Me,
(info.nbRated > 0) option Rated,
(info.nbWin > 0) option Win,
(info.nbLoss > 0) option Loss,
(info.nbDraw > 0) option Draw,
(info.user.nbWins > 0) option Win,
(info.user.nbLosses > 0) option Loss,
(info.user.nbDraws > 0) option Draw,
(info.nbPlaying > 0) option Playing,
(info.nbBookmark > 0) option Bookmark
).flatten)
@ -67,9 +67,9 @@ object GameFilterMenu extends NonEmptyLists {
val cachedNb: Option[Int] = current match {
case All info.user.nbGames.some
case Rated info.nbRated.some
case Win info.nbWin.some
case Loss info.nbLoss.some
case Draw info.nbDraw.some
case Win info.user.nbWins.some
case Loss info.user.nbLosses.some
case Draw info.user.nbDraws.some
case _ None
}

View File

@ -14,6 +14,10 @@ case class User(
nbWins: Int,
nbLosses: Int,
nbDraws: Int,
nbWinsH: Int, // only against human opponents
nbLossesH: Int, // only against human opponents
nbDrawsH: Int, // only against human opponents
nbAi: Int,
isChatBan: Boolean = false,
enabled: Boolean,
roles: List[String],

View File

@ -12,9 +12,6 @@ import scalaz.effects._
case class UserInfo(
user: User,
rank: Option[(Int, Int)],
nbWin: Int,
nbDraw: Int,
nbLoss: Int,
nbPlaying: Int,
nbWithMe: Option[Int],
nbBookmark: Int,
@ -47,9 +44,6 @@ object UserInfo {
Some(rank -> countUsers())
},
io(None))
nbWin = user.nbWins
nbLoss = user.nbLosses
nbDraw = user.nbDraws
nbPlaying (ctx is user).fold(
gameRepo count (_ notFinished user) map (_.some),
io(none)
@ -61,7 +55,7 @@ object UserInfo {
nbBookmark = bookmarkApi countByUser user
eloChart eloChartBuilder(user)
winChart = (user.nbRatedGames > 0) option {
new WinChart(nbWin, nbDraw, nbLoss)
new WinChart(user.nbWinsH, user.nbDrawsH, user.nbLossesH, user.nbAi)
}
eloWithMe = ctx.me.filter(user!=) map { me
List(
@ -73,9 +67,6 @@ object UserInfo {
} yield new UserInfo(
user = user,
rank = rank,
nbWin = nbWin,
nbDraw = nbDraw,
nbLoss = nbLoss,
nbPlaying = nbPlaying | 0,
nbWithMe = nbWithMe,
nbBookmark = nbBookmark,

View File

@ -8,7 +8,7 @@ import scalaz.effects._
import com.codahale.jerkson.Json
import i18n.I18nKeys
final class WinChart(nbWin: Int, nbDraw: Int, nbLoss: Int) {
final class WinChart(nbWin: Int, nbDraw: Int, nbLoss: Int, nbAi: Int) {
val columns = Json generate List(
"string" :: "Result" :: Nil,
@ -18,6 +18,7 @@ final class WinChart(nbWin: Int, nbDraw: Int, nbLoss: Int) {
List(
List(trans.nbWins.str(nbWin), nbWin),
List(trans.nbLosses.str(nbLoss), nbLoss),
List(trans.nbDraws.str(nbDraw), nbDraw))
List(trans.nbDraws.str(nbDraw), nbDraw),
List("AI", nbAi))
}
}

View File

@ -11,13 +11,13 @@ case lila.user.GameFilter.Rated => {
@info.nbRated @trans.rated()
}
case lila.user.GameFilter.Win => {
@trans.nbWins(info.nbWin)
@trans.nbWins(info.user.nbWins)
}
case lila.user.GameFilter.Loss => {
@trans.nbLosses(info.nbLoss)
@trans.nbLosses(info.user.nbLosses)
}
case lila.user.GameFilter.Draw => {
@trans.nbDraws(info.nbDraw)
@trans.nbDraws(info.user.nbDraws)
}
case lila.user.GameFilter.Playing => {
@info.nbPlaying playing

View File

@ -1,9 +1,13 @@
db.user2.find({}).forEach(function(user) {
var uid = user['_id'];
var data = {
nbWins: db.game2.count({"winId": uid, "players.aiLevel":{$exists:false}}),
nbLosses: db.game2.count({"userIds": uid, "status": { "$in": [ 30, 31, 35, 33 ] }, "winId": {"$ne": uid}, "players.aiLevel":{$exists:false}}),
nbDraws: db.game2.count({"userIds": uid, "status": { "$in": [34, 32] }, "players.aiLevel":{$exists:false}})
nbWins: db.game2.count({"winId": uid}),
nbLosses: db.game2.count({"userIds": uid, "status": { "$in": [ 30, 31, 35, 33 ] }, "winId": {"$ne": uid}}),
nbDraws: db.game2.count({"userIds": uid, "status": { "$in": [34, 32] }}),
nbWinsH: db.game2.count({"winId": uid, "players.aiLevel":{$exists:false}}),
nbLossesH: db.game2.count({"userIds": uid, "status": { "$in": [ 30, 31, 35, 33 ] }, "winId": {"$ne": uid}, "players.aiLevel":{$exists:false}}),
nbDrawsH: db.game2.count({"userIds": uid, "status": { "$in": [34, 32] }, "players.aiLevel":{$exists:false}}),
nbAi: db.game2.count({"userIds": uid, "players.aiLevel":{$exists:true}})
};
db.user2.update({"_id": uid}, {"$set":data});
});

2
todo
View File

@ -43,4 +43,4 @@ count ai games in nb wins/losses http://en.lichess.org/@/ivym http://en.lichess.
index game positions
integrate with google+
elo stats
feedback changes to do http://en.lichess.org/forum/lichess-feedback/new-feature-landing-advanced-search#3
player search autocomplete regex escapement