Пример #1
0
def post_if_goal_reached(date):
    # bail out if this day's already been submitted
    for link in get_recent_name_submissions():
        if link.revenue_date == date:
            return

    revenue = gold_revenue_multi([date]).get(date, 0)
    goal = gold_goal_on(date)
    percent = revenue / float(goal)
    bucket = int(percent)
    if bucket == 0:
        return

    buyer_count = len(gold_buyers_on(date))
    template_wp = WikiPage.get(SERVERNAME_SR, "templates/selftext")
    template = random.choice(template_wp._get("content").split("\r\n---\r\n"))
    boilerplate = WikiPage.get(SERVERNAME_SR,
                               "templates/boilerplate")._get("content")
    selftext_template = template + "\n\n---\n\n" + boilerplate

    link = Link._submit(
        is_self=True,
        title=date.strftime("%a %Y-%m-%d"),
        content=selftext_template % {
            "percent": int(percent * 100),
            "buyers": buyer_count,
        },
        author=SYSTEM_ACCOUNT,
        sr=SERVERNAME_SR,
        ip="127.0.0.1",
        spam=False,
    )

    link.flair_text = "Name pending..."
    link.flair_css_class = "goal-bucket-%d-active" % bucket
    link.revenue_date = date
    link.revenue_bucket = bucket
    link.server_names = []
    link._commit()

    queries.new_link(link)
    link.update_search_index()

    template = WikiPage.get(SERVERNAME_SR,
                            "templates/notification-message")._get("content")
    subject_template, sep, body_template = template.partition("\r\n")
    for id in gold_buyers_on(date):
        recipient = Account._byID(id, data=True)
        send_system_message(
            recipient,
            subject_template,
            body_template % {
                "percent": int(percent * 100),
                "buyers": buyer_count,
                "user": recipient.name,
                "link": link.url,
            },
        )
def post_if_goal_reached(date):
    # bail out if this day's already been submitted
    for link in get_recent_name_submissions():
        if link.revenue_date == date:
            return

    revenue = gold_revenue_multi([date]).get(date, 0)
    goal = gold_goal_on(date)
    percent = revenue / float(goal)
    bucket = int(percent)
    if bucket == 0:
        return

    buyer_count = len(gold_buyers_on(date))
    template_wp = WikiPage.get(SERVERNAME_SR, "templates/selftext")
    template = random.choice(template_wp._get("content").split("\r\n---\r\n"))
    boilerplate = WikiPage.get(SERVERNAME_SR, "templates/boilerplate")._get("content")
    selftext_template = template + "\n\n---\n\n" + boilerplate

    link = Link._submit(
        is_self=True,
        title=date.strftime("%a %Y-%m-%d"),
        content=selftext_template % {
            "percent": int(percent * 100),
            "buyers": buyer_count,
        },
        author=SYSTEM_ACCOUNT,
        sr=SERVERNAME_SR,
        ip="127.0.0.1",
        spam=False,
    )

    link.flair_text = "Name pending..."
    link.flair_css_class = "goal-bucket-%d-active" % bucket
    link.revenue_date = date
    link.revenue_bucket = bucket
    link.server_names = []
    link._commit()

    UPVOTE = True
    queries.queue_vote(SYSTEM_ACCOUNT, link, UPVOTE, "127.0.0.1")
    queries.new_link(link)
    link.update_search_index()

    template = WikiPage.get(SERVERNAME_SR, "templates/notification-message")._get("content")
    subject_template, sep, body_template = template.partition("\r\n")
    for id in gold_buyers_on(date):
        recipient = Account._byID(id, data=True)
        send_system_message(
            recipient,
            subject_template,
            body_template % {
                "percent": int(percent * 100),
                "buyers": buyer_count,
                "user": recipient.name,
                "link": link.url,
            },
        )
Пример #3
0
def determine_gold_goal(date):
    # fetch the revenues from the previous 7 days
    date_list = [date - datetime.timedelta(days=i) for i in range(1, 8)]
    previous_revenues = gold_revenue_multi(date_list).values()

    # throw out highest value and set goal to 105% of average
    previous_revenues = sorted(previous_revenues)[:-1]
    average_revenue = sum(previous_revenues) / float(len(previous_revenues))
    goal = average_revenue * 1.05

    # don't let this be more than 20% different from the previous goal
    previous_goal = gold_goal_on(date - datetime.timedelta(days=1))
    goal = min(previous_goal * 1.2, goal)
    goal = max(previous_goal * 0.8, goal)

    goal = round(goal, 0)
    GoldRevenueGoalByDate.set(date, goal)
    # force update to memoized value
    gold_goal_on(date, _update=True)
def determine_gold_goal(date):
    # fetch the revenues from the previous 7 days
    date_list = [date - datetime.timedelta(days=i)
                 for i in range(1, 8)]
    previous_revenues = gold_revenue_multi(date_list).values()

    # throw out highest value and set goal to 105% of average
    previous_revenues = sorted(previous_revenues)[:-1]
    average_revenue = sum(previous_revenues) / float(len(previous_revenues))
    goal = average_revenue * 1.05

    # don't let this be more than 20% different from the previous goal
    previous_goal = gold_goal_on(date - datetime.timedelta(days=1))
    goal = min(previous_goal * 1.2, goal)
    goal = max(previous_goal * 0.8, goal)

    goal = round(goal, 0)
    GoldRevenueGoalByDate.set(date, goal)
    # force update to memoized value
    gold_goal_on(date, _update=True)