Current section

Files

Jump to
dqe src dqe_first_below_aggr.erl~
Raw

src/dqe_first_below_aggr.erl~

-module(dqe_first_below_aggr).
-behaviour(dqe_fun).
-include_lib("mmath/include/mmath.hrl").
-export([spec/0, describe/1, init/1, chunk/1, resolution/2, run/2, help/0]).
-record(state, {
const :: number()
}).
init([Const]) when is_integer(Const) ->
#state{const = Const*1.0};
init([Const]) when is_float(Const) ->
#state{const = Const};
chunk(#state{const = Const}) ->
Const * ?RDATA_SIZE.
resolution(_Resolution, State) ->
{1, State}.
describe(#state{const = Const}) when is_integer(Const)->
["first_below(", integer_to_list(Const), ")"];
describe(#state{const = Const}) when is_float(Const)->
["first_below(", float_to_list(Const), ")"].
spec() ->
[{<<"first_below">>, [metric, integer], none, metric},
{<<"first_below">>, [metric, float], none, metric}].
run([Data], S = #state{const = Const}) ->
{mmath_trans:first_below(Data, Const), S}.
help() ->
<<"Returns the first value below a given threashold.">>.