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.

183 lines
5.4 KiB

  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. pickup = []
  11. replace = []
  12. def throw_check():
  13. for i in range(0,len(moves_return),2):
  14. loc = i + 2;
  15. if moves_return[i + 1] != 0:
  16. break
  17. if 0 in moves_return[loc:]:
  18. return True
  19. return False
  20. def seperate():
  21. global pickup
  22. global replace
  23. for i in range(1,len(moves_return),2):
  24. pickup.append(moves_return[i-1])
  25. replace.append(moves_return[i])
  26. def backArray( myArray ):
  27. global shelf_back
  28. shelf_back = [ ]
  29. for i in range( len( myArray ) ):
  30. shelf_back.append( myArray[ i ] )
  31. def eqArray( myArray ):
  32. global exp_date
  33. exp_date = [ ]
  34. for i in range( len( myArray ) ):
  35. exp_date.append( myArray[ i ] )
  36. def place():
  37. global exp_date
  38. global shelf_new
  39. global repeats
  40. global shelf_back
  41. global moves_return
  42. repeats += 1
  43. backArray( exp_date )
  44. moved_item = None
  45. moved_item_loc = None
  46. if (exp_date[ len( exp_date ) - 1 ] != None):
  47. empty_loc = exp_date.index( None )
  48. moved_item_loc = exp_date.index( shelf_new[ empty_loc ] )
  49. reps = 0
  50. while True:
  51. reps += 1
  52. if (moved_item_loc in correct_locs):
  53. exp_date.pop( moved_item_loc )
  54. moved_item_loc = exp_date.index( shelf_new[ empty_loc ] ) + reps
  55. continue
  56. break
  57. eqArray( shelf_back )
  58. moved_item = exp_date[ moved_item_loc ]
  59. if (exp_date[ moved_item_loc ] != shelf_new[ moved_item_loc ]):
  60. exp_date[ moved_item_loc ] = None
  61. exp_date[ empty_loc ] = moved_item
  62. correct_locs.append( empty_loc )
  63. print " Moved item {0} to location {1}. Location {2} is now empty!".format( moved_item,
  64. empty_loc + 1,
  65. moved_item_loc + 1 )
  66. print "============================================================================="
  67. moves_return.append( str( moved_item_loc + 1 ) )
  68. moves_return.append( str( empty_loc + 1 ) )
  69. else:
  70. print " Leaving item {0} in location {1}. Location {2} is still empty!".format( moved_item,
  71. moved_item_loc + 1,
  72. empty_loc + 1 )
  73. print "============================================================================"
  74. correct_locs.append( moved_item_loc )
  75. place()
  76. else:
  77. return
  78. def faster():
  79. global moves_return
  80. for i in range( 1, len( moves_return ) - 1, 2 ):
  81. if (moves_return[ i ] == moves_return[ i + 1 ]):
  82. moves_return.pop( i )
  83. moves_return.pop( i )
  84. faster()
  85. else:
  86. continue
  87. return moves_return
  88. def generate( dates, date_cur ):
  89. global exp_date
  90. global shelf_new
  91. global repeats
  92. global moves_return
  93. shelf_new = [ ]
  94. moves_return = [ ]
  95. exp_date = sort_date.calcDate( dates, date_cur )
  96. shelf_back = exp_date[ : ]
  97. try:
  98. expired = exp_date.count( -1 )
  99. for i in range( expired ):
  100. shelf_back.pop( shelf_back.index( -1 ) )
  101. shelf_new = sorted( shelf_back )
  102. for i in range( expired ):
  103. shelf_new.append( -1 )
  104. except ValueError:
  105. print('')
  106. exp_date.append( None )
  107. shelf_new.append( None )
  108. repeats = 0
  109. print "\n\n\n//////////////////////////////////////////////////////////////////////////////"
  110. print(" {} ".format( exp_date ))
  111. print(" {} ".format( shelf_new ))
  112. print "/////////////////////////////////////////////////////////////////////////////\n\n\n"
  113. while True:
  114. if (repeats < len( exp_date )):
  115. for i in range( len( exp_date ) ):
  116. if (exp_date[ len( exp_date ) - 1 ] == None):
  117. if (exp_date[ i ] == shelf_new[ i ]):
  118. continue
  119. else:
  120. exp_date[ len( exp_date ) - 1 ] = exp_date[ i ]
  121. print '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
  122. print ' TEMP IS EMPTY, MOVING {0} FROM LOCATION {1} TO THE TEMP'.format( exp_date[ i ],
  123. i + 1 )
  124. print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n'
  125. print "============================================================================"
  126. exp_date[ i ] = None
  127. moves_return.append( str( i + 1 ) )
  128. moves_return.append( str( len( exp_date ) ) )
  129. else:
  130. break
  131. place()
  132. try:
  133. print('***********************************************************************************')
  134. print(' The last {} items have expired, throwing them away.'.format(
  135. len( exp_date ) - shelf_new.index( -1 ) - 1 ))
  136. print('***********************************************************************************')
  137. if (len( shelf_new ) != 3):
  138. for i in range( len( shelf_new ) - 1, len( shelf_new ) - shelf_new.index( -1 ), -1 ):
  139. print "aaa"
  140. moves_return.append( str( i ) )
  141. moves_return.append( "0" )
  142. else:
  143. for i in range( len( shelf_new ), len( shelf_new ) - shelf_new.index( -1 ), -1 ):
  144. print "aaa"
  145. moves_return.append( str( i - 1 ) )
  146. moves_return.append( "0" )
  147. except ValueError:
  148. print(" No items have expired")
  149. print('***********************************************************************************')
  150. faster()
  151. return moves_return
  152. print generate( [ "11.07.2019", "12.09.2019" ], "10.08.2019" )
  153. seperate()
  154. print(pickup)
  155. print replace