<commit_before>package org.jousse
package bot

import controllers.routes
import play.api.libs.json._
import system.Replay

object JsonFormat {

  def apply(i: system.PlayerInput, host: String): JsObject = Json.obj(
    "game" -> apply(i.game),
    "hero" -> i.hero.map(apply(_, i.game)),
    "token" -> i.token,
    "viewUrl" -> ("http://" + host + routes.Game.show(i.game.id).url),
    "playUrl" -> ("http://" + host + routes.Api.move(i.game.id, i.token).url)
  )

  def apply(g: Game): JsObject = Json.obj(
    "id" -> g.id,
    "turn" -> g.turn,
    "maxTurns" -> g.maxTurns,
    "heroes" -> JsArray(g.heroes map { apply(_, g) }),
    "board" -> Json.obj(
      "size" -> g.board.size,
      "tiles" -> (g.board.posTiles map {
        case (pos, tile) => (g hero pos).fold(tile.render)(_.render)
      }).mkString
    ),
    "finished" -> g.finished
  )

  def apply(h: Hero, g: Game): JsObject = Json.obj(
    "id" -> h.id,
    "name" -> h.name,
    "pos" -> Json.obj("x" -> h.pos.x, "y" -> h.pos.y),
    "life" -> h.life,
    "gold" -> h.gold,
    "mineCount" -> g.board.countMines(h.id),
    "crashed" -> h.crashed)

  def apply(r: Replay): JsObject = Json.obj(
    "id" -> r.id,
    "games" -> JsArray(r.games)
  )
}<commit_msg>add user id and elo to hero json<commit_after>package org.jousse
package bot

import controllers.routes
import play.api.libs.json._
import system.Replay

object JsonFormat {

  def apply(i: system.PlayerInput, host: String): JsObject = Json.obj(
    "game" -> apply(i.game),
    "hero" -> i.hero.map(apply(_, i.game)),
    "token" -> i.token,
    "viewUrl" -> ("http://" + host + routes.Game.show(i.game.id).url),
    "playUrl" -> ("http://" + host + routes.Api.move(i.game.id, i.token).url)
  ).noNull

  def apply(g: Game): JsObject = Json.obj(
    "id" -> g.id,
    "turn" -> g.turn,
    "maxTurns" -> g.maxTurns,
    "heroes" -> JsArray(g.heroes map { apply(_, g) }),
    "board" -> Json.obj(
      "size" -> g.board.size,
      "tiles" -> (g.board.posTiles map {
        case (pos, tile) => (g hero pos).fold(tile.render)(_.render)
      }).mkString
    ),
    "finished" -> g.finished
  ).noNull

  def apply(h: Hero, g: Game): JsObject = Json.obj(
    "id" -> h.id,
    "name" -> h.name,
    "userId" -> h.userId,
    "elo" -> h.elo,
    "pos" -> Json.obj("x" -> h.pos.x, "y" -> h.pos.y),
    "life" -> h.life,
    "gold" -> h.gold,
    "mineCount" -> g.board.countMines(h.id),
    "crashed" -> h.crashed
  ).noNull

  def apply(r: Replay): JsObject = Json.obj(
    "id" -> r.id,
    "games" -> JsArray(r.games)
  )

  private implicit final class PimpedJsObject(js: JsObject) {
    def noNull = JsObject {
      js.fields collect {
        case (key, value) if value != JsNull ⇒ key -> value
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.20697167755991286, 'fraction_numerical': 0.0, 'mean_word_length': 2.4096534653465347, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 56, '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': '6396204', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1102, 'n_words': 234}