anchor.diff:      end.
   
   
  -write_point_from_base(IO, Archive, Interval, Value, 0) ->
  -    % this is the file's first update
  -    Offset = Archive#archive_header.offset,
  -    {ok, _Pos} = file:position(IO, {bof, Offset}),
  -    file:write(IO, data_point(Archive, Interval, Value));
  -
  -write_point_from_base(IO, Archive, Interval, Value, BaseInterval) ->
  -    % all subsequent updates
  +get_data_point_offset(Archive, Interval, 0) ->
  +    Archive#archive_header.offset;
  +get_data_point_offset(Archive, Interval, BaseInterval) ->
       Distance = Interval - BaseInterval,
       PointDistance = Distance div Archive#archive_header.seconds,
       ByteDistance = PointDistance * ?POINT_SIZE,
  -    Position = Archive#archive_header.offset + (ByteDistance rem Archive#archive_header.size),
  -    {ok, _Pos} = file:position(IO, {bof, Position}),
  -    file:write(IO, data_point(Archive, Interval, Value)).
  +    Archive#archive_header.offset + (ByteDistance rem Archive#archive_header.size).
   
   
   update_point(File, Value, TimeStamp) ->
  
positive.code: -module(statser_whisper).
  
  -export([read_metadata/1,
           aggregation_type/1,
  
negative.code:             {Archive, LowerArchives} = highest_precision_archive(TimeDiff, Header#metadata.archives),
  
              % seek first data point
              {ok, _} = file:position(IO, {bof, Archive#archive_header.offset}),
  
              % read base data point
              {BaseInterval, _Value} = read_point(IO),
              Position = get_data_point_offset(Archive, TimeStamp, BaseInterval),
  
              % write data point based on initial data point
              {ok, _} = file:position(IO, {bof, Position}),
              file:write(IO, data_point(Archive, TimeStamp, Value))
  
              % TODO: update lower archives
      end.
  
  %%
  %% TESTS
  %%
  
  highest_precision_archive_test_() ->
      Archive = make_archive_header(28, 60, 1440),
      Archive2 = make_archive_header(28, 300, 1000),
  
      [?_assert(highest_precision_archive(100, []) =:= error),
       ?_assert(highest_precision_archive(100, [Archive]) =:= {Archive, []}),
       ?_assert(highest_precision_archive(86400, [Archive]) =:= {Archive, []}),
       ?_assert(highest_precision_archive(100, [Archive, Archive2]) =:= {Archive, [Archive2]}),
       ?_assert(highest_precision_archive(86400, [Archive, Archive2]) =:= {Archive, [Archive2]}),
       ?_assert(highest_precision_archive(86401, [Archive, Archive2]) =:= {Archive2, []}),
       ?_assert(highest_precision_archive(300 * 1000 + 1, [Archive, Archive2]) =:= error)].
  
  get_data_point_offset_test_() ->
      Now = erlang:system_time(second),
      Offset = 28,
      Archive = make_archive_header(Offset, 60, 1440),
  
      [?_assert(get_data_point_offset(Archive, Now, 0) =:= Offset),
       ?_assert(get_data_point_offset(Archive, Now+60, Now) =:= Offset + ?POINT_SIZE),
       ?_assert(get_data_point_offset(Archive, Now+119, Now) =:= Offset + ?POINT_SIZE),
       ?_assert(get_data_point_offset(Archive, Now+120, Now) =:= Offset + ?POINT_SIZE + ?POINT_SIZE)].
  