Пример #1
0
def calc_rising():
    sr_count = count.get_counts()
    link_count = dict((k, v[0]) for k,v in sr_count.iteritems())
    link_names = Link._by_fullname(sr_count.keys(), data=True)

    #max is half the average of the top 10 counts
    counts = link_count.values()
    counts.sort(reverse=True)
    maxcount = sum(counts[:10]) / 20
    
    #prune the list
    rising = [(n, link_names[n].sr_id)
              for n in link_names.keys() if link_count[n] < maxcount]

    cur_time = datetime.now(g.tz)

    def score(pair):
        name = pair[0]
        link = link_names[name]
        hours = (cur_time - link._date).seconds / 3600 + 1
        return float(link._ups) / (max(link_count[name], 1) * hours)

    def r(x):
        return 1 if x > 0 else -1 if x < 0 else 0

    rising.sort(lambda x, y: r(score(y) - score(x)))
    return rising
Пример #2
0
def cached_organic_links(username):
    user = Account._by_name(username)

    sr_count = count.get_counts()
    srs = Subreddit.user_subreddits(user)
    link_names = filter(lambda n: sr_count[n][1] in srs, sr_count.keys())
    link_names.sort(key = lambda n: sr_count[n][0])

    builder = IDBuilder(link_names, num = 30, skip = True, keep_fn = keep_link)
    links = builder.get_items()[0]
    cache.set(pos_key(user), 0)
    return [l._fullname for l in links]