eval cache bootstrap

eval-cache
Thibault Duplessis 2017-01-31 01:42:17 +01:00
parent 0698f1bfe0
commit 265bbc1128
9 changed files with 105 additions and 1 deletions

View File

@ -173,4 +173,5 @@ object Env {
def coach = lila.coach.Env.current
def pool = lila.pool.Env.current
def practice = lila.practice.Env.current
def evalCache = lila.evalCache.Env.current
}

View File

@ -542,6 +542,9 @@ challenge {
uid.timeout = 7 seconds
max_playing = ${setup.max_playing}
}
eval_cache {
collection.eval_cache = eval_cache
}
study {
collection.study = study
collection.chapter = study_chapter

View File

@ -0,0 +1,15 @@
package lila.evalCache
import lila.db.BSON
import lila.db.dsl._
import lila.tree.Eval._
import reactivemongo.bson._
object BSONHandlers {
// private implicit val nbMovesHandler = intIsoHandler(PracticeProgress.nbMovesIso)
// private implicit val chapterNbMovesHandler = BSON.MapValue.MapHandler[Chapter.Id, NbMoves]
// implicit val practiceProgressIdHandler = stringAnyValHandler[PracticeProgress.Id](_.value, PracticeProgress.Id.apply)
// implicit val practiceProgressHandler = Macros.handler[PracticeProgress]
}

View File

@ -0,0 +1,21 @@
package lila.evalCache
import com.typesafe.config.Config
import scala.concurrent.duration._
final class Env(
config: Config,
db: lila.db.Env) {
private val CollectionEvalCache = config getString "collection.eval_cache"
lazy val api = new EvalCacheApi(
coll = db(CollectionEvalCache))
}
object Env {
lazy val current: Env = "evalCache" boot new Env(
config = lila.common.PlayApp loadConfig "evalCache",
db = lila.db.Env.current)
}

View File

@ -0,0 +1,26 @@
package lila.evalCache
import org.joda.time.DateTime
import chess.format.{ FEN, Uci }
import lila.tree.Eval.{ Score }
case class EvalCache(
_id: FEN,
evals: List[EvalCache.Eval])
object EvalCache {
case class Trust(value: Float) extends AnyVal
case class Eval(
score: Score,
pv: List[Uci],
nodes: Int,
depth: Int,
engine: String,
by: lila.user.User.ID,
trust: Trust,
date: DateTime) {
}
}

View File

@ -0,0 +1,10 @@
package lila.evalCache
import scala.concurrent.duration._
import lila.db.dsl._
final class EvalCacheApi(coll: Coll) {
import BSONHandlers._
}

View File

@ -0,0 +1,6 @@
package lila
package object evalCache extends PackageObject with WithPlay {
private[evalCache] val logger = lila.log("evalCache")
}

View File

@ -16,6 +16,24 @@ case class Eval(
object Eval {
case class Score(value: Either[Cp, Mate]) extends AnyVal {
def cp: Option[Cp] = value.left.toOption
def mate: Option[Mate] = value.right.toOption
def isCheckmate = value == Right(0)
def mateFound = value.isRight
def invert = copy(value = value.left.map(_.invert).right.map(_.invert))
def invertIf(cond: Boolean) = if (cond) invert else this
}
object Score {
def cp(x: Cp): Score = Score(Left(x))
def mate(y: Mate): Score = Score(Right(y))
}
case class Cp(value: Int) extends AnyVal {
def centipawns = value

View File

@ -59,7 +59,7 @@ object ApplicationBuild extends Build {
history, video, shutup, push,
playban, insight, perfStat, slack, quote, challenge,
study, studySearch, fishnet, explorer, learn, plan,
event, coach, practice)
event, coach, practice, evalCache)
lazy val moduleRefs = modules map projectToRef
lazy val moduleCPDeps = moduleRefs map { new sbt.ClasspathDependency(_, None) }
@ -254,6 +254,10 @@ object ApplicationBuild extends Build {
libraryDependencies ++= provided(play.api, reactivemongo.driver)
)
lazy val evalCache = project("evalCache", Seq(common, db, user, tree)).settings(
libraryDependencies ++= provided(play.api, reactivemongo.driver)
)
lazy val practice = project("practice", Seq(common, db, memo, user, study)).settings(
libraryDependencies ++= provided(play.api, reactivemongo.driver, configs)
)