# mirabelle.math

### count-events

`(count-events events)`

Count the number of events. The latest event is used as a base to build the event returned by this funcion.

### extremum-n

`(extremum-n nb comparator events)`

Takes a number of events, a comparator and a list of events. Sort the events based on the :metric field and by using the comparator and Return the first nb events.

### max-event

`(max-event events)`

Takes a list of event and returns the event with the biggest metric

### mean

`(mean events)`

Takes a list of events and returns the metrics mean. The latest event is used as a base to build the event returned by this funcion.

### min-event

`(min-event events)`

Takes a list of event and returns the event with the smallest metric

### quotient

`(quotient events)`

Takes a list of events Divide the first event `:metrìc`

field by all subsequent events `:metric`

Throws if it divides by zero.

### rate

`(rate events)`

Takes a list of events and compute the rate for them. Use the most recent event as a base for the new event.

### sorted-sample

`(sorted-sample s points)`

Sample a sequence of events at points. Returns events with the :quantile key set to the computed quantile. For instance, (sorted-sample events [0 1]) returns a 2-element seq of the smallest event and the biggest event, by metric. The first has a quantile set to 0 and the second one set to in 1. Useful for extracting histograms and percentiles.

When s is empty, returns an empty list.

### sorted-sample-extract

`(sorted-sample-extract s points)`

Returns the events in seqable s, sorted and taken at each point p of points, where p ranges from 0 (smallest metric) to 1 (largest metric). 0.5 is the median event, 0.95 is the 95th’ percentile event, and so forth. Ignores events without a metric.

### sum-events

`(sum-events events)`

Sum all events :metric. Use the most recent event as a base for the new event.