def get_total_week_points(account_id, week_num): league_id = account_key(account_id).get().league active_teams = lineup_key(Choice_key(account_key(account_id), league_id), week_num).get().active_teams total_points = 0 for team in active_teams: total_points += get_team_schedule(team)[week_num - 1]['points'] # -1 for conversion to 0 based index return total_points
def get(self, week_number): """Updates the active teams for the user""" #The choice_key of the request action = self.request.get('action') team_number = self.request.get('team_number') user = users.get_current_user() #Current user's id, used to identify their data user_id = user.user_id() account = globals.get_or_create_account(user) league_id = account.league if is_week_editable(week_number): active_lineup = lineup_key(Choice_key(account.key, league_id), week_number).get() if action == "bench": active_lineup.active_teams.remove(int(team_number)) elif action == "putin": active_lineup.active_teams.append(int(team_number)) elif action == "drop": choice = Choice_key(account.key, league_id).get() choice.current_team_roster.remove(int(team_number)) if int(team_number) in active_lineup.active_teams: active_lineup.active_teams.remove(int(team_number)) choice.put() active_lineup.put() self.redirect('/allianceManagement/viewAlliance/' + str(week_number))
def get(self, week_number): """ Update the active teams for the user and redirects them to /viewAlliance/ for the week number Expects a post parameter: 'action' to be one of the following: - bench: Takes a team off the active lineup - putin: Adds a team to the lineup - drop: Drops a team from the user's roster Expects a post parameter: 'team_number' to be the number of the team to perform this action on :parameter week_number: Taken from the url, in string form """ #The choice_key of the request action = self.request.get('action') team_number = self.request.get('team_number') user = users.get_current_user() #Current user's id, used to identify their data user_id = user.user_id() account = globals.get_or_create_account(user) league_id = account.league choice = choice_key(account_key(user_id), league_id).get() roster = [] for team in choice.current_team_roster: roster.append(int(team)) #Only allow changes to the lineup if the week is editable if is_week_editable(week_number): error = False active_lineup = lineup_key(choice_key(account.key, league_id), week_number).get() if action == "bench": active_lineup.active_teams.remove(int(team_number)) elif action == "putin": if len(active_lineup.active_teams) < maximum_active_teams: if int(team_number) in roster: active_lineup.active_teams.append(int(team_number)) else: error = True else: error = True globals.display_error_page( self, self.request.referer, error_messages.maximum_active_teams_reached) elif action == "drop": if not str(team_number) in get_top_teams( globals.number_of_locked_teams): choice = choice_key(account.key, league_id).get() choice.current_team_roster.remove(int(team_number)) if int(team_number) in active_lineup.active_teams: active_lineup.active_teams.remove(int(team_number)) choice.put() active_lineup.put() if not error: self.redirect(self.request.referer)
def get_total_week_points(account_id, week_num): league_id = account_key(account_id).get().league active_teams = lineup_key(choice_key(account_key(account_id), league_id), week_num).get().active_teams total_points = 0 for team in active_teams: total_points += get_team_schedule(team)[week_num - 1][ 'points'] # -1 for conversion to 0 based index return total_points
def initialize_lineup(lineup_id, choice): """ Creates a lineup for a given id :param lineup_id: The week number used to identify the lineup :param choice: The parent for this lineup item """ lineup = Lineup.get_or_insert(lineup_key(choice.key, lineup_id).id(), parent=choice.key) #Only initialize if its' empty if lineup.active_teams: # If active_teams == None, lineup.active_teams = [] # Initialize it to an empty array lineup.put()
def get(self, week_number): """ Update the active teams for the user and redirects them to /viewAlliance/ for the week number Expects a post parameter: 'action' to be one of the following: - bench: Takes a team off the active lineup - putin: Adds a team to the lineup - drop: Drops a team from the user's roster Expects a post parameter: 'team_number' to be the number of the team to perform this action on :parameter week_number: Taken from the url, in string form """ #The choice_key of the request action = self.request.get('action') team_number = self.request.get('team_number') user = users.get_current_user() #Current user's id, used to identify their data user_id = user.user_id() account = globals.get_or_create_account(user) league_id = account.league choice = choice_key(account_key(user_id), league_id).get() roster = [] for team in choice.current_team_roster: roster.append(int(team)) #Only allow changes to the lineup if the week is editable if is_week_editable(week_number): error = False active_lineup = lineup_key(choice_key(account.key, league_id), week_number).get() if action == "bench": active_lineup.active_teams.remove(int(team_number)) elif action == "putin": if len(active_lineup.active_teams) < maximum_active_teams: if int(team_number) in roster: active_lineup.active_teams.append(int(team_number)) else: error = True else: error = True globals.display_error_page(self, self.request.referer, error_messages.maximum_active_teams_reached) elif action == "drop": if not str(team_number) in get_top_teams(globals.number_of_locked_teams): choice = choice_key(account.key, league_id).get() choice.current_team_roster.remove(int(team_number)) if int(team_number) in active_lineup.active_teams: active_lineup.active_teams.remove(int(team_number)) choice.put() active_lineup.put() if not error: self.redirect(self.request.referer)
def get_bench_points(account_id, week_num): league_id = account_key(account_id).get().league active_teams = lineup_key(choice_key(account_key(account_id), league_id), week_num).get().active_teams roster = choice_key(account_key(account_id), league_id).get().current_team_roster bench_teams = roster for team in active_teams: bench_teams.remove(team) total_points = 0 for team in bench_teams: total_points += get_team_schedule(team)[week_num - 1][ 'points'] # -1 for conversion to 0 based index return total_points
def get_team_lists(user_id, week_number): account = account_key(user_id).get() choice = Choice_key(account.key, account.league).get() roster = choice.current_team_roster active_lineup = lineup_key(Choice_key(account.key, account.league), week_number).get().active_teams current_lineup = [] for number in active_lineup: team = {} team['number'] = number team['detail_url'] = '/allianceManagement/teamDetail/%s' % number team['schedule'] = get_team_schedule(number) if is_week_editable(week_number): team['total_points'] = get_points_to_date(int(number)) else: team['total_points'] = 0 event_key = get_team_schedule(int(number))[int(week_number) - 1]['event_key']#-1 to convert to 0-based index if event_key: #Check if the team is competing that week team['total_points'] = get_team_points_at_event(int(number), event_key) current_lineup.append(team) bench_numbers = [] for team in roster: #Just trust me on this one, don't mess with this bench_numbers.append(team) for number in active_lineup: if number in bench_numbers: bench_numbers.remove(number) current_bench = [] for number in bench_numbers: if is_week_editable(week_number): total_points = get_points_to_date(int(number)) else: total_points = 0 event_key = get_team_schedule(int(number))[int(week_number) - 1]['event_key']#-1 to convert to 0-based index if event_key: #Check if the team is competing that week total_points = get_team_points_at_event(int(number), event_key) current_bench.append({'number':number, 'total_points': total_points}) logging.info(current_bench) return [current_lineup, current_bench]
def get_team_lists(user_id, week_number): """ Return the bench and active team lists for a particular user on a particular week :parameter user_id: The id of the user to gather lists from :type str or int :parameter week_number: The week to gather data on :type str or int :return: An array of two arrays(lineup, bench) containing, for each team in the lineup, a dictionary: - number: The name of the event (int) - detail_url: A link to the team's individual page (string) - schedule: An array containing scheduling data (schedule) (See get_team_schedule()) - total_points: The number of points(our system) this team scored in total. (int) If week_number is editable, this is actually the points scored this week, not total - disabled: Is 'True' if team is locked because of good performance (string(bool)) For each team in the bench list, the dictionary contains the following: - number: The name of the event (int) - total_points: The number of points(our system) this team scored in total. (int) If week_number is editable, this is actually the points scored this week, not total - disabled: Is 'True' if team is locked because of good performance (string(bool)) """ account = account_key(user_id).get() choice = choice_key(account.key, account.league).get() roster = choice.current_team_roster active_lineup = lineup_key(choice_key(account.key, account.league), week_number).get().active_teams current_lineup = [] for number in active_lineup: team = {} team['number'] = number team['detail_url'] = '/allianceManagement/teamDetail/%s' % number team['schedule'] = get_team_schedule(number) if is_week_editable(week_number): team['total_points'] = get_points_to_date(int(number)) else: team['total_points'] = 0 event_key = get_team_schedule(int(number))[int(week_number) - 1]['event_key'] # -1 convert to 0-based index if event_key: # Check if the team is competing that week team['total_points'] = get_team_points_at_event(int(number), event_key) if str(number) in get_top_teams(globals.number_of_locked_teams): team['disabled'] = 'True' current_lineup.append(team) bench_numbers = [] for team in roster: # Just trust me on this one, don't mess with this bench_numbers.append(team) for number in active_lineup: if number in bench_numbers: bench_numbers.remove(number) current_bench = [] for number in bench_numbers: if is_week_editable(week_number): total_points = get_points_to_date(int(number)) else: total_points = 0 event_key = get_team_schedule(int(number))[int(week_number) - 1]['event_key'] # -1 convert to 0-based index if event_key: # Check if the team is competing that week total_points = get_team_points_at_event(int(number), event_key) disabled = '' if str(number) in get_top_teams(globals.number_of_locked_teams): disabled = 'True' current_bench.append({'number':number, 'total_points': total_points, 'disabled': disabled}) return [current_lineup, current_bench]
def get_team_lists(user_id, week_number): """ Return the bench and active team lists for a particular user on a particular week :parameter user_id: The id of the user to gather lists from :type str or int :parameter week_number: The week to gather data on :type str or int :return: An array of two arrays(lineup, bench) containing, for each team in the lineup, a dictionary: - number: The name of the event (int) - detail_url: A link to the team's individual page (string) - schedule: An array containing scheduling data (schedule) (See get_team_schedule()) - total_points: The number of points(our system) this team scored in total. (int) If week_number is editable, this is actually the points scored this week, not total - disabled: Is 'True' if team is locked because of good performance (string(bool)) For each team in the bench list, the dictionary contains the following: - number: The name of the event (int) - total_points: The number of points(our system) this team scored in total. (int) If week_number is editable, this is actually the points scored this week, not total - disabled: Is 'True' if team is locked because of good performance (string(bool)) """ account = account_key(user_id).get() choice = choice_key(account.key, account.league).get() roster = choice.current_team_roster active_lineup = lineup_key(choice_key(account.key, account.league), week_number).get().active_teams current_lineup = [] for number in active_lineup: team = {} team['number'] = number team['detail_url'] = '/allianceManagement/teamDetail/%s' % number team['schedule'] = get_team_schedule(number) if is_week_editable(week_number): team['total_points'] = get_points_to_date(int(number)) else: team['total_points'] = 0 event_key = get_team_schedule( int(number))[int(week_number) - 1]['event_key'] # -1 convert to 0-based index if event_key: # Check if the team is competing that week team['total_points'] = get_team_points_at_event( int(number), event_key) if str(number) in get_top_teams(globals.number_of_locked_teams): team['disabled'] = 'True' current_lineup.append(team) bench_numbers = [] for team in roster: # Just trust me on this one, don't mess with this bench_numbers.append(team) for number in active_lineup: if number in bench_numbers: bench_numbers.remove(number) current_bench = [] for number in bench_numbers: if is_week_editable(week_number): total_points = get_points_to_date(int(number)) else: total_points = 0 event_key = get_team_schedule( int(number))[int(week_number) - 1]['event_key'] # -1 convert to 0-based index if event_key: # Check if the team is competing that week total_points = get_team_points_at_event(int(number), event_key) disabled = '' if str(number) in get_top_teams(globals.number_of_locked_teams): disabled = 'True' current_bench.append({ 'number': number, 'total_points': total_points, 'disabled': disabled }) return [current_lineup, current_bench]