anchor.diff:  			(Used div Size) + 1
   	end,
   	Charge = UnitsNeeded * Price,
  -	case charge(cents, Charge, Buckets) of
  +	case charge(cents, Charge, Final, Buckets) of
   		{Charged, NewBuckets} when Charged < Charge ->
   			{Charged, NewBuckets};
   		{Charged, NewBuckets} ->
  
positive.code: %%----------------------------------------------------------------------
  %%  internal functions
  %%----------------------------------------------------------------------
  -spec charge(Type, Charge, Buckets) -> Result
  	when
  		Type :: octets | seconds | cents,
  		Charge :: integer(),
  		Buckets :: [#bucket{}],
  		Result :: {Charged, Buckets},
  		Charged :: integer().
  charge(Type, Charge, Buckets) ->
  	Now = erlang:system_time(?MILLISECOND),
  	charge(Type, Charge, Now, Buckets, [], 0).
  %% @hidden
  charge(Type, Charge, Now, [#bucket{bucket_type = Type,
  		termination_date = T1} | T], Acc, Charged) when T1 =/= undefined, T1 =< Now->
  	charge(Type, Charge, Now, T, Acc, Charged);
  charge(Type, Charge, _Now, [#bucket{bucket_type = Type,
  		remain_amount = R} = B | T], Acc, Charged) when R > Charge ->
  	NewBuckets = [B#bucket{remain_amount = R - Charge} | T],
  	{Charged + Charge, NewBuckets ++ Acc};
  charge(Type, Charge, Now, [#bucket{bucket_type = Type,
  		remain_amount = R} | T], Acc, Charged) when R =< Charge ->
  	charge(Type, Charge - R, Now, T, Acc, Charged + R);
  charge(_Type, 0, _Now, Buckets, Acc, Charged) ->
  	{Charged, Buckets ++ Acc};
  charge(_Type, _Charge, _Now, [], Acc, Charged) ->
  	{Charged, Acc};
  charge(_Type, _Charge, _Now, Buckets, Acc, Charged) ->
  	{Charged, Buckets ++ Acc}.
  
  -spec purchase(Type, Price, Size, Used, Validity, Buckets) -> Result
  	when
  		Type :: octets | seconds,
  		Price :: integer(),
  		Size :: integer(),
  		Used :: integer(),
  		Validity :: integer(),
  		Buckets :: [#bucket{}],
  		Result :: {Charged, Buckets},
  		Charged :: integer().
  purchase(Type, Price, Size, Used, Validity, Buckets) ->
  	UnitsNeeded = case (Used rem Size) of
  		0 ->
  			Used div Size;
  
negative.code: -module(ocs_rating).
  -copyright('Copyright (c) 2016 - 2017 SigScale Global Inc.').
  
  -export([rating/4]).
  
  -include("ocs.hrl").
  
  