add analysis data to mobile game API
This commit is contained in:
parent
f11e1c3302
commit
bf269ae540
|
@ -141,21 +141,20 @@ object Round extends LilaController with TheftPrevention {
|
|||
|
||||
def watcher(gameId: String, color: String) = Open { implicit ctx =>
|
||||
GameRepo.pov(gameId, color) flatMap {
|
||||
case Some(pov) =>
|
||||
get("pov") match {
|
||||
case Some(requestedPov) => (pov.player.userId, pov.opponent.userId) match {
|
||||
case (Some(_), Some(opponent)) if opponent == requestedPov =>
|
||||
Redirect(routes.Round.watcher(gameId, (!pov.color).name)).fuccess
|
||||
case (Some(player), Some(_)) if player == requestedPov =>
|
||||
Redirect(routes.Round.watcher(gameId, pov.color.name)).fuccess
|
||||
case _ =>
|
||||
Redirect(routes.Round.watcher(gameId, "white")).fuccess
|
||||
}
|
||||
case None => {
|
||||
env.checkOutoftime(pov.game)
|
||||
watch(pov)
|
||||
}
|
||||
case Some(pov) => get("pov") match {
|
||||
case Some(requestedPov) => (pov.player.userId, pov.opponent.userId) match {
|
||||
case (Some(_), Some(opponent)) if opponent == requestedPov =>
|
||||
Redirect(routes.Round.watcher(gameId, (!pov.color).name)).fuccess
|
||||
case (Some(player), Some(_)) if player == requestedPov =>
|
||||
Redirect(routes.Round.watcher(gameId, pov.color.name)).fuccess
|
||||
case _ =>
|
||||
Redirect(routes.Round.watcher(gameId, "white")).fuccess
|
||||
}
|
||||
case None => {
|
||||
env.checkOutoftime(pov.game)
|
||||
watch(pov)
|
||||
}
|
||||
}
|
||||
case None => Challenge showId gameId
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +183,14 @@ object Round extends LilaController with TheftPrevention {
|
|||
Ok(html.round.watcherBot(pov, initialFen, pgn, crosstable))
|
||||
}
|
||||
}.mon(_.http.response.watcher.website),
|
||||
api = apiVersion => Env.api.roundApi.watcher(pov, apiVersion, tv = none) map { Ok(_) }
|
||||
api = apiVersion =>
|
||||
Env.api.roundApi.watcher(pov, apiVersion, tv = none) flatMap { json =>
|
||||
pov.game.metadata.analysed.??(analyser get pov.game.id) map { analysis =>
|
||||
Ok(analysis.fold(json) { a =>
|
||||
json + ("analysis" -> lila.analyse.JsonView.mobile(pov.game, a))
|
||||
})
|
||||
}
|
||||
}
|
||||
) map NoCache
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import lila.game.Game
|
|||
|
||||
object JsonView {
|
||||
|
||||
def game(analysis: Analysis) = JsArray(analysis.infoAdvices map {
|
||||
def moves(analysis: Analysis) = JsArray(analysis.infoAdvices map {
|
||||
case ((info, adviceOption)) => Json.obj(
|
||||
"eval" -> info.score.map(_.centipawns),
|
||||
"mate" -> info.mate,
|
||||
|
@ -28,4 +28,9 @@ object JsonView {
|
|||
def bothPlayers(game: Game, analysis: Analysis) = Json.obj(
|
||||
"white" -> player(game.whitePov)(analysis),
|
||||
"black" -> player(game.blackPov)(analysis))
|
||||
|
||||
def mobile(game: Game, analysis: Analysis) = Json.obj(
|
||||
"summary" -> bothPlayers(game, analysis),
|
||||
"moves" -> moves(analysis)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ private[api] final class GameApi(
|
|||
"analysis" -> analysisOption.flatMap(analysisJson.player(g pov p.color))
|
||||
).noNull
|
||||
}),
|
||||
"analysis" -> analysisOption.ifTrue(withAnalysis).map(analysisJson.game),
|
||||
"analysis" -> analysisOption.ifTrue(withAnalysis).map(analysisJson.moves),
|
||||
"moves" -> withMoves.option(g.pgnMoves mkString " "),
|
||||
"opening" -> withOpening.??(g.opening),
|
||||
"fens" -> withFens ?? {
|
||||
|
|
Loading…
Reference in a new issue