Esempio n. 1
0
def get_overall_performance_data(comp_id):
    """ TODO: comment """

    user_points = dict()

    for comp_event in get_all_comp_events_for_comp(comp_id):
        results = list(
            get_all_complete_user_results_for_comp_event(comp_event.id))

        # If nobody has participated in this particular comp event, skip performing the sorting
        # and ranking. Ranking package doesn't like empty iterables.
        if not results:
            continue

        results_with_ranks = sort_user_results_with_rankings(
            results, comp_event.Event.eventFormat)

        total_participants = len(results)
        for i, _, result in results_with_ranks:
            username = result.User.username
            if username not in user_points.keys():
                user_points[username] = 0
            user_points[username] += (total_participants - i)

    user_points = [(username, points)
                   for username, points in user_points.items()]
    user_points.sort(key=lambda x: x[1], reverse=True)

    if not user_points:
        return "Nobody has participated in anything yet this week?"

    return user_points
Esempio n. 2
0
def generate_fake_comp_results():
    """ Generates a bunch of fake results for the current competition with realistic-ish results. """

    test_users = [
        update_or_create_user_for_reddit(name, '')
        for name in __TEST_USER_NAMES
    ]

    for comp_event in get_all_comp_events_for_comp(
            get_active_competition().id):
        event_name = comp_event.Event.name

        if event_name in ('FMC', 'MBLD'):
            continue

        thresholds = __AUTO_BLACKLIST_THRESHOLDS.get(event_name)
        if not thresholds:
            continue

        wr_average = thresholds[1]

        for i, user in enumerate(test_users):
            results = UserEventResults(comp_event_id=comp_event.id,
                                       user_id=user.id,
                                       comment='')
            for solve in [
                    __build_solve(i, wr_average, event_name, s.id)
                    for s in comp_event.scrambles
            ]:
                results.solves.append(solve)

            process_event_results(results, comp_event, user)
            save_event_results(results)
Esempio n. 3
0
def comp_results(comp_id):
    """ A route for showing results for a specific competition. """

    competition = get_competition(comp_id)
    if not competition:
        return "Oops, that's not a real competition. Try again, ya clown.", 404

    comp_events = get_all_comp_events_for_comp(comp_id)
    comp_events = sort_comp_events_by_global_sort_order(comp_events)

    # alternative_title = "{} leaderboards".format(competition.title)

    events = map(
        lambda c: {
            'name': c.Event.name,
            'format': c.Event.eventFormat,
            'compEventId': c.id,
            'eventId': c.Event.id,
            'slug': slugify(c.Event.name)
        }, comp_events)

    comp_data = {
        "compId": competition.id,
        "compTitle": competition.title,
        "events": list(events)
    }

    return jsonify(comp_data)
Esempio n. 4
0
def prepare_new_competition_notification(comp_id, is_all_events):
    """ Builds a new competition notification message, looks up all users who want to receive
    this sort of message, and queues up tasks to send those users PMs. """

    competition = get_competition(comp_id)

    if is_all_events:
        event_desc = ALL_EVENTS_DESC
    else:
        all_events = get_all_comp_events_for_comp(comp_id)
        all_event_names = [event.Event.name for event in all_events]

        all_bonus_event_names = get_all_bonus_events_names()
        bonus_event_names = [
            name for name in all_event_names if name in all_bonus_event_names
        ]
        bonus_event_names = naturally_join(bonus_event_names)

        event_desc = ROTATING_EVENTS_DESC.format(
            bonus_events_list=bonus_event_names)

    for user_id in get_all_user_ids_with_setting_value(
            SettingCode.REDDIT_COMP_NOTIFY, TRUE_STR):
        reddit_id = get_user_by_id(user_id).reddit_id
        # If the user doesn't have Reddit info, skip them
        if not reddit_id:
            continue

        message_body = NEW_COMP_TEMPLATE.format(comp_title=competition.title,
                                                bonus_events_desc=event_desc,
                                                username=reddit_id,
                                                opt_out_info=OPT_OUT_INFO)
        send_competition_notification_pm(reddit_id, message_body)
Esempio n. 5
0
def prepare_new_competition_notification(comp_id, is_all_events):
    """ Builds a new competition notification message, looks up all users who want to receive
    this sort of message, and queues up tasks to send those users PMs. """

    if IS_DEVO:
        return

    competition = get_competition(comp_id)

    if is_all_events:
        event_desc = ALL_EVENTS_DESC
    else:
        all_events = get_all_comp_events_for_comp(comp_id)
        all_event_names = [event.Event.name for event in all_events]

        all_bonus_event_names = get_all_bonus_events_names()
        bonus_event_names = [name for name in all_event_names if name in all_bonus_event_names]
        bonus_event_names = naturally_join(bonus_event_names)

        event_desc = ROTATING_EVENTS_DESC.format(bonus_events_list=bonus_event_names)

    for user_id in get_all_user_ids_with_setting_value(SettingCode.REDDIT_COMP_NOTIFY, TRUE_STR):
        username = get_user_by_id(user_id).username
        message_body = NEW_COMP_TEMPLATE.format(comp_title=competition.title,
                                                bonus_events_desc=event_desc, username=username)
        send_competition_notification_pm(username, message_body)
Esempio n. 6
0
def comp_results(comp_id):
    """ A route for showing results for a specific competition. """

    competition = get_competition(comp_id)
    if not competition:
        msg = "Oops, that's not a real competition. Try again, ya clown."
        return render_template('error.html', error_message=msg)

    comp_events = get_all_comp_events_for_comp(comp_id)
    comp_events = sort_comp_events_by_global_sort_order(comp_events)

    events_names_ids = list()
    id_3x3 = None
    for comp_event in comp_events:
        if comp_event.Event.name == '3x3':
            id_3x3 = comp_event.id
        events_names_ids.append({
            'name': comp_event.Event.name,
            'comp_event_id': comp_event.id,
            'event_id': comp_event.Event.id,
        })

    alternative_title = "{} leaderboards".format(competition.title)

    return render_template("results/results_comp.html",
                           alternative_title=alternative_title,
                           events_names_ids=events_names_ids,
                           id_3x3=id_3x3,
                           comp_id=comp_id)
Esempio n. 7
0
def backfill_results_medals():
    """ Utility command to backfill all UserEventResults for past competitions with
    gold, silver, bronze medal flags. """

    all_comps = get_complete_competitions()
    total_num = len(all_comps)
    for i, comp in enumerate(all_comps):
        print('\nBackfilling for comp {} ({}/{})'.format(comp.id, i + 1, total_num))
        set_medals_on_best_event_results(get_all_comp_events_for_comp(comp.id))
Esempio n. 8
0
def wrap_weekly_competition():
    """ A periodic task to schedule sub-tasks related to wrapping up the weekly competitions. """

    current_comp = get_active_competition()

    comp_events_in_comp = get_all_comp_events_for_comp(current_comp.id)
    set_medals_on_best_event_results(comp_events_in_comp)

    post_results_thread_task(current_comp.id)
    generate_new_competition_task()
    prepare_end_of_competition_info_notifications(current_comp.id)
    send_gift_code_winner_approval_pm(current_comp.id)
def wrap_weekly_competition():
    """ A periodic task to schedule sub-tasks related to wrapping up the weekly competitions. """

    current_comp = get_active_competition()
    comp_events_in_comp = get_all_comp_events_for_comp(current_comp.id)
    set_medals_on_best_event_results(comp_events_in_comp)

    post_results_thread_task(current_comp.id, current_comp.title)
    generate_new_competition_task()
    clearly_weekly_blacklist()
    send_weekly_report(current_comp.id)
    prepare_end_of_competition_info_notifications(current_comp.id)
Esempio n. 10
0
def rerun_podiums_for_comp(comp_id):
    """ Utility command to backfill all UserEventResults for a specific past competitions with
    gold, silver, bronze medal flags. """

    set_medals_on_best_event_results(get_all_comp_events_for_comp(comp_id))