anchor.diff:      end.
   
   
  +consolidate(Series, ValuesPP) ->
  +    consolidate(Series, ValuesPP, fun safe_average/1).
  +
  +consolidate(Series, ValuesPP, _Func) when ValuesPP =< 1 -> Series;
  +consolidate(Series, ValuesPP, Func) ->
  +    Values = consolidate_values(Series#series.values, ValuesPP, Func),
  +    Step = Series#series.step * ValuesPP,
  +    Series#series{values=Values,step=Step}.
  +
  +
  +consolidate_values([], _ValuesPP, _Func) -> [];
  +consolidate_values([{TS0, Val0}=Hd | Tl], ValuesPP, Func) ->
  +    {Vs, Cs, TS, _} = lists:foldl(fun({TS, null}, {Result, ConsVs, TS0, Cnt}) when Cnt == ValuesPP->
  +                                          {[{TS0, Func(ConsVs)} | Result], [], TS, 1};
  +                                     ({TS, Val}, {Result, ConsVs, TS0, Cnt}) when Cnt == ValuesPP ->
  +                                          {[{TS0, Func(ConsVs)} | Result], [Val], TS, 1};
  +                                     ({_TS, null}, {Result, ConsVs, TS, Cnt}) ->
  +                                          {Result, ConsVs, TS, Cnt+1};
  +                                     ({_TS, Val}, {Result, ConsVs, TS, Cnt}) ->
  +                                          {Result, [Val | ConsVs], TS, Cnt+1}
  +                                  end, {[], [Val0], TS0, 1}, Tl),
  +    case Cs of
  +        [] -> lists:reverse(Vs);
  +        _ -> lists:reverse([{TS, Func(Cs)} | Vs])
  +    end.
  +
  +
   safe_minimum([]) -> null;
   safe_minimum(Values) ->
       safe_minimum(Values, null).
  
positive.code:     ].
  
  integral_test_() ->
      [?_assertEqual(pseudo_series([1,2,3]), evaluate_call(<<"integral">>, [pseudo_series([1,1,1])], 0, 0, 0)),
       ?_assertEqual(pseudo_series([1,null,2,3]), evaluate_call(<<"integral">>, [pseudo_series([1,null,1,1])], 0, 0, 0)),
       ?_assertEqual(pseudo_series([]), evaluate_call(<<"integral">>, [pseudo_series([])], 0, 0, 0)),
       ?_assertEqual(pseudo_series([null,null]), evaluate_call(<<"integral">>, [pseudo_series([null,null])], 0, 0, 0))
      ].
  
  offset_to_zero_test_() ->
      Series = pseudo_series([102, 101, 104, 101, 100, 111]),
      Expected = pseudo_series([2, 1, 4, 1, 0, 11]),
      [?_assertEqual(Expected, evaluate_call(<<"offsetToZero">>, [Series], 0, 0, 0))].
  
  sort_non_null_test_() ->
  
negative.code:     #series{target=Target}.
  
  pseudo_values(Series) ->
      pseudo_values(Series, 10).
  
  pseudo_values(Series, Step) ->
      {Lst, _Idx} = lists:foldl(fun(V, {Acc, Idx}) -> {[{Idx, V} | Acc], Idx + Step} end, {[], 100}, Series),
      lists:reverse(Lst).
  
  pseudo_series(Values) ->
      pseudo_series(Values, 10).
  
  pseudo_series(Values, Step) ->
      Target = <<"target">>,
      #series{target=Target,values=pseudo_values(Values, Step),step=Step}.
  
  derivative_test_() ->
      [?_assertEqual([], derivative([])),
  