more tree extraction

puzzle-ui
Thibault Duplessis 2016-11-26 14:59:27 +01:00
parent 157d8180b3
commit afe6b7445e
22 changed files with 151 additions and 31 deletions

View File

@ -107,7 +107,7 @@ object Main extends LilaController {
private lazy val glyphsResult: Result = {
import chess.format.pgn.Glyph
import lila.socket.tree.Node.glyphWriter
import lila.tree.Node.glyphWriter
Ok(Json.obj(
"move" -> Glyph.MoveAssessment.display,
"position" -> Glyph.PositionAssessment.display,

View File

@ -98,7 +98,7 @@ object Study extends LilaController {
env.jsonView(study, chapters, chapter, ctx.me) zip
env.version(study.id) flatMap {
case (((baseData, chat), studyJson), sVersion) =>
import lila.socket.tree.Node.partitionTreeJsonWriter
import lila.tree.Node.partitionTreeJsonWriter
val analysis = baseData ++ Json.obj(
"treeParts" -> partitionTreeJsonWriter.writes(lila.study.TreeBuilder(chapter.root)))
val data = lila.study.JsonView.JsData(
@ -175,7 +175,7 @@ object Study extends LilaController {
members = lila.study.StudyMembers(Map.empty) // don't need no members
), List(chapter.metadata), chapter, ctx.me) flatMap {
case (baseData, studyJson) =>
import lila.socket.tree.Node.partitionTreeJsonWriter
import lila.tree.Node.partitionTreeJsonWriter
val analysis = baseData ++ Json.obj(
"treeParts" -> partitionTreeJsonWriter.writes(lila.study.TreeBuilder(chapter.root)))
val data = lila.study.JsonView.JsData(

View File

@ -107,7 +107,7 @@ private[api] final class RoundApi(
jsonView.userAnalysisJson(pov, pref, orientation, owner = false) map
withTree(pov, analysis = none, initialFen, withOpening = true)_
import lila.socket.tree.Node.partitionTreeJsonWriter
import lila.tree.Node.partitionTreeJsonWriter
private def withTree(pov: Pov, analysis: Option[Analysis], initialFen: Option[String], withOpening: Boolean)(obj: JsObject) =
obj + ("treeParts" -> partitionTreeJsonWriter.writes(lila.round.TreeBuilder(
id = pov.game.id,

View File

@ -0,0 +1,121 @@
package lila.puzzle
import chess.format.{ Forsyth, Uci, UciCharPair }
import chess.opening._
import chess.variant.Variant
// import lila.tree._
// object TreeBuilder {
// private type Ply = Int
// private type OpeningOf = String => Option[FullOpening]
// private def makeEval(info: Info) = Node.Eval(
// cp = info.score.map(_.ceiled.centipawns),
// mate = info.mate,
// best = info.best)
// def apply(
// game: lila.game.Game,
// analysis: Option[Analysis],
// initialFen: String,
// withOpening: Boolean): Root = apply(
// id = game.id,
// pgnMoves = game.pgnMoves,
// variant = game.variant,
// analysis = analysis,
// initialFen = initialFen,
// withOpening = withOpening)
// def apply(
// id: String,
// pgnMoves: List[String],
// variant: Variant,
// analysis: Option[Analysis],
// initialFen: String,
// withOpening: Boolean): Root = {
// chess.Replay.gameMoveWhileValid(pgnMoves, initialFen, variant) match {
// case (init, games, error) =>
// error foreach logChessError(id)
// val openingOf: OpeningOf =
// if (withOpening && Variant.openingSensibleVariants(variant)) FullOpeningDB.findByFen
// else _ => None
// val fen = Forsyth >> init
// val infos: Vector[Info] = analysis.??(_.infos.toVector)
// val advices: Map[Ply, Advice] = analysis.??(_.advices.map { a =>
// a.ply -> a
// }.toMap)
// val root = Root(
// ply = init.turns,
// fen = fen,
// check = init.situation.check,
// opening = openingOf(fen),
// crazyData = init.situation.board.crazyData,
// eval = infos lift 0 map makeEval)
// def makeBranch(index: Int, g: chess.Game, m: Uci.WithSan) = {
// val fen = Forsyth >> g
// val info = infos lift (index - 1)
// val advice = advices get g.turns
// val branch = Branch(
// id = UciCharPair(m.uci),
// ply = g.turns,
// move = m,
// fen = fen,
// check = g.situation.check,
// opening = openingOf(fen),
// crazyData = g.situation.board.crazyData,
// eval = info map makeEval,
// glyphs = Glyphs.fromList(advice.map(_.judgment.glyph).toList),
// comments = Node.Comments {
// advice.map(_.makeComment(false, true)).toList.map { text =>
// Node.Comment(
// Node.Comment.Id.make,
// Node.Comment.Text(text),
// Node.Comment.Author.Lichess)
// }
// })
// advices.get(g.turns + 1).flatMap { adv =>
// games.lift(index - 1).map {
// case (fromGame, _) =>
// val fromFen = Forsyth >> fromGame
// withAnalysisChild(id, branch, variant, fromFen, openingOf)(adv.info)
// }
// } getOrElse branch
// }
// games.zipWithIndex.reverse match {
// case Nil => root
// case ((g, m), i) :: rest => root prependChild rest.foldLeft(makeBranch(i + 1, g, m)) {
// case (node, ((g, m), i)) => makeBranch(i + 1, g, m) prependChild node
// }
// }
// }
// }
// private def withAnalysisChild(id: String, root: Branch, variant: Variant, fromFen: String, openingOf: OpeningOf)(info: Info): Branch = {
// def makeBranch(index: Int, g: chess.Game, m: Uci.WithSan) = {
// val fen = Forsyth >> g
// Branch(
// id = UciCharPair(m.uci),
// ply = g.turns,
// move = m,
// fen = fen,
// check = g.situation.check,
// opening = openingOf(fen),
// crazyData = g.situation.board.crazyData,
// eval = none)
// }
// chess.Replay.gameMoveWhileValid(info.variation take 20, fromFen, variant) match {
// case (init, games, error) =>
// error foreach logChessError(id)
// games.zipWithIndex.reverse match {
// case Nil => root
// case ((g, m), i) :: rest => root addChild rest.foldLeft(makeBranch(i + 1, g, m)) {
// case (node, ((g, m), i)) => makeBranch(i + 1, g, m) addChild node
// }.setComp
// }
// }
// }
// private val logChessError = (id: String) => (err: String) =>
// logger.warn(s"round.TreeBuilder https://lichess.org/$id ${err.lines.toList.headOption}")
// }

View File

@ -5,7 +5,7 @@ import chess.format.{ Forsyth, Uci, UciCharPair }
import chess.opening._
import chess.variant.Variant
import lila.analyse.{ Analysis, Info, Advice }
import lila.socket.tree._
import lila.tree._
object TreeBuilder {

View File

@ -7,7 +7,7 @@ import play.api.libs.json.JsObject
import scalaz.Validation.FlatMap._
import lila.common.PimpedJson._
import tree.Branch
import lila.tree.Branch
case class AnaDrop(
role: chess.Role,

View File

@ -7,7 +7,7 @@ import play.api.libs.json.JsObject
import scalaz.Validation.FlatMap._
import lila.common.PimpedJson._
import tree.Branch
import lila.tree.Branch
case class AnaMove(
orig: chess.Pos,

View File

@ -10,8 +10,8 @@ import actorApi._
import lila.common.PimpedJson._
import lila.hub.actorApi.relation.ReloadOnlineFriends
import makeTimeout.large
import tree.Node.defaultNodeJsonWriter
import tree.Node.openingWriter
import lila.tree.Node.defaultNodeJsonWriter
import lila.tree.Node.openingWriter
object Handler {

View File

@ -11,7 +11,7 @@ import lila.common.LightUser
import lila.db.BSON
import lila.db.BSON.{ Reader, Writer }
import lila.db.dsl._
import lila.socket.tree.Node.{ Shape, Shapes }
import lila.tree.Node.{ Shape, Shapes }
private object BSONHandlers {
@ -67,7 +67,7 @@ private object BSONHandlers {
private implicit val FenBSONHandler = stringAnyValHandler[FEN](_.value, FEN.apply)
import lila.socket.tree.Node.{ Comment, Comments }
import lila.tree.Node.{ Comment, Comments }
private implicit val CommentIdBSONHandler = stringAnyValHandler[Comment.Id](_.value, Comment.Id.apply)
private implicit val CommentTextBSONHandler = stringAnyValHandler[Comment.Text](_.value, Comment.Text.apply)
implicit val CommentAuthorBSONHandler = new BSONHandler[BSONValue, Comment.Author] {

View File

@ -7,7 +7,7 @@ import chess.variant.Variant
import org.joda.time.DateTime
import chess.opening.{ FullOpening, FullOpeningDB }
import lila.socket.tree.Node.{ Shape, Shapes, Comment }
import lila.tree.Node.{ Shape, Shapes, Comment }
import lila.user.User
case class Chapter(

View File

@ -1,7 +1,7 @@
package lila.study
import chess.{ Pos, Color }
import lila.socket.tree.Node.{ Shape, Shapes }
import lila.tree.Node.{ Shape, Shapes }
private[study] object CommentParser {

View File

@ -10,7 +10,7 @@ import lila.common.LightUser
import lila.common.PimpedJson._
import lila.game.{ Game, GameRepo }
import lila.socket.Socket.Uid
import lila.socket.tree.Node.Shape
import lila.tree.Node.Shape
import lila.user.User
final class JsonView(

View File

@ -5,7 +5,7 @@ import chess.format.{ Uci, UciCharPair, Forsyth, FEN }
import chess.opening.FullOpening
import chess.variant.Crazyhouse
import lila.socket.tree.Node.{ Shape, Shapes, Comment, Comments }
import lila.tree.Node.{ Shape, Shapes, Comment, Comments }
import lila.user.User
sealed trait RootOrNode {
@ -183,7 +183,7 @@ object Node {
crazyData = variant.crazyhouse option Crazyhouse.Data.init,
children = emptyChildren)
def fromRoot(b: lila.socket.tree.Root): Root = Root(
def fromRoot(b: lila.tree.Root): Root = Root(
ply = b.ply,
fen = FEN(b.fen),
check = b.check,
@ -191,7 +191,7 @@ object Node {
children = Children(b.children.toVector map fromBranch))
}
def fromBranch(b: lila.socket.tree.Branch): Node = Node(
def fromBranch(b: lila.tree.Branch): Node = Node(
id = b.id,
ply = b.ply,
move = b.move,

View File

@ -5,7 +5,7 @@ import scalaz.Validation.FlatMap._
import chess.format.pgn.{ Pgn, Tag, TagType, Parser, ParsedPgn, Glyphs, San, Dumper }
import chess.format.{ Forsyth, FEN, Uci, UciCharPair }
import lila.importer.{ ImportData, Preprocessed }
import lila.socket.tree.Node.{ Comment, Comments, Shape, Shapes }
import lila.tree.Node.{ Comment, Comments, Shape, Shapes }
private object PgnImport {

View File

@ -10,7 +10,7 @@ import lila.common.LightUser
import lila.hub.TimeBomb
import lila.socket.actorApi.{ Connected => _, _ }
import lila.socket.Socket.Uid
import lila.socket.tree.Node.{ Shape, Shapes, Comment }
import lila.tree.Node.{ Shape, Shapes, Comment }
import lila.socket.{ SocketActor, History, Historical, AnaDests }
import lila.user.User
@ -27,7 +27,7 @@ private final class Socket(
import Socket._
import JsonView._
import jsonView.membersWrites
import lila.socket.tree.Node.{ openingWriter, commentWriter, glyphsWriter, shapesWrites }
import lila.tree.Node.{ openingWriter, commentWriter, glyphsWriter, shapesWrites }
private val timeBomb = new TimeBomb(socketTimeout)

View File

@ -13,7 +13,7 @@ import lila.hub.actorApi.map._
import lila.socket.actorApi.{ Connected => _, _ }
import lila.socket.Socket.makeMessage
import lila.socket.Socket.Uid
import lila.socket.tree.Node.{ Shape, Shapes, Comment }
import lila.tree.Node.{ Shape, Shapes, Comment }
import lila.socket.{ Handler, AnaMove, AnaDests, AnaDrop }
import lila.user.User
import makeTimeout.short
@ -27,7 +27,7 @@ private[study] final class SocketHandler(
import Handler.AnaRateLimit
import JsonView.shapeReader
import lila.socket.tree.Node.openingWriter
import lila.tree.Node.openingWriter
private val InviteLimitPerUser = new lila.memo.RateLimit(
credits = 50,

View File

@ -10,7 +10,7 @@ import lila.hub.actorApi.map.Tell
import lila.hub.actorApi.timeline.{ Propagate, StudyCreate, StudyLike }
import lila.hub.Sequencer
import lila.socket.Socket.Uid
import lila.socket.tree.Node.{ Shape, Shapes, Comment }
import lila.tree.Node.{ Shape, Shapes, Comment }
import lila.user.{ User, UserRepo }
final class StudyApi(

View File

@ -2,7 +2,7 @@ package lila.study
import chess.format.{ Forsyth, Uci, UciCharPair }
import chess.opening._
import lila.socket.tree
import lila.tree
import play.api.libs.json._

View File

@ -2,8 +2,8 @@ package lila.study
import org.specs2.mutable._
import org.specs2.specification._
import lila.socket.tree.Node.Shapes
import lila.socket.tree.Node.Shape._
import lila.tree.Node.Shapes
import lila.tree.Node.Shape._
class CommentParserTest extends Specification {

View File

@ -3,8 +3,8 @@ package lila.study
import chess.format.pgn._
import chess.format.{ FEN, Uci, UciCharPair }
import chess.variant
import lila.socket.tree.Node.Shape._
import lila.socket.tree.Node.Shapes
import lila.tree.Node.Shape._
import lila.tree.Node.Shapes
import Node._
import org.specs2.mutable._
import org.specs2.specification._

View File

@ -8,7 +8,7 @@ import scala.concurrent.duration._
import chess.format.pgn.Tag
import lila.hub.MultiThrottler
import lila.search._
import lila.socket.tree.Node.{ Comments, Comment }
import lila.tree.Node.{ Comments, Comment }
import lila.study.{ Study, Chapter, StudyRepo, ChapterRepo, RootOrNode }
final class StudySearchApi(

View File

@ -1,5 +1,4 @@
package lila.socket
package tree
package lila.tree
import chess.format.pgn.{ Glyph, Glyphs }
import chess.format.{ Uci, UciCharPair }