(podcast, num=20, user_sample=100)
return podcasts.most_common(num)
Get a list of podcasts that seem to be similar to the given one.

    The similarity is based on similar subscriptions; for performance
    reasons, only a sample of subscribers is considered
Get a list of podcasts that seem to be similar to the given one.
Get a list of podcasts that seem to be similar to the given one .
def calc_similar_podcasts(podcast, num=20, user_sample=100):
    """Get a list of podcasts that seem to be similar to the given one.

    The similarity is based on similar subscriptions; for performance
    reasons, only a sample of subscribers is considered"""

    logger.info("Calculating podcasts similar to {podcast}".format(podcast=podcast))

    # get all users that subscribe to this podcast
    user_ids = (
        Subscription.objects.filter(podcast=podcast)
        .order_by("user")
        .distinct("user")
        .values_list("user", flat=True)
    )
    logger.info(
        "Found {num_subscribers} subscribers, taking a sample "
        "of {sample_size}".format(
            num_subscribers=len(user_ids), sample_size=user_sample
        )
    )

    # take a random sample of ``user_sample`` subscribers
    user_ids = list(user_ids)  # evaluate ValuesQuerySet
    random.shuffle(user_ids)
    user_ids = user_ids[:user_sample]

    # get other podcasts that the user sample subscribes to
    podcasts = Counter()
    for user_id in user_ids:
        subscriptions = (
            Podcast.objects.filter(subscription__user__id__in=user_ids)
            .distinct("pk")
            .exclude(pk=podcast.pk)
        )
        podcasts.update(Counter(subscriptions))
    logger.info(
        "Found {num_podcasts}, returning top {num_results}".format(
            num_podcasts=len(podcasts), num_results=num
        )
    )

    return podcasts.most_common(num)
def calc_similar_podcasts ( podcast , num = 20 , user_sample = 100 ) : logger . info ( "Calculating podcasts similar to {podcast}" . format ( podcast = podcast ) ) # get all users that subscribe to this podcast user_ids = ( Subscription . objects . filter ( podcast = podcast ) . order_by ( "user" ) . distinct ( "user" ) . values_list ( "user" , flat = True ) ) logger . info ( "Found {num_subscribers} subscribers, taking a sample " "of {sample_size}" . format ( num_subscribers = len ( user_ids ) , sample_size = user_sample ) ) # take a random sample of ``user_sample`` subscribers user_ids = list ( user_ids ) # evaluate ValuesQuerySet random . shuffle ( user_ids ) user_ids = user_ids [ : user_sample ] # get other podcasts that the user sample subscribes to podcasts = Counter ( ) for user_id in user_ids : subscriptions = ( Podcast . objects . filter ( subscription__user__id__in = user_ids ) . distinct ( "pk" ) . exclude ( pk = podcast . pk ) ) podcasts . update ( Counter ( subscriptions ) ) logger . info ( "Found {num_podcasts}, returning top {num_results}" . format ( num_podcasts = len ( podcasts ) , num_results = num ) ) return podcasts . most_common ( num )