<commit_before>package controllers

import lila.api.Context
import lila.app._
import lila.user.UserRepo

import play.api.libs.json._
import play.api.mvc._

object Irwin extends LilaController {

  import lila.irwin.JSONHandlers.reportReader

  def saveReport = OpenBody(parse.json) { implicit ctx =>
    ModExternalBot {
      UserRepo.irwin.flatten("Missing irwin user") flatMap { irwin =>
        ctx.body.body.validate[lila.irwin.IrwinReport].fold(
          err => fuccess(BadRequest(err.toString)),
          report => Env.irwin.api.reports.insert(report) inject Ok
        )
      }
    }
  }

  def getRequest = Open { implicit ctx =>
    ModExternalBot {
      Env.irwin.api.requests.getAndStart map {
        case None => NotFound
        case Some(req) => Ok(req.id)
      }
    }
  }

  def assessment(username: String) = Open { implicit ctx =>
    ModExternalBot {
      OptionFuResult(UserRepo named username) { user =>
        Env.mod.jsonView(user) flatMap {
          case None => NotFound.fuccess
          case Some(data) => Env.mod.userHistory(user) map { history =>
            Ok(data + ("history" -> history))
          }
        } map (_ as JSON)
      }
    }
  }

  def usersMarkAndCurrentReport(idsStr: String) = Open { implicit ctx =>
    ModExternalBot {
      val ids = idsStr.split(',').toList map lila.user.User.normalize
      for {
        engineIds <- UserRepo filterByEngine ids
        reportedIds <- Env.report.api.currentlyReportedForCheat
      } yield Ok(Json.toJson(ids.map { id =>
        id -> Json.obj("engine" -> engineIds(id), "report" -> reportedIds(id))
      }.toMap)) as JSON
    }<commit_msg>re-assess player on irwin request<commit_after>package controllers

import lila.api.Context
import lila.app._
import lila.user.UserRepo

import play.api.libs.json._
import play.api.mvc._

object Irwin extends LilaController {

  import lila.irwin.JSONHandlers.reportReader

  def saveReport = OpenBody(parse.json) { implicit ctx =>
    ModExternalBot {
      UserRepo.irwin.flatten("Missing irwin user") flatMap { irwin =>
        ctx.body.body.validate[lila.irwin.IrwinReport].fold(
          err => fuccess(BadRequest(err.toString)),
          report => Env.irwin.api.reports.insert(report) inject Ok
        )
      }
    }
  }

  def getRequest = Open { implicit ctx =>
    ModExternalBot {
      Env.irwin.api.requests.getAndStart map {
        case None => NotFound
        case Some(req) => Ok(req.id)
      }
    }
  }

  def assessment(username: String) = Open { implicit ctx =>
    ModExternalBot {
      OptionFuResult(UserRepo named username) { user =>
        Env.mod.assessApi.refreshAssessByUsername(user.id) >>
          Env.mod.jsonView(user).flatMap {
            case None => NotFound.fuccess
            case Some(data) => Env.mod.userHistory(user) map { history =>
              Ok(data + ("history" -> history))
            }
          }.map(_ as JSON)
      }
    }
  }

  def usersMarkAndCurrentReport(idsStr: String) = Open { implicit ctx =>
    ModExternalBot {
      val ids = idsStr.split(',').toList map lila.user.User.normalize
      for {
        engineIds <- UserRepo filterByEngine ids
        reportedIds <- Env.report.api.currentlyReportedForCheat
      } yield Ok(Json.toJson(ids.map { id =>
        id -> Json.obj("engine" -> engineIds(id), "report" -> reportedIds(id))
      }.toMap)) as JSON
    }
{'fraction_non_alphanumeric': 0.11808227286179343, 'fraction_numerical': 0.0, 'mean_word_length': 2.473792394655704, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, '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': '4862862', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1040, 'n_words': 218}