exclude players inactive for 2 months from ranking and leaderboards

This commit is contained in:
Thibault Duplessis 2014-05-25 14:01:23 +02:00
parent 173ff682ac
commit 619954b4b8
3 changed files with 9 additions and 6 deletions

View file

@ -25,6 +25,7 @@ final class Cached(
private def oneDayAgo = DateTime.now minusDays 1
private def oneWeekAgo = DateTime.now minusWeeks 1
private def oneMonthAgo = DateTime.now minusMonths 1
val topProgressDay = AsyncCache(
(nb: Int) => UserRepo.topProgressSince(oneDayAgo, nb),
timeToLive = 14 minutes)

View file

@ -3,6 +3,7 @@ package lila.user
import scala.concurrent.duration._
import play.api.libs.json.Json
import org.joda.time.DateTime
import lila.db.api._
import lila.db.Implicits._
@ -18,7 +19,9 @@ private[user] final class Ranking(ttl: Duration) {
private def compute: Fu[Map[String, Int]] =
$primitive(
UserRepo.stableGoodLadSelect ++ Json.obj("rating" -> $gt(Glicko.default.intRating)),
UserRepo.stableGoodLadSelect ++
UserRepo.perfSince("global", DateTime.now minusMonths 2) ++
Json.obj("rating" -> $gt(Glicko.default.intRating)),
"_id",
_ sort UserRepo.sortRatingDesc
)(_.asOpt[String]) map { _.zipWithIndex.map(x => x._1 -> (x._2 + 1)).toMap }

View file

@ -29,8 +29,8 @@ trait UserRepo {
def all: Fu[List[User]] = $find.all
def topRating(nb: Int): Fu[List[User]] =
$find($query(stableGoodLadSelect) sort sortRatingDesc, nb)
def topRating(nb: Int): Fu[List[User]] = topRatingSince(DateTime.now minusMonths 2, nb)
def topRatingSince(since: DateTime, nb: Int): Fu[List[User]] =
$find($query(stableGoodLadSelect ++ perfSince("global", since)) sort sortRatingDesc, nb)
@ -113,12 +113,11 @@ trait UserRepo {
val enabledSelect = Json.obj(F.enabled -> true)
def engineSelect(v: Boolean) = Json.obj(F.engine -> v.fold(JsBoolean(true), $ne(true)))
val stableSelect = Json.obj("perfs.global.nb" -> $gte(50))
val activeSelect = perfSince("global", DateTime.now minusMonths 2)
val goodLadSelect = enabledSelect ++ engineSelect(false)
val stableGoodLadSelect = stableSelect ++ goodLadSelect
def minRatingSelect(rating: Int) = Json.obj(F.rating -> $gt(rating))
def perfSince(perf: String, since: DateTime) = Json.obj(
s"perfs.$perf.la" -> Json.obj("$gt" -> $date(since))
)
def perfSince(perf: String, since: DateTime) = Json.obj(s"perfs.$perf.la" -> $gt($date(since)))
val goodLadQuery = $query(goodLadSelect)
val sortRatingDesc = $sort desc "rating"