Guest User

Untitled

a guest
Jun 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1.  
  2. import Order
  3. import BoundedPriorityQueue
  4. import string
  5. def main_function():
  6. orderFile = open("inputFileName", 'r')
  7. lines = orderFile.readlines()
  8. myQueue = BoundedPriorityQueue.BoundedPriorityQueue(4)
  9. orderNumber=0
  10. totalSales = {"redOrders":0, "redItems":0, "whiteOrders":0, "whiteItems":0, "blueOrders":0, "blueItems":0}
  11. for item in lines:
  12. color=""
  13. name=""
  14. quantity=0
  15. priority=0
  16. print item.number
  17. if "name:" in item:
  18. name = item
  19.  
  20. if name.isdigit():
  21. print "you cannot enter a number for the customer name. Order cancelled."
  22. continue
  23.  
  24.  
  25. if "color:" in item:
  26. index = string.find(item, ": ")
  27. color = item[index+1:]
  28. if color !="red" and color != "white" and color !="blue":
  29. print "Sorry that's not a color we offer. Order cancelled."
  30. continue
  31.  
  32. if "quantity:" in item:
  33. index = string.find(item, ": ")
  34. quantity = item[index+1:]
  35.  
  36. # check if the quantity is a negative number or not a number
  37. if int(quantity) < 0:
  38. print "You can't order a negative number of our product! Order cancelled. "
  39. continue
  40.  
  41.  
  42.  
  43. if "priority:" in item:
  44. index = string.find(item, ": ")
  45. priority = item[index+1:]
  46.  
  47. order = Order.Order(orderNumber, name, color, quantity, priority)
  48.  
  49. if myQueue.isFull:
  50. print "Clearing the orders queue:"
  51. while (myQueue.is_empty() != True):
  52.  
  53. item = myQueue.dequeue()
  54. if item.color == "red":
  55. totalSales["redItems"] = totalSales["redItems"] + quantity
  56. totalSales["redOrders"] = totalSales["redOrders"] + 1
  57. if item.color == "white":
  58. totalSales["whiteItems"] = totalSales["whiteItems"] + quantity
  59. totalSales["whiteOrders"] = totalSales["whiteOrders"] + 1
  60. if item.color == "blue":
  61. totalSales["blueItems"] = totalSales["blueItems"] + quantity
  62. totalSales["blueOrders"] = totalSales["blueOrders"] + 1
  63.  
  64. print " Order shipped:"
  65. print " Order " + str(item.number) + ": customer " + item.name + " requests " + str(item.quantity) + " " + item.color + " widgets. (priority: "+ str(item.priority)+")"
  66. print "Queue empty"
  67.  
  68.  
  69. print "Enqueuing order:"
  70. print " Order " + str(item.number) + ": customer " + item.name + " requests " + str(item.quantity) + " " + item.color + " widgets. (priority: " + str(item.priority) + ")"
  71. myQueue.enqueue(order)
  72. orderNumber = orderNumber + 1
  73.  
  74.  
  75.  
  76. print " "
  77. print "Total sales"
  78. print " Red orders: " + totalSales["redOrders"] + " Total red widgets: " + totalSales["redItems"]
  79. print " White orders: " + totalSales["whiteOrders"] + " Total white widgets: " + totalSales["whiteItems"]
  80. print " Blue orders: " + totalSales["blueOrders"] + " Total blue widgets: " + totalSales["blueItems"]
  81.  
  82.  
  83.  
  84.  
  85. if __name__ == "__main__":
  86. main_function()
Add Comment
Please, Sign In to add comment