fix unlimited games should be considered as correspondence

pull/185/head
Thibault Duplessis 2014-12-30 16:52:28 +01:00
parent 9938ca688a
commit e6321758a9
9 changed files with 26 additions and 29 deletions

View File

@ -34,7 +34,7 @@ trait GameHelper { self: I18nHelper with UserHelper with AiHelper with StringHel
import pov._
val p1 = playerText(player, withRating = true)
val p2 = playerText(opponent, withRating = true)
val speedAndClock = game.clock.fold(chess.Speed.Unlimited.name) { c =>
val speedAndClock = game.clock.fold(chess.Speed.Correspondence.name) { c =>
s"${chess.Speed(c.some).name} (${c.show})"
}
val mode = game.mode.name

@ -1 +1 @@
Subproject commit f598e76b27a9acca2db382d4d4ec5bb4b14b6149
Subproject commit 0cefcae7c8ed7a9f26b07d109c398079178a35ce

View File

@ -336,7 +336,7 @@ case class Game(
if c outoftime player.color
} yield player
def isCorrespondence = perfType == PerfType.Correspondence
def isCorrespondence = speed == chess.Speed.Correspondence
def hasClock = clock.isDefined

View File

@ -13,7 +13,7 @@ object PerfPicker {
def key(speed: Speed, variant: Variant, daysPerTurn: Option[Int]): String =
if (variant.standard) {
if (daysPerTurn.isDefined || speed == Speed.Unlimited) PerfType.Correspondence.key
if (daysPerTurn.isDefined || speed == Speed.Correspondence) PerfType.Correspondence.key
else speed.key
}
else variant.key

View File

@ -15,7 +15,6 @@ final class HistoryApi(coll: Coll) {
def add(user: User, game: Game, perfs: Perfs): Funit = {
val isStd = game.variant.standard
val isCor = game.isCorrespondence
val changes = List(
isStd.option("standard" -> perfs.standard),
game.variant.chess960.option("chess960" -> perfs.chess960),
@ -24,8 +23,8 @@ final class HistoryApi(coll: Coll) {
game.variant.antichess.option("antichess" -> perfs.antichess),
(isStd && game.speed == Speed.Bullet).option("bullet" -> perfs.bullet),
(isStd && game.speed == Speed.Blitz).option("blitz" -> perfs.blitz),
(isStd && !isCor && game.speed == Speed.Classical).option("classical" -> perfs.classical),
(isStd && isCor).option("correspondence" -> perfs.correspondence)
(isStd && game.speed == Speed.Classical).option("classical" -> perfs.classical),
(isStd && game.speed == Speed.Correspondence).option("correspondence" -> perfs.correspondence)
).flatten.map {
case (k, p) => k -> p.intRating
}

View File

@ -58,7 +58,7 @@ case class Seek(
"name" -> perfType.map(_.name))
)
lazy val perfType = PerfPicker.perfType(Speed.Unlimited, realVariant, daysPerTurn)
lazy val perfType = PerfPicker.perfType(Speed.Correspondence, realVariant, daysPerTurn)
}
object Seek {

View File

@ -1,6 +1,6 @@
package lila.round
import chess.Speed
import chess.{ Variant, Speed }
import org.goochjs.glicko2._
import org.joda.time.DateTime
import play.api.Logger
@ -23,29 +23,25 @@ final class PerfsUpdater(historyApi: HistoryApi) {
val ratingsB = mkRatings(black.perfs)
val result = resultOf(game)
game.variant match {
case chess.Variant.Chess960 =>
case Variant.Chess960 =>
updateRatings(ratingsW.chess960, ratingsB.chess960, result, system)
case chess.Variant.KingOfTheHill =>
case Variant.KingOfTheHill =>
updateRatings(ratingsW.kingOfTheHill, ratingsB.kingOfTheHill, result, system)
case chess.Variant.ThreeCheck =>
case Variant.ThreeCheck =>
updateRatings(ratingsW.threeCheck, ratingsB.threeCheck, result, system)
case chess.Variant.Antichess =>
case Variant.Antichess =>
updateRatings(ratingsW.antichess, ratingsB.antichess, result, system)
case _ =>
}
if (game.variant.standard) {
if (game.isCorrespondence)
updateRatings(ratingsW.correspondence, ratingsB.correspondence, result, system)
else game.speed match {
case chess.Speed.Bullet =>
case Variant.Standard => game.speed match {
case Speed.Bullet =>
updateRatings(ratingsW.bullet, ratingsB.bullet, result, system)
case chess.Speed.Blitz =>
case Speed.Blitz =>
updateRatings(ratingsW.blitz, ratingsB.blitz, result, system)
case chess.Speed.Classical =>
case Speed.Classical =>
updateRatings(ratingsW.classical, ratingsB.classical, result, system)
case chess.Speed.Unlimited =>
// should have been handled by the correspondence case above
case Speed.Correspondence =>
updateRatings(ratingsW.correspondence, ratingsB.correspondence, result, system)
}
case _ =>
}
val perfsW = mkPerfs(ratingsW, white.perfs, game)
val perfsB = mkPerfs(ratingsB, black.perfs, game)
@ -110,7 +106,6 @@ final class PerfsUpdater(historyApi: HistoryApi) {
private def mkPerfs(ratings: Ratings, perfs: Perfs, game: Game): Perfs = {
val speed = game.speed
val isStd = game.variant.standard
val isCor = game.isCorrespondence
val date = game.updatedAt | game.createdAt
val perfs1 = perfs.copy(
chess960 = game.variant.chess960.fold(perfs.chess960.add(ratings.chess960, date), perfs.chess960),
@ -119,8 +114,8 @@ final class PerfsUpdater(historyApi: HistoryApi) {
antichess = game.variant.antichess.fold(perfs.antichess.add(ratings.antichess, date), perfs.antichess),
bullet = (isStd && speed == Speed.Bullet).fold(perfs.bullet.add(ratings.bullet, date), perfs.bullet),
blitz = (isStd && speed == Speed.Blitz).fold(perfs.blitz.add(ratings.blitz, date), perfs.blitz),
classical = (!isCor && isStd && speed == Speed.Classical).fold(perfs.classical.add(ratings.classical, date), perfs.classical),
correspondence = (isCor && isStd).fold(perfs.correspondence.add(ratings.correspondence, date), perfs.correspondence))
classical = (isStd && speed == Speed.Classical).fold(perfs.classical.add(ratings.classical, date), perfs.classical),
correspondence = (isStd && speed == Speed.Correspondence).fold(perfs.correspondence.add(ratings.correspondence, date), perfs.correspondence))
if (isStd) perfs1.updateStandard else perfs1
}

View File

@ -125,7 +125,7 @@ case object Perfs {
case Speed.Bullet => perfs => perfs.bullet
case Speed.Blitz => perfs => perfs.blitz
case Speed.Classical => perfs => perfs.classical
case Speed.Unlimited => perfs => perfs.correspondence
case Speed.Correspondence => perfs => perfs.correspondence
}
private def PerfsBSONHandler = new BSON[Perfs] {

View File

@ -107,7 +107,10 @@ trait UserRepo {
s"perfs.$name" -> Perf.perfBSONHandler.write(lens(perfs))
}
}
$update($select(user.id), BSONDocument("$set" -> BSONDocument(diff)))
diff.nonEmpty ?? $update(
$select(user.id),
BSONDocument("$set" -> BSONDocument(diff))
)
}
def setPerf(userId: String, perfName: String, perf: Perf) = $update($select(userId), $setBson(