calculate time left too

master
Paul Walko 2018-04-25 15:20:56 +00:00
parent e6103169cb
commit 0e90f31d50
1 changed files with 9 additions and 4 deletions

View File

@ -102,7 +102,12 @@ def allowed_drinks(id):
drinks_left = int(math.ceil((.06 - bac) / one_drink)) drinks_left = int(math.ceil((.06 - bac) / one_drink))
checkpoint("Allowed drinks for id \'{}\': {}".format(id, drinks_left)) checkpoint("Allowed drinks for id \'{}\': {}".format(id, drinks_left))
return drinks_left # Calculate time left till they can drink again
time_left = 0
if bac > .06:
time_left = ((bac - .06) / .01) * (2 / 3)
return drinks_left, time_left
def order_callback(ch, method, properties, body): def order_callback(ch, method, properties, body):
"""Process 1 drink being ordered """Process 1 drink being ordered
@ -118,7 +123,7 @@ def order_callback(ch, method, properties, body):
port = int(client_params.get('port')) port = int(client_params.get('port'))
add_drink(id) add_drink(id)
drinks = allowed_drinks(id) drinks, time = allowed_drinks(id)
# Add drink for user # Add drink for user
@ -130,7 +135,7 @@ def order_callback(ch, method, properties, body):
checkpoint("Created socket at {} on port {}".format(host, port)) checkpoint("Created socket at {} on port {}".format(host, port))
# Send num drinks to client # Send num drinks to client
s.send(pickle.dumps(drinks)) s.send(pickle.dumps((drinks, time)))
s.close() s.close()
except Exception as ex: except Exception as ex:
print(ex) print(ex)