anchor.diff:  speed_chart_span(?MIN_TIME_WINDOW) -> 3600;
   speed_chart_span(?HOUR_TIME_WINDOW) -> 86400; % 24 hours
   speed_chart_span(?DAY_TIME_WINDOW) -> 2592000. % 30 days
  +
  +
  +%%--------------------------------------------------------------------
  +%% @private
  +%% @doc
  +%% Returns status of given transfer. Adds one special status 'finalizing' to
  +%% indicate that the transfer itself has finished, but source replica
  +%% invalidation is still in progress (concerns only replica migration transfers).
  +%% @end
  +%%--------------------------------------------------------------------
  +-spec get_status(transfer:transfer()) -> transfer:status() | finalizing.
  +get_status(T = #transfer{invalidate_source_replica = true, status = completed}) ->
  +    case T#transfer.invalidation_status of
  +        completed -> completed;
  +        skipped -> completed;
  +        cancelled -> cancelled;
  +        failed -> failed;
  +        scheduled -> finalizing;
  +        active -> finalizing
  +    end;
  +get_status(#transfer{status = Status}) ->
  +    Status.
  +
  +
  +-spec get_last_update(#transfer{}) -> non_neg_integer().
  +get_last_update(#transfer{start_time = StartTime, last_update = LastUpdateMap}) ->
  +    % It is possible that there is no last update, if 0 bytes were
  +    % transferred, in this case take the start time.
  +    lists:max([StartTime | maps:values(LastUpdateMap)]).
positive.code:         files_transferred = FilesTransferred,
          min_hist = MinHistograms
      }}} = transfer:get(TransferId),
      CurrentTime = provider_logic:zone_time_seconds(),
      % No need to use actual start time, because only the newest measurements
      % are needed to calculate current speed.
      StartTime = CurrentTime - 2 * ?FIVE_SEC_TIME_WINDOW,
      BytesPerSec = maps:to_list(maps:map(fun(ProviderId, HistogramValues) ->
          LastUpdate = maps:get(ProviderId, LastUpdateMap),
          ShiftedHistogram = shift_histogram(
              HistogramValues, LastUpdate, CurrentTime, ?FIVE_SEC_TIME_WINDOW
          ),
          % Take the second value as current speed (the first one changes very
          % dynamically and does not show current trend from past couple of
          % seconds).
          [_, CurrentSpeed | _] = histogram_to_speed_chart(
              ShiftedHistogram, StartTime, CurrentTime, ?FIVE_SEC_TIME_WINDOW
          ),
          CurrentSpeed
      end, MinHistograms)),
      {ok, [
          {<<"id">>, TransferId},
          {<<"status">>, get_status(Transfer)},
          {<<"timestamp">>, CurrentTime},
          {<<"transferredBytes">>, BytesTransferred},
          {<<"transferredFiles">>, FilesTransferred},
          {<<"bytesPerSec">>, BytesPerSec}
      ]}.
  
  
  %%--------------------------------------------------------------------
  %% @private
  %% @doc
  %% Returns status of given transfer. Adds one special status 'finalizing' to
  %% indicate that the transfer itself has finished, but source replica
  %% invalidation is still in progress (concerns only replica migration transfers).
  %% @end
  %%--------------------------------------------------------------------
  -spec get_status(transfer:transfer()) -> transfer:status() | finalizing.
  get_status(T = #transfer{invalidate_source_replica = true, status = completed}) ->
      case T#transfer.invalidation_status of
          completed -> completed;
          skipped -> completed;
          cancelled -> cancelled;
          failed -> failed;
          scheduled -> finalizing;
          active -> finalizing
      end;
  get_status(#transfer{status = Status}) ->
      Status.
  
  
  %%--------------------------------------------------------------------
  
negative.code:         ?MONTH_STAT_TYPE -> {T#transfer.mth_hist, ?DAY_TIME_WINDOW}
      end,
      StartTime = T#transfer.start_time,
      LastUpdate = get_last_update(T),
      % Calculate bytes per sec histograms
      StatsMap = maps:map(fun(_ProviderId, HistogramValues) ->
          histogram_to_speed_chart(HistogramValues, StartTime, LastUpdate, TimeWindow)
      end, Histograms),
      {ok, [
          {<<"id">>, StatId},
          {<<"timestamp">>, LastUpdate},
          {<<"type">>, TypePrefix},
          {<<"stats">>, maps:to_list(StatsMap)}
      ]}.
  