<commit_before>package controllers

import lila._
import views._
import analyse._

import play.api.mvc._
import play.api.http.ContentTypes
import play.api.templates.Html
import play.api.libs.concurrent._
import scalaz.effects._

object Analyse extends LilaController {

  def gameRepo = env.game.gameRepo
  def pgnDump = env.analyse.pgnDump
  def openingExplorer = chess.OpeningExplorer
  def bookmarkApi = env.bookmark.api
  def roundMessenger = env.round.messenger
  def roundSocket = env.round.socket
  def analyser = env.analyse.analyser
  def notification = env.notificationApi

  def computer(id: String, color: String) = Auth { implicit ctx ⇒
    me ⇒
      analyser.getOrGenerate(id, me.id) onComplete {
        case Left(e) ⇒ println(e.getMessage)
        case Right(a) ⇒ a.fold(
          err ⇒ println("Computer analysis failure: " + err.shows),
          analysis ⇒ {
            notification.add(me, views.html.analyse.notification(analysis, id).toString)
          }
        )
      }
      Redirect(routes.Analyse.replay(id, color))
  }

  def replay(id: String, color: String) = Open { implicit ctx ⇒
    IOptionIOk(gameRepo.pov(id, color)) { pov ⇒
      for {
        roomHtml ← roundMessenger renderWatcher pov.game
        bookmarkers ← bookmarkApi usersByGame pov.game
        pgn ← pgnDump >> pov.game
        analysis ← analyser get pov.game.id
        _ = for {
          me ← ctx.me
          a ← analysis
        } yield notification.add(me, views.html.analyse.notification(a, id).toString)
      } yield html.analyse.replay(
        pov,
        pgn.toString,
        Html(roomHtml),
        bookmarkers,
        openingExplorer openingOf pov.game.pgn,
        analysis,
        roundSocket blockingVersion pov.gameId)
    }<commit_msg>remove debug code<commit_after>package controllers

import lila._
import views._
import analyse._

import play.api.mvc._
import play.api.http.ContentTypes
import play.api.templates.Html
import play.api.libs.concurrent._
import scalaz.effects._

object Analyse extends LilaController {

  def gameRepo = env.game.gameRepo
  def pgnDump = env.analyse.pgnDump
  def openingExplorer = chess.OpeningExplorer
  def bookmarkApi = env.bookmark.api
  def roundMessenger = env.round.messenger
  def roundSocket = env.round.socket
  def analyser = env.analyse.analyser
  def notification = env.notificationApi

  def computer(id: String, color: String) = Auth { implicit ctx ⇒
    me ⇒
      analyser.getOrGenerate(id, me.id) onComplete {
        case Left(e) ⇒ println(e.getMessage)
        case Right(a) ⇒ a.fold(
          err ⇒ println("Computer analysis failure: " + err.shows),
          analysis ⇒ {
            notification.add(me, views.html.analyse.notification(analysis, id).toString)
          }
        )
      }
      Redirect(routes.Analyse.replay(id, color))
  }

  def replay(id: String, color: String) = Open { implicit ctx ⇒
    IOptionIOk(gameRepo.pov(id, color)) { pov ⇒
      for {
        roomHtml ← roundMessenger renderWatcher pov.game
        bookmarkers ← bookmarkApi usersByGame pov.game
        pgn ← pgnDump >> pov.game
        analysis ← analyser get pov.game.id
      } yield html.analyse.replay(
        pov,
        pgn.toString,
        Html(roomHtml),
        bookmarkers,
        openingExplorer openingOf pov.game.pgn,
        analysis,
        roundSocket blockingVersion pov.gameId)
    }
{'fraction_non_alphanumeric': 0.09322284699615271, 'fraction_numerical': 0.0, 'mean_word_length': 2.658008658008658, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5369032', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1092, 'n_words': 267}