def _MergeByIdKeepNew(self):
    """Migrate all entities, discarding duplicates from the old/a schedule.

    This method migrates all entities from the new/b schedule. It then migrates
    entities in the old schedule where there isn't already an entity with the
    same ID.

    Unlike _MergeSameId this method migrates entities to the merged schedule
    before comparing their IDs. This allows transfers to be compared when they
    refer to stops that had their ID updated by migration.

    This method makes use of various methods like _Migrate and _Add which
    are not implemented in the abstract DataSetMerger class. These methods
    should be overwritten in a subclass to allow _MergeByIdKeepNew to work with
    different entity types.

    Returns:
      The number of merged entities.
    """
    # Maps from migrated ID to tuple(original object, migrated object)
    a_orig_migrated = {}
    b_orig_migrated = {}

    for orig in self._GetIter(self.feed_merger.a_schedule):
      migrated = self._Migrate(orig, self.feed_merger.a_schedule)
      a_orig_migrated[self._GetId(migrated)] = (orig, migrated)

    for orig in self._GetIter(self.feed_merger.b_schedule):
      migrated = self._Migrate(orig, self.feed_merger.b_schedule)
      b_orig_migrated[self._GetId(migrated)] = (orig, migrated)

    for migrated_id, (orig, migrated) in b_orig_migrated.items():
      self._Add(None, orig, migrated)
      self._num_not_merged_b += 1

    for migrated_id, (orig, migrated) in a_orig_migrated.items():
      if migrated_id not in b_orig_migrated:
        self._Add(orig, None, migrated)
        self._num_not_merged_a += 1
    return self._num_merged
def _MergeByIdKeepNew ( self ) : a_orig_migrated = { } b_orig_migrated = { } for orig in self . _GetIter ( self . feed_merger . a_schedule ) : migrated = self . _Migrate ( orig , self . feed_merger . a_schedule ) a_orig_migrated [ self . _GetId ( migrated ) ] = ( orig , migrated ) for orig in self . _GetIter ( self . feed_merger . b_schedule ) : migrated = self . _Migrate ( orig , self . feed_merger . b_schedule ) b_orig_migrated [ self . _GetId ( migrated ) ] = ( orig , migrated ) for migrated_id , ( orig , migrated ) in b_orig_migrated . items ( ) : self . _Add ( None , orig , migrated ) self . _num_not_merged_b += 1 for migrated_id , ( orig , migrated ) in a_orig_migrated . items ( ) : if migrated_id not in b_orig_migrated : self . _Add ( orig , None , migrated ) self . _num_not_merged_a += 1 return self . _num_merged
Migrate all entities, discarding duplicates from the old/a schedule.

    This method migrates all entities from the new/b schedule. It then migrates
    entities in the old schedule where there isn't already an entity with the
    same ID.

    Unlike _MergeSameId this method migrates entities to the merged schedule
    before comparing their IDs. This allows transfers to be compared when they
    refer to stops that had their ID updated by migration.

    This method makes use of various methods like _Migrate and _Add which
    are not implemented in the abstract DataSetMerger class. These methods
    should be overwritten in a subclass to allow _MergeByIdKeepNew to work with
    different entity types.

    Returns:
      The number of merged entities.