<commit_before>package io.gearpump.streaming.metrics

import com.typesafe.config.Config
import io.gearpump.cluster.ClientToMaster.ReadOption
import io.gearpump.cluster.MasterToClient.HistoryMetricsItem
import io.gearpump.metrics.MetricsAggregator
import io.gearpump.util.{LogUtil, Constants}

import scala.collection.mutable.ListBuffer
import scala.util.{Failure, Success, Try}

/**
 * It filters the latest metrics data by specifying a
 * processor Id range, and taskId range.
 */
class TaskFilterAggregator (maxLimit: Int) extends MetricsAggregator {

  import TaskFilterAggregator._

  def this(config: Config) = {
    this(config.getInt(Constants.GEARPUMP_METRICS_MAX_LIMIT))
  }
  override def aggregate(options: Map[String, String], inputs: Iterator[HistoryMetricsItem]): List[HistoryMetricsItem] = {
    if (options.get(ReadOption.Key) != ReadOption.ReadLatest) {
      // return empty set
      List.empty[HistoryMetricsItem]
    } else {
      val parsed = Options.parse(options)
      if (parsed != null) {
        aggregate(parsed, inputs)
      } else {
        List.empty[HistoryMetricsItem]
      }
    }
  }

  def aggregate(options: Options, inputs: Iterator[HistoryMetricsItem]): List[HistoryMetricsItem] = {
<commit_msg>fix #1768, TaskFilterAggregator is not working<commit_after>package io.gearpump.streaming.metrics

import com.typesafe.config.Config
import io.gearpump.cluster.ClientToMaster.ReadOption
import io.gearpump.cluster.MasterToClient.HistoryMetricsItem
import io.gearpump.metrics.MetricsAggregator
import io.gearpump.util.{LogUtil, Constants}

import scala.collection.mutable.ListBuffer
import scala.util.{Failure, Success, Try}

/**
 * It filters the latest metrics data by specifying a
 * processor Id range, and taskId range.
 */
class TaskFilterAggregator (maxLimit: Int) extends MetricsAggregator {

  import TaskFilterAggregator._

  def this(config: Config) = {
    this(config.getInt(Constants.GEARPUMP_METRICS_MAX_LIMIT))
  }
  override def aggregate(options: Map[String, String], inputs: Iterator[HistoryMetricsItem]): List[HistoryMetricsItem] = {
    if (options.get(ReadOption.Key) != Some(ReadOption.ReadLatest)) {
      // return empty set
      List.empty[HistoryMetricsItem]
    } else {
      val parsed = Options.parse(options)
      if (parsed != null) {
        aggregate(parsed, inputs)
      } else {
        List.empty[HistoryMetricsItem]
      }
    }
  }

  def aggregate(options: Options, inputs: Iterator[HistoryMetricsItem]): List[HistoryMetricsItem] = {

{'fraction_non_alphanumeric': 0.10099403578528827, 'fraction_numerical': 0.0015904572564612327, 'mean_word_length': 4.3760683760683765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1377072', 'n_tokens_mistral': 754, 'n_tokens_neox': 758, 'n_words': 161}