<commit_before>package service

import java.io.File
import java.util.concurrent.Executors

import spray.json.{DeserializationException, JsString, JsValue, RootJsonFormat}

import scala.concurrent.{ExecutionContext, Future}
import scala.sys.process._

sealed trait ImageSize { def pixels : Int }
case object WebSize extends ImageSize { val pixels: Int = 500000 }

object ImageSizeFormat extends RootJsonFormat[ImageSize] {

  val jsMappings: Map[String, ImageSize] = Map("WEB_SIZE" -> WebSize)

  private def asString(imageSize: ImageSize): String = jsMappings.filter(pair => pair._2 == imageSize).head._1

  def write(imageSize: ImageSize) = JsString(asString(imageSize))

  def read(value: JsValue): ImageSize =
    value match {
      case JsString(asString) => jsMappings(asString)
      case _ => throw new DeserializationException("ImageSize should be encoded as JsString!")
    }
}

class ImageResizingService {

  implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(10))

  val resize : (File, ImageSize) => Future[File] = (originalFile, imageSize: ImageSize) => {
    val resized = new File(originalFile.getAbsolutePath + s"_resized_${imageSize.pixels}")
    val cmd = s"convert ${originalFile.getAbsolutePath} -resize ${imageSize.pixels}@> ${resized.getAbsolutePath}"

    Future {

      if (cmd.! != 0) {
        println("Could not resize image!!!")
        throw new RuntimeException(s"Could not resize the image ${originalFile.getAbsolutePath}")
      }

      resized
    }
  }
}
<commit_msg>Increase WEB_SIZE, otherwise some receipts are not really readable<commit_after>package service

import java.io.File
import java.util.concurrent.Executors

import spray.json.{DeserializationException, JsString, JsValue, RootJsonFormat}

import scala.concurrent.{ExecutionContext, Future}
import scala.sys.process._

sealed trait ImageSize { def pixels : Int }
case object WebSize extends ImageSize { val pixels: Int = 1000000 }

object ImageSizeFormat extends RootJsonFormat[ImageSize] {

  val jsMappings: Map[String, ImageSize] = Map("WEB_SIZE" -> WebSize)

  private def asString(imageSize: ImageSize): String = jsMappings.filter(pair => pair._2 == imageSize).head._1

  def write(imageSize: ImageSize) = JsString(asString(imageSize))

  def read(value: JsValue): ImageSize =
    value match {
      case JsString(asString) => jsMappings(asString)
      case _ => throw new DeserializationException("ImageSize should be encoded as JsString!")
    }
}

class ImageResizingService {

  implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(10))

  val resize : (File, ImageSize) => Future[File] = (originalFile, imageSize: ImageSize) => {
    val resized = new File(originalFile.getAbsolutePath + s"_resized_${imageSize.pixels}")
    val cmd = s"convert ${originalFile.getAbsolutePath} -resize ${imageSize.pixels}@> ${resized.getAbsolutePath}"

    Future {

      if (cmd.! != 0) {
        println("Could not resize image!!!")
        throw new RuntimeException(s"Could not resize the image ${originalFile.getAbsolutePath}")
      }

      resized
    }
  }
}

{'fraction_non_alphanumeric': 0.10815147625160462, 'fraction_numerical': 0.007381258023106547, 'mean_word_length': 4.536412078152753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '3394861', 'n_tokens_mistral': 965, 'n_tokens_neox': 926, 'n_words': 236}