Skip to content

Commit

Permalink
Use sitAndDcCounter in calculations for PR lichess-org#5252
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-daniels authored and RoepStoep committed May 23, 2020
1 parent b699d60 commit d7a9d00
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion modules/playban/src/main/PlaybanApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ final class PlaybanApi(
}(scala.collection.breakOut)
}

def getSitAndDcCounterById(userId: User.ID): Fu[Int] =
coll.primitiveOne[Int]($doc("_id" -> userId, "c" $exists true), "c").map(~_)

def getSitAndDcCounter(user: User): Fu[Int] =
coll.primitiveOne[Int]($doc("_id" -> user.id, "c" $exists true), "c").map(~_)
getSitAndDcCounterById(user.id)

private def save(outcome: Outcome, userId: User.ID, sitAndDcCounterChange: Int): Funit = {
lidraughts.mon.playban.outcome(outcome.key)()
Expand Down
24 changes: 18 additions & 6 deletions modules/round/src/main/RoundSocket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ private[round] final class RoundSocket(
}
}

// do NOT evaluate nbPlaybansForSomeUser when userId is none
private lazy val sitCounterForSomeUser: Fu[Int] =
userId ?? { u =>
dependencies.playbanApi.getSitAndDcCounterById(u)
}

// do NOT evaluate nbPlaybansForSomeUser or sitCounterForSomeUser when userId is none
// doing so will set it to 0 while userId might just not be known yet
def nbPlaybans: Fu[Int] =
userId.isDefined ?? nbPlaybansForSomeUser
def sitCounter: Fu[Int] =
userId.isDefined ?? sitCounterForSomeUser

def ping: Unit = {
isGone foreach { _ ?? notifyGone(color, false) }
Expand All @@ -84,12 +91,17 @@ private[round] final class RoundSocket(
lidraughtsBus.ask[Set[User.ID]]('simulGetHosts)(GetHostIds).map(_ contains u)
}

def weigh(orig: Long, startAt: Int) =
nbPlaybans map { n =>
if (n < startAt) orig else orig * (1d - 0.75 * sqrt(log10(n + 1 - startAt)))
def weigh(orig: Long, startAtPlaybans: Int, startAtSit: Int) =
nbPlaybans zip sitCounter map {
case (np, sc) =>
if (np < startAtPlaybans || sc > startAtSit) {
orig
} else {
orig * ((1d - 0.8 * log10(np - sc)) atMost 0.02) // sc is negative for abusers
}
}
def weightedRagequitTimeout = weigh(ragequitTimeout.toMillis, 4)
def weightedDisconnectTimeout = weigh(gameDisconnectTimeout(gameSpeed).toMillis, 4)
def weightedRagequitTimeout = weigh(ragequitTimeout.toMillis, 4, -4)
def weightedDisconnectTimeout = weigh(gameDisconnectTimeout(gameSpeed).toMillis, 4, -4)

def isGone: Fu[Boolean] = {
weightedRagequitTimeout zip weightedDisconnectTimeout map {
Expand Down

0 comments on commit d7a9d00

Please sign in to comment.