def merge_states(self, podcast1, podcast2): """Merges the Podcast states that are associated with the two Podcasts. This should be done after two podcasts are merged """ key = lambda x: x.user states1 = sorted(all_podcast_states(podcast1), key=key) states2 = sorted(all_podcast_states(podcast2), key=key) logger.info("Merging %d podcast states of %s into %s", len(states2), podcast2, podcast1) for state, state2 in utils.iterate_together([states1, states2], key): if state == state2: continue if state is None: self.actions["move-podcast-state"] += 1 update_podcast_state_podcast(state2, podcast1.get_id(), podcast1.url) elif state2 is None: continue else: psm = PodcastStateMerger(state, state2, self.actions) psm.merge()
def merge_states(self, podcast1, podcast2): """Merges the Podcast states that are associated with the two Podcasts. This should be done after two podcasts are merged """ key = lambda x: x.user states1 = sorted(podcast1.get_all_states(), key=key) states2 = sorted(podcast2.get_all_states(), key=key) for state, state2 in utils.iterate_together([states1, states2], key): if state == state2: continue if state == None: self.actions['move-podcast-state'] += 1 self._move_state(state2=state2, new_id=podcast1.get_id(), new_url=podcast1.url) elif state2 == None: continue else: psm = PodcastStateMerger(state, state2, self.actions) psm.merge()
def rewrite_newpodcast(p_old, p_new): p_n = models.Podcast.for_oldid(p_new.id) p_o = models.Podcast.for_oldid(p_old.id) if None in (p_n, p_o): return # merge subscriber data subscribers = [] compare = lambda a, b: cmp(a.timestamp, b.timestamp) for n, o in iterate_together([p_n.subscribers, p_o.subscribers]): # we assume that the new podcast has much more subscribers # taking only count of the old podcast would look like a drop if None in (n, o): continue subscribers.append( models.SubscriberData( timestamp=o.timestamp, subscriber_count=n.subscriber_count + n.subscriber_count if n else 0 ) ) p_n.subscribers = subscribers p_n.save() p_o.delete()
def _merge_objs(self, podcast1, podcast2): podcast1.merged_ids = set_filter(podcast1.merged_ids, [podcast2.get_id()], podcast2.merged_ids) podcast1.merged_slugs = set_filter(podcast1.merged_slugs, [podcast2.slug], podcast2.merged_slugs) podcast1.merged_oldids = set_filter(podcast1.merged_oldids, [podcast2.oldid], podcast2.merged_oldids) # the first URL in the list represents the podcast main URL main_url = podcast1.url podcast1.urls = set_filter(podcast1.urls, podcast2.urls) # so we insert it as the first again podcast1.urls.remove(main_url) podcast1.urls.insert(0, main_url) # we ignore related_podcasts because # * the elements should be roughly the same # * element order is important but could not preserved exactly podcast1.content_types = set_filter(podcast1.content_types, podcast2.content_types) key = lambda x: x.timestamp for a, b in utils.iterate_together( [podcast1.subscribers, podcast2.subscribers], key): if a is None or b is None: continue # avoid increasing subscriber_count when merging # duplicate entries of a single podcast if a.subscriber_count == b.subscriber_count: continue a.subscriber_count += b.subscriber_count for src, tags in podcast2.tags.items(): podcast1.tags[src] = set_filter(podcast1.tags.get(src, []), tags) podcast1.save()
def merge_states(self, episode, episode2): key = lambda x: x.user states1 = sorted(self.episode1.get_all_states(), key=key) states2 = sorted(self.episode2.get_all_states(), key=key) for state, state2 in utils.iterate_together([states1, states2], key): if state == state2: continue if state == None: self.actions['move-episode-state'] += 1 self._move(state2=state2, podcast_id=self.episode1.podcast, episode_id=self.episode1._id) elif state2 == None: continue else: esm = EpisodeStateMerger(state, state2, self.actions) esm.merge()
def merge_states(self, episode, episode2): key = lambda x: x.user states1 = sorted(all_episode_states(self.episode1), key=key) states2 = sorted(all_episode_states(self.episode2), key=key) logger.info("Merging %d episode states of %s into %s", len(states2), episode2, episode) for state, state2 in utils.iterate_together([states1, states2], key): if state == state2: continue if state is None: self.actions["move-episode-state"] += 1 update_episode_state_object(state2, self.episode1.podcast, self.episode1._id) elif state2 is None: continue else: esm = EpisodeStateMerger(state, state2, self.actions) esm.merge()
def merge_podcasts(self, podcasts): """ Merges some entries into the current category. """ key = lambda e: e.podcast podcasts = sorted(podcasts, key=key) self.podcasts = sorted(self.podcasts, key=key) new_entries = [] for e1, e2 in iterate_together([self.podcasts, podcasts], key): if e1 is None: new_entries.append(e2) elif e2 is None: new_entries.append(e1) else: new_entries.append( max(e1, e2) ) self.podcasts = new_entries