make fishnet/analysis more typesafe, fix eval cache hit monitoring

This commit is contained in:
Thibault Duplessis 2017-11-24 11:49:56 -05:00
parent 6b62a29fea
commit fbbd388292
6 changed files with 11 additions and 17 deletions

View file

@ -1,6 +1,7 @@
package lila.analyse
import chess.Color
import chess.format.Uci
import org.joda.time.DateTime
@ -29,11 +30,6 @@ case class Analysis(
lazy val advices: List[Advice] = infoAdvices.flatMap(_._2)
// ply -> UCI
def bestMoves: Map[Int, String] = infos.flatMap { i =>
i.best map { b => i.ply -> b.keys }
}(scala.collection.breakOut)
def summary: List[(Color, List[(Advice.Judgment, Int)])] = Color.all map { color =>
color -> (Advice.Judgment.all map { judgment =>
judgment -> (advices count { adv =>

View file

@ -72,9 +72,9 @@ final class Analyser(
}
private def evalCacheHits(work: Work.Analysis): Fu[Map[Int, lila.evalCache.EvalCacheEntry.Eval]] =
chess.Replay.games(
work.game.moveList.take(12),
work.game.initialFen map (_.value),
chess.Replay.situationsFromUci(
work.game.uciList.take(12),
work.game.initialFen,
work.game.variant
).fold(
_ => fuccess(Map.empty),

View file

@ -23,7 +23,7 @@ private object AnalysisBuilder {
val uciAnalysis = Analysis(
id = work.game.id,
infos = makeInfos(evals, work.game.moveList, work.startPly),
infos = makeInfos(evals, work.game.uciList, work.startPly),
startPly = work.startPly,
uid = work.sender.userId,
by = !client.lichess option client.userId.value,
@ -51,14 +51,14 @@ private object AnalysisBuilder {
}
}
private def makeInfos(evals: List[Option[Evaluation]], moves: List[String], startedAtPly: Int): List[Info] =
private def makeInfos(evals: List[Option[Evaluation]], moves: List[Uci], startedAtPly: Int): List[Info] =
(evals filterNot (_ ?? (_.isCheckmate)) sliding 2).toList.zip(moves).zipWithIndex map {
case ((List(Some(before), Some(after)), move), index) => {
val variation = before.cappedPvList match {
case first :: rest if first != move => first :: rest
case _ => Nil
}
val best = variation.headOption flatMap Uci.Move.apply
val best = variation.headOption
val info = Info(
ply = index + 1 + startedAtPly,
eval = Eval(
@ -66,7 +66,7 @@ private object AnalysisBuilder {
after.score.mate,
best
),
variation = variation
variation = variation.map(_.uci)
)
if (info.ply % 2 == 1) info.invert else info
}

View file

@ -114,7 +114,7 @@ object JsonApi {
) {
// use first pv move as bestmove
val pvList = pv.??(_.split(' ').toList)
val pvList: List[Uci] = ~(pv flatMap Uci.readList)
val cappedNps = nps.map(_ min Evaluation.npsCeil)

View file

@ -50,9 +50,7 @@ object Work {
moves: String
) {
def moveList = moves.split(' ').toList
def uciList = Uci readList moves
def uciList: List[Uci] = ~(Uci readList moves)
}
case class Sender(

View file

@ -28,7 +28,7 @@ object Dependencies {
val findbugs = "com.google.code.findbugs" % "jsr305" % "3.0.1"
val hasher = "com.roundeights" %% "hasher" % "1.2.0"
val jodaTime = "joda-time" % "joda-time" % "2.9.9"
val chess = "org.lichess" %% "scalachess" % "7.3"
val chess = "org.lichess" %% "scalachess" % "7.4"
val maxmind = "com.sanoma.cda" %% "maxmind-geoip2-scala" % "1.2.3-THIB"
val prismic = "io.prismic" %% "scala-kit" % "1.2.11-THIB"
val java8compat = "org.scala-lang.modules" %% "scala-java8-compat" % "0.8.0"