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.

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