View Single Post
Old 12-20-2016, 10:11 AM   #170
CraigSca
Pro Starter
 
Join Date: Jul 2001
Location: Not Delaware - hurray!
Quote:
Originally Posted by Groundhog View Post
No, not a stupid question at all!

Ignore the invalid dates, because we only need those to determine which days are valid, and they will be skipped over. The False/True flags just tell the method that it needs to compile a list of all True days for each week between a range of dates. So if we feed the class a starting date of June 30 2016 up until January 31 2017, the method would first check which days are valid - let's say Saturday and Sunday - and then split up the the period between those dates into units of weeks, and append all the dates of Saturday and Sundays to a list. When we assign the matchups to days, it would be a random.choice() type of operation to randomly assign the individual matchups to these valid dates.

This could all be stored in memory, but this calculation will need to be run for all 70ish leagues once per offseason, as they all have their own unique True/False flags for valid game days, and obviously the dates will also change from year to year.

The final output of this would be a list of all games in a season, with the date, league id, home team id, and road team id, which would then be written to the database.

An instance of this class would be used inside another method somewhere along the lines of (and this is probably full of syntax errors, but just to give you a quick idea):

Code:
def generate_all_schedules(dict_of_all_leagues, dict_of_all_teams, current_year=2016, season_start_month=9, season_start_day=30, season_end_month=3, season_end_day=28): # dict_of_all leagues: A dictionary with league_id as the key, all league attributes as values in another dict. # dict_of_all_teams: A dictionary with the league_id as the key, and all team ids in a list as value. season_schedule = [] sg = ScheduleGen(current_year, season_start_month, season_start_day, season_end_month, season_end_day) for league in dict_of_all_leagues: # Create a 'shortcut' reference directly to the league to be processed l = dict_of_all_leagues[league] # Create a 'shortcut' reference to list of teams in league t = dict_of_all_teams[l['id']] league_sched = sg.create_round_robin_schedule(team_ids=dict_of_all_teams[l['id']], play_each_team=l['play_each_team'], valid_game_days=l['valid_game_days']) season_schedule.append(league_sched) return season_schedule

Yeah - getting back to my question - does that mean the list of true/false flags are ONLY for days of the week, or could you have something like false for all Saturdays and also Christmas day?
__________________
She loves you, yeah, yeah, yeah, yeah!
She loves you, yeah!
how do you know?
how do you know?

CraigSca is offline   Reply With Quote