def convert_index_to_hour(index, time_span, remainder):
  """Convert index to hour."""
  # This needs -1 because the end hour is inclusive. For example, if the period
  # represents [2, 26), the end hour is 25.
  #
  # Index is added 1 because, in our SQL, we subtract the remainder, divide,
  # and floor. So, in order to get the original hour, we need to add 1 to the
  # index.
  return ((index + 1) * time_span) + remainder - 1