index all tournaments, not only scheduled ones
This commit is contained in:
parent
b3e9c64f55
commit
bdb7ad5b76
|
@ -136,8 +136,8 @@ object BSONHandlers {
|
|||
score = r int "s",
|
||||
rank = r int "r",
|
||||
rankRatio = r.get[LeaderboardApi.Ratio]("w"),
|
||||
freq = Schedule.Freq.byId(r int "f") err "Invalid leaderboard freq",
|
||||
speed = Schedule.Speed.byId(r int "p") err "Invalid leaderboard speed",
|
||||
freq = r intO "f" flatMap Schedule.Freq.byId,
|
||||
speed = r intO "p" flatMap Schedule.Speed.byId,
|
||||
perf = PerfType.byId get r.int("v") err "Invalid leaderboard perf",
|
||||
date = r date "d")
|
||||
|
||||
|
@ -149,8 +149,8 @@ object BSONHandlers {
|
|||
"s" -> o.score,
|
||||
"r" -> o.rank,
|
||||
"w" -> o.rankRatio,
|
||||
"f" -> o.freq.id,
|
||||
"p" -> o.speed.id,
|
||||
"f" -> o.freq.map(_.id),
|
||||
"p" -> o.speed.map(_.id),
|
||||
"v" -> o.perf.id,
|
||||
"d" -> w.date(o.date))
|
||||
}
|
||||
|
|
|
@ -80,8 +80,8 @@ object LeaderboardApi {
|
|||
score: Int,
|
||||
rank: Int,
|
||||
rankRatio: Ratio, // ratio * rankRatioMultiplier. function of rank and tour.nbPlayers. less is better.
|
||||
freq: Schedule.Freq,
|
||||
speed: Schedule.Speed,
|
||||
freq: Option[Schedule.Freq],
|
||||
speed: Option[Schedule.Speed],
|
||||
perf: PerfType,
|
||||
date: DateTime)
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import play.api.libs.iteratee._
|
|||
import reactivemongo.bson._
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import chess.variant.Variant
|
||||
import lila.db.BSON._
|
||||
import lila.db.Types.Coll
|
||||
|
||||
|
@ -42,26 +41,24 @@ private final class LeaderboardIndexer(
|
|||
ordered = false
|
||||
).void
|
||||
|
||||
private def generateTour(tour: Tournament): Fu[List[Entry]] = tour.schedule ?? { sched =>
|
||||
for {
|
||||
nbGames <- PairingRepo.countByTourIdAndUserIds(tour.id)
|
||||
players <- PlayerRepo.bestByTourWithRank(tour.id, nb = 5000, skip = 0)
|
||||
} yield players.flatMap {
|
||||
case RankedPlayer(rank, player) => for {
|
||||
perfType <- tour.perfType
|
||||
nb <- nbGames get player.userId
|
||||
} yield Entry(
|
||||
id = player._id,
|
||||
tourId = tour.id,
|
||||
userId = player.userId,
|
||||
nbGames = nb,
|
||||
score = player.score,
|
||||
rank = rank,
|
||||
rankRatio = Ratio(if (tour.nbPlayers > 0) rank.toDouble / tour.nbPlayers else 0),
|
||||
freq = sched.freq,
|
||||
speed = sched.speed,
|
||||
perf = perfType,
|
||||
date = tour.startsAt)
|
||||
}
|
||||
private def generateTour(tour: Tournament): Fu[List[Entry]] = for {
|
||||
nbGames <- PairingRepo.countByTourIdAndUserIds(tour.id)
|
||||
players <- PlayerRepo.bestByTourWithRank(tour.id, nb = 5000, skip = 0)
|
||||
} yield players.flatMap {
|
||||
case RankedPlayer(rank, player) => for {
|
||||
perfType <- tour.perfType
|
||||
nb <- nbGames get player.userId
|
||||
} yield Entry(
|
||||
id = player._id,
|
||||
tourId = tour.id,
|
||||
userId = player.userId,
|
||||
nbGames = nb,
|
||||
score = player.score,
|
||||
rank = rank,
|
||||
rankRatio = Ratio(if (tour.nbPlayers > 0) rank.toDouble / tour.nbPlayers else 0),
|
||||
freq = tour.schedule.map(_.freq),
|
||||
speed = tour.schedule.map(_.speed),
|
||||
perf = perfType,
|
||||
date = tour.startsAt)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue