def main(): ''' Test program for this class ''' stu0 = Student("aic4242", "pass", "Alice", "in Chains") stu1 = Student("bob8888", "pass", "Bob", "Man") stu2 = Student("exo6666", "xkcd", "Evil", "Oscar") tut0 = Tutor("tut1234", "pass", "Tutor", "A", "SLI") queue = QueueStu("Primary Queue") print("##### Push commands #####") print(queue.len() == 0) print(queue.is_empty() == True) queue.push(stu0) queue.push(stu1) queue.push(stu2) queue.push(tut0) # This should not be pushed print(queue.len() == 3) print(queue.is_empty() == False) print(str(queue)) print("##### Pop/Top commands #####") print(queue.top()) print(queue.top() == stu0) print(queue.pop() == stu0) print(str(queue)) print("##### Purge commands #####") print(queue.purge(tut0) == None) print(queue.purge(stu2) == stu2) print(not (stu2 in queue)) print(stu1 in queue) print(queue.purge_all() == None) print(str(queue))
def main(): ''' Test program for this class ''' tut0 = Tutor("aic4242", "pass", "Alice", "in Chains", "SLI") tut1 = Tutor("bob8888", "pass", "Bob", "Man", "TA") tut2 = Tutor("exo6666", "xkcd", "Evil", "Oscar", "Tutor") stu0 = Student("stu1234", "pass", "Student", "A") stu1 = Student("stu2345", "word", "Student", "B") queue = QueueTut() print("##### Add commands #####") print(queue.len() == 0) print(queue.is_empty() == True) queue.add(tut0) queue.add(tut1) queue.add(tut2) queue.add(stu0) # This should not be pushed print(queue.len() == 3) print(queue.is_empty() == False) print(str(queue)) print("##### Next/Update commands #####") print("next() call:" + str(queue.next())) print("next() call:" + str(queue.next())) print(tut0.help(stu0) == stu0) print(queue.update(tut0) == True) print(tut1.help(stu1) == stu1) print(queue.update(tut1) == True) print("next() call:" + str(queue.next())) print(str(queue)) # tutors finish helping students print(tut1.done() == stu1) print(queue.update(tut1) == False) print(tut0.done() == stu0) print(queue.update(tut0) == False) print(str(queue)) print("##### Purge commands #####") print(queue.remove(stu0) == None) print(queue.remove(tut2) == tut2) print(not (tut2 in queue)) print(tut1 in queue) print(tut0 in queue) print(str(queue)) print(queue.purge_all() == None) print(str(queue))
def main(): ''' Test program for this class ''' stu0 = Student("stu1234", "pass", "Student", "A") tut0 = Tutor("aic4242", "pass", "Alice", "in Chains", "SLI") print(stu0) print("------------------------------------------------------------------") print(JSON_DB_Encoder.dumps(stu0)) print() print(tut0) print("------------------------------------------------------------------") print(JSON_DB_Encoder.dumps(tut0))
def register_tut(self, rit_name, passwd, f_name, l_name, title=""): ''' Registers a tutor with the system :param: rit_name Username of the user (RIT email, sans @rit.edu) :param: passwd Password, encrypted by client :param: f_name First name of the user :param: l_name Last name of the user :param: title Optional title of the tutor :return: New user object ''' user = Tutor(rit_name, passwd, f_name, l_name, title) self.bunny.register(user) self.tut_queue.add(user) # newly registered tutors should check the queue Student queue self.__dispatch_tut() return user
def login_user(self, user_name, passwd): ''' Loads a user object from the DB; user logs into the system :param: user User object being created :return: User object added or None if failure ''' # pull user from the DB user = self.bunny.login(user_name, passwd) # determine user type and add them to the correct queue if (Student.is_stu(user)): self.stu_queue.push(user) elif (Tutor.is_tut(user)): self.tut_queue.add(user) # newly registered users should check the queue Student queue self.__dispatch_tut() return user
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