<commit_before>package spotlight.model.outlier

import org.joda.{time => joda}
import peds.commons.log.Trace
import peds.commons.util._


trait IsQuorum extends Serializable {
  def apply( results: OutlierAlgorithmResults ): Boolean
  def totalIssued: Int

  protected def evaluateRemainder( results: OutlierAlgorithmResults ): Boolean = results.size >= totalIssued
}

object IsQuorum {
  case class AtLeastQuorumSpecification( override val totalIssued: Int, triggerPoint: Int ) extends IsQuorum {
    override def apply( results: OutlierAlgorithmResults ): Boolean = {
      if (
        results.count{ _._2.hasAnomalies } >= triggerPoint &&
        OutlierAlgorithmResults.tallyMax(results) >= triggerPoint
      ) {
        true
      } else {
        evaluateRemainder( results )
      }
    }

    override def toString: String = s"${getClass.safeSimpleName}(trigger:[${triggerPoint}] of total:[${totalIssued}])"
  }

  case class MajorityQuorumSpecification( override val totalIssued: Int, triggerPoint: Double ) extends IsQuorum {
    override def apply( results: OutlierAlgorithmResults ): Boolean = {
      val actual = results.count{ _._2.hasAnomalies }.toDouble / totalIssued.toDouble
      if (
        actual > triggerPoint &&
        ( OutlierAlgorithmResults.tallyMax(results).toDouble / totalIssued.toDouble ) > triggerPoint
      ) {
        true
      } else {
        evaluateRemainder( results )
      }
    }

    override def toString: String = s"${getClass.safeSimpleName}(trigger:[${triggerPoint}]% of total:[${totalIssued}])"
  }
}
<commit_msg>fix cosmetic toString error in percentage calculation<commit_after>package spotlight.model.outlier

import org.joda.{time => joda}
import peds.commons.log.Trace
import peds.commons.util._


trait IsQuorum extends Serializable {
  def apply( results: OutlierAlgorithmResults ): Boolean
  def totalIssued: Int

  protected def evaluateRemainder( results: OutlierAlgorithmResults ): Boolean = results.size >= totalIssued
}

object IsQuorum {
  case class AtLeastQuorumSpecification( override val totalIssued: Int, triggerPoint: Int ) extends IsQuorum {
    override def apply( results: OutlierAlgorithmResults ): Boolean = {
      if (
        results.count{ _._2.hasAnomalies } >= triggerPoint &&
        OutlierAlgorithmResults.tallyMax(results) >= triggerPoint
      ) {
        true
      } else {
        evaluateRemainder( results )
      }
    }

    override def toString: String = s"${getClass.safeSimpleName}(trigger:[${triggerPoint}] of total:[${totalIssued}])"
  }

  case class MajorityQuorumSpecification( override val totalIssued: Int, triggerPoint: Double ) extends IsQuorum {
    override def apply( results: OutlierAlgorithmResults ): Boolean = {
      val actual = results.count{ _._2.hasAnomalies }.toDouble / totalIssued.toDouble
      if (
        actual > triggerPoint &&
        ( OutlierAlgorithmResults.tallyMax(results).toDouble / totalIssued.toDouble ) > triggerPoint
      ) {
        true
      } else {
        evaluateRemainder( results )
      }
    }

    override def toString: String = s"${getClass.safeSimpleName}(trigger:[${triggerPoint * 100}]% of total:[${totalIssued}])"
  }
}

{'fraction_non_alphanumeric': 0.09956030150753768, 'fraction_numerical': 0.0021984924623115578, 'mean_word_length': 3.530583214793741, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4624670', 'n_tokens_mistral': 929, 'n_tokens_neox': 895, 'n_words': 217}