import user games into the explorer as they complete
This commit is contained in:
parent
7cbf8d536d
commit
253e463b3f
|
@ -82,7 +82,8 @@ final class Env(
|
|||
Env.worldMap, // required to load the actor
|
||||
Env.push, // required to load the actor
|
||||
Env.perfStat, // required to load the actor
|
||||
Env.slack // required to load the actor
|
||||
Env.slack, // required to load the actor
|
||||
Env.explorer // required to load the actor
|
||||
)
|
||||
play.api.Logger("boot").info("Preloading complete")
|
||||
}
|
||||
|
@ -148,4 +149,5 @@ object Env {
|
|||
def push = lila.push.Env.current
|
||||
def perfStat = lila.perfStat.Env.current
|
||||
def slack = lila.slack.Env.current
|
||||
def explorer = lila.explorer.Env.current
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package lila.explorer
|
||||
|
||||
import akka.actor._
|
||||
import com.typesafe.config.Config
|
||||
|
||||
final class Env(config: Config) {
|
||||
final class Env(
|
||||
config: Config,
|
||||
system: ActorSystem) {
|
||||
|
||||
private val Endpoint = config getString "endpoint"
|
||||
private val ActorName = config getString "actor.name"
|
||||
|
||||
private lazy val indexer = new ExplorerIndexer(endpoint = Endpoint)
|
||||
|
||||
|
@ -13,10 +17,18 @@ final class Env(config: Config) {
|
|||
case "explorer" :: "index" :: variant :: Nil => indexer(variant) inject "done"
|
||||
}
|
||||
}
|
||||
|
||||
system.actorOf(Props(new Actor {
|
||||
context.system.lilaBus.subscribe(self, 'finishGame)
|
||||
def receive = {
|
||||
case lila.game.actorApi.FinishGame(game, _, _) => indexer(game)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
object Env {
|
||||
|
||||
lazy val current = "explorer" boot new Env(
|
||||
config = lila.common.PlayApp loadConfig "explorer")
|
||||
config = lila.common.PlayApp loadConfig "explorer",
|
||||
system = lila.common.PlayApp.system)
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ package lila.explorer
|
|||
import scala.util.{ Success, Failure }
|
||||
|
||||
import chess.variant.Variant
|
||||
import org.joda.time.DateTime
|
||||
import play.api.libs.iteratee._
|
||||
import play.api.libs.ws.{ WS, WSAuthScheme }
|
||||
import play.api.Play.current
|
||||
import org.joda.time.DateTime
|
||||
|
||||
import lila.db.api._
|
||||
import lila.db.Implicits._
|
||||
|
@ -16,28 +16,10 @@ import lila.game.{ Game, GameRepo, Query, PgnDump, Player }
|
|||
|
||||
private final class ExplorerIndexer(endpoint: String) {
|
||||
|
||||
val maxGames = Int.MaxValue
|
||||
val batchSize = 100
|
||||
val separator = "\n\n\n"
|
||||
|
||||
def stableRating(player: Player) = player.rating ifFalse player.provisional
|
||||
|
||||
private def makeFastPgn(game: Game): Fu[Option[String]] = ~(for {
|
||||
whiteRating <- stableRating(game.whitePlayer)
|
||||
blackRating <- stableRating(game.blackPlayer)
|
||||
} yield GameRepo initialFen game map { initialFen =>
|
||||
val fenTags = initialFen.?? { fen => List(s"[FEN $fen]") }
|
||||
val otherTags = List(
|
||||
s"[LichessID ${game.id}]",
|
||||
s"[TimeControl ${game.clock.fold("-")(_.show)}]",
|
||||
s"[WhiteElo $whiteRating]",
|
||||
s"[BlackElo $blackRating]",
|
||||
s"[Result ${PgnDump.result(game)}]")
|
||||
val allTags = fenTags ::: otherTags
|
||||
s"${allTags.mkString("\n")}\n\n${game.pgnMoves.mkString(" ")}".some
|
||||
})
|
||||
|
||||
private val logger = play.api.Logger("explorer")
|
||||
private val maxGames = Int.MaxValue
|
||||
private val batchSize = 100
|
||||
private val minRating = 1600
|
||||
private val separator = "\n\n\n"
|
||||
|
||||
def apply(variantKey: String): Funit = Variant.byKey get variantKey match {
|
||||
case None => fufail(s"Invalid variant $variantKey")
|
||||
|
@ -67,4 +49,41 @@ private final class ExplorerIndexer(endpoint: String) {
|
|||
}
|
||||
} void
|
||||
}
|
||||
|
||||
def apply(game: Game): Funit = makeFastPgn(game).flatMap {
|
||||
_ ?? { pgn =>
|
||||
val url = s"$endpoint/lichess/${game.variant.key}"
|
||||
WS.url(url).put(pgn) andThen {
|
||||
case Success(res) if res.status == 200 =>
|
||||
case Success(res) => logger.warn(s"[${res.status}]")
|
||||
case Failure(err) => logger.warn(s"$err")
|
||||
} void
|
||||
}
|
||||
}
|
||||
|
||||
private def valid(game: Game) =
|
||||
game.finished &&
|
||||
game.rated &&
|
||||
game.turns >= 10 &&
|
||||
game.variant != chess.variant.FromPosition
|
||||
|
||||
private def stableRating(player: Player) = player.rating ifFalse player.provisional
|
||||
|
||||
private def makeFastPgn(game: Game): Fu[Option[String]] = ~(for {
|
||||
whiteRating <- stableRating(game.whitePlayer)
|
||||
blackRating <- stableRating(game.blackPlayer)
|
||||
if valid(game)
|
||||
} yield GameRepo initialFen game map { initialFen =>
|
||||
val fenTags = initialFen.?? { fen => List(s"[FEN $fen]") }
|
||||
val otherTags = List(
|
||||
s"[LichessID ${game.id}]",
|
||||
s"[TimeControl ${game.clock.fold("-")(_.show)}]",
|
||||
s"[WhiteElo $whiteRating]",
|
||||
s"[BlackElo $blackRating]",
|
||||
s"[Result ${PgnDump.result(game)}]")
|
||||
val allTags = fenTags ::: otherTags
|
||||
s"${allTags.mkString("\n")}\n\n${game.pgnMoves.mkString(" ")}".some
|
||||
})
|
||||
|
||||
private val logger = play.api.Logger("explorer")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue