improve elo adjustement and user profile

pull/1/merge
Thibault Duplessis 2012-06-02 13:05:11 +02:00
parent 89fe82e606
commit 6437c0297a
12 changed files with 68 additions and 51 deletions

View File

@ -18,6 +18,7 @@ object User extends LilaController {
def gamePaginator = env.game.paginator
def forms = user.DataForm
def eloUpdater = env.user.eloUpdater
def lobbyMessenger = env.lobby.messenger
def show(username: String) = showFilter(username, "all", 1)
@ -81,24 +82,14 @@ object User extends LilaController {
def engine(username: String) = Secure(Permission.MarkEngine) { _
_
IORedirect {
for {
uOption userRepo byId username
_ uOption.fold(
u for {
_ userRepo toggleEngine u.id
_ (!u.engine && u.elo > UserModel.STARTING_ELO).fold(
eloUpdater.adjust(u, UserModel.STARTING_ELO),
io())
} yield (),
io())
} yield routes.User show username
eloUpdater adjust username map { _ routes.User show username }
}
}
def mute(username: String) = Secure(Permission.MutePlayer) { _
_
IORedirect {
userRepo toggleMute username map { _ routes.User show username }
lobbyMessenger mute username map { _ routes.User show username }
}
}

View File

@ -0,0 +1,36 @@
package lila
package elo
import user.{ UserRepo, User, HistoryRepo }
import scalaz.effects._
import scala.math.max
final class EloUpdater(
userRepo: UserRepo,
historyRepo: HistoryRepo,
floor: Int) {
def game(user: User, elo: Int, gameId: String): IO[Unit] = {
val newElo = max(elo, floor)
userRepo.setElo(user.id, newElo) flatMap { _
historyRepo.addEntry(user.id, newElo, Some(gameId))
}
}
val adjustTo = User.STARTING_ELO
def adjust(username: String) = for {
uOption userRepo byId username
_ uOption.fold(
u for {
_ userRepo toggleEngine u.id
_ (!u.engine && u.elo > adjustTo).fold(
userRepo.setElo(u.id, adjustTo) flatMap { _
historyRepo.addEntry(u.id, adjustTo, entryType = HistoryRepo.TYPE_ADJUST)
},
io())
} yield (),
io())
} yield ()
}

View File

@ -22,7 +22,7 @@ extends CappedRepo[Message](collection, max) {
"u" -> obj.username,
"t" -> obj.text)
def deleteByUsername(username: String): IO[Unit] = io {
def censorUsername(username: String): IO[Unit] = io {
collection.update(
DBObject("u" -> username),
$set("t" -> ""),

View File

@ -33,4 +33,16 @@ final class Messenger(
!!("Empty message")
)
}
def mute(username: String): IO[Unit] = for {
uOption userRepo byId username
_ uOption.fold(
u for {
_ userRepo toggleMute u.id
_ u.isChatBan.fold(
io(),
messageRepo censorUsername u.username)
} yield (),
io())
} yield ()
}

View File

@ -2,8 +2,9 @@ package lila
package round
import game.{ GameRepo, DbGame, Pov }
import user.{ UserRepo, EloUpdater }
import user.UserRepo
import i18n.I18nKey.{ Select SelectI18nKey }
import elo.EloUpdater
import chess.{ EloCalculator, Status, Color }
import Status._
import Color._

View File

@ -8,7 +8,8 @@ import play.api.libs.concurrent._
import play.api.Application
import game.{ GameRepo, DbGame }
import user.{ UserRepo, User, EloUpdater }
import user.{ UserRepo, User}
import elo.EloUpdater
import ai.Ai
import core.Settings
import i18n.I18nKeys

View File

@ -1,23 +0,0 @@
package lila
package user
import scalaz.effects._
import scala.math.max
final class EloUpdater(
userRepo: UserRepo,
historyRepo: HistoryRepo,
floor: Int) {
def game(user: User, elo: Int, gameId: String): IO[Unit] = {
val newElo = max(elo, floor)
userRepo.setElo(user.id, newElo) flatMap { _
historyRepo.addEntry(user.id, newElo, Some(gameId))
}
}
def adjust(user: User, elo: Int): IO[Unit] =
userRepo.setElo(user.id, elo) flatMap { _
historyRepo.addEntry(user.id, elo, entryType = HistoryRepo.TYPE_ADJUST)
}
}

View File

@ -5,6 +5,7 @@ import com.mongodb.casbah.MongoCollection
import chess.EloCalculator
import game.GameRepo
import elo.EloUpdater
import core.Settings
final class UserEnv(

View File

@ -13,12 +13,16 @@ case class UserInfo(
nbWin: Int,
nbDraw: Int,
nbLoss: Int,
nbRated: Int,
nbPlaying: Int,
nbWithMe: Option[Int],
eloWithMe: Option[List[(String, Int)]],
eloChart: Option[EloChart],
winChart: Option[WinChart])
winChart: Option[WinChart]) {
def nbRated = user.nbRatedGames
def percentRated: Int = math.round(nbRated / user.nbGames.toFloat * 100)
}
object UserInfo {
@ -39,7 +43,6 @@ object UserInfo {
nbWin gameRepo count (_ win user)
nbDraw gameRepo count (_ draw user)
nbLoss gameRepo count (_ loss user)
nbRated gameRepo count (_ rated user)
nbPlaying (ctx is user).fold(
gameRepo count (_ notFinished user) map (_.some),
io(none)
@ -64,7 +67,6 @@ object UserInfo {
nbWin = nbWin,
nbDraw = nbDraw,
nbLoss = nbLoss,
nbRated = nbRated,
nbPlaying = nbPlaying | 0,
nbWithMe = nbWithMe,
eloWithMe = eloWithMe,

View File

@ -11,10 +11,9 @@ google.setOnLoadCallback(function() {
width: 460,
height: 340,
axisTitlePosition: 'none',
chartArea:{left:"10%",top:"3%",width:"90%",height:"80%"},
title: $(this).attr('title'),
titlePosition: 'in',
hAxis: {textStyle: {fontSize: 0.1}}
chartArea:{left:"10%",top:"2%",width:"90%",height:"96%"},
titlePosition: 'none',
hAxis: {textPosition: "none"}
});
});
@ -24,6 +23,7 @@ google.setOnLoadCallback(function() {
chart.draw(data, {
width: 312,
height: 200,
titlePosition: 'none',
chartArea:{left:"0%",width:"100%",height:"100%"},
is3D: true,
});

View File

@ -32,12 +32,11 @@ div.user_show .elo_history {
float:right;
display: block;
width: 460px;
height: 320px;
height: 340px;
margin-top: -12px;
}
div.user_show .win_stats {
float:left;
display: block;
width: 312px;
height: 200px;

3
todo
View File

@ -20,7 +20,6 @@ check sf2 commands to port
make the wiki static html pages managed by git?
compensate lag http://fr.lichess.org/forum/lichess-feedback/the-clock-display-should-account-for-lag?page=1#4
show lobby room logs
lobby sync
push enumerator is deprecated
http://fr.lichess.org/forum/lichess-feedback/game-history-bug#1
pie elo chart
@ -29,8 +28,6 @@ new elo system http://en.wikipedia.org/wiki/Glicko_rating_system
spectator chat!
guess friend list
star people and games (and forum threads?)
elo chart average
chat IP block
new translations:
-rematchOfferCanceled=Rematch offer canceled