Property definitions

nitc $ IntMetric :: defaultinit
# A Metric that collects integer data
#
# Used to count things
class IntMetric
	super Metric

	redef type VAL: Int is fixed
	redef type RES: Counter[ELM]

	# `IntMetric` uses a Counter to store values in intern.
	protected var values_cache = new Counter[ELM]

	redef fun values do return values_cache

	redef fun clear do values_cache.clear

	redef fun sum do return values_cache.sum

	redef fun max do
		assert not values_cache.is_empty
		return values_cache.max.as(not null)
	end

	redef fun min do
		assert not values_cache.is_empty
		return values_cache.min.as(not null)
	end

	# Values average
	redef fun avg do return values_cache.avg

	redef fun std_dev do return values_cache.std_dev

	redef fun above_threshold do
		var above = new HashSet[ELM]
		var threshold = threshold
		for element, value in values do
			if value.to_f > threshold then above.add(element)
		end
		return above
	end

	redef fun to_console(indent, colors) do
		super
		if colors then
			print "{"\t" * indent}  sum: {sum}".light_gray
		else
			print "{"\t" * indent}  sum: {sum}"
		end
	end
end
src/metrics/metrics_base.nit:235,1--285,3