def genSchedule(): ''' Update the input.json file in algorithm folder from the database. runScheduler then, update the database with the new data. ''' input_dict = {'professor':[],'subject':[],'classroom':[],'studentGroup':[]} prof_format = {'name':'','id':0,'courseTable':{}} subject_format = {'component':[],'pillar':0,'sessionNumber':0,'name':'','term':1,'cohortNumber':1,'totalEnrollNumber':10,'type':0,'courseId':''} class_format = {'name':'','location':'','id':1,'roomType':0,'capacity':10} studentGroup_format = {'pillar': 0, 'size': 0, 'subjects': [], 'name': '', 'cohort': 0, 'term': 1,'id':0} input_dict['subject'] = Subjects.getAllSubjects() input_dict['classroom'] = Rooms.geAllRooms() input_dict['studentGroup'] = studentGroup.getAllGroups() classroomlist = [i for i in range(len(input_dict['classroom']))] for professor in Users.getAllProfessors(): input_dict['professor'].append({'name':professor.fullname,'id':professor.professor_id,'coursetable':ast.literal_eval(professor.coursetable)}) for each_professor in input_dict['professor']: each_professor['coursetable'] = {str(k):ast.literal_eval(v) for k,v in each_professor['coursetable'].items()} for each_subject in input_dict['subject']: for each_component in each_subject['component']: each_component['classroom'] = classroomlist print(input_dict) file_to_open = os.path.join(os.getcwd(), "input.json") with open(file_to_open,'w+') as input_file: print(json.dump(input_dict, input_file)) with open(file_to_open, 'r') as data_file: data = json.load(data_file) print(data) """ file_to_open2 = os.path.join(os.getcwd(),"algorithm/input.json") with open(file_to_open2,'w') as input_file: print(json.dump(input_dict, input_file)) input_file.close() with open(file_to_open2, 'r') as data_file: data = json.load(data_file) print(data) data_file.close() """ runScheduler() timetablePath = os.path.join(os.getcwd(), "timetable.json") with open(timetablePath, 'r') as data_file: data = json.load(data_file) Timetable.replace_all(data) return redirect(url_for('home'))
def viewStudentSchedule(): """ A schedule contains the following information per specific class: subject id subject name type of session(cohort based learning, lecture, lab) start time to end time location of session(room id) professors teaching """ input_dict = {'professor':[],'subject':[],'classroom':[],'studentGroup':[]} prof_format = {'name':'','id':0,'courseTable':{}} subject_format = {'component':[],'pillar':0,'sessionNumber':0,'name':'','term':1,'cohortNumber':1,'totalEnrollNumber':10,'type':0,'courseId':''} class_format = {'name':'','location':'','id':1,'roomType':0,'capacity':10} studentGroup_format = {'pillar': 0, 'size': 0, 'subjects': [], 'name': '', 'cohort': 0, 'term': 1,'id':0} for professor in Users.getAllProfessors(): input_dict['professor'].append({'name':professor.fullname,'id':professor.professor_id,'coursetable':ast.literal_eval(professor.coursetable)}) for each_professor in input_dict['professor']: each_professor['coursetable'] = {str(k):ast.literal_eval(v) for k,v in each_professor['coursetable'].items()} input_dict['subject'] = Subjects.getAllSubjects() input_dict['classroom'] = Rooms.geAllRooms() input_dict['studentGroup'] = studentGroup.getAllGroups() Session = {'Lab':2,'Cohort Based Learning':0,'Lecture':1} student_schedule = [['Monday','Tuesday','Wedneday','Thursday','Friday'], ['08:30-09:00',None,None,None,None,None], ['09:00-09:30',None,None,None,None,None], ['09:30-10:00',None,None,None,None,None], ['10:00-10:30',None,None,None,None,None], ['10:30-11:00',None,None,None,None,None], ['11:00-11:30',None,None,None,None,None], ['11:30-12:00',None,None,None,None,None], ['12:00-12:30',None,None,None,None,None], ['12:30-13:00',None,None,None,None,None], ['13:00-13:30',None,None,None,None,None], ['13:30-14:00',None,None,None,None,None], ['14:00-14:30',None,None,None,None,None], ['14:30-15:00',None,None,None,None,None], ['15:00-15:30',None,None,None,None,None], ['15:30-16:00',None,None,None,None,None], ['16:00-16:30',None,None,None,None,None], ['16:30-17:00',None,None,None,None,None], ['17:00-17:30',None,None,None,None,None], ['17:30-18:00',None,None,None,None,None], ['18:00-18:30',None,None,None,None,None], ['18:30-19:00',None,None,None,None,None]] if current_user.user_group == 'student': subject_cohort_dict = {} for each_student_group in input_dict['studentGroup']: if each_student_group['name'] == current_user.student_group: for subject in each_student_group['subjects']: subject_cohort_dict[str(subject)] = int(each_student_group['cohort']) break print(subject_cohort_dict) user_timetable = Timetable.find_Timetable(subject_cohort_dict) for specific_class in user_timetable['user_timetable']: class_info = [] subject_id = str(specific_class['subject']) subject_name = '' for each_subject in input_dict['subject']: if each_subject['courseId'] == specific_class['subject']: subject_name = each_subject['name'] break session_type = 'Lecture' if len(ast.literal_eval(specific_class['cohort'])) > 1 else 'Cohort Based Learning' start_to_end = student_schedule[int(specific_class['startTime'])+1][0][0:6] +\ student_schedule[int(float(specific_class['duration'])*2)+int(specific_class['startTime'])][0][6:] location = specific_class['classroom'] professors_teaching = '' for professor in input_dict['professor']: if subject_id in list(professor['coursetable'].keys()): professors_teaching += professor['name'] + "," professors_teaching = professors_teaching[:len(professors_teaching)-1] input_specific_class = subject_id + "<br>"\ + subject_name + "<br>"\ + session_type + "<br>"\ + start_to_end + "<br>"\ + location + "<br>"\ + professors_teaching class_info.append(int(float(specific_class['duration'])*2)) class_info.append(input_specific_class) student_schedule[int(specific_class['startTime'])+1][int(specific_class['weekday'])+1] = class_info print(student_schedule) #redirect(url_for('home')) return render_template("viewStudentSchedule.html",student_schedule=student_schedule)