Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No active exception to reraise #91

Open
Jman4190 opened this issue Aug 30, 2022 · 7 comments
Open

No active exception to reraise #91

Jman4190 opened this issue Aug 30, 2022 · 7 comments

Comments

@Jman4190
Copy link

When running this block I receive an error

games_played={}
weekly_matchups=[]

for week, game_type in enumerate(game_types_per_week):
    #print(week)
        
    print(week,game_type)
    matchups=None
    #Potentially invalid matchups can happen depending on the contstraints so each week will have a given number of attempts. 
    #It's also possible a prior week leads to an impossible state. We will only support rerunning on the week level
    ATTEMPTS=100
    for attempt in range(ATTEMPTS):
        try:
            matchups=gen_matchups(all_teams,universes[game_type])
            break
        except:
            continue
    if not matchups:
        raise 
    else:
        for name, universe in universes.items():
            for team_1,team_2 in matchups:
                for a,b in permutations([team_1,team_2], 2):
                    if b in universe.get(a,[]):                        
                        universes[name][a].remove(b)

        weekly_matchups.append(matchups)

[x[0] for x in weekly_matchups]

Error message

RuntimeError Traceback (most recent call last)
/var/folders/h0/ffqb5f990rqfgzshykzbr2gm0000gn/T/ipykernel_88125/299313015.py in
21 continue
22 if not matchups:
---> 23 raise
24 else:
25 for name, universe in universes.items():

RuntimeError: No active exception to reraise


The only change I have made is to use 4 divisions instead of 3:

```from collections import defaultdict

divisions = defaultdict(list)
for i,team in enumerate(all_teams):
    divisions[i//3].append(team)#every 4th team from the random list is assigned to the same division
divisions```
@rogerfitz
Copy link
Owner

rogerfitz commented Aug 30, 2022

How many teams, divisions, and conferences do you have? It looks like that code is actually generating divisions of size 3 not size 4. i//3 Gives the following pairs of values:

0,0
1,0,
2,0,
3,1,
4,1,
5,1,
6,2,
...

All divisions should be the same size. And every conference should be the same size too.

That exception just means that no valid solution was found after 100 attempts for that week (you could try increasing the number of attempts). I should change the code to actually describe the exception more clearly.

Not ruling out there isn't a bug but please let me know those values. And then what your game_types_per_week variable looks like

@rogerfitz
Copy link
Owner

my comment was also bad next to that i//4. Updated in my last commits to reflect what it actually is doing

@Jman4190
Copy link
Author

Yes I have 12 teams in the league with 4 divisions made up of 3 teams each. There are 2 conferences with 6 teams in each each. So two divisions within each conference. I increased the attempts to 1000 and it's still failing. This is my game_types_per_week

['divisional',
 'non_conference',
 'non_conference',
 'conference',
 'divisional',
 'divisional',
 'conference',
 'divisional',
 'conference',
 'conference',
 'divisional',
 'non_conference',
 'non_conference',
 'divisional']

@Jman4190
Copy link
Author

I think I found where the issue is coming from. It doesn't look like conferences is generating as expected. The output is the same as divisions and when I look at universes['conference'] I see empty lists. Any potential issue here:

conferences = defaultdict(list)
conference_nums=[]

for division, teams in divisions.items():
    division_num=len(teams)//2 #2 conferences
    conferences[division//division_num]+=teams
    conference_nums.append(division_num)
    
conferences

@Jman4190
Copy link
Author

Jman4190 commented Aug 30, 2022

Ok I got conferences to work now by just setting division_num=2 and the output is:

defaultdict(list,
            {0: ["Team One",
              'Team Two',
              'Team Three',
              'Team Four',
              'Team Five',
              'Team Six'],
             1: ['Team Seven',
              "Team Eight",
              'Team Nine',
              'Team Ten',
              'Team Eleven',
              'Team Twelve']})

And I got my universes['non_conference'] and universes['conference'] to output the correct info. However I am still seeing this error

Exception: No valid matchups found for week 0 after 1000000 attempts. Please check your settings are valid or try increasing the number of attempts

@rogerfitz
Copy link
Owner

Ah sorry, the code does not work with an odd number of teams in a division or conference. There was a bug in the conferences code you found as well.

The schedule generator does not support an odd number of teams in a division since each week is a "themed" week. Divisional week requires every team to play a team from their division and after the first matchup is set the third team in the division has no one left to play. You could probably edit the code to make it work for your use case though. Or do 2 divisions of size 6. See the new notebook https://github.com/rogerfitz/tutorials/blob/master/fantasy_football_schedule_generator/jman_issue.ipynb (it might take a few runs to get this schedule to generate validly but it should work most of the times)

@rogerfitz
Copy link
Owner

Maybe in a follow up video I'll add support for odd numbered teams (it is a more complicated approach but would be way more flexible), for now I added a warning in the notebooks, README, and Youtube video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants