parent
1e272929b5
commit
b5a4d350e5
|
@ -78,7 +78,6 @@ final class StormHighApi(coll: Coll, cacheApi: CacheApi)(implicit ctx: Execution
|
|||
) -> Nil
|
||||
}
|
||||
.map2 { doc =>
|
||||
println(lila.db.BSON.debug(doc))
|
||||
def readScore(doc: Bdoc, field: String) =
|
||||
~doc.getAsOpt[List[Bdoc]](field).flatMap(_.headOption).flatMap(_.getAsOpt[Int]("score"))
|
||||
StormHigh(
|
||||
|
|
|
@ -22,9 +22,11 @@ final class StormSelector(colls: PuzzleColls, cacheApi: CacheApi)(implicit ec: E
|
|||
private val poolSize = 130
|
||||
private val theme = lila.puzzle.PuzzleTheme.mix.key.value
|
||||
private val tier = lila.puzzle.PuzzleTier.Good.key
|
||||
private val maxDeviation = 90
|
||||
|
||||
private val ratings = (1000 to 2800 by 150).toList
|
||||
private val ratingBuckets = ratings.size
|
||||
private val puzzlesPerBucket = poolSize / ratingBuckets
|
||||
|
||||
private val current = cacheApi.unit[List[StormPuzzle]] {
|
||||
_.refreshAfterWrite(6 seconds)
|
||||
|
@ -39,34 +41,26 @@ final class StormSelector(colls: PuzzleColls, cacheApi: CacheApi)(implicit ec: E
|
|||
Match(
|
||||
$doc(
|
||||
"min" $lte f"${theme}_${tier}_${rating}%04d",
|
||||
"max" $gt f"${theme}_${tier}_${rating}%04d"
|
||||
"max" $gte f"${theme}_${tier}_${rating}%04d"
|
||||
)
|
||||
),
|
||||
Project($doc("_id" -> false, "ids" -> true)),
|
||||
Sample(1),
|
||||
UnwindField("ids"),
|
||||
Sample((poolSize * 5) / ratingBuckets),
|
||||
Group(BSONNull)("ids" -> PushField("ids"))
|
||||
)
|
||||
}
|
||||
) -> List(
|
||||
Project($doc("all" -> $doc("$setUnion" -> ratings.map(r => s"$$$r")))),
|
||||
UnwindField("all"),
|
||||
UnwindField("all.ids"),
|
||||
Project($doc("id" -> "$all.ids")),
|
||||
Sample(puzzlesPerBucket * 6), // ensure we have enough after filtering deviation & color
|
||||
PipelineOperator(
|
||||
$doc(
|
||||
"$lookup" -> $doc(
|
||||
"from" -> colls.puzzle.name.value,
|
||||
"as" -> "puzzle",
|
||||
"let" -> $doc("id" -> "$id"),
|
||||
"let" -> $doc("id" -> "$ids"),
|
||||
"pipeline" -> $arr(
|
||||
$doc(
|
||||
"$match" -> $doc(
|
||||
"$expr" -> $doc(
|
||||
"$and" -> $arr(
|
||||
$doc("$eq" -> $arr("$_id", "$$id")),
|
||||
$doc("$lt" -> $arr("$glicko.d", 90)),
|
||||
$doc("$lte" -> $arr("$glicko.d", maxDeviation)),
|
||||
$doc(
|
||||
"$regexMatch" -> $doc(
|
||||
"input" -> "$fen",
|
||||
|
@ -91,12 +85,18 @@ final class StormSelector(colls: PuzzleColls, cacheApi: CacheApi)(implicit ec: E
|
|||
)
|
||||
),
|
||||
UnwindField("puzzle"),
|
||||
ReplaceRootField("puzzle"),
|
||||
Sample(poolSize),
|
||||
Sample(puzzlesPerBucket),
|
||||
ReplaceRootField("puzzle")
|
||||
)
|
||||
}
|
||||
) -> List(
|
||||
Project($doc("all" -> $doc("$setUnion" -> ratings.map(r => s"$$$r")))),
|
||||
UnwindField("all"),
|
||||
ReplaceRootField("all"),
|
||||
Sort(Ascending("rating"))
|
||||
)
|
||||
}.map { docs =>
|
||||
docs.flatMap(StormPuzzleBSONReader.readOpt)
|
||||
}.map {
|
||||
_.flatMap(StormPuzzleBSONReader.readOpt)
|
||||
}
|
||||
}
|
||||
.mon(_.storm.selector.time)
|
||||
|
|
Loading…
Reference in New Issue