code: def diffs2persistence(rev_docs, window_size=50, revert_radius=15, sunset=None,
                        verbose=False):
      rev_docs = mwxml.utilities.normalize(rev_docs)
      window_size = int(window_size)
      revert_radius = int(revert_radius)
      sunset = Timestamp(sunset) if sunset is not None \
                                 else Timestamp(time.time())
      page_docs = groupby(rev_docs, key=lambda d: d['page']['title'])
      for page_title, rev_docs in page_docs:
          if verbose:
              sys.stderr.write(page_title + ": ")
          rev_docs = peekable(rev_docs)
          window = deque(maxlen=window_size)
          state = DiffState(revert_radius=revert_radius)
          while rev_docs:
              rev_doc = next(rev_docs)
              next_doc = rev_docs.peek(None)
              if next_doc is not None:
                  seconds_visible = Timestamp(next_doc['timestamp']) - \
                                    Timestamp(rev_doc['timestamp'])
              else:
                  seconds_visible = sunset - Timestamp(rev_doc['timestamp'])
              if seconds_visible < 0:
                  logger.warn("Seconds visible {0} is less than zero."
                              .format(seconds_visible))
                  seconds_visible = 0
              _, tokens_added, _ = \
                  state.update_opdocs(rev_doc['sha1'], rev_doc['diff']['ops'],
                                      (rev_doc['user'], seconds_visible))
              if len(window) == window_size:
                  old_doc, old_added = window[0]
                  window.append((rev_doc, tokens_added))
                  persistence = token_persistence(old_doc, old_added, window,
                                                  None)
                  old_doc['persistence'] = persistence
                  yield old_doc
                  if verbose:
                      sys.stderr.write(".")
                      sys.stderr.flush()
              else:
                  window.append((rev_doc, tokens_added))
          while len(window) > 0:
              old_doc, old_added = window.popleft()
              persistence = token_persistence(old_doc, old_added, window, sunset)
              old_doc['persistence'] = persistence
              yield old_doc
              if verbose:
                  sys.stderr.write("_")
                  sys.stderr.flush()
          if verbose:
              sys.stderr.write("\n")