Update users eloDiff
This commit is contained in:
parent
08abfe0f0a
commit
a2449002cb
|
@ -62,12 +62,12 @@ final class Finisher(
|
|||
g3 ← message some { messenger.systemMessage(g2, _) } none io(g2)
|
||||
_ ← gameRepo.applyDiff(game, g3)
|
||||
_ ← versionMemo put g3
|
||||
_ ← updateElo(g2)
|
||||
_ ← incNbGames(g2, White)
|
||||
_ ← incNbGames(g2, Black)
|
||||
_ ← updateElo(g3)
|
||||
_ ← incNbGames(g3, White)
|
||||
_ ← incNbGames(g3, Black)
|
||||
} yield ())
|
||||
|
||||
private def incNbGames(game: DbGame, color: Color) =
|
||||
private def incNbGames(game: DbGame, color: Color): IO[Unit] =
|
||||
game.player(color).userId.fold(
|
||||
id ⇒ userRepo.incNbGames(id, game.rated),
|
||||
io()
|
||||
|
@ -84,6 +84,10 @@ final class Finisher(
|
|||
whiteUser ← userRepo user whiteUserId
|
||||
blackUser ← userRepo user blackUserId
|
||||
(whiteElo, blackElo) = eloCalculator.calculate(whiteUser, blackUser, game.winnerColor)
|
||||
_ ← gameRepo.setEloDiffs(
|
||||
game.id,
|
||||
whiteElo - whiteUser.elo,
|
||||
blackElo - blackUser.elo)
|
||||
_ ← userRepo.setElo(whiteUser.id, whiteElo)
|
||||
_ ← userRepo.setElo(blackUser.id, blackElo)
|
||||
_ ← historyRepo.addEntry(whiteUser.username, whiteElo, game.id)
|
||||
|
|
|
@ -44,7 +44,7 @@ class GameRepo(collection: MongoCollection)
|
|||
diff(encode(a), encode(b)) |> { diffs ⇒
|
||||
if (diffs.nonEmpty) {
|
||||
val fullDiffs = ("updatedAt" -> new Date()) :: diffs
|
||||
io { update(DBObject("_id" -> a.id), $set (fullDiffs: _*)) }
|
||||
io { update(DBObject("_id" -> a.id), $set(fullDiffs: _*)) }
|
||||
}
|
||||
else io()
|
||||
}
|
||||
|
@ -82,6 +82,15 @@ class GameRepo(collection: MongoCollection)
|
|||
insert(encode(game))
|
||||
}
|
||||
|
||||
// makes the asumption that player 0 is white!
|
||||
// proved to be true on prod DB at March 31 2012
|
||||
def setEloDiffs(id: String, white: Int, black: Int) = io {
|
||||
update(
|
||||
DBObject("_id" -> id),
|
||||
$set("players.0.eloDiff" -> white, "players.1.eloDiff" -> black)
|
||||
)
|
||||
}
|
||||
|
||||
def decode(raw: RawDbGame): Option[DbGame] = raw.decode
|
||||
|
||||
def encode(dbGame: DbGame): RawDbGame = RawDbGame encode dbGame
|
||||
|
|
Loading…
Reference in a new issue