download random finished game API WIP

pull/2156/head
Thibault Duplessis 2016-07-28 18:29:44 +02:00
parent c2d3b4af32
commit c115606e79
4 changed files with 16 additions and 1 deletions

View File

@ -34,6 +34,10 @@ object Export extends LilaController {
}
}
def random = Action.async {
Ok.fuccess
}
def pdf(id: String) = Open { implicit ctx =>
OnlyHumans {
OptionResult(GameRepo game id) { game =>

View File

@ -250,6 +250,7 @@ POST /$gameId<\w{8}>/request-analysis controllers.Analyse.requestAnalysi
GET /game/export/$gameId<\w{8}>.pgn controllers.Export.pgn(gameId: String)
GET /game/export/pdf/$gameId<\w{8}>.pdf controllers.Export.pdf(gameId: String)
GET /game/export/png/$gameId<\w{8}>.png controllers.Export.png(gameId: String)
GET /game/export/png/random.png controllers.Export.random
# Fishnet
POST /fishnet/acquire controllers.Fishnet.acquire

View File

@ -241,11 +241,19 @@ object GameRepo {
}
def findRandomStandardCheckmate(distribution: Int): Fu[Option[Game]] = coll.find(
Query.mate ++ $doc("v" $exists false)
Query.mate ++ Query.variantStandard
).sort(Query.sortCreated)
.skip(Random nextInt distribution)
.uno[Game]
def randomFinished(distribution: Int): Fu[Option[Game]] = coll.find(
Query.finished ++ Query.rated ++
Query.variantStandard ++ Query.bothRatingsGreaterThan(1600)
).sort(Query.sortCreated)
.skip(Random nextInt distribution)
.cursor[Game](ReadPreference.secondary)
.uno
def insertDenormalized(g: Game, ratedCheck: Boolean = true, initialFen: Option[chess.format.FEN] = None): Funit = {
val g2 = if (ratedCheck && g.rated && g.userIds.distinct.size != 2)
g.copy(mode = chess.Mode.Casual)

View File

@ -87,6 +87,8 @@ object Query {
def variant(v: chess.variant.Variant) =
$doc(F.variant -> v.standard.fold[BSONValue]($exists(false), $int(v.id)))
lazy val variantStandard = variant(chess.variant.Standard)
lazy val notHordeOrSincePawnsAreWhite: Bdoc = $or(
F.variant $ne chess.variant.Horde.id,
sinceHordePawnsAreWhite