Created
March 14, 2016 03:09
-
-
Save adpoe/69883e90dd0fd9e78b9a to your computer and use it in GitHub Desktop.
Sample Serve for Python Simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################### | |
##### AIRPORT SERVERS ##### | |
########################### | |
class CheckInServer: | |
""" Class used to model a server at the Check-in terminal | |
""" | |
def __init__(self): | |
""" Initialize the class variables | |
""" | |
self.service_time = 0.0 | |
self.busy = False | |
self.customer_being_served = q.Queue() | |
self.is_first_class = False | |
self.customers_added = 0 | |
self.customers_served = 0 | |
self.idle_time = 0.00 | |
def set_service_time(self, passenger_type): | |
""" Sets the service time for a new passenger | |
:param passenger_type: either "commuter" or "international" | |
""" | |
self.service_time = ag.gen_check_in_service_time_per_passenger( passenger_type ) | |
self.busy = True | |
def update_service_time(self): | |
""" Updates the service time and tells us if the server is busy or not | |
""" | |
self.service_time -= 0.01 | |
if self.service_time <= 0: | |
self.service_time = 0 | |
self.busy = False | |
if not self.is_busy(): | |
self.idle_time += 0.01 | |
def is_busy(self): | |
""" Call this after updating the service time at each change in system time (delta). Tells us if server is busy. | |
:return: True if server is busy. False if server is NOT busy. | |
""" | |
return self.busy | |
def add_customer(self, new_passenger): | |
""" Adds a customer to the sever and sets his service time | |
:param new_passenger: the passenger we are adding | |
""" | |
# get the type of flight his passenger is on | |
type_of_flight = new_passenger.type_of_flight | |
# add the passenger to our service queue | |
self.customer_being_served.put_nowait(new_passenger) | |
# set the service time, depending on what type of flight the customer is on | |
self.set_service_time(type_of_flight) | |
# update the count of customers added | |
self.customers_added += 1 | |
def complete_service(self): | |
""" Models completion of our service | |
:return: the customer who has just finished at this station | |
""" | |
# return completed_customer | |
next_customer = None | |
# only try to pull a customer from the queue if we are NOT busy | |
# AND the queue isn't empty. ELSE, we just return a None | |
if not self.is_busy() and not self.customer_being_served.empty(): | |
next_customer = self.customer_being_served.get_nowait() | |
self.customer_being_served.task_done() | |
self.customers_served += 1 | |
else: | |
next_customer = None | |
return next_customer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment