<commit_before>package io.coral.actors.transform

import io.coral.actors.CoralActor
import akka.actor.ActorLogging
import org.json4s._
import org.json4s.JsonDSL._
import org.json4s.jackson.JsonMethods._
import scalaz.OptionT
import scala.concurrent.Future
import akka.actor.Props

object ThresholdActor {
  implicit val formats = org.json4s.DefaultFormats
  
  def getParams(json: JValue) = {
    for {
      key <- (json \ "params" \ "key").extractOpt[String]
      threshold <- (json \ "params" \ "threshold").extractOpt[Double]
    } yield(key, threshold)
  }
  
  def apply(json: JValue): Option[Props] = {
    getParams(json).map(_ => Props(classOf[ThresholdActor], json))
    // todo: take better care of exceptions and error handling
  }
}

class ThresholdActor(json: JObject) extends CoralActor with ActorLogging {
  private val (key, threshold) = ThresholdActor.getParams(json).get
  
  private var thresholdReached = false
  
  def jsonDef = json
  
  def state = Map.empty
  
  def timer = notSet
  
  override def trigger = {
    json: JObject =>
    for {
      value <- getTriggerInputField[Double](json \ key)
    } yield {
      thresholdReached = value >= threshold
    }
  }
  
  override def emit = {
    json: JObject =>
    thresholdReached match {
      case true => {
        val result = ("thresholdReached" -> key)
        json merge render(result)
      }
      case false => JNothing<commit_msg>Akka actors provide enough encapsulation. No need for private member declarations.<commit_after>package io.coral.actors.transform

import io.coral.actors.CoralActor
import akka.actor.ActorLogging
import org.json4s._
import org.json4s.JsonDSL._
import org.json4s.jackson.JsonMethods._
import scalaz.OptionT
import scala.concurrent.Future
import akka.actor.Props

object ThresholdActor {
  implicit val formats = org.json4s.DefaultFormats
  
  def getParams(json: JValue) = {
    for {
      key <- (json \ "params" \ "key").extractOpt[String]
      threshold <- (json \ "params" \ "threshold").extractOpt[Double]
    } yield(key, threshold)
  }
  
  def apply(json: JValue): Option[Props] = {
    getParams(json).map(_ => Props(classOf[ThresholdActor], json))
    // todo: take better care of exceptions and error handling
  }
}

class ThresholdActor(json: JObject) extends CoralActor with ActorLogging {
  val (key, threshold) = ThresholdActor.getParams(json).get
  
  var thresholdReached = false
  
  def jsonDef = json
  
  def state = Map.empty
  
  def timer = notSet
  
  override def trigger = {
    json: JObject =>
    for {
      value <- getTriggerInputField[Double](json \ key)
    } yield {
      thresholdReached = value >= threshold
    }
  }
  
  override def emit = {
    json: JObject =>
    thresholdReached match {
      case true => {
        val result = ("thresholdReached" -> key)
        json merge render(result)
      }
      case false => JNothing
{'fraction_non_alphanumeric': 0.10355540214014498, 'fraction_numerical': 0.002761477390403866, 'mean_word_length': 3.087447108603667, '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': '6891258', 'n_tokens_mistral': 907, 'n_tokens_neox': 891, 'n_words': 229}