def fullSeason(self): lg = League() print("What is the name of your database?") n = input(">") try: self.loadDB(n, lg) self.setLeague(lg) #print(self.league.name) if (self.foundFile == True): self.foundfile = False print("--------------------------------------") print("1. Run whole season") print("2. Just schedule season") print("3. Return to menu") print("--------------------------------------") i = input(">") if (i == "1"): self.createEveryMatch() self.runSeason() elif (i == "2"): self.scheduleSeason() elif (i == "3"): pass else: print("'" + i + "' is not a valid option!") except FileNotFoundError: print("The file {0} does not exist!".format(n))
def listTeamsInDB(): print("What is the name of your database? (xml)") lg = League() n = input(">") loadDB(n, lg) if (foundFile == True): lg.listTeams() else: pass
def do_create(self, line): """ This command is used to create a league Usage: create 'league name' Example: create league2 """ if self.league is None: self.league = League(line) print("Created league: {}".format(line)) else: print("A league called {} currently exists".format(line))
def put_all_clubs_in_a_league(self): other_league = League("Other") for club in self.all_clubs: belongs_to_known_leagues = False for league in self.all_leagues: if club in league.clubs: belongs_to_known_leagues = True break if not belongs_to_known_leagues: other_league.clubs.add(club) self.all_leagues.add(other_league)
def twoTeamSeason(self): lg = League() print("What is the name of your database?") n = input(">") self.loadDB(n, lg) self.setLeague(lg) #print(self.league.teams[0].name) print("What is the first team's id?") fID = input(">") fID = fID.lower() print("What is the second team's id?") sID = input(">") sID = sID.lower() t1 = self.findTeamInDB(lg, str(fID)) t2 = self.findTeamInDB(lg, str(sID)) try: self.testCreateMatches(t1, t2) self.testGames(t1, t2) #testing it out between two teams except AttributeError: print("Valid team IDs must be entered")
def mainDriver(self): leagueId = '605590064432504832' year = 2020 numWeeksCompleted = 10 numSimulations = 10000 league = League.League(leagueId, year, numWeeksCompleted) league.populateTeams() league.populateMatchups() league.populateMedianWins() league.populateOriginalSeeds() teamArray = league.teamsDictToArray() self.playSimulatedSeasons(numSimulations, teamArray, numWeeksCompleted) simulationSummary = self.evaluateResults(teamArray, numSimulations) self.printResults(simulationSummary)
def testMatchFromDB(): #load from what the player says to load from testLG = League() t1 = Team() t2 = Team() print("|Test Match from Database|") print("What is the name of your database? (xml)") n = input(">") loadDB(n, testLG) if (foundFile == True): print("What is the first team's id?") fID = input(">") fID = fID.lower() #check for team 1 id and then team 2 id print("What is the second team's id?") sID = input(">") sID = sID.lower() t1 = findTeamInDB(testLG, str(fID)) t2 = findTeamInDB(testLG, str(sID)) try: testMatch(t1, t2) except AttributeError: print("Valid team ID's must be entered") else: pass
def add_league(self, name): return League(name)
def parse(i): jsonFileString = open('FUTS/fut' + str(i) + '.json').read() jsonObject = json.loads(jsonFileString) for p in jsonObject['items']: commonName = p['commonName'] firstName = p['firstName'] headshotImgUrl = p['headshotImgUrl'] lastName = p['lastName'] league = League(p['league']['abbrName'], p['league']['id'], p['league']['imgUrl'], p['league']['name']) nation = Nation(p['nation']['imageUrls']['large'], p['nation']['abbrName'], p['nation']['id'], None, p['nation']['name']) club = Club(p['club']['imageUrls']['dark']['large'], p['club']['imageUrls']['normal']['large'], p['club']['abbrName'], p['club']['id'], p['club']['imgUrl'], ['name']) largeTOTWImgUrl = p['specialImages']['largeTOTWImgUrl'] position = p['position'] playStyle = p['playStyle'] playStyleId = p['playStyleId'] height = p['height'] weight = p['weight'] birthdate = p['birthdate'] age = p['age'] aggression = p['aggression'] agility = p['agility'] balance = p['balance'] ballcontrol = p['ballcontrol'] foot = p['foot'] skillMoves = p['skillMoves'] crossing = p['crossing'] curve = p['curve'] dribbling = p['dribbling'] finishing = p['finishing'] freekickaccuracy = p['freekickaccuracy'] gkdiving = p['gkdiving'] gkhandling = p['gkhandling'] gkpositioning = p['gkpositioning'] gkreflexes = p['gkreflexes'] headingaccuracy = p['headingaccuracy'] interceptions = p['interceptions'] jumping = p['jumping'] longpassing = p['longpassing'] longshots = p['longshots'] marking = p['marking'] penalties = p['penalties'] positioning = p['positioning'] potential = p['potential'] reactions = p['reactions'] shortpassing = p['shortpassing'] shotpower = p['shotpower'] slidingtackle = p['slidingtackle'] stamina = p['stamina'] strength = p['strength'] vision = p['vision'] volleys = p['volleys'] weakfoot = None # for value in p['traits']: # traits.append(str(value)) # for value in p['specialties']: # specialties.append(str(value)) # specialties = None # for value in p['attributes']: # attributes.append(str(value)) name = p['name'] quality = p['quality'] color = p['color'] isGk = None positionFull = p['positionFull'] isSpecialType = p['isSpecialType'] contracts = p['contracts'] fitness = p['fitness'] rawAttributeChemistryBonus = p['rawAttributeChemistryBonus'] isLoan = p['isLoan'] squadPosition = p['squadPosition'] itemType = p['itemType'] discardValue = p['discardValue'] id = p['id'] modelName = p['modelName'] baseId = p['baseId'] rating = p['rating'] players.append( Player(commonName, firstName, headshotImgUrl, lastName, league, nation, club, largeTOTWImgUrl, position, playStyle, playStyleId, height, weight, birthdate, age, aggression, agility, balance, ballcontrol, foot, skillMoves, crossing, curve, dribbling, finishing, freekickaccuracy, gkdiving, gkhandling, gkpositioning, gkreflexes, headingaccuracy, interceptions, jumping, longpassing, longshots, marking, penalties, positioning, potential, reactions, shortpassing, shotpower, slidingtackle, stamina, strength, vision, volleys, weakfoot, traits, specialties, attributes, name, quality, color, isGk, positionFull, isSpecialType, contracts, fitness, rawAttributeChemistryBonus, isLoan, squadPosition, itemType, discardValue, id, modelName, baseId, rating))
t1 = Team("Team1", "coach1") t2 = Team("Team2", "coach2") t3 = Team("Team3", "coach3") t4 = Team("Team4", "coach4") t5 = Team("Team5", "coach5") ts1 = [t1, t2, t3, t4, t5] for i in range(12): t1.addPlayer(ps1[i]) t2.addPlayer(ps1[i]) t3.addPlayer(ps1[i]) t4.addPlayer(ps1[i]) t5.addPlayer(ps1[i]) l1 = League() for i in ts1: l1.addTeam(i) m1 = Match(t1, t2) m1.incrementTeamOneScore() m1.incrementTeamOneScore() m1.incrementTeamTwoScore() m1.incrementTeamTwoScore() m1.incrementTeamTwoScore() m1.endMatch() m2 = Match(t3, t4) m2.incrementTeamOneScore() m2.incrementTeamOneScore()
def process_all_data(self, start_year, end_year): for league_name in LeagueURLConstants.league_names_with_urls: print("=================================working on " + league_name + "=========================") league = League(league_name) # league_edges = [] for year in range(start_year, end_year + 1): max_amount_for_year = self.most_expensive_transfer_for_each_year[year] league.transfers_for_year[year] = set() year_as_string = str(year) print("calculating data for " + year_as_string + "..........") source_file = "../html/" + year_as_string + league_name + ".html" with open(source_file, "rb") as fetched_content: page_soup = BeautifulSoup(fetched_content, 'html.parser') boxes = page_soup.findAll("div", {"class": "box"}) club_boxes = [box for box in boxes if box] country_header_box = club_boxes[0] # Remove the First 3 Box elements that are at the top of each page. club_boxes = club_boxes[3:] tuples_out = [] tuples_in = [] for box in club_boxes: table_headers = box.find_all("div", {"class": "table-header"}) # Get only the Transfer out Boxes from Each Box. responsive_table_out_transfers = box.find_all("div", {"class": "responsive-table"})[1::2] responsive_table_in_transfers = box.find_all("div", {"class": "responsive-table"})[0::1] header_div_tuple_out = (table_headers, responsive_table_out_transfers) tuples_out.append(header_div_tuple_out) header_div_tuple_in = (table_headers, responsive_table_in_transfers) tuples_in.append(header_div_tuple_in) header_team_country = self.get_header_country(country_header_box) if header_team_country not in self.all_countries_and_clubs: self.all_countries_and_clubs[header_team_country] = set() for t in tuples_out: if t[0] and t[1]: # print("=====================================================================================") source_team_details = self.get_header_team_details(t) source_team_name = self.get_header_team_name(source_team_details) source_team_id = self.get_header_team_id(source_team_details) transfers_out = t[1][0] trs = self.get_all_trs(transfers_out) if "No departures" in trs[1].find("td").get_text(): continue else: source_team_club = Club(source_team_id, source_team_name, header_team_country) self.all_countries_and_clubs[header_team_country].add(source_team_club) if source_team_club not in self.all_clubs: self.all_clubs.add(source_team_club) for i in range(1, len(trs)): tr = trs[i] player_name = self.get_player_name(tr) player_amount = self.get_player_amount(tr) player_pos = self.get_player_position(tr) player_age = self.get_player_age(tr) player_nationality = self.get_player_nationality(tr) target_team_details = self.get_tr_team_details(tr) target_team = self.get_tr_team(target_team_details) target_team_name = self.get_tr_team_name(tr) transfer_type = self.get_transfer_type(player_amount) processed_amount = self.process_amount(player_amount) calculated_normalized_amount = self.get_normalized_amount(processed_amount, max_amount_for_year) if target_team: target_team_id = self.get_tr_team_id(target_team) if self.valid_football_club(target_team_id): target_team_country = self.get_tr_team_country(target_team_details) link = TransferLink(source_team_id=source_team_id, target_team_id=target_team_id, amount=processed_amount, player_pos=player_pos, source_team_name=source_team_name, target_team_name=target_team_name, player_name=player_name, player_nationality=player_nationality, player_age=player_age, transfer_type=transfer_type, year=year, normalized_amount=calculated_normalized_amount) league.transfers_for_year[year].add(link) league.all_transfers.add(link) self.all_transfers.add(link) target_club = Club(target_team_id, target_team_name, target_team_country) if target_team_country not in self.all_countries_and_clubs: self.all_countries_and_clubs[target_team_country] = set() self.all_countries_and_clubs[target_team_country].add(target_club) if target_club not in self.all_clubs: self.all_clubs.add(target_club) # Change in filtering if transfer_type != "Loan": if player_pos in front_pos: self.all_front_transfers.add(link) league.front_transfers.add(link) # print("Add front position") # print("Total front position ", len(league.front_transfers)) elif player_pos in midfield_pos: self.all_midfield_transfers.add(link) league.midfield_transfers.add(link) # print("Add Midfield position") # print("Total Midfield position ",len(league.midfield_transfers)) elif player_pos in back_pos: self.all_back_transfers.add(link) league.back_transfers.add(link) # print("Add Back position") # print("Total Back position ", len(league.back_transfers)) elif player_pos in goalkeeper_pos: self.all_goalkeeper_transfers.add(link) league.goalkeeper_transfers.add(link) # print("Add Goalkeeper position") # print("Total Goalkeeper position ", len(league.goalkeeper_transfers)) if source_team_club not in league.clubs: league.clubs.add(source_team_club) self.all_player_names=[] self.all_player_names_dup=[] # -----------------Transfers IN ------------------------------------------------------------------------ for t in tuples_in: if t[0] and t[1]: # print("=====================================================================================") target_team_details = self.get_header_team_details(t) target_team_name = self.get_header_team_name(target_team_details) target_team_id = self.get_header_team_id(target_team_details) transfers_in = t[1][0] trs = self.get_all_trs(transfers_in) if "No arrivals" in trs[1].find("td").get_text(): continue else: target_team_club = Club(target_team_id, target_team_name, header_team_country) self.all_countries_and_clubs[header_team_country].add(target_team_club) if target_team_club not in self.all_clubs: self.all_clubs.add(target_team_club) for i in range(1, len(trs)): tr = trs[i] player_name = self.get_player_name(tr) player_amount = self.get_player_amount(tr) player_pos = self.get_player_position(tr) player_age = self.get_player_age(tr) player_nationality = self.get_player_nationality(tr) source_team_details = self.get_tr_team_details(tr) source_team = self.get_tr_team(source_team_details) source_team_name = self.get_tr_team_name(tr) transfer_type = self.get_transfer_type(player_amount) processed_amount = self.process_amount(player_amount) calculated_normalized_amount = self.get_normalized_amount(processed_amount, max_amount_for_year) if source_team: source_team_id = self.get_tr_team_id(source_team) if self.valid_football_club(source_team_id): source_team_country = self.get_tr_team_country(source_team_details) link = TransferLink(source_team_id=source_team_id, target_team_id=target_team_id, amount=processed_amount, player_pos=player_pos, player_age=player_age, player_nationality=player_nationality, source_team_name=source_team_name, target_team_name=target_team_name, player_name=player_name, transfer_type=transfer_type, year=year, normalized_amount=calculated_normalized_amount) league.transfers_for_year[year].add(link) league.all_transfers.add(link) self.all_transfers.add(link) source_club = Club(source_team_id, source_team_name, source_team_country) if source_team_country not in self.all_countries_and_clubs: self.all_countries_and_clubs[source_team_country] = set() self.all_countries_and_clubs[source_team_country].add(source_club) if source_club not in self.all_clubs: self.all_clubs.add(source_club) # Change in filtering if transfer_type != "Loan": if player_pos in front_pos: self.all_front_transfers.add(link) league.front_transfers.add(link) # print("Add front position") # print("Total front position ", len(league.front_transfers)) elif player_pos in midfield_pos: self.all_midfield_transfers.add(link) league.midfield_transfers.add(link) # print("Add Midfield position") # print("Total Midfield position ",len(league.midfield_transfers)) elif player_pos in back_pos: self.all_back_transfers.add(link) league.back_transfers.add(link) # print("Add Back position") # print("Total Back position ", len(league.back_transfers)) elif player_pos in goalkeeper_pos: self.all_goalkeeper_transfers.add(link) league.goalkeeper_transfers.add(link) # print("Add Goalkeeper position") # print("Total Goalkeeper position ", len(league.goalkeeper_transfers)) if target_team_club not in league.clubs: league.clubs.add(target_team_club) print("------Finished calculating data for " + year_as_string + "----------") self.all_leagues.add(league)
def new_game(): def_competitions = [] def_managers = [] min_active_rep = TEAM_GLOBALS["MAX_REP"] - (TEAM_GLOBALS["MAX_REP"] - TEAM_GLOBALS["MIN_REP"]) * 0.85 rep_step = (TEAM_GLOBALS["MAX_REP"] - min_active_rep) / float( GAME_GLOBALS["ACTIVE_LEAGUES"] * GAME_GLOBALS["TEAMS_PER_LEAGUE"]) current_rep = TEAM_GLOBALS["MAX_REP"] for comp_id in range(GAME_GLOBALS["ACTIVE_LEAGUES"]): c = League.League("League " + str(comp_id + 1)) for team_id in range(GAME_GLOBALS["TEAMS_PER_LEAGUE"]): t = Team.Team(rep=int(current_rep)) m = Manager.Manager() hire_manager(team=t, manager=m) def_managers.append(m) #CREATE PLAYERS player_list = [] average_skill = sum( t.skill) / 3.0 - PLAYER_GLOBALS["MAX_SKILL"] * 0.05 for pos, qty in enumerate(TEAM_GLOBALS["PLAYERS_PER_POSITION"]): if pos == 0: how_many_players = qty + random.randint(0, 1) else: how_many_players = qty + random.randint(0, 2) for i in range(how_many_players): this_player_skill = average_skill - ( PLAYER_GLOBALS["MAX_SKILL"] * 0.05 * i) / float(how_many_players) player = Player.Player(skill=this_player_skill, pos=pos, avg_skill=True) player.season_training_increase_per_turn() player_list.append(player) t.players = player_list t.league_stats = TeamStats.TeamStats(c) c.teams.append(t) current_rep -= rep_step def_competitions.append(c) c = League.League("Non League") for team_id in range(GAME_GLOBALS["TEAMS_PER_LEAGUE"]): t = Team.Team(rep=int(current_rep - rep_step)) m = Manager.Manager() hire_manager(team=t, manager=m) def_managers.append(m) #CREATE PLAYERS player_list = [] average_skill = sum(t.skill) / 3.0 for pos, qty in enumerate(TEAM_GLOBALS["PLAYERS_PER_POSITION"]): for i in range(qty): player = Player.Player(skill=average_skill, pos=pos, avg_skill=True) player.season_training_increase_per_turn() player_list.append(player) t.players = player_list t.league_stats = TeamStats.TeamStats(c) c.teams.append(t) def_competitions.append(c) global competitions competitions = def_competitions global managers managers = def_managers
import urllib import RosterParse import League import json import JSONSerializer teams = [ "bos", "nyy", "nym", "laa", "lad", "sf", "tb", "tor", "bal", "stl", "col", "hou", "cle", "det", "mia", "phi", "cin", "atl", "chc", "cws", "wsh", "mil", "ari", "tex", "pit", "oak", "sea" ] index = 0 l = League.League() while index < len(teams): mlb = "http://m.mlb.com/" + teams[ index] + "/roster/" #set url to the current team page = urllib.urlopen(mlb) # grabs page html soup = page.read() #read in page data parser = RosterParse.RosterParse( soup, teams[index]) #set the html in RosterPasrse l.addTeam( parser.getPlayers(b"section") ) #retrieves the cleaned html from RosterParse and replaces all \\n line endings with windows line endings #print(str(teams[index])) #prints team name for debugginh purposes #print(html)#prints players for debugging purposes page.close() #close file index = index + 1 #rinse and repeat #from django.forms.models import model_to_dict