def check_scramble_pool(): """ A periodic task to check the pre-generated pool of scrambles for all events. If the pool is too low for any event, enqueue a task to generate more scrambles for those events. """ event_scramble_msgs = list() for event in get_all_events(): # Don't pre-generate COLL scrambles. The fact we need a specific COLL each week, and that # rotates weekly, makes this more difficult than it needs to be. We'll just generate them # on the fly during competition generation, since it's fast anyway if event.name == EVENT_COLL.name: continue # Determine if the scramble pool is too low for this event. If so, enqueue a task to # generate enough scrambles for this event to bring the pool up to (2 * number of solves) # for that event num_missing = (2 * event.totalSolves) - len(event.scramble_pool) if num_missing > 0: top_off_scramble_pool( ScramblePoolTopOffInfo(event.id, event.name, num_missing)) event_scramble_msgs.append('{} for {}'.format( num_missing, event.name)) # No need to notify anybody of anything if no scrambles were generated if not event_scramble_msgs: return title = 'Generating scrambles' body = '\n'.join(event_scramble_msgs) notify_admin(title, body, AdminNotificationType.PUSHBULLET_NOTE)
def recalculate_pbs(): """ Works through every user, every event type, and re-calculates PB averages and singles and sets appropriate flags on UserEventResults. """ all_users = get_all_users() user_count = len(all_users) all_events = get_all_events() for i, user in enumerate(all_users): print("\nRecalculating PBs for {} ({}/{})".format(user.username, i + 1, user_count)) for event in all_events: recalculate_user_pbs_for_event(user.id, event.id)
def events_settings(): """ A route for editing a user's preferred events. """ if not current_user.is_authenticated: return redirect(url_for('index')) # Load hidden event IDs out of comma-delimited string and into a list of ints hidden_event_setting = get_setting_for_user(current_user.id, SettingCode.HIDDEN_EVENTS) if hidden_event_setting: hidden_event_ids = [int(s) for s in hidden_event_setting.split(',')] else: hidden_event_ids = list() return render_template("user/settings/events_settings.html", is_mobile=request.MOBILE, hidden_event_ids=hidden_event_ids, events=sort_events_by_global_sort_order(get_all_events()))
def __handle_get(user): """ Handles displaying a user's settings for edit. """ all_settings = get_settings_for_user_for_edit(user.id, list()) settings_sections = OrderedDict([]) # Parse out the hidden event IDs into a separate list so we handle that separately hidden_event_setting = [ s for s in all_settings if s.code == SettingCode.HIDDEN_EVENTS ][0] hidden_event_ids = set([ int(s) for s in hidden_event_setting.value.split(',') ]) if hidden_event_setting.value else set() # If the user doesn't have Reddit account info, omit the Reddit Settings section if not user.reddit_id: del settings_sections['Reddit Settings'] # If the user doesn't have WCA account info, omit the WCA Settings section if not user.wca_id: del settings_sections['WCA Settings'] # Disable the relevant settings, if other setting values affect them disabled_settings = list() for setting in all_settings: if setting.type != SettingType.BOOLEAN: continue if bool(setting.affects): if setting.value == TRUE_STR and setting.opposite_affects: disabled_settings.extend(setting.affects) if setting.value == FALSE_STR and not setting.opposite_affects: disabled_settings.extend(setting.affects) default_colors = get_color_defaults() return render_template("user/settings.html", settings_sections=settings_sections, disabled_settings=disabled_settings, default_colors=default_colors, alternative_title="Preferences", is_mobile=request.MOBILE, hidden_event_ids=hidden_event_ids, events=get_all_events())
def precalculate_user_site_rankings(): """ Precalculate user site rankings for event PBs for all users. """ all_events = get_all_events() wca_events = get_all_WCA_events() # Each of these dicts are of the following form: # dict[Event][ordered list of PersonalBestRecords] events_pb_singles = dict() events_pb_averages = dict() for event in all_events: # It doesn't make sense to keep COLL records, since it's a single alg that changes weekly if event.name == "COLL": continue # Retrieve the the ordered list of PersonalBestRecords for singles for this event ordered_pb_singles = get_ordered_pb_singles_for_event(event.id) # If nobody at all has competed in this event, just move on to the next if not ordered_pb_singles: continue events_pb_singles[event] = ordered_pb_singles # Retrieve the the ordered list of PersonalBestRecords for averages for this event ordered_pb_averages = get_ordered_pb_averages_for_event(event.id) events_pb_averages[event] = ordered_pb_averages # Iterate through all users to determine their site rankings and PBs for user in get_all_users(): # Calculate site rankings for the user # pylint: disable=C0301 rankings = _calculate_site_rankings_for_user(user.id, events_pb_singles, events_pb_averages, wca_events, all_events) # Save to the database save_or_update_site_rankings_for_user(user.id, rankings)
def show_slugified_event_names(): """ Utility command to slugify all event names and display them in the terminal. """ for event in get_all_events(): print(slugify(event.name))