week 9 day 3 final


no your reading the title right it says week 9 day 3 final becuase i got everything to work finally

import random
import pandas as pd
from flags import flags


# --- Team and Division Setup ---

divisions = {
    "AFC East": ["BUF", "MIA", "NE", "NYJ"],
    "AFC North": ["BAL", "CIN", "CLE", "PIT"],
    "AFC South": ["HOU", "IND", "JAX", "TEN"],
    "AFC West": ["DEN", "KC", "LV", "LAC"],
    "NFC East": ["DAL", "NYG", "PHI", "WAS"],
    "NFC North": ["CHI", "DET", "GB", "MIN"],
    "NFC South": ["ATL", "CAR", "NO", "TB"],
    "NFC West": ["ARI", "LAR", "SEA", "SF"]
}

all_teams = [t for teams in divisions.values() for t in teams]

# --- Team schedule generation ---
def generate_team_schedule(team, divisions):
    """Return a set of opponents for one team (simplified NFL style)."""
    division = next(div for div, teams in divisions.items() if team in teams)
    div_teams = divisions[division]

    opponents = []

    # Division home & away (6 games)
    for opp in div_teams:
        if opp != team:
            opponents.append(opp)
            opponents.append(opp)

    # Fill remaining 11 with random others
    others = [t for t in all_teams if t not in div_teams and t != team]
    random.shuffle(others)
    opponents.extend(others[:11])

    return opponents # 17 games

# --- Full Schedule ---
def generate_schedule(divisions, weeks=18):
    random.seed(42)
    schedule = []
    team_games = {team: generate_team_schedule(team, divisions) for team in all_teams}
    
    week = 1
    while week <= weeks:
        used = set()
        weekly_games = [13 or 14]
        random.shuffle(all_teams)

        for team in all_teams:
            if team in used or not team_games[team]:
                continue
            opp = team_games[team].pop()
            if opp in used or team not in team_games[opp]:
                continue
            # Assign game
            weekly_games.append((week, team, opp))
            used.add(team)
            used.add(opp)
            team_games[opp].remove(team)

        schedule.extend(weekly_games)
        week += 1

    return ("Week", "Home", "Away")


def calculate_standings(results):
    standings = {team: {"W": 0, "L": 0, "PF": 0, "PA": 0} for team in all_teams}
    for _, row in results.iterrows():
        home, away = row["Home"], row["Away"]
        hs, as_ = row["HomeScore"], row["AwayScore"]
        standings[home]["PF"] += hs
        standings[home]["PA"] += as_
        standings[away]["PF"] += as_
        standings[away]["PA"] += hs
        if hs > as_:
            standings[home]["W"] += 1
            standings[away]["L"] += 1
        else:
            standings[away]["W"] += 1
            standings[home]["L"] += 1
    df = pd.DataFrame([
        {"Team": t, "W": d["W"], "L": d["L"], "PF": d["PF"], "PA": d["PA"]}
        for t, d in standings.items()
    ])
    df["WinPct"] = df["W"] / (df["W"] + df["L"])
    return df.sort_values(["WinPct", "PF"], ascending=[False, False]).reset_index(drop=True)


schedule = generate_schedule(divisions)
simulate_scores= random

class standings:
  standings = calculate_standings
results= ("W-L")


class playoffs:
    

        """Simplified playoffs: 7 teams per conference, single elimination."""
        # Split AFC/NFC
        afc = [t for div, teams in divisions.items() if "AFC" in div for t in teams]
        nfc = [t for div, teams in divisions.items() if "NFC" in div for t in teams]

    

        def play_game(team1, team2):
            s1, s2 = random.randint(14, 38), random.randint(14, 38)
            return team1 if s1 >= s2 else team2

        def run_bracket(seeds):
            # 1 seed bye, 2v7, 3v6, 4v5

            play_game=play_game
            winner_2_7 = play_game(seeds[1]["Team"], seeds[6]["Team"])
            winner_3_6 = play_game(seeds[2]["Team"], seeds[5]["Team"])
            winner_4_5 = play_game(seeds[3]["Team"], seeds[4]["Team"])
            # Next rounds (simplified seeding)
            semis = [seeds[0]["Team"], winner_2_7, winner_3_6, winner_4_5]
            random.shuffle(semis)
            finals = [play_game(semis[0], semis[1]), play_game(semis[2], semis[3])]
            champ = play_game(finals[0], finals[1])
            return champ 
        

class flag_penalties:

    flag_penalties={}
    def throw_flag(self):
        return self.get_random_flag()
    
    def get_random_flag(self):
        return random.choice(flags)

the final main file don’t worry i already ran everything it works well im honestly sad its over it was fun you know but on the postive this opens up possbly for next week and the weeks that fellow im thinking of doing a chat bot next but im not sure but ill have it figured out by next week

now back to why your here today was just making sure everything works and putting it all as 1 if im being honest i didnt think i could do it u know theres a saying it goes you miss 100% of the shots you dont take and well i took mine and it landed perfectly im sorry this post really is not about coding but there really not much more to say about this project but it was fun i want to thank you for these 9 weeks it was really fun

THANK YOU !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Leave a Reply

Your email address will not be published. Required fields are marked *