def _IsAcceptableRowId(row_id, last_row_id):
  """Checks whether the given row id (aka revision) is not too large or small.

  For each data series (i.e. TestMetadata entity), we assume that row IDs are
  monotonically increasing. On a given chart, points are sorted by these
  row IDs. This way, points can arrive out of order but still be shown
  correctly in the chart.

  However, sometimes a bot might start to use a different *type* of row ID;
  for example it might change from revision numbers or build numbers to
  timestamps, or from timestamps to build numbers. This causes a lot of
  problems, including points being put out of order.

  If a sender of data actually wants to switch to a different type of
  row ID, it would be much cleaner for them to start sending it under a new
  chart name.

  Args:
    row_id: The proposed Row entity id (usually sent as "revision")
    last_row_id: The previous Row id, or None if there were none previous.

  Returns:
    True if acceptable, False otherwise.
  """
  if row_id <= 0:
    return False
  if last_row_id is None:
    return True
  # Too big of a decrease.
  if row_id < 0.5 * last_row_id:
    return False
  # Too big of an increase.
  if row_id > 2 * last_row_id:
    return False
  return True