anchor.diff:      safe_average(Vs, Cnt + 1, NewAvg).
   
   
  +derivative(Values) ->
  +    derivative(Values, null, []).
  +
  +derivative([], _Prev, Acc) ->
  +    lists:reverse(Acc);
  +derivative([{TS, Value} | Vs], null, Acc) ->
  +    derivative(Vs, Value, [{TS, null} | Acc]);
  +derivative([{TS, null} | Vs], _Prev, Acc) ->
  +    derivative(Vs, null, [{TS, null} | Acc]);
  +derivative([{TS, Value} | Vs], Prev, Acc) ->
  +    derivative(Vs, Value, [{TS, Value - Prev} | Acc]).
  +
  +
   %%
   %% TESTS
   %%
  
positive.code:      ?_assertEqual(<<"test">>, alias_target(<<"foo.bar.test">>, [2])),
       ?_assertEqual(<<"test">>, alias_target(<<"foo.bar.test">>, [-1])),
       ?_assertEqual(<<"foo">>, alias_target(<<"foo.bar.test">>, [0]))
      ].
  
  safe_average_test_() ->
  
negative.code: evaluate_call(<<"averageBelow">>, [Series, Avg], _From, _Until, _Now) ->
      lists:filter(fun({_, Values}) -> safe_average(Values) =< Avg end, Series);
  
  % derivative
  evaluate_call(<<"derivative">>, [Series], _From, _Until, _Now) ->
      lists:map(fun({Target, Values}) ->
                        {Target, derivative(Values)}
                end, Series);
  
  evaluate_call(Unknown, _Args, _From, _Until, _Now) ->
      lager:error("unknown function call ~p or invalid arguments", [Unknown]),
      error.
  