示例#1
0
def calc_all_hot_window_scores(hot_eligible_age = timedelta(hours = 48)):
    # by default, only stories from the last 48 hours are eligible for "hot" status
    stories = dbsession.query(Submission).filter(Submission.deleted == False).filter(Submission.added_on > (general.now_in_utc() - hot_eligible_age)).all()

    for s in stories:
        calc_hot_window_score(s.id)

    general.set_key_in_stat('mass_hot_window_timestamp', general.now_in_utc(), type = 'datetime')

    dbsession.flush()

    return 0
示例#2
0
def calc_all_hot_window_scores(hot_eligible_age=timedelta(hours=48)):
    # by default, only stories from the last 48 hours are eligible for "hot" status
    stories = dbsession.query(Submission).filter(
        Submission.deleted == False).filter(
            Submission.added_on > (general.now_in_utc() -
                                   hot_eligible_age)).all()

    for s in stories:
        calc_hot_window_score(s.id)

    general.set_key_in_stat('mass_hot_window_timestamp',
                            general.now_in_utc(),
                            type='datetime')

    dbsession.flush()

    return 0
示例#3
0
def calc_hot_average(hot_point_window=timedelta(hours=6)):
    """
    Calculate the average point assignment of stories over the last hot_point_window time.
    """
    story_votes = dbsession.query(
        Vote.submission_id,
        func.sum(Vote.points).label('points')).filter(
            Vote.added_on < general.now_in_utc(), Vote.added_on >
            (general.now_in_utc() - hot_point_window)).group_by(
                Vote.submission_id).all()

    aggregate = 0
    count = 0

    for sv in story_votes:
        aggregate += sv.points
        count += 1

    print "aggregate: " + str(aggregate)
    print "count: " + str(count)

    if aggregate <= 0:
        hot_avg = 0
    else:
        # @TODO: this floating point division is basically extraneous
        # but I want it to look like something is happening for now
        # someone who cares about performance might want to remove this
        # especially since we are just creating an integer further down
        # if this is >= 1, which it will be in most sites.
        # especially since decimal comparison is meaningless here; < 1 = 0
        # users only vote in integers
        hot_avg = float(aggregate) / float(count)

    if hot_avg >= 1.0:
        hot_avg = math.floor(hot_avg)

    general.set_key_in_stat('hot_avg', hot_avg)
    general.set_key_in_stat('hot_avg_timestamp',
                            general.now_in_utc(),
                            type='datetime')

    print("hot_avg: {0}".format(hot_avg))

    return hot_avg
示例#4
0
def calc_hot_average(hot_point_window = timedelta(hours = 6)):
    """
    Calculate the average point assignment of stories over the last hot_point_window time.
    """
    story_votes = dbsession.query(Vote.submission_id, func.sum(Vote.points).label('points')).filter(Vote.added_on < general.now_in_utc(), Vote.added_on > (general.now_in_utc() - hot_point_window)).group_by(Vote.submission_id).all()

    aggregate = 0
    count = 0

    for sv in story_votes:
        aggregate += sv.points
        count += 1

    print "aggregate: " + str(aggregate)
    print "count: " + str(count)

    if aggregate <= 0:
        hot_avg = 0
    else:
        # @TODO: this floating point division is basically extraneous
        # but I want it to look like something is happening for now
        # someone who cares about performance might want to remove this
        # especially since we are just creating an integer further down
        # if this is >= 1, which it will be in most sites.
        # especially since decimal comparison is meaningless here; < 1 = 0
        # users only vote in integers
        hot_avg = float(aggregate) / float(count)

    if hot_avg >= 1.0:
        hot_avg = math.floor(hot_avg)

    general.set_key_in_stat('hot_avg', hot_avg)
    general.set_key_in_stat('hot_avg_timestamp', general.now_in_utc(), type = 'datetime')

    print("hot_avg: {0}".format(hot_avg))

    return hot_avg