def run_each_week(string): global division_standings for week, games in sorted(schedule.iteritems(), key=lambda (k, v): int(k.split(" ")[1])): string = determine_winners(week, games, string) string = common.add_breaks_to_string(string) division_standings = common.update_division_records(records) string = common.print_records_by_div(string, division_standings) string = common.add_breaks_to_string(string) return string
def predict_games(uptoweek, endweek, string): global schedule, records, games, division_standings schedule = common.schedule games = common.get_games(uptoweek) records = common.update_records(games, records, uptoweek) i = uptoweek while i <= endweek: week = "WEEK {0}".format(i) gamestoplay = schedule.get(week) string = determine_winners(week, gamestoplay, string) string = common.add_breaks_to_string(string) division_standings = common.update_division_records(records) string = common.print_records_by_div(string, division_standings) i += 1 return string
def determine_playoff_matchups(string): afc = [] afc_5th = {'name': 'holder', 'record': {'win': 0, 'loss': 0}} afc_6th = {'name': 'holder', 'record': {'win': 0, 'loss': 0}} nfc = [] nfc_5th = {'name': 'holder', 'record': {'win': 0, 'loss': 0}} nfc_6th = {'name': 'holder', 'record': {'win': 0, 'loss': 0}} for div in division_standings: if div['division'][0:1] is 'A': afc.append(div['records'][0]) if div['records'][1]['record']['win'] > afc_5th['record']['win']: afc_5th = div['records'][1] if div['records'][2]['record']['win'] > afc_6th['record'][ 'win']: afc_6th = div['records'][2] else: if div['records'][1]['record']['win'] > afc_6th['record'][ 'win']: afc_6th = div['records'][1] else: nfc.append(div['records'][0]) if div['records'][1]['record']['win'] > nfc_5th['record']['win']: nfc_5th = div['records'][1] if div['records'][2]['record']['win'] > nfc_6th['record'][ 'win']: nfc_6th = div['records'][2] else: if div['records'][1]['record']['win'] > nfc_6th['record'][ 'win']: nfc_6th = div['records'][1] afc = sorted(afc, key=lambda a: a['record']['loss']) nfc = sorted(nfc, key=lambda a: a['record']['loss']) string = common.add_breaks_to_string(string) string += "<div>Playoff Week 1</div>" game1 = {'home': afc[2]['name'], 'visitor': afc_6th['name']} game2 = {'home': afc[3]['name'], 'visitor': afc_5th['name']} game3 = {'home': nfc[2]['name'], 'visitor': afc_6th['name']} game4 = {'home': nfc[3]['name'], 'visitor': afc_5th['name']} winner1 = return_winner(game1, string) string += winner1[1] winner2 = return_winner(game2, string) string += winner2[1] winner3 = return_winner(game3, string) string += winner3[1] winner4 = return_winner(game4, string) string += winner4[1] string = common.add_breaks_to_string(string) string += "<div>Playoff Week 2</div>" game1 = {'home': afc[0]['name'], 'visitor': winner1[0]} game2 = {'home': afc[1]['name'], 'visitor': winner2[0]} game3 = {'home': nfc[0]['name'], 'visitor': winner3[0]} game4 = {'home': nfc[1]['name'], 'visitor': winner4[0]} winner1 = return_winner(game1, string) string += winner1[1] winner2 = return_winner(game2, string) string += winner2[1] winner3 = return_winner(game3, string) string += winner3[1] winner4 = return_winner(game4, string) string += winner4[1] string = common.add_breaks_to_string(string) string += "<div>Championships</div>" game1 = {'home': winner1[0], 'visitor': winner2[0]} game2 = {'home': winner3[0], 'visitor': winner4[0]} winner1 = return_winner(game1, string) string += winner1[1] winner2 = return_winner(game2, string) string += winner2[1] string = common.add_breaks_to_string(string) string += "<div>Superbowl</div>" game1 = {'home': winner1[0], 'visitor': winner2[0]} winner1 = return_winner(game1, string) string += winner1[1] string += "<div>Champion: {0}</div>".format(winner1[0]) return string