The concept is reified here for a better organization and documentation
nitc :: Metric :: above_threshold
The set of element above the thresholdnitc :: Metric :: defaultinit
nitc :: Metric :: has_element
Does the element have a value for this metric?nitc :: Metric :: to_console
Pretty print the metric results in consolenitc :: api_metrics $ Metric :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: Metric :: above_threshold
The set of element above the thresholdserialization :: Serializable :: accept_inspect_serializer_core
serialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: Metric :: defaultinit
core :: Object :: defaultinit
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
nitc :: Metric :: has_element
Does the element have a value for this metric?core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
serialization :: Serializable :: serialize_to_or_delay
Accept references or force direct serialization (usingserialize_to
)
nitc :: Metric :: to_console
Pretty print the metric results in consoleserialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
Serializer::serialize
# A Metric is used to collect data about things
#
# The concept is reified here for a better organization and documentation
interface Metric
# Type of elements measured by this metric.
type ELM: Object
# Type of values used to measure elements.
type VAL: Object
# Type of data representation used to associate elements and values.
type RES: Map[ELM, VAL]
# The name of this metric (generally an acronym about the metric).
fun name: String is abstract
# A long and understandable description about what is measured by this metric.
fun desc: String is abstract
# Clear all results for this metric
fun clear is abstract
# Values for each element
fun values: RES is abstract
# Collect metric values on elements
fun collect(elements: Collection[ELM]) is abstract
# The value calculated for the element
fun [](element: ELM): VAL do return values[element]
# Does the element have a value for this metric?
fun has_element(element: ELM): Bool do return values.has_key(element)
# The values average
fun avg: Float is abstract
# Pretty print the metric results in console
fun to_console(indent: Int, colors: Bool) do
if values.is_empty then
if colors then
print "{"\t" * indent}{name}: {desc} -- nothing".green
else
print "{"\t" * indent}{name}: {desc} -- nothing"
end
return
end
var max = self.max
var min = self.min
if colors then
print "{"\t" * indent}{name}: {desc}".green
print "{"\t" * indent} avg: {avg}".light_gray
print "{"\t" * indent} max: {max} ({self[max]})".light_gray
print "{"\t" * indent} min: {min} ({self[min]})".light_gray
print "{"\t" * indent} std: {std_dev}".light_gray
else
print "{"\t" * indent}{name}: {desc}"
print "{"\t" * indent} avg: {avg}"
print "{"\t" * indent} max: {max} ({self[max]})"
print "{"\t" * indent} min: {min} ({self[min]})"
print "{"\t" * indent} std: {std_dev}"
end
end
# The sum of all the values.
fun sum: VAL is abstract
# The values standard derivation
fun std_dev: Float is abstract
# The element with the highest value
fun max: ELM is abstract
# The element with the lowest value
fun min: ELM is abstract
# The value threshold above what elements are considered as 'interesting'
fun threshold: Float do return avg + std_dev
# The set of element above the threshold
fun above_threshold: Set[ELM] is abstract
# Sort the metric keys by values
fun sort: Array[ELM] do
return values.keys_sorted_by_values(default_reverse_comparator)
end
end
src/metrics/metrics_base.nit:145,1--233,3
redef class Metric
super Serializable
redef fun core_serialize_to(v) do
v.serialize_attribute("name", name)
v.serialize_attribute("desc", desc)
v.serialize_attribute("empty", values.is_empty)
if values.not_empty then v.serialize_attribute("avg", avg)
if values.not_empty then v.serialize_attribute("std_dev", std_dev)
if values.not_empty then v.serialize_attribute("threshold", threshold)
end
end
src/doc/api/api_metrics.nit:162,1--173,3