Commit 924158e1 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

mean bucket

parent 16efc0e8
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -34,7 +34,15 @@ object BucketFactory {
    val flush_timeout = java.lang.Double.parseDouble(key.flush_timeout).
      longValue * 1000

    new SumBucket(flush_timeout)
    key.mode match {

      case "sum" =>
        return new SumBucket(flush_timeout)

      case "mean" =>
        return new MeanBucket(flush_timeout)

    }
  }

}
+33 −0
Original line number Diff line number Diff line

//   (c) 2011-2013 Paul Asmuth <paul@paulasmuth.com>
//
// Licensed under the MIT License (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of
// the License at: http://opensource.org/licenses/MIT

package com.fnordmetric.enterprise

class MeanBucket(_flush_timeout: Long) extends AbstractBucket {
  val flush_timeout = _flush_timeout
  var tmp_sum : Double = 0
  var tmp_cnt : Int = 0

  def sample(value: Double) : Unit = {
    tmp_sum += value
    tmp_cnt += 1
  }

  def flush : Double = {
    val res = if (tmp_cnt == 0)
      0
    else
      tmp_sum / tmp_cnt

    tmp_sum = 0.toDouble
    tmp_cnt = 0

    println("flush: " + res)
    res
  }

}
+7 −2
Original line number Diff line number Diff line
@@ -14,7 +14,12 @@ class SumBucket(_flush_timeout: Long) extends AbstractBucket {
  def sample(value: Double) : Unit = {
    tmp += value; println("val: " + tmp) }

  def flush : Double =
    { val res = tmp; tmp = 0; println("flush: " + res); res }
  def flush : Double = {
    val res = tmp
    tmp = 0.toDouble

    println("flush: " + res)
    res
  }

}