-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecking_UI.py
479 lines (447 loc) · 23.8 KB
/
checking_UI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
#checking_UI.py
from guizero import *
import readfile
import matrixgenerate, instruction
import textwrap
class checking_UI:
def __init__(self):
self.filename = 'shelflist.xlsx'
self.shelfCheckWindow = App(title = "Shelf Checking is in Progress", width = 1000)
Text(self.shelfCheckWindow, text="", size=12)
self.booktitle_box = Box(self.shelfCheckWindow, width=900, height=110)
self.bookList, self.bookDic = readfile.readfile(self.filename)
self.currentBook = self.bookList.getHead()
self.BookTitle = None
self.BookCallNum = None
self.BookBarcode = None
self.BookVersion = None
self.ButtonBookFound = None #button number0
self.ButtonSubmit = None #button number1
self.barcodeBox = None
self.reachlast = False
self.NbooktracerReachLast = False
self.startCounting = False
self.theNthBookTracer = self.bookList.getHead()
self.N = 7 #this is heuristic value of N
self.Noffset = 0
self.desiredBookArray = []
self.desiredBookDic = {}
self.expandDesiredBookArray(self.N)
self.actualBookArray = []
self.lostBookDic = {}
self.misplaceCount = 0 #Number of books that are misplaced, but within shelf.
self.outsiderBookCount = 0 #Number of books that are from other shelves.
self.lostBookCount = 0
self.outsiderBooks = []
def reportGen(self):
result = {}
result['Misplaced'] = self.misplaceCount
result['Misplaced Percentage'] = self.misplaceCount/len(self.bookList)
result['Stranger'] = self.outsiderBookCount
result['Stranger barcode'] = self.outsiderBooks
result['LostCount'] = self.lostBookCount
return result
def checkIfCurrentBookAndFirstDeisreMatch(self):
print(self.currentBook,self.theNthBookTracer)
if self.currentBook != self.theNthBookTracer:
for item in self.bookList:
if item == self.currentBook.next_book:
self.theNthBookTracer = item
break
def destroyWindow(self):
self.shelfCheckWindow.warn('Session Over', 'Your Session is over, congratulations')
self.shelfCheckWindow.destroy()
def expandDesiredBookArray(self, count = 1):
if not self.NbooktracerReachLast:
for i in range(count):
if not self.NbooktracerReachLast:
self.desiredBookArray.append(self.theNthBookTracer)
print('currently adding',self.theNthBookTracer.barcode)
self.desiredBookDic[self.theNthBookTracer.barcode] = True
self.theNthBookTracer = self.theNthBookTracer.next_book
if self.theNthBookTracer is None:
self.NbooktracerReachLast = True
def start(self, student = None):
def toEnter():
self.barcodeBox.value = ''
self.barcodeBox.text_color='black'
print(student)
while not self.reachlast:#the window should be destroyed already by the previous method
self.BookTitle = Text(self.booktitle_box, text =textwrap.fill(self.currentBook.title[:-1], width=70), size=19)
self.BookCallNum = Text(self.shelfCheckWindow, text = self.currentBook.call_number, size = 40)
self.BookVersion = Text(self.shelfCheckWindow, text= self.currentBook.version, size=20)
Text(self.shelfCheckWindow, text="", size=5)
# barcode_box=Box(self.shelfCheckWindow, width=900, height=100, border=True)
self.barcodeBox = TextBox(self.shelfCheckWindow, text="scan in barcode if not found", width=40)
self.barcodeBox.text_size = 20
self.barcodeBox.text_color = "grey"
self.barcodeBox.when_clicked = toEnter
Text(self.shelfCheckWindow, text="", size=10)
self.ButtonBookFound = PushButton(self.shelfCheckWindow, text = 'Book Found', command = self.foundButtonPressed, width="fill", height="fill", align='left')
self.ButtonBookFound.text_size = 20
self.ButtonSubmit = PushButton(self.shelfCheckWindow, text = 'Submit', command = self.submitButtonPressed, width='fill', height='fill', align='right')
self.ButtonSubmit.text_size = 20
self.shelfCheckWindow.set_full_screen()
print(self.desiredBookDic)
self.shelfCheckWindow.display()
def showNextBook(self):
if self.currentBook is not None:
if self.currentBook.next_book is not None:
#if self.currentBook.next_book.ifNeedsSkip():
while int(self.currentBook.next_book.barcode) in self.desiredBookDic and self.desiredBookDic[int(self.currentBook.next_book.barcode)] is False:
print(self.currentBook.title,'skiped')
self.desiredBookDic[int(self.currentBook.next_book.barcode)] = True
self.currentBook = self.currentBook.next_book
self.currentBook = self.currentBook.next_book
if self.currentBook.ifneedsAnounce():
self.shelfCheckWindow.warn('Reshelf', 'This next book needs to be reshelved to the current position')
self.BookTitle.clear()
self.BookTitle.append(textwrap.fill(self.currentBook.title[:-1], width=70))
self.BookCallNum.clear()
self.BookCallNum.append(self.currentBook.call_number)
self.BookVersion.clear()
self.BookVersion.append(self.currentBook.version)
if self.currentBook.next_book is None:
self.reachlast = True
else:
self.reachlast = True
def checkIfIsTimeToReorder(self):
#A session should only stop when: startcounting is set
#and
#The size of actualBook became N
if len(self.desiredBookArray) == len(self.actualBookArray) + self.Noffset:
self.reorderLoop()
print('End of one reorderLoop')
self.actualBookArray = []
self.desiredBookArray = []
self.desiredBookDic.clear()
self.Noffset = 0
self.checkIfCurrentBookAndFirstDeisreMatch()
self.expandDesiredBookArray(self.N)
self.startCounting = False
pass
def foundButtonPressed(self):
#when the foundbutton has been pressed, check if the startCounting flag is on
#The startCounting flag should be on when within a small session, the first "not in place" book was encountered.
if not self.reachlast:
if(self.startCounting):#this if and else block is used to do the shifitng of the N size block along the linked list
self.actualBookArray.append(self.currentBook)
self.desiredBookDic[int(self.currentBook.barcode)] = True
self.checkIfIsTimeToReorder()
pass
else:
del self.desiredBookDic[int(self.desiredBookArray[0].barcode)]
self.desiredBookArray.remove(self.desiredBookArray[0])
self.expandDesiredBookArray()
self.showNextBook()
else:
#at the end of shelf, no more book to look at
for eachBook in self.lostBookDic:
thisBook = self.lostBookDic[eachBook]
self.lostBookCount += 1
print('lost books', thisBook)
if thisBook.ifneedsAnounce():
self.lostBookCount -= 1
self.misplaceCount += 1
print('this book needs anounce')
nextBookAvailable = thisBook.next_book
while int(nextBookAvailable.barcode) in self.lostBookDic:
nextBookAvailable = nextBookAvailable.next_book
reshelfInstruction = 'Place \n' + thisBook.title + ' in front of \n' + nextBookAvailable.title
self.shelfCheckWindow.warn('Reshelf',reshelfInstruction)
self.destroyWindow()
pass
print(self.desiredBookDic)
def submitButtonPressed(self):
#this button press means a book doesn't match was found
#When the first time in session when the button was pressed, the flag "StartCounting" should be set to True
if self.barcodeBox.value is not None and self.barcodeBox.value != 'scan in barcode if not found':
#The nextbook should sure be printed
print(self.barcodeBox.value)#this is for debug
if int(self.barcodeBox.value) in self.bookDic:#meaning, if this book is belong to the list
shouldShow = True
shouldStart = True
if int(self.barcodeBox.value) in self.lostBookDic: #if this book is lost
shouldStart = False
shouldShow = False#shouldn't show the next book
self.shelfCheckWindow.warn('warning', 'Remove this book and put it on the cart, this will be reshelfed')
if int(self.barcodeBox.value) in self.desiredBookDic:
if self.desiredBookDic[int(self.barcodeBox.value)] == True:
self.Noffset += 1
self.desiredBookDic[int(self.barcodeBox.value)] = False
self.desiredBookDic[int(self.currentBook.barcode)] = False
print('within method', self.desiredBookDic)
else:
print('reached here')
self.Noffset -= 1
self.desiredBookDic[int(self.barcodeBox.value)] = True
self.shelfCheckWindow.warn('Next Book', 'Please look at the next Book.')
shouldShow = False
#self.bookDic[int(self.barcodeBox.value)].needsSkip()
else:
self.desiredBookDic[int(self.currentBook.barcode)] = False
self.bookDic[int(self.barcodeBox.value)].needsAnounce()
print(self.bookDic[int(self.barcodeBox.value)].title,'needs anounce')
if (not self.startCounting) and shouldStart:
self.startCounting = True
if shouldStart:
self.actualBookArray.append(self.bookDic[int(self.barcodeBox.value)])
if shouldShow:
self.checkIfIsTimeToReorder()
self.showNextBook()
else:
self.outsiderBookCount += 1
self.outsiderBooks.append(self.barcodeBox.value + '\n')
self.shelfCheckWindow.warn('warning', 'Remove this book and put it on the cart, this is gonna be returned to the desk')
#reset the barcodebox
self.barcodeBox.value = 'scan in barcode if not found'
self.barcodeBox.text_color = "grey"
else:
self.shelfCheckWindow.warn('warning', 'Please put in barcode before hitting button')
print(self.desiredBookDic)
def reorderLoop(self): #this method initiates the reorder loop.
def exitReshelf():
print('pressedd')
InstructionWindow.destroy()
'''
def findBookToDealWith(handBook):
ind = 0
for book in actualBookArray:
if book == handBook:
return ind
ind += 1
return -1
def findIfCanInsert():
handBook = actualBookArray[int(self.bookinHand)]
for key in solutionDic:
if solutionDic[key] == '-2':
if desiredBookArray[int(key)+1] == handBook:
return int(key)
return -1
def bookInHandRefresh():
BookInHandText.clear()
print('setting book in hand text to', self.bookinHand)
BookInHandText.append(actualBookArray[int(self.bookinHand)].title)
def bookInHandClear():
self.bookinHand = None
BookInHandText.clear()
BookInHandText.append('Nothing')
def takeOutInstruction(theBook):
InstructionLine1.clear()
InstructionLine1.append('Take Out')
InstructionLine2.clear()
InstructionLine2.append(theBook.title)
InstructionLine3.clear()
InstructionLine3.append('From Shelf')
def putAwayInstruction():
InstructionLine1.clear()
InstructionLine1.append('Put')
InstructionLine2.clear()
InstructionLine2.append('the book in your hand')
InstructionLine3.clear()
InstructionLine3.append('On the cart for future use')
def replaceInstruction(theBook):
InstructionLine1.clear()
InstructionLine1.append('Replace')
InstructionLine2.clear()
InstructionLine2.append(theBook.title)
InstructionLine3.clear()
InstructionLine3.append('with the Book in Hand')
def insertInstruction(theBook):
InstructionLine1.clear()
InstructionLine1.append('Put')
InstructionLine2.clear()
InstructionLine2.append('The book in hand')
InstructionLine3.clear()
done = False
for book in desiredBookArray:
if book is not None:
if book.next_book == theBook:
InstructionLine3.append('to the right of ' + book.title)
done = True
if not done:
if desiredBookArray[1] != theBook:
InstructionLine3.append(('to the left of ' + desiredBookArray[1].title))
else:
InstructionLine3.append(('to the left of ' + desiredBookArray[2].title))
def nextStepShow():
if self.bookinHand is not None:
bookInHandRefresh()
else:
bookInHandClear()
if self.bookinHand is None:
if len(booksNeedRemoval) > 0 :
takeOutInstruction(actualBookArray[int(booksNeedRemoval[0])])
self.bookinHand = booksNeedRemoval[0]
del booksNeedRemoval[0]
#bookInHandRefresh()
else:
if len(solutionInd) > 0:
takeOutInstruction(actualBookArray[int(solutionInd[0])])
self.bookinHand = solutionInd[0]
if self.loophead == None:
self.loophead = actualBookArray[int(self.bookinHand)]
print('loophead', self.loophead)
del solutionInd[0]
#bookInHandRefresh()
else:
exitReshelf()
else:
if self.bookinHand in solutionDic:
print('is it in solutiondic?')
situation = solutionDic[self.bookinHand]#situation can be -2: plugin -1: remove positive number:index
print('situation',situation)
if situation == '-1':#if remove
insertPlace = findIfCanInsert()
if insertPlace != -1:
insertInstruction(actualBookArray[int(self.bookinHand)])
del solutionDic[self.bookinHand]
solutionInd.remove(str(insertPlace))
del solutionDic[str(insertPlace)]
self.bookinHand = None
else:
temp = None
bookHand = actualBookArray[int(self.bookinHand)]
print('bh',bookHand)
for key in solutionDic:
if desiredBookArray[int(solutionDic[key])] == bookHand:
bookToReplace = actualBookArray[int(key)]
temp = key
print('temp:',temp)
replaceInstruction(bookToReplace)
print('about to delete', self.bookinHand)
del solutionDic[self.bookinHand]
self.bookinHand = temp
print('then, delete', self.bookinHand)
del solutionDic[self.bookinHand]
solutionInd.remove(self.bookinHand)
break
print('ever been here?')
if temp == None:
insertInstruction(actualBookArray[int(self.bookinHand)])
self.bookinHand = None
else:
bookToReplace = desiredBookArray[int(self.bookinHand)]
if bookToReplace != self.loophead:
replaceInstruction(bookToReplace)
del solutionDic[self.bookinHand]
self.bookinHand = str(findBookToDealWith(bookToReplace))
solutionInd.remove(self.bookinHand)
print('okay I am here, book in hand', self.bookinHand)
else:
insertInstruction(actualBookArray[int(self.bookinHand)])
print('maybe Im here')
del solutionDic[self.bookinHand]
self.loophead = None
self.bookinHand = None
else:
print("This next book in hand is not in the solution dic")
print(self.bookinHand)
print(solutionDic)
inserted = False
for key in solutionDic:
if solutionDic[key] == '-2':
if desiredBookArray[int(key)+1] == actualBookArray[int(self.bookinHand)]:
insertInstruction(actualBookArray[int(self.bookinHand)])
#del solutionDic[self.bookinHand]
solutionInd.remove(key)
del solutionDic[key]
self.bookinHand = None
inserted = True
break
if not inserted:
putAwayInstruction()
bookInHandClear()
print(booksNeedRemoval)
print(solutionDic)
print(solutionInd)
pass
#It takes in the actualBookArray and desiredBookArray, it will call the matrixgenerate.py
#after getting the matrix back from the call, it will pass the matrix to the instruction.py
#the instruction.py will have a solution dictionary and solution index passed back.
#Using the solution dictionary and solution index, the book reordering solution should be performed at this order
#Create a temporary Book object, as "Book in the hand", its initial value should be the first book needed to be fixed on the shelf
#The loop should be: use the "Book in the hand" as the key, find where it should fit, replace it, and the replaced book is the new
#"Book in the hand"
#For the extra book in the list, it will point to "-1". We can let the student pull out all the books needed to be picked out first
'''
desiredBookArray =[None]+self.desiredBookArray
actualBookArray = [None]+self.actualBookArray
for eachBook in self.desiredBookArray:
#print('key',eachBook)
#print('value',self.desiredBookDic[eachBook])
if(eachBook not in self.actualBookArray):
desiredBookArray.remove(eachBook)
self.lostBookDic[eachBook.barcode] = eachBook#add this book to the lostBookDictionary
print(self.desiredBookDic)
print("desiredBook")
for i in desiredBookArray:# this is for debugging#TODO:CLEAR THIS OUT WHEN PACK
if i is not None:
print(i.title + i.version)
print('')
print("CurrentBook")
for i in actualBookArray:# this is for debugging#TODO:CLEAR THIS OUT WHEN PACK
if i is not None:
print(i.title + i.version)
print('')
#reorderWindow.full_screen = True
#Calling matrix generation for desired list and actual list
mg = matrixgenerate.matrixgenerate(desiredBookArray, actualBookArray)
mg.generating()
matrix = mg.getMatrix()
ig = instruction.instructionGenerate(matrix)
ig.printMinSteps()
ig.tracBackToTop()
#ig.flipSolutionIndex()
solutionDic, solutionInd = ig.getSolution()
print(solutionDic)
print(solutionInd)
print(desiredBookArray)
print(actualBookArray)
solutionString = ''
for eachKey in solutionDic:
self.misplaceCount += 1
if solutionDic[eachKey] == '-1':
solutionString += ('Remove \n' + actualBookArray[int(eachKey)].call_number + '\n from shelf\n')
elif solutionDic[eachKey] == '-2':
solutionString += ('Add \n' + desiredBookArray[int(eachKey)].call_number + '\n to the left of \n' + desiredBookArray[int(eachKey)].next_book.call_number + '\n')
else:
print(eachKey,solutionDic[eachKey])
solutionString += 'Replace \n' + actualBookArray[int(eachKey)].call_number + '\n with \n' + desiredBookArray[int(solutionDic[eachKey])].call_number + '\n'
if solutionString != '':
InstructionWindow = Window(self.shelfCheckWindow, title="Reshelfing")
titleBox = Box(InstructionWindow)
Text(titleBox, text="", size = 5)
Text(titleBox, text="Please Following the instructions below", size = 20, color="red")
Text(titleBox, text="", size = 5)
instructionBox = Box(InstructionWindow, height='fill', width='fill')
InstructionLine1 = Text(instructionBox, text = solutionString, size=20)
finishButton = PushButton(titleBox, text="Finish",command = exitReshelf, align='bottom', width=900, height=3)
finishButton.text_size = 18
Text(titleBox, text="", size = 5)
InstructionWindow.set_full_screen()
'''booksNeedRemoval = []
for step in solutionInd:
if(int(solutionDic[step] == '-1')):
solutionInd.remove(step)
#del solutionDic[step]
booksNeedRemoval.append(step)
#The following commented line are for step-by-step instruction generation
self.bookinHand = None
self.loophead = None
if(solutionInd != [] or booksNeedRemoval != []):
reorderWindow = Window(self.shelfCheckWindow, title="Reshelfing")
titleBox = Box(reorderWindow)
titleText = Text(titleBox, text = "Please wait until the solution is generated", size = 20, color="red", font="Arial")
instructionBox = Box(reorderWindow)
Text(instructionBox, text = "Book in Hand")
BookInHandText = Text(instructionBox, text = "Nothing")
InstructionLine1 = Text(instructionBox, text = "Instruction Line 1")
InstructionLine2 = Text(instructionBox, text = "Instruction Line 2")
InstructionLine3 = Text(instructionBox, text = "Instruction Line 3")
finishButton = PushButton(titleBox, text="Finish",command = exitReshelf)
nextStepButton = PushButton(instructionBox, text="Next Step", command = nextStepShow)
nextStepShow()
reorderWindow.show()
'''
pass