<commit_before>package controllers.dos

import com.mongodb.casbah.Imports._
import com.mongodb.casbah.gridfs.{ GridFS, GridFSDBFile }
import java.awt.image.BufferedImage
import javax.imageio.ImageIO
import java.io._
import org.imgscalr.Scalr
import play.api.libs.Files.TemporaryFile
import org.apache.commons.io.{ FileUtils, IOUtils }
import org.im4java.core.{ IMOperation, ImageCommand }
import play.api.Logger
import play.api.Play.current
import java.util.UUID
import org.im4java.process.ErrorConsumer
import com.mongodb.casbah.commons.MongoDBObject
import models.OrganizationConfiguration

/**
 * TODO refactor the createThumbnails method to allow batch processing on all sizes
 *
 * @author <NAME> <<EMAIL>>
 */

trait ThumbnailSupport {

  val logger = Logger("CultureHub")

  protected def createThumbnailsFromStream(imageStream: InputStream, fileIdentifier: String, filename: String, contentType: String, store: GridFS, params: Map[String, String] = Map.empty[String, String])(implicit configuration: OrganizationConfiguration): Map[Int, ObjectId] = {
    thumbnailSizes.map { size =>
      logger.info("Creating thumbnail for file " + filename)
      createThumbnailFromStream(imageStream, filename, contentType, size._2, store, params + (FILE_POINTER_FIELD -> fileIdentifier))
    }
  }

  protected def createThumbnails(image: GridFSDBFile, store: GridFS, globalParams: Map[String, String] = Map.empty[String, String])(implicit configuration: OrganizationConfiguration): Map[Int, ObjectId] = {
    thumbnailSizes.map { size =>
      logger.info("Creating thumbnail for file " + image.filename)
      createThumbnailFromStream(image.inputStream, image.filename.getOrElse(""), image.contentType.getOrElse("unknown/unknown"), size._2, store, globalParams + (FILE_POINTER_FIELD -> image._id.get))<commit_msg>Updating TODO<commit_after>package controllers.dos

import com.mongodb.casbah.Imports._
import com.mongodb.casbah.gridfs.{ GridFS, GridFSDBFile }
import java.awt.image.BufferedImage
import javax.imageio.ImageIO
import java.io._
import org.imgscalr.Scalr
import play.api.libs.Files.TemporaryFile
import org.apache.commons.io.{ FileUtils, IOUtils }
import org.im4java.core.{ IMOperation, ImageCommand }
import play.api.Logger
import play.api.Play.current
import java.util.UUID
import org.im4java.process.ErrorConsumer
import com.mongodb.casbah.commons.MongoDBObject
import models.OrganizationConfiguration

/**
 * TODO merge createThumbnails and createAndStoreThumbnail - go for full GM action
 *
 * @author <NAME> <<EMAIL>>
 */

trait ThumbnailSupport {

  val logger = Logger("CultureHub")

  protected def createThumbnailsFromStream(imageStream: InputStream, fileIdentifier: String, filename: String, contentType: String, store: GridFS, params: Map[String, String] = Map.empty[String, String])(implicit configuration: OrganizationConfiguration): Map[Int, ObjectId] = {
    thumbnailSizes.map { size =>
      logger.info("Creating thumbnail for file " + filename)
      createThumbnailFromStream(imageStream, filename, contentType, size._2, store, params + (FILE_POINTER_FIELD -> fileIdentifier))
    }
  }

  protected def createThumbnails(image: GridFSDBFile, store: GridFS, globalParams: Map[String, String] = Map.empty[String, String])(implicit configuration: OrganizationConfiguration): Map[Int, ObjectId] = {
    thumbnailSizes.map { size =>
      logger.info("Creating thumbnail for file " + image.filename)
      createThumbnailFromStream(image.inputStream, image.filename.getOrElse(""), image.contentType.getOrElse("unknown/unknown"), size._2, store, globalParams + (FILE_POINTER_FIELD -> image._id.get))
{'fraction_non_alphanumeric': 0.10835401157981803, 'fraction_numerical': 0.0022056796250344637, 'mean_word_length': 5.644688644688645, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5996359', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1081, 'n_words': 246}