print(len(a[0]), len(a[1])) # # print(len(a[0]) * len(a[1])) for h in range(0, 1): try: # Sampling cm = CourseManager() for i in cm._break_down_nested_list(a[0][h]): print(i.get_code()) print(i.get_meeting_section()) # =====Testing Purposes===== t = TimetableManager() f = Timetable() for i in cm._break_down_nested_list(a[0][0]): f.add_course([i], u.get_first_semester_filter()) print(f.get_first_semester_table()) print(f.get_second_semester_table()) except (IndexError): print("No Solutions Found") # # print(len(u._get_combinations())) # for i in u._get_combinations(): # for b in i: # print(b._get_meeting_section()) # print("----------------") # print(u._second_semester_courses) # print(u._first_semester_courses[0].get_meeting_sections()) # print(u.get_combinations()) # Visual aspect - Set a color for each subject and make the timetables that have the colors in the blocks? # TODO: Add full year course support (Later) # TODO: When you add courses, make a new function to only generate valid combinations for first sem and second sem separately
def timetable(): u = User() for course in list_of_courses: if course + ".json" in os.listdir( "/Users/chris/PycharmProjects/Timetable-Generator/another_one" ): u.add_course(course) # global courses_color global courses_color courses_color = assign_color_to_courses() u.set_first_semester_filter( (fall_start_time) * 3600, (fall_end_time) * 3600, days_excluded_fall, fall_lunch_start_time, fall_lunch_end_time, first_semester_max_courses, first_semester_tutorials_practicals) u.set_second_semester_filter( (winter_start_time) * 3600, (winter_end_time) * 3600, days_excluded_winter, winter_lunch_start_time, winter_lunch_end_time, second_semester_max_courses, second_semester_tutorials_practicals) possible_timetables = u.get_valid_combinations() cm = CourseManager() fst = Timetable() # print(str(len(possible_timetables[0])) + " timetables generated") if len(possible_timetables[0]) != 0: fs = random.randint( 0, (len(possible_timetables[0]) - 1)) # Can get a -1 error for no possible timetables else: fs = -1 if len(possible_timetables[1]) != 0: ss = random.randint(0, (len(possible_timetables[1]) - 1)) else: ss = -1 # print(str(a) + " is the timetable picked") if fs != -1: fst.add_course(cm._break_down_nested_list(possible_timetables[0][fs]), u.get_first_semester_filter()) if ss != -1: fst.add_course(cm._break_down_nested_list(possible_timetables[1][ss]), u.get_second_semester_filter()) columns = ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY'] index = [ '8:00am', '8:30am', '9:00am', '9:30am', '10:00am', '10:30am', '11:00am', '11:30am', '12:00pm', '12:30pm', '1:00pm', '1:30pm', '2:00pm', '2:30pm', '3:00pm', '3:30pm', '4:00pm', '4:30pm', '5:00pm', '5:30pm', '6:00pm', '6:30pm', '7:00pm', '7:30pm', '8:00pm', '8:30pm', '9:00pm', '9:30pm' ] # print(t.get_first_semester_table()) data_first_semester = fst.get_first_semester_table() data_second_semester = fst.get_second_semester_table() for i in range(len(data_first_semester)): for h in range(len(data_first_semester[i])): if data_first_semester[i][h] is None: data_first_semester[i][h] = '' else: data_first_semester[i][h] = str( data_first_semester[i][h].get_code() + " " + data_first_semester[i][h].get_meeting_section_codes()) for i in range(len(data_second_semester)): for h in range(len(data_second_semester[i])): if data_second_semester[i][h] is None: data_second_semester[i][h] = '' else: data_second_semester[i][h] = str( data_second_semester[i][h].get_code() + " " + data_second_semester[i][h].get_meeting_section_codes()) df1 = pd.DataFrame(data_first_semester, columns=columns, index=index) th_props = [('text-align', 'center'), ('color', '#6d6d6d'), ('background-color', '#f7f7f9')] td_props = [('font-size', '20px')] styles = [ dict(selector="tr", props=th_props), dict(selector="td", props=td_props) ] # df1.style.applymap(highlight_courses) test = dict(selector="th", props=[('text-align', 'center')]) df1.style.set_table_styles([test]) df1.style.set_table_styles(styles).render() df2 = pd.DataFrame(data_second_semester, columns=columns, index=index) df2.style.set_table_styles([test]) df2.style.set_table_styles(styles).render() # print(df2.style.render()) # print(df1.style.render()) for day, content in df1.iteritems(): for item in content: if item != '': if item not in temp_dict[day]: temp_dict[day][0][item] = False # print(temp_dict) # print(type(df1.iteritems())) # df1.to_html(border=0, escape=False) # print(courses_color) return render_template( "timetable.html", data_frame=df1.style.applymap(highlight_courses_background, subset=columns).render(), data_frame2=df2.style.applymap(highlight_courses_background, subset=columns).render())