def generate(eventData, competitors, debug): activeSchedule = Schedule( ) # Create object for initial schedule. Probably add something to store all these objects externally later activeSchedule.events = copy.deepcopy( eventData) # Create a local instance of eventData[] seniors = [] team = [] # Assign periods randomly for self-schedule eventData for obj in activeSchedule.events: if (obj.selfSchedule == True): obj.period = random.randint(1, 6) # Loop through all the possible competitor slots in an event. for phase in range(3): # Shuffle the event lsit so that there is no bias as to when the event is random.shuffle(activeSchedule.events) # Loop through each event in the current schedule for event in activeSchedule.events: # If the event isn't filled yet if len(event.competitors) < event.size: # If we can still add people to the team, get the best competitor out of everyone if len(team) < 15: competitor = Competitor.getBestCompetitor( competitors, event.name, event.period, seniors, MAX_GRADE, MAX_QUANTITY) # If we're full, get the best competitor out of the people on the team already else: competitor = Competitor.getBestCompetitor( team, event.name, event.period, seniors, MAX_GRADE, MAX_QUANTITY) # Now that the competitor has been added to this time slot, they are occupied competitor.occupied.append(event.period) # Add the competitor to the list of poeple competing in the event event.competitors.append(competitor) # Add the competitor to the list of seniors if they are a senior and aren't already there if competitor.grade == MAX_GRADE and competitor.name not in seniors: seniors.append(competitor.name) # Add the competitor to the competing team roster if they aren't already there if competitor not in team: team.append(competitor) # Reset the occupied status of the competitors for the next schedule for c in competitors: c.occupied = [] activeSchedule.members = team return activeSchedule