def main(): course1 = Course("CSCE", "181") sec1 = Section("CSCE", "181", "500", "3:55PM", "5:10pm", "TR") sec2 = Section("CSCE", "181", "002", "9:00pm", "9:50pm", "MWF") section_list = [sec1, sec2] [course1.addSection(sec) for sec in section_list] course2 = Course("CSCE", "313") sec3 = Section("CSCE", "313", "505", "11:10am", "12:25pm", "TR") sec4 = Section("CSCE", "313", "004", "9:00am", "9:50am", "TR") section_list = [sec3, sec4] [course2.addSection(sec) for sec in section_list] course3 = Course("CSCE", "314") sec5 = Section("CSCE", "314", "502", "10:00am", "10:50pm", "MWF") sec6 = Section("CSCE", "314", "503", "9:30am", "11:50am", "TR") section_list = [sec5, sec6] [course3.addSection(sec) for sec in section_list] course4 = Course("MATH", "304") sec8 = Section("MATH", "304", "502", "9:10am", "9:50am", "MWF") sec9 = Section ("MATH", "304", "888", "2:00pm", "3:00pm", "TR") section_list = [sec8, sec9] [course4.addSection(sec) for sec in section_list] course5 = Course("ENGL", "204") sec10 = Section("ENGL", "204", "999", "8:10am", "8:50am", "MWF") section_list = [sec10] [course5.addSection(sec) for sec in section_list] course_list = [course1, course2, course3, course4, course5] # Create section list to use in itertools's product function sec_list = [courses.getSections() for courses in course_list] scheduleList = generate_schedules(sec_list) i = 1 for schedule in scheduleList: print("Schedule", i, ":") i += 1 for section in list(schedule): print(section.secInfo)
def output(): f = request.form departments = f.getlist('department') courseNums = f.getlist('courseNum') secNums = f.getlist('secNum') startTimes = f.getlist('startTime') finishTimes = f.getlist('finishTime') days = get_days(f) secs = f.getlist('sec-indicator') # print(departments, courseNums, secNums, startTimes, finishTimes, days, secs) # Remove blank inputs section = 0 course = 0 coursesToDelete = [] sectionsToDelete = [] # Remove blank courses for num_secs in secs: if departments[course] == '' and courseNums[course] == '': coursesToDelete.append(course) for sections in range(int(num_secs)): sectionsToDelete.append(section) section += 1 course += 1 else: for sections in range(int(num_secs)): section += 1 course += 1 # print(coursesToDelete, sectionsToDelete) for c in reversed(coursesToDelete): del departments[c] del courseNums[c] del secs[c] for s in reversed(sectionsToDelete): del secNums[s] del startTimes[s] del finishTimes[s] # print(departments, courseNums, secNums, startTimes, finishTimes, days, secs) # Remove blank sections s = 0 c = 0 blankSecNum = 1 sectionsToDelete = [] for num_secs in secs: for sections in range(int(num_secs)): if secNums[s] == '' and startTimes[s] == '' and finishTimes[s] == '' and s not in days: # Completely blank section sectionsToDelete.append((s, c)) elif startTimes[s] == '' or finishTimes[s] == '' or s not in days: # Input ERROR # render_template('input.html') sectionsToDelete.append((s, c)) elif secNums[s] == '': # Insert number for section number if left blank secNums[s] = str(blankSecNum) blankSecNum += 1 s += 1 c += 1 for s in reversed(sectionsToDelete): # s[0] == section number, s[1] == course number del secNums[s[0]] del startTimes[s[0]] del finishTimes[s[0]] secs[s[1]] = str(int(secs[s[1]]) - 1) coursesToDelete = [] i = 0 for s in secs: # print(s) if s == '0': coursesToDelete.append(i) i += 1 for c in reversed(coursesToDelete): del secs[c] print(departments, courseNums, secNums, startTimes, finishTimes, days, secs) # Create sections course_list = [] section = 0 course = 0 for num_secs in secs: c = Course(departments[course], courseNums[course]) course_list.append(c) for sections in range(int(num_secs)): s = Section(c.department, c.courseNum, secNums[section], startTimes[section], finishTimes[section], days[section] ) c.addSection(s) section += 1 course += 1 # Find all possible schedules section_list = [courses.getSections() for courses in course_list] for l in section_list: for sec in l: print(sec.secInfo, sec.outputInfo['size'], sec.outputInfo['topMargin']) scheduleList = generate_schedules(section_list) # print("NUMBER OF SCHEDULES:", len(scheduleList)) # Print schedules # i = 1 # for schedule in scheduleList: # print("Schedule" + str(i) + ":") # i += 1 # for section in list(schedule): # print(section.secInfo) # Prep data for user output # Each schedule in outputScheduleList is a dict with keys: M,T,W,R,F # with values holding the section information. outputScheduleList = [] for schedule in scheduleList: s = defaultdict(list) s['M'] = [] s['T'] = [] s['W'] = [] s['R'] = [] s['F'] = [] for section in list(schedule): for day, value in section.days.items(): if value: s[day].append(section.outputInfo) outputScheduleList.append(s) return render_template('output.html', scheduleList=outputScheduleList)