def main(): """Quick tests.""" a1 = Appointment("yo", "saturday", "12:30pm", "1:30pm", [1, 2, 3]) a3 = Appointment("yo1", "saturday", "1:30am", "12:30pm", [1]) a4 = Appointment("yo2", "sunday", "2:30am", "12:30pm", [1]) a5 = Appointment("yo3", "monday", "12:30am", "3:30am", [1]) a6 = Appointment("yo4", "tuesday", "4:30am", "12:30pm", [1]) a7 = Appointment("yo5", "wednesday", "5:30am", "12:30pm", [1]) a8 = Appointment("yo6", "thursday", "6:30am", "12:30pm", [1]) a9 = Appointment("yo7", "friday", "7:30am", "12:30pm", [1]) a10 = Appointment("yo8", "monday", "8:30am", "9:30am", [1]) a11 = Appointment("yo9", "tuesday", "12:30pm", "2:30pm", [1]) c3 = Calendar(a1, a3, a4, a5, a6, a7, a8, a9, a10, a11) serial_calendar = Calendar.serialize(c3) import pickle import sys msg = pickle.dumps(serial_calendar) size = sys.getsizeof(msg) print "size", size uC = Calendar.deserialize(serial_calendar) print c3 == uC pass
def main(): """Quick tests.""" "schedule yaboi (user0,user1,user2,user3) (4:00pm,6:00pm) Friday" "schedule xxboi (user1,user3,user4) (1:30am,11:30am) Wednesday" "schedule beez (user0,user1,user2,user3) (4:00pm,6:00pm) Saturday" "schedule beez2 (user0,user1,user2,user3) (3:00pm,4:00pm) Saturday" "schedule zo (user1,user2,user3) (12:30pm,1:30pm) Friday" "schedule hamma (user1,user2,user3) (1:00am,1:30am) Friday" "cancel yaboi (user0,user1,user2,user3) (4:00pm,6:00pm) Friday" "cancel xxboi (user1,user3,user4) (1:30am,11:30am) Wednesday" a1 = Appointment("zo", "Friday", "12:30pm", "1:30pm", [1, 2, 8]) a2 = Appointment("xxboi", "Wednesday", "1:30am", "11:30am", [1, 4, 5]) a3 = Appointment("lol", "saturday", "11:30am", "12:30pm", [1]) a4 = Appointment("yeee", "MondAy", "11:30am", "12:30pm", [1]) a5 = Appointment("lolololol", "Thursday", "11:30am", "12:30pm", [1]) c = Calendar() c1 = Calendar(a1) c2 = Calendar(a1, a2) c3 = Calendar(a1, a2, a3) c4 = Calendar(a1, a2, a3, a4) c5 = Calendar(a1, a2, a3, a4, a5) set_verbosity(4) N = Node(int(sys.argv[1])) ''' N._log[0] = c1 N._log[1] = c2 N._log[2] = c3 N._log[3] = c4 N._log[4] = c5 ''' N._calendar = c #try to load a previous state of this Node #''' try: N = Node.load() except ValueError: pass except IOError: pass #''' N.elect_leader(poll_time=6, timeout=3) N.paxos() print("@> Node Started") while True: message = raw_input('') if message == "quit": Node.save(N) N.terminate() break else: Node._parse_command(message, N)
def main(): strt = datetime.datetime(2017, 10, 28, 10, 30, 12) end = datetime.datetime(2017, 10, 28, 11, 30, 12) a = Appointment(strt, end, 'Appnt1', 'an example of an appointment') strt = datetime.datetime(2017, 10, 28, 11, 30, 12) end = datetime.datetime(2017, 10, 28, 12, 30, 12) b = Appointment(strt, end, 'Appnt2', 'another example of an appointment') d = Diary('guru''s') print(d) d += a d += b print(d, len(d)) print(d.next_appointments(1))
def negateAppointments(self, start: int, end: int): ans = [] for inx, a in enumerate(self.mergedAppointments): if (inx == 0): ans.append(Appointment(start, a.start, "Description")) else: ans.append( Appointment(self.mergedAppointments[inx - 1].end, a.start, "Descripion")) ans.append( Appointment(self.mergedAppointments[-1].end, end, "Description")) self.negatedAppointments = ans
def findTimeSlot(earliest: int, duration: int, participants: List[Participant]): #Get intersections of participants intersections = getAllIntersections(participants) #Iterate free slots and check for beginning time and duration for intersection in intersections: if (intersection.start <= earliest && intersection.end >= earliest+duration): return Appointment(earliest, earliest+duration, "Slot") else if(intersection.start > earliest && intersection.start+duration <= intersection.end): return(Appointment(start, start+duration, "Slot")) else: return(null)
def _parse_appointment(argv): """Try to parse an Appointment object from given argv.""" generic_error_msg = "Invalid command; Schedule and cancel " + \ "commands must be of form: \n" + \ "{schedule,cancel} [Appointment name] " + \ "(user1,user2,...usern) (start_time,end_time) [day]" if len(argv) != 5: raise ValueError(generic_error_msg) name, participants, times, day = argv[1:] participants = participants[1:-1].split(",") try: participants = [int(user[4:]) for user in participants] except ValueError: raise ValueError( "Invalid command; participants must be of form " "(user1,user2,...,usern)") try: start, end = times[1:-1].split(',') except ValueError: raise ValueError("Invalid command; times must be of form " "(start_time,end_time)") try: return Appointment(name, day, start, end, participants) except ValueError as excinfo: raise ValueError("Invalid command; " + excinfo.message)
def deserialize(serial_msg): """Return a Calendar object parsed from a serialized string""" if not serial_msg: return serial_msg if type(serial_msg) != str: return serial_msg appt_list = serial_msg.split("#") appt_for_calendar = [] for appt_str in appt_list: first_str = appt_str.split(" on ") appt_name = first_str[0].split("Appointment ")[1][1:-1] second_str = first_str[1].split(" with ") user_list = second_str[1].split(" and ") users_final = [] for part in user_list: users = part.split(" ") for part in users: if len(part) == 2: users_final.append(int(part[:-1])) else: users_final.append(int(part)) dates_part_1 = first_str[1].split(" from ") times = dates_part_1[1].split(" to ") start_time = times[0] end_time = times[1].split(" with ")[0] appointment_day = dates_part_1[0] start_time_hour, start_time_minute = [ int(comp_time) for comp_time in start_time.split(":") ] end_time_hour, end_time_minute = [ int(comp_time) for comp_time in end_time.split(":") ] start_time_final = datetime.time(start_time_hour, start_time_minute) end_time_final = datetime.time(end_time_hour, end_time_minute) appointment = Appointment(appt_name, appointment_day, start_time_final, end_time_final, users_final) appt_for_calendar.append(appointment) return Calendar(*appt_for_calendar)
def request_appointment(self, database, medicalWorkerUserName, appointmentDateTimeTuple, reason): now = datetime.now() appointmentID = now.strftime("%Y%m%d%H%M%S") + self.userName result = Appointment(self.userName, medicalWorkerUserName, appointmentDateTimeTuple, reason) database["appointment"][appointmentID] = result try: database["user_confirmed"][ medicalWorkerUserName].appointment_waiting[ appointmentDateTimeTuple].append(appointmentID) except KeyError: database["user_confirmed"][ medicalWorkerUserName].appointment_waiting[ appointmentDateTimeTuple] = [appointmentID]
def getIntersections(A: List[Appointment], B: List[Appointment]): ans = [] i = j = 0 while i < len(A) and j < len(B): # Let's check if A[i] intersects B[j]. # lo - the startpoint of the intersection # hi - the endpoint of the intersection lo = max(A[i].start, B[j].start) hi = min(A[i].end, B[j].end) if lo <= hi: ans.append(Appointment(lo, hi, "Description")) # Remove the interval with the smallest endpoint if A[i].end < B[j].end: i += 1 else: j += 1 return ans
def bookAppointment(self): print('Please Enter the following information.') print('1. First Name') firstName = input() print('2. Surname') lastName = input() print('3. Telephone') phone = input() print('4. Date of Birth (dd//MM//YYYY) format') dateOfBirth = input() print('Country of Origin') countryOfOrigin = input() # creating patient object patient = Patient(firstName, lastName, phone, dateOfBirth, countryOfOrigin) print('Succesful register!') print('**************************************\n') print( 'Now please enter the time you want to make an appointment (hour 8-14)' ) hour = input() print('\n') # validation of hour goes here while (True): if hour.isdigit(): hourInt = int(hour) if hourInt >= 8 and hourInt <= 14: break else: print('Please enter valid input hour') hour = input() else: print('Please enter valid input hour') hour = input() # ... schedules = self.findSchedules(hourInt) print('Available doctors are: ') index = 1 for schedule in schedules: print( str(index) + ') ' + schedule.getDoctor().getFriendlyName() + ' - ' + str(schedule.getStartHour()) + ' to ' + str(schedule.getEndHour())) index += 1 # ... print('Choose a appointment 1 - ' + str(index - 1)) indexRead = input() print('\n') # validation goes here valid = False indexReadInt = 0 while (not valid): if indexRead.isdigit(): indexReadInt = int(indexRead) if indexReadInt > 0 and indexReadInt < index: valid = True else: print('Enter a index in interval 1 - ' + str(index - 1)) else: print('Enter a index in interval 1 - ' + str(index - 1)) # creating appointment object appointment = Appointment(schedules[indexReadInt], patient) self.appointments.append(appointment) print('Congrats! You have made a appointment') print('**************************************\n') return True
def __init__(self, root, appointment_id=None): AppointmentBase.isopen = True # Variables self.log = logging.getLogger(__name__) self.colour = Colours.calendarbase self.relief = Relief.calendarbase self.root = root self.appointment_id = appointment_id self.dataappointment = DataAppointment() self.datapatient = DataPatient() self.datadoctor = DataDoctor() # Build Window tk.Toplevel.__init__(self, root, bg=self.colour['frame']) self.title('Appointment') self.protocol('WM_DELETE_WINDOW', self.Close) # Configure Window for i in range(4): self.grid_columnconfigure(i, weight=1) self.grid_rowconfigure(0, weight=0) self.grid_rowconfigure(1, weight=1) # Widgets self.checkbutton = tk.Button( self, text='Check', bg=self.colour['button'], highlightthickness=0, activebackground=self.colour['buttonactive'], relief=self.relief['button']) self.seepatientbutton = tk.Button( self, text='See Patient', bg=self.colour['button'], highlightthickness=0, activebackground=self.colour['buttonactive'], relief=self.relief['button']) self.typemenu = tk.Menubutton(self, text='Type', bg=self.colour['button'], relief=self.relief['button']) self.printbutton = tk.Button( self, text='Print', bg=self.colour['button'], highlightthickness=0, activebackground=self.colour['buttonactive'], relief=self.relief['button']) self.savebutton = tk.Button( self, text='Save', bg=self.colour['savebutton'], highlightthickness=0, activebackground=self.colour['buttonactive'], relief=self.relief['button'], command=self.SaveAppointment) self.appointment = Appointment(self, self.appointment_id) # Place Widgets self.checkbutton.grid(row=0, column=0, sticky=tk.N + tk.E + tk.S + tk.W) self.seepatientbutton.grid(row=0, column=1, sticky=tk.N + tk.E + tk.S + tk.W) self.typemenu.grid(row=0, column=2, sticky=tk.N + tk.E + tk.S + tk.W) self.printbutton.grid(row=0, column=3, sticky=tk.N + tk.E + tk.S + tk.W) self.savebutton.grid(row=0, column=4, sticky=tk.N + tk.E + tk.S + tk.W) self.appointment.grid(row=1, column=0, columnspan=5, sticky=tk.N + tk.S + tk.E + tk.W)