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