def time(task = :default, type = :current)
      return nil unless tasks.keys.include?(task)
      numbers = tasks[task][:history].map { |v| v[:time] }
      case type
      when :current
        return nil unless tasks[task][:current]
        Time.now.to_f - tasks[task][:current]
      when :min, :max, :first, :last
        numbers.send(type)
      when :avg
        numbers.size.zero? ? nil : numbers.inject { |sum, n| sum + n }.to_f / numbers.size
      when :sum
        numbers.inject { |sum, n| sum + n }
      when :all
        numbers
      when :count
        numbers.size
      end
    end
def time(task = :default, type = :current)
      return nil unless tasks.keys.include?(task)
      numbers = tasks[task][:history].map { |v| v[:time] }
      case type
      when :current
        return nil unless tasks[task][:current]
        Time.now.to_f - tasks[task][:current]
      when :min, :max, :first, :last
        numbers.send(type)
      when :avg
        numbers.size.zero? ? nil : numbers.inject { |sum, n| sum + n }.to_f / numbers.size
      when :sum
        numbers.inject { |sum, n| sum + n }
      when :all
        numbers
      when :count
        numbers.size
      end
    end
Returns an aggregated metric for a given type.

 @param [Symbol] task The key value of the task to retrieve
 @param [Symbol] type The metric to return.
   Options are :avg, :min, :max, :first, :last, :sum, :all and :count.
 @return [Float, Integer, Array] Returns either the aggregation (Numeric) or an Array in the case of :all.