Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(4)  |  Call(3)  |  Derive(0)  |  Import(1)
Calculate how 'hot' an item is given its response since publication.

In our ranking algorithm, being base_life_hours newer is equivalent
to having log_base times more votes.

:type publish_date: datetime.datetime
:param publish_date: The date of publication. An older date reduces
    the popularity score.
:param int score: The number of likes, dislikes or likes - dislikes.
:rtype: int(more...)

        def calculate_popularity(publish_date, score):
    """Calculate how 'hot' an item is given its response since publication.

    In our ranking algorithm, being base_life_hours newer is equivalent
    to having log_base times more votes.

    :type publish_date: datetime.datetime
    :param publish_date: The date of publication. An older date reduces
        the popularity score.
    :param int score: The number of likes, dislikes or likes - dislikes.
    :rtype: int
    :returns: Popularity points.

    """
    settings = request.settings
    log_base = int(settings['popularity_decay_exponent'])
    base_life = int(settings['popularity_decay_lifetime']) * 3600
    # FIXME: The current algorithm assumes that the earliest publication
    #        date is January 1, 2000.
    if score > 0:
        sign = 1
    elif score < 0:
        sign = -1
    else:
        sign = 0
    delta = publish_date - datetime(2000, 1, 1) # since January 1, 2000
    t = delta.days * 86400 + delta.seconds
    popularity = math.log(max(abs(score), 1), log_base) + sign * t / base_life
    return max(int(popularity), 0)
        


src/m/e/mediadrop-HEAD/mediadrop/model/media.py   mediadrop(Download)
from mediadrop.lib.filetypes import AUDIO, AUDIO_DESC, VIDEO, guess_mimetype
from mediadrop.lib.players import pick_any_media_file, pick_podcast_media_file
from mediadrop.lib.util import calculate_popularity
from mediadrop.lib.xhtml import line_break_xhtml, strip_xhtml
from mediadrop.model import (get_available_slug, SLUG_LENGTH, 
    def update_popularity(self):
        if self.is_published:
            self.popularity_points = calculate_popularity(
                self.publish_on,
                self.likes - self.dislikes,
            )
            self.popularity_likes = calculate_popularity(
                self.publish_on,
            )
            self.popularity_dislikes = calculate_popularity(
                self.publish_on,
                self.dislikes,
            )