def __contains__(self, uid): ''' Checks if user is in the queue :param: uid User/UID that identifies who we are looking up :return: True if the UID is found, False otherwise ''' uid = User.get_uid(uid) return (uid in self.busy_queue) or (uid in self.free_queue)
def is_stu(uid): ''' Checks if a UID or User is a student UID :param: uid UID string or User to extract a UID out of :return: True if the UID is a Student, False otherwise ''' uid = User.get_uid(uid) if (type(uid) is str): return UID_PREFIX_STU == uid[:len(UID_PREFIX_STU)] return False
def is_tut(uid): ''' Checks if a UID or User is a tutor UID :param: uid UID string or User to extract a UID out of :return: True if the UID is a Tutor, False otherwise ''' uid = User.get_uid(uid) if (uid != None): return UID_PREFIX_TUT == uid[:len(UID_PREFIX_TUT)] return False
def push(self, stu_uid): ''' Adds a student to the back of the queue :param: stu_uid UID/Student object to add :return: Student UID added or None if there's an error ''' stu_uid = User.get_uid(stu_uid) if (Student.is_stu(stu_uid)): self.queue.append(stu_uid) self.lt_count += 1 return stu_uid return None
def help(self, stu_uid): ''' A tutor helps a student :param: stu_uid UID/Student object to help :return: UID of student that was just helped or None ''' stu_uid = User.get_uid(stu_uid) if (stu_uid != None): self.helped.append(stu_uid) self.busy = True return stu_uid return None
def remove(self, tut_uid): ''' Remove a tutor from the queue; presumably they are now off duty :param: tut_uid Tutor object/UID of Tutor to be removed :return: UID of Tutor removed or None if there's an error ''' tut_uid = User.get_uid(tut_uid) if (Tutor.is_tut(tut_uid)): val = None if (tut_uid in self.busy_queue): val = self.busy_queue[tut_uid] del self.busy_queue[tut_uid] elif (tut_uid in self.free_queue): val = self.free_queue[tut_uid] del self.free_queue[tut_uid] return val return None
def add(self, tut_uid, busy_state=False): ''' Add a tutor to the queue; presumably they just went on duty :param: tut_uid UID/Tutor object to add :param: busy_state Optional parameter specifies if the tutor is busy :return: Tutor UID added or None if there's an error ''' # override busy state if tutor object is provided if (type(tut_uid) is Tutor): busy_state = tut_uid.busy_status() tut_uid = User.get_uid(tut_uid) if (Tutor.is_tut(tut_uid)): if (busy_state): self.busy_queue[tut_uid] = tut_uid else: self.free_queue[tut_uid] = tut_uid return tut_uid return None
def update(self, tut_uid, busy_state=False): ''' Update the status of the tutor, based on the current status of the tutor instance :param: tut_uid UID/Tutor object to update :param: busy_state Optional parameter specifies if the tutor is busy :return: tut.busy_status() or None if update failed ''' # override busy state if tutor object is provided if (type(tut_uid) is Tutor): busy_state = tut_uid.busy_status() tut_uid = User.get_uid(tut_uid) if (Tutor.is_tut(tut_uid)): # remove the tutor from either queue self.remove(tut_uid) # re-assign the tutor self.add(tut_uid, busy_state) # return the current status of the Tutor return busy_state else: return None