def print_teacher_schedule(teacher_name, current_week): wb = xlwt.Workbook() teacher = models.Teacher.query.filter_by(name=teacher_name).first() ws = wb.add_sheet(teacher_name + ' Schedule') # Write the header ws.write(0, 3, teacher_name) ws.write(1, 1, "Monday") ws.write(1, 2, "Tuesday") ws.write(1, 3, "Wednesday") ws.write(1, 4, "Thursday") ws.write(1, 5, "Friday") # Write the timeslots timeslots = timeslotHelp.get_timeslots() for idx, timeslot in enumerate(timeslots): ws.write(idx * 5 + 2, 0, timeslot) display_appointments = util.build_display_teacher_appointments(current_week, teacher) # Print out each appointment for timeslot in range(0, 20): for count in range(0, 5): for date_num in range(0, 5): if display_appointments[date_num][timeslot][count] is not None: ws.write(timeslot * 5 + count + 2, date_num + 1, display_appointments[date_num][timeslot][count].tutee.first_name + ' ' + display_appointments[date_num][timeslot][count].tutee.last_name + '-' + display_appointments[date_num][timeslot][count].service.name) return wb
def print_full_schedule(current_day): wb = xlwt.Workbook() ws = wb.add_sheet(current_day + ' Schedule') all_teachers = models.Teacher.query.all() # Write the header ws.write(0, 3, current_day) for idx, teacher in enumerate(all_teachers): ws.write(1, idx + 1, teacher.name) # Write the timeslots timeslots = timeslotHelp.get_timeslots() for idx, timeslot in enumerate(timeslots): ws.write(idx * 5 + 2, 0, timeslot) display_appointments = util.build_display_appointments(timeslotHelp.date_string_to_object(current_day).date(), all_teachers) # Print out each appointment for timeslot in range(0, 20): for count in range(0, 5): for teacherNum in range(0, len(all_teachers)): if display_appointments[teacherNum][timeslot][count] is not None: ws.write(timeslot * 5 + count + 2, teacherNum + 1, display_appointments[teacherNum][timeslot][count].tutee.first_name + ' ' + display_appointments[teacherNum][timeslot][count].tutee.last_name + '-' + display_appointments[teacherNum][timeslot][count].service.name) return wb
def build_display_appointments(today_date, teachers): # TODO take a look at this today date appointments = list() all_appointments = models.Appointment.query.filter_by(is_active=True).all() all_makeups = [app for app in all_appointments if app.is_makeup == True] all_absences = models.Absence.query.all() for app in all_appointments: if ( is_appointment_today(today_date, app) and not is_absent(today_date, app, all_absences) and not is_rescheduled(today_date, app, all_makeups) ): appointments.append(app) display_appointments = numpy.empty((len(teachers), len(timeslotHelp.get_timeslots()), 5), dtype=object) teacher_ids = [teacher.id for teacher in teachers] for appointment in appointments: # Skip the appointment if it is not from one of the teachers being displayed if appointment.teacher_id not in teacher_ids: continue for slot in timeslotHelp.timeslot_string_to_timeslot_num(appointment.times): for count in range(0, 5): if display_appointments[teacher_ids.index(appointment.teacher_id)][slot - 1][count] is None: display_appointments[teacher_ids.index(appointment.teacher_id)][slot - 1][count] = appointment break return display_appointments
def build_display_teacher_appointments(dates_of_week, current_teacher): display_appointments = numpy.empty((5, len(timeslotHelp.get_timeslots()), 5), dtype=object) teacher_appointments = models.Appointment.query.filter_by(teacher_id=current_teacher.id).all() # Remove makeup appointments and absences teacher_makeups = [app for app in teacher_appointments if app.is_makeup == True] all_absences = models.Absence.query.all() # Display all the appointments that are during that week for app in teacher_appointments: for idx, date in enumerate(dates_of_week): if is_appointment_today(date, app): for slot in timeslotHelp.timeslot_string_to_timeslot_num(app.times): for count in range(0, 5): # Add if not absent or rescheduled for that day if not is_teacher_appointment_absent( date, app, all_absences ) and not is_teacher_appointment_rescheduled(date, app, teacher_makeups): if display_appointments[idx][slot - 1][count] is None: display_appointments[idx][slot - 1][count] = app break return display_appointments