<commit_before>package lila.game

import org.joda.time.DateTime
import scala.collection.Searching._
import scala.collection.breakOut
import scala.concurrent.duration._

import chess._
import chess.variant.Variant

import org.lichess.clockencoder.{ Encoder => ClockEncoder }

import lila.db.ByteArray

object BinaryFormat {

  object pgn {

    def write(moves: PgnMoves): ByteArray = ByteArray {
      format.pgn.Binary.writeMoves(moves).get.toArray
    }

    def read(ba: ByteArray): PgnMoves =
      format.pgn.Binary.readMoves(ba.value.toList).get

    def read(ba: ByteArray, nb: Int): PgnMoves =
      format.pgn.Binary.readMoves(ba.value.toList, nb).get
  }

  object clockHistory {

    def writeSide(start: FiniteDuration, times: Vector[FiniteDuration]): ByteArray = {
      val centis: Array[Int] = times.map(_.toHundredths.toInt)(breakOut)
      val startCentis = start.toHundredths.toInt
      ByteArray(ClockEncoder.encode(centis, startCentis))
    }

    def readSide(start: FiniteDuration, ba: ByteArray, numMoves: Int): Vector[FiniteDuration] = {
      if (ba.isEmpty) { Vector.empty }
      else {
        val startCentis = start.toHundredths.toInt
        ClockEncoder.decode(ba.value, numMoves, startCentis).map(_ * 10.millis).toVector
      }
    }

    def read(start: FiniteDuration, bw: ByteArray, bb: ByteArray, startTurn: Int, turns: Int): ClockHistory = {
      val ply = turns - startTurn
      val bmoves = (((startTurn & 1) + ply) >> 1) - 1
      val wmoves = ply - bmoves
      ClockHistory(readSide(start, bw, wmoves), readSide(start, bb, bmoves))
    }
  }

  object moveTime {

    private type MT = Int // tenths of seconds
    private val size = 16
    private val buckets = List(1, 5, 10, 15, 20, 30, 40, 50, 60, 80, 100, 150, 200, 300, 400, 600)
    private val encodeCutoffsMS = buckets zip buckets.tail map { case (i1, i2) => (i1 + i2) * 50 } toVector

    private val decodeList: List[(Int, MT)] = buckets.zipWithIndex.map(x => x._2 -> x._1)
    private val decodeMap: Map[Int, MT] = decodeList.toMap
<commit_msg>fix move calc<commit_after>package lila.game

import org.joda.time.DateTime
import scala.collection.Searching._
import scala.collection.breakOut
import scala.concurrent.duration._

import chess._
import chess.variant.Variant

import org.lichess.clockencoder.{ Encoder => ClockEncoder }

import lila.db.ByteArray

object BinaryFormat {

  object pgn {

    def write(moves: PgnMoves): ByteArray = ByteArray {
      format.pgn.Binary.writeMoves(moves).get.toArray
    }

    def read(ba: ByteArray): PgnMoves =
      format.pgn.Binary.readMoves(ba.value.toList).get

    def read(ba: ByteArray, nb: Int): PgnMoves =
      format.pgn.Binary.readMoves(ba.value.toList, nb).get
  }

  object clockHistory {

    def writeSide(start: FiniteDuration, times: Vector[FiniteDuration]): ByteArray = {
      val centis: Array[Int] = times.map(_.toHundredths.toInt)(breakOut)
      val startCentis = start.toHundredths.toInt
      ByteArray(ClockEncoder.encode(centis, startCentis))
    }

    def readSide(start: FiniteDuration, ba: ByteArray, numMoves: Int): Vector[FiniteDuration] = {
      if (ba.isEmpty) { Vector.empty }
      else {
        val startCentis = start.toHundredths.toInt
        ClockEncoder.decode(ba.value, numMoves, startCentis).map(_ * 10.millis).toVector
      }
    }

    def read(start: FiniteDuration, bw: ByteArray, bb: ByteArray, startTurn: Int, turns: Int): ClockHistory = {
      val ply = turns - startTurn
      val bmoves = (((startTurn & 1) + ply) >> 1)
      val wmoves = ply - bmoves
      ClockHistory(readSide(start, bw, wmoves), readSide(start, bb, bmoves))
    }
  }

  object moveTime {

    private type MT = Int // tenths of seconds
    private val size = 16
    private val buckets = List(1, 5, 10, 15, 20, 30, 40, 50, 60, 80, 100, 150, 200, 300, 400, 600)
    private val encodeCutoffsMS = buckets zip buckets.tail map { case (i1, i2) => (i1 + i2) * 50 } toVector

    private val decodeList: List[(Int, MT)] = buckets.zipWithIndex.map(x => x._2 -> x._1)
    private val decodeMap: Map[Int, MT] = decodeList.toMap

{'fraction_non_alphanumeric': 0.11823500731350561, 'fraction_numerical': 0.02462213554363725, 'mean_word_length': 3.3372093023255816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7236147', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1372, 'n_words': 345}