You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.3 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. import sort_date
  2. correct_locs = []
  3. temp = None
  4. moved_item = None
  5. moved_item_loc = None
  6. exp_date = []
  7. shelf_new = []
  8. repeats = 0
  9. def backArray(myArray):
  10. global shelf_back
  11. shelf_back = []
  12. for i in range(len(myArray)):
  13. shelf_back.append(myArray[i])
  14. def eqArray(myArray):
  15. global exp_date
  16. exp_date = []
  17. for i in range(len(myArray)):
  18. exp_date.append(myArray[i])
  19. def place():
  20. global exp_date
  21. global shelf_new
  22. global repeats
  23. global shelf_back
  24. repeats += 1
  25. backArray(exp_date)
  26. moved_item = None
  27. moved_item_loc = None
  28. if (exp_date[len(exp_date) - 1] != None):
  29. empty_loc = exp_date.index(None)
  30. moved_item_loc = exp_date.index(shelf_new[empty_loc])
  31. reps = 0
  32. while True:
  33. reps += 1
  34. if (moved_item_loc in correct_locs):
  35. exp_date.pop(moved_item_loc)
  36. moved_item_loc = exp_date.index(shelf_new[empty_loc]) + reps
  37. continue
  38. break
  39. eqArray(shelf_back)
  40. moved_item = exp_date[moved_item_loc]
  41. if (exp_date[moved_item_loc] != shelf_new[moved_item_loc]):
  42. exp_date[moved_item_loc] = None
  43. exp_date[empty_loc] = moved_item
  44. correct_locs.append(empty_loc)
  45. print " Moved item {0} to location {1}. Location {2} is now empty!".format(moved_item, empty_loc + 1,
  46. moved_item_loc + 1)
  47. print "============================================================================"
  48. else:
  49. print " Leaving item {0} in location {1}. Location {2} is still empty!".format(moved_item,
  50. moved_item_loc + 1,
  51. empty_loc + 1)
  52. print "============================================================================"
  53. correct_locs.append(moved_item_loc)
  54. place()
  55. else:
  56. return
  57. def generate(dates,date_cur):
  58. global exp_date
  59. global shelf_new
  60. global repeats
  61. exp_date = sort_date. calcDate(dates,date_cur)
  62. shelf_back = exp_date[:]
  63. try:
  64. expired = exp_date.count(-1)
  65. for i in range(expired):
  66. shelf_back.pop(shelf_back.index(-1))
  67. shelf_new = sorted(shelf_back)
  68. for i in range(expired):
  69. shelf_new.append(-1)
  70. except ValueError:
  71. print('')
  72. exp_date.append(None)
  73. shelf_new.append(None)
  74. repeats = 0
  75. print "\n\n\n//////////////////////////////////////////////////////////////////////////////"
  76. print(" {} ".format(exp_date))
  77. print(" {} ".format(shelf_new))
  78. print "/////////////////////////////////////////////////////////////////////////////\n\n\n"
  79. while True:
  80. if(repeats < len(exp_date)):
  81. for i in range(len(exp_date)):
  82. if(exp_date[len(exp_date)-1] == None):
  83. if(exp_date[i] == shelf_new[i]):
  84. continue
  85. else:
  86. exp_date[len(exp_date)-1] = exp_date[i]
  87. print '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
  88. print ' TEMP IS EMPTY, MOVING {0} FROM LOCATION {1} TO THE TEMP'.format(exp_date[i],i+1)
  89. print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
  90. print "============================================================================"
  91. exp_date[i] = None
  92. else:
  93. break
  94. place()
  95. try:
  96. print('***********************************************************************************')
  97. print(' The last {} items have expired, throwing them away.'.format(len(exp_date)-shelf_new.index(-1)-1))
  98. print('***********************************************************************************')
  99. except ValueError:
  100. print(" No items have expired")
  101. print('***********************************************************************************')