add rated filter to game export endpoint

This commit is contained in:
Thibault Duplessis 2018-04-21 19:45:46 +02:00
parent 8a2acde19c
commit 7289b53eca
2 changed files with 27 additions and 20 deletions

View file

@ -38,19 +38,23 @@ object Game extends LilaController {
RequireHttp11(req) {
Api.GlobalLinearLimitPerIP(HTTPRequest lastRemoteAddress req) {
Api.GlobalLinearLimitPerUserOption(me) {
val since = getLong("since", req) map { ts => new DateTime(ts) }
val until = getLong("until", req) map { ts => new DateTime(ts) }
val moves = getBoolOpt("moves", req) | true
val tags = getBoolOpt("tags", req) | true
val clocks = getBoolOpt("clocks", req) | false
val max = getInt("max", req) map (_ atLeast 1)
val perSecond = MaxPerSecond(me match {
case None => 10
case Some(m) if m is user.id => 50
case Some(_) => 20
})
val formatFlags = lila.game.PgnDump.WithFlags(moves = moves, tags = tags, clocks = clocks)
val config = PgnDump.Config(user, since, until, max, formatFlags, perSecond)
val config = PgnDump.Config(
user = user,
since = getLong("since", req) map { ts => new DateTime(ts) },
until = getLong("until", req) map { ts => new DateTime(ts) },
max = getInt("max", req) map (_ atLeast 1),
rated = getBoolOpt("rated", req),
flags = lila.game.PgnDump.WithFlags(
moves = getBoolOpt("moves", req) | true,
tags = getBoolOpt("tags", req) | true,
clocks = getBoolOpt("clocks", req) | false
),
perSecond = MaxPerSecond(me match {
case None => 10
case Some(m) if m is user.id => 50
case Some(_) => 20
})
)
val date = (DateTimeFormat forPattern "yyyy-MM-dd") print new DateTime
Ok.chunked(Env.api.pgnDump.exportUserGames(config)).withHeaders(
CONTENT_TYPE -> pgnContentType,

View file

@ -44,15 +44,15 @@ final class PgnDump(
batchSize = config.perSecond.value
).bulkEnumerator(maxDocs = config.max | Int.MaxValue) &>
lila.common.Iteratee.delay(1 second) &>
Enumeratee.mapConcat(_.toSeq) &>
Enumeratee.mapConcat(_.filter(config.postFilter).toSeq) &>
toPgn(config.flags)
}
def exportGamesFromIds(ids: List[String]): Enumerator[String] =
Enumerator.enumerate(ids grouped 50) &>
Enumeratee.mapM[List[String]].apply[List[Game]](GameRepo.gamesFromSecondary) &>
Enumeratee.mapConcat(identity) &>
toPgn(WithFlags())
// def exportGamesFromIds(ids: List[String]): Enumerator[String] =
// Enumerator.enumerate(ids grouped 50) &>
// Enumeratee.mapM[List[String]].apply[List[Game]](GameRepo.gamesFromSecondary) &>
// Enumeratee.mapConcat(identity) &>
// toPgn(WithFlags())
}
object PgnDump {
@ -62,7 +62,10 @@ object PgnDump {
since: Option[DateTime] = None,
until: Option[DateTime] = None,
max: Option[Int] = None,
rated: Option[Boolean] = None,
flags: WithFlags,
perSecond: MaxPerSecond
)
) {
def postFilter(g: Game) = rated.fold(true)(g.rated ==)
}
}