def test_team_remove_unlisted(): # Test that if no results found return 0 team = Team("One") jodie = Hero("Jodie Foster") team.add_hero(jodie) code = team.remove_hero("Athena") assert code == 0
def test_add_team(self): team = Team(team_name, score) teamA = Team('Team A', 0) teamB = Team('Team B', 0) team.add_team(teamA) team.add_team(teamB) self.assertEqual(len(lab.teams), 2)
def __init__(self): '''Instantiate properties team_one: None team_two: None ''' self.team_one = Team("Team One") self.team_two = Team("Team Two")
def team(team=None): team = Team(team) estimate = team.get_estimate() cards = app.config['CARDS'] return render_template( "team.html", team=team, estimate=estimate, cards = cards )
def test_get_record(): t = Team('Canucks') record = t.get_record() assert (record['wins']) assert (record['losses']) assert (record['OTL']) assert (record['wins'] + record['losses'] + record['OTL'] == record['games']) assert (2 * record['wins'] + record['OTL'] == record['points'])
def __init__(self, num_teams=12, per_team=13, starting_money=200): self.num_teams = num_teams self.team_size = per_team self.money_pool = starting_money * num_teams self.max_players_drafted = num_teams * per_team self.player_pool = Fantasy().players self.player_pool = self.sort(self.player_pool) self.drafted_players = [] self.player_costs = self.estimate_costs() self.team = Team("my team")
async def convert(cls, ctx, argument): teamname = None try: trole = await super().convert(ctx, argument) database.cur.execute("SELECT teamname FROM teamTable WHERE teamroleid=%s;" % trole.id) teamname = database.cur.fetchone() if teamname == None: return None teamname = teamname[0] except: database.cur.execute("SELECT teamname FROM teamTable WHERE lower(teamname)='%s';" % argument.lower()) teamname = database.cur.fetchone() if teamname == None: return None teamname = teamname[0] database.cur.execute("SELECT teamname, captainID FROM teamTable WHERE teamname='%s';" % teamname) data = database.cur.fetchone() team = Team(teamname) captainID = data[1] team.captain = captainID database.cur.execute("SELECT discordID FROM playerTable WHERE team='%s';" % teamname) members = database.cur.fetchall() for id in members: team.add_player(bot.guild.get_member(id[0])) captain = bot.guild.get_member(captainID) if bot.guild.get_role(bot.NA_ROLE) in captain.roles: team.region = "NA" elif bot.guild.get_role(bot.EU_ROLE) in captain.roles: team.region = "EU" database.cur.execute("SELECT awards FROM teamTable WHERE teamname='%s';" % teamname) team.awards = database.cur.fetchone()[0] return team
def getTeamMap(filename="/opt/futbol/data/teams.csv"): league_years = {} teams = {} with open(filename) as teams_in: team_rdr = csv.reader(teams_in) # Columns after the first represent years. Each team will be playing in a certain # league in a certain year. header = next(team_rdr) years = header[1:] # For each team, map which league they are in during each year. for row in team_rdr: team_name = row[0] leagues = row[1:] # Add newly discovered teams to the set of all teams, get the team we are working on if team_name not in teams: teams[team_name] = Team(team_name) current_team = teams[team_name] # Add team to league for all years for yr, lg in zip(years, leagues): if (lg, yr) not in league_years: league_years[(lg, yr)] = League(lg, yr) current_league = league_years[(lg, yr)] current_league.addTeam(current_team) return teams, league_years
def create_new_team(self, name): """ Creates Team and sets it's name :param name: str :return: str, teams name """ tmp_name = Team(name) self.teams_list.append(tmp_name) return tmp_name
def read_playersCSV(bstats_settings, playerdict, teams): teamsFile = open('PlayerLists/playerlist.csv') teamsReader = csv.reader(teamsFile) teamsData = list(teamsReader) for index, info in enumerate(teamsData): if int(info[1]) < 0: teams.append(Team(bstats_settings, info[0], info[1], info[2])) else: playerdict['player{0}'.format(index)] = \ players.Player(bstats_settings, info[0], info[1], info[2])
def main(): try: is_one_player, game_length, bot_depth, is_player_white = screen.starting_screen( ) timer.set_game_length(game_length) screen.add_squares_to_board() white_team = Team(True) black_team = Team(False) place_pieces(white_team, black_team) bot_team = black_team if is_player_white else white_team game_loop(white_team, black_team, is_one_player, bot_depth, bot_team) except exceptions.UserExitGame: return except exceptions.GameEnd: print("Game ended.") timer.sleep(10) # TODO: Return to main screen. return
def test_team_remove_hero(): team = Team("One") jodie = Hero("Jodie Foster") team.add_hero(jodie) assert team.heroes[0].name == "Jodie Foster" team.remove_hero("Jodie Foster") assert len(team.heroes) == 0
def get_data(): postseason_start_date = datetime.datetime(2019, 3, 18) data = pandas.read_csv('data/cbb-2019.csv') for game in data.itertuples(): date = game[1].split("/") date = datetime.datetime(int(date[2]), int(date[0]), int(date[1])) team = game[2] opponent = game[5] points = game[7] opponent_points = game[8] if team not in teams.keys(): teams[team] = Team(team) teams[team].add_game(points, opponent_points)
def test_print_heroes(): team = Team("One") jodie = Hero("Jodie Foster") team.add_hero(jodie) athena = Hero("Athena") team.add_hero(athena) output_string = capture_console_output(team.view_all_heroes) assert "Jodie Foster" in output_string assert "Athena" in output_string
def getTeamInfo(team_name, info_list, season): ''' given the name of a team, create a team object with data retrieved from the list @param team_name: the name of a football club @param info_list: output from the processData function @param season: a string indicating the input season @return: a Team object ''' home_team_list = info_list[0] home_score = info_list[1] away_team_list = info_list[2] away_score = info_list[3] # get the index of the team at home idx_home = [i for i, x in enumerate(home_team_list) if x == team_name] # get the index of the team away idx_away = [i for i, x in enumerate(away_team_list) if x == team_name] idx = sorted(idx_home + idx_away) opponents = [] goals_scored = [] goals_conceded = [] # a list that indicates whether the team is playing at home in each round at_home = [] for i in idx: if (i in idx_home): # meaning this is a home game for the team opponents.append(away_team_list[i]) goals_scored.append(home_score[i]) goals_conceded.append(away_score[i]) at_home.append(1) else: # meaning this is an away game for the team opponents.append(home_team_list[i]) goals_scored.append(away_score[i]) goals_conceded.append(home_score[i]) at_home.append(0) return Team(team_name,season,opponents,goals_scored,goals_conceded, at_home)
def test_team_instance(): team = Team("One") assert team
class Arena: def __init__(self): '''Instantiate properties team_one: None team_two: None ''' self.team_one = Team("Team One") self.team_two = Team("Team Two") def create_ability(self): name = input("What is the ability name?") max_damage = input("What is the max damage of the ability?") return Ability(name, max_damage) def create_weapon(self): name_of_weapon = input("What is this weapons name?") damage_of_weapon = input("What is the weapons max damage ?") return Weapon(name_of_weapon, damage_of_weapon) def create_armor(self): name_of_armor = input("What is this armors name ?") max_health = input("What is the armors max health?") return Weapon(name_of_armor, max_health) def create_hero(self): hero_name = input("Hero's name: ") hero = Hero(hero_name) add_item = None while add_item != "4": add_item = input( "[1] Add ability\n[2] Add weapon\n[3] Add armor\n[4] Done adding items\n\nYour choice: " ) if add_item == "1": ability = self.create_ability() hero.add_ability(ability) elif add_item == "2": weapon = self.create_weapon() hero.add_weapon(weapon) elif add_item == "3": armor = self.create_armor() hero.add_armor(armor) return hero # build_team_one is provided to you def build_team_one(self): '''Prompt the user to build team_one ''' numOfTeamMembers = int( input("How many members would you like on Team One?\n")) for hero in range(numOfTeamMembers): hero = self.create_hero() self.team_one.add_hero(hero) def build_team_two(self): '''Prompt the user to build team_two''' numOfTeamMembers = int( input("How many members would you like on Team Two?\n")) for hero in range(numOfTeamMembers): hero = self.create_hero() self.team_two.add_hero(hero) def team_battle(self): self.team_one.attack(self.team_two) def show_stats(self): print("\n") print(self.team_one.name + " statistics: ") self.team_one.stats() print("\n") print(self.team_two.name + " statistics: ") self.team_two.stats() print("\n") # This is how to calculate the average K/D for Team One team_kills = 0 team_deaths = 0 for hero in self.team_one.heroes: team_kills += hero.kills team_deaths += hero.deaths if team_deaths == 0: team_deaths = 1 print(self.team_one.name + " average K/D was: " + str(team_kills / team_deaths)) team_kills = 0 team_deaths = 0 for hero in self.team_two.heroes: team_kills += hero.kills team_deaths += hero.deaths if team_deaths == 0: team_deaths = 1 print(self.team_two.name + " average K/D was: " + str(team_kills / team_deaths)) # Here is a way to list the heroes from Team One that survived for hero in self.team_one.heroes: if hero.deaths == 0: print("survived from " + self.team_one.name + ": " + hero.name) for hero in self.team_two.heroes: if hero.deaths == 0: print("survived from " + self.team_two.name + ": " + hero.name)
def test_team_name(): team = Team("One") assert team.name == "One"
def test_team_remove_empty_list(): team = Team("One") assert team.remove_hero("Athena") == 0
from teams import Team, create_matchups from unittest.mock import patch import print_statements import single_game import pprint pp = pprint.PrettyPrinter() test_team_1 = Team("test_team_1", "TT1", 0) test_team_2 = Team("test_team_2", "TT2", 0) test_team_3 = Team("test_team_3", "TT3", 0) all_test_teams = [test_team_1, test_team_2, test_team_3] expected_results = [ (test_team_1, test_team_2), (test_team_1, test_team_3), (test_team_2, test_team_3) ] def test_create_matchups(): assert(create_matchups(all_test_teams)) == expected_results @patch('single_game.get_input', return_value='TT1') def test_play_single_game_single_winner(self): output = single_game.play_single_game([test_team_1, test_team_2], 1, 1) assert output == [test_team_1] @patch('single_game.get_input', return_value='DRAW')
def test_teamname_notfound(): with pytest.raises(ValueError) as excinfo: t = Team('abcde') assert (t is None) assert (excinfo is not None)
def test_find_teamid(): t = Team('Canucks') assert (t is not None) assert (t._id is not None)
def test_team_division(): t = Team('Canucks') assert (type(t.division) is dict) assert (t.division)
def test_team_conference(): t = Team('Canucks') assert (type(t.conference) is dict) assert (t.conference)
def test_teamname(): t = Team('Canucks') assert (t.name == 'Canucks')
def test_TeamFunctions(self): # create a sample team to help us check functions t1 = Team('t1', 's1', ['A', 'B', 'C'], [2, 3, 1], [1, 3, 2], [1, 0, 1]) # this team win in the 1st round, draw in the second, and lose in the third self.assertEqual(3, t1.getPoints(1)) # 3 points after 1st round self.assertEqual(4, t1.getPoints(2)) self.assertEqual(4, t1.getPoints(3)) # test goal scored functions self.assertEqual(2, t1.getGoalScored(1)) self.assertEqual(5, t1.getGoalScored(2)) self.assertEqual(6, t1.getGoalScored(3)) self.assertEqual(1, t1.getGoalConceded(1)) self.assertEqual(4, t1.getGoalConceded(2)) self.assertEqual(6, t1.getGoalConceded(3)) self.assertEqual(1, t1.getGoalDifference(1)) self.assertEqual(1, t1.getGoalDifference(2)) self.assertEqual(0, t1.getGoalDifference(3)) # test record functions self.assertEqual([1, 0, 0], t1.getRecord(1)) self.assertEqual([1, 1, 0], t1.getRecord(2)) self.assertEqual([1, 1, 1], t1.getRecord(3)) # test largest difference self.assertEqual([0, 2], t1.getLargestDifference())
if (resp.status_code != 200): print("bad status code bye ", resp.status_code) print("url: ", base + url) quit() soup = BeautifulSoup(resp.content, 'html.parser') over_under = GO.get_over_under(soup) if (over_under == -1): print('skipping this game') continue spread = GO.get_spread(soup) game = Game(over_under, spread) #find past 5 games past_games = soup.find( 'div', attrs={'class': 'tab-content sub-module__parallel'}) teams = past_games.find_all('article') for t in teams: squad = Team(GO.get_team_name(t), GO.get_last_five_scores(t)) if (squad.is_favorite(GO.get_favorite(soup))): game.favorite = squad else: game.underdog = squad game.display_game() game.check_over_under() game.check_spread() print('-' * 50)
def test_TeamFunctions(self): # create a sample team to help us check functions t1 = Team('t1','s1',['A','B','C'],[2,3,1],[1,3,2],[1,0,1]) # this team win in the 1st round, draw in the second, and lose in the third self.assertEqual(3, t1.getPoints(1)) # 3 points after 1st round self.assertEqual(4, t1.getPoints(2)) self.assertEqual(4, t1.getPoints(3)) # test goal scored functions self.assertEqual(2, t1.getGoalScored(1)) self.assertEqual(5, t1.getGoalScored(2)) self.assertEqual(6, t1.getGoalScored(3)) self.assertEqual(1, t1.getGoalConceded(1)) self.assertEqual(4, t1.getGoalConceded(2)) self.assertEqual(6, t1.getGoalConceded(3)) self.assertEqual(1, t1.getGoalDifference(1)) self.assertEqual(1, t1.getGoalDifference(2)) self.assertEqual(0, t1.getGoalDifference(3)) # test record functions self.assertEqual([1,0,0], t1.getRecord(1)) self.assertEqual([1,1,0], t1.getRecord(2)) self.assertEqual([1,1,1], t1.getRecord(3)) # test largest difference self.assertEqual([0,2], t1.getLargestDifference())
def test_get_roster(): t = Team('Canucks') assert (type(t.players) is list) assert (t.players)
team_services = dict() for service in services.values(): team_services[service.name] = Service( service.name, Binary(service.binary.name), 0) if team_type == 'pov_type_1_half': teams[name] = TeamPoVType1Half(name, team_services) elif team_type == 'pov_type_1_all': teams[name] = TeamPoVType1All(name, team_services) else: teams[name] = Team(name, team_services, type1_probability=type1_probability, type2_probability=type2_probability, patching_probability=patching_probability, overhead_memory_range=overhead_memory_range, overhead_time_range=overhead_time_range, overhead_size_range=overhead_size_range, functionality_range=functionality_range, protection_range=protection_range, reaction=reaction) if len(teams.values()) == num_teams: break # Fill in the unspecified teams for _ in range(len(teams.keys()), num_teams): name = "TEAM-" + random_string(length=4) teams[name] = Team(name, services) for team in teams.values(): logger.debug(str(team))
class Draft: def __init__(self, num_teams=12, per_team=13, starting_money=200): self.num_teams = num_teams self.team_size = per_team self.money_pool = starting_money * num_teams self.max_players_drafted = num_teams * per_team self.player_pool = Fantasy().players self.player_pool = self.sort(self.player_pool) self.drafted_players = [] self.player_costs = self.estimate_costs() self.team = Team("my team") def sort(self, pool): return sorted(pool, key=lambda p: p.score, reverse=True) def show(self, count=15): self.estimate_costs(True, count) def show_drafted(self): i = 0 for p in self.drafted_players: print(f"{i}. {p}") i += 1 def undraft(self, i, cost): player = self.drafted_players.pop(i) print(f"Undrafting {player} for {cost}") self.player_pool.append(player) self.money_pool += cost def i_undraft(self, i, cost): player = self.drafted_players.pop(i) print(f"You undrafting {player} for {cost}") self.player_pool.append(player) self.money_pool += cost self.team.players.remove(player) def show_team(self): self.team.show() def i_draft(self, i, cost): player = self.player_pool.pop(i) print(f"You drafted {player} for ${cost}") self.team.add_player(player) self.drafted_players.append(player) self.money_pool -= cost def draft_player(self, i, cost): player = self.player_pool.pop(i) print(f"{player} drafted for ${cost}") self.drafted_players.append(player) self.money_pool -= cost def estimate_costs(self, verbose=False, shown=15): count = self.max_players_drafted - len(self.drafted_players) players = self.player_pool[:count] economy = self.money_pool total_score = reduce(lambda x, y: x + y, [p.score for p in players]) point_cost = economy / total_score player_costs = [(p, int(p.score * point_cost)) for p in players] if verbose: print(f"Total score: {int(total_score)}") print(f"Total money: {int(economy)}") print("Cost per point: {0:.2f}".format(point_cost)) print() i = 0 for player, cost in player_costs[:shown]: print(f"{i}. {player}: ${cost}") i += 1 return player_costs