main.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import hashlib
  2. import sys
  3. from tkinter import *
  4. import helpers
  5. root = Tk()
  6. titleLabel = StringVar()
  7. text = StringVar()
  8. filesInfo = None
  9. csvFiles = None
  10. state = None
  11. acceptedDataCSV = None
  12. rejectedDataCSV = None
  13. def findDuplicate (hashDict, title):
  14. if title in hashDict:
  15. return True
  16. else:
  17. return False
  18. def acceptPaper (file, csvRow, index):
  19. global state
  20. global acceptedDataCSV
  21. fileFilter = helpers.getFilter(file)
  22. data = fileFilter.getCSVData(csvRow)
  23. digest = hashlib.sha256(str.encode(fileFilter.getTitle(csvRow))).hexdigest()
  24. duplicate = findDuplicate(rejectedDataCSV, digest) or findDuplicate(acceptedDataCSV, digest)
  25. if duplicate:
  26. state['duplihttps://mail.google.com/mail/u/0/#inboxcate'] += 1
  27. else:
  28. data.append("{0} - {1}".format(file['path'],index))
  29. acceptedDataCSV[digest] = data
  30. state['accepted'] += 1
  31. return
  32. def rejectPaper (file, csvRow, index):
  33. global rejectedDataCSV
  34. global state
  35. fileFilter = helpers.getFilter(file)
  36. data = fileFilter.getCSVData(csvRow)
  37. digest = hashlib.sha256(str.encode(fileFilter.getTitle(csvRow))).hexdigest()
  38. duplicate = findDuplicate(rejectedDataCSV, digest) or findDuplicate(acceptedDataCSV, digest)
  39. if duplicate:
  40. state['duplicate'] += 1
  41. else:
  42. data.append("{0} - {1}".format(file['path'],index))
  43. rejectedDataCSV[digest] = data
  44. state['rejected'] += 1
  45. return
  46. def rejectButtonHandler (*arg):
  47. global state
  48. global csvFiles
  49. index = state['row_index']
  50. fileIndex = state['file_index']
  51. fileTuple = csvFiles[fileIndex]
  52. rejectPaper(fileTuple[1], fileTuple[0][index], index)
  53. nextPaper()
  54. return
  55. def acceptButtonHandler (*arg):
  56. global state
  57. global csvFiles
  58. index = state['row_index']
  59. fileIndex = state['file_index']
  60. fileTuple = csvFiles[fileIndex]
  61. acceptPaper(fileTuple[1], fileTuple[0][index], index)
  62. nextPaper()
  63. return
  64. def updateAndClear (textField, *args):
  65. textField.config(state=NORMAL)
  66. textField.delete('1.0', END)
  67. textField.insert(INSERT, text.get())
  68. textField.tag_add("center", '1.0', END)
  69. textField.config(state=DISABLED)
  70. def loadFiles ():
  71. global filesInfo
  72. global csvFiles
  73. global state
  74. global root
  75. global acceptedDataCSV
  76. global rejectedDataCSV
  77. filesInfo = helpers.loadConfigFile()
  78. if len(filesInfo) == 0:
  79. sys.exit("csvconfig.txt not found. You need this file to run the program")
  80. state = helpers.loadState(root)
  81. acceptedDataCSV = helpers.restoreAcceptedCSV() #load default file, if present append else create new one
  82. rejectedDataCSV = helpers.restoreRejectedCSV()
  83. if len(acceptedDataCSV) == 0:
  84. acceptedDataCSV['header'] = helpers.FINAL_CSV_HEADERS
  85. if len(rejectedDataCSV) == 0:
  86. rejectedDataCSV['header'] = helpers.FINAL_CSV_HEADERS
  87. csvFiles = [(list(f[0]), f[1]) for f in helpers.loadFiles(filesInfo)]
  88. setPaperFromState()
  89. def setPaperFromState ():
  90. global titleLabel
  91. global text
  92. fileIndex = state['file_index']
  93. if fileIndex >= len(filesInfo):
  94. return #finished processing
  95. fileList = csvFiles[fileIndex][0]
  96. index = state['row_index']
  97. if index >= len(fileList):
  98. state['file_index'] += 1
  99. state['row_index'] = 0
  100. setPaperFromState()
  101. else:
  102. file = fileList[index]
  103. fileFilter = helpers.getFilter(csvFiles[fileIndex][1])
  104. title = fileFilter.getTitle(file)
  105. abstract = fileFilter.getAbstract(file)
  106. titleLabel.set(title)
  107. text.set(abstract)
  108. def nextPaper ():
  109. global titleLabel
  110. global text
  111. global root
  112. fileIndex = state['file_index']
  113. if fileIndex >= len(filesInfo):
  114. helpers.removeStateFile()
  115. helpers.writeFinalLog(state)
  116. helpers.saveAcceptedCSV(acceptedDataCSV)
  117. helpers.saveRejectedCSV(rejectedDataCSV)
  118. root.destroy()#acabou, fecha essa porra
  119. return
  120. fileList = csvFiles[fileIndex][0]
  121. index = state['row_index'] = state['row_index'] + 1
  122. if index >= len(fileList):
  123. state['file_index'] += 1
  124. state['row_index'] = -1
  125. nextPaper()
  126. else:
  127. file = fileList[index]
  128. fileFilter = helpers.getFilter(csvFiles[fileIndex][1])
  129. title = fileFilter.getTitle(file)
  130. abstract = fileFilter.getAbstract(file)
  131. titleLabel.set(title)
  132. text.set(abstract)
  133. def onClosing ():
  134. global state
  135. global root
  136. global acceptedDataCSV
  137. global rejectedDataCSV
  138. helpers.saveState(state)
  139. helpers.saveAcceptedCSV(acceptedDataCSV)
  140. helpers.saveRejectedCSV(rejectedDataCSV)
  141. root.destroy()
  142. def main ():
  143. global root
  144. root.title('Reviewer')
  145. root.geometry('800x600')
  146. topFrame = Frame(root)
  147. bottomFrame = Frame(root)
  148. bottomFrame.pack(side=BOTTOM)
  149. topFrame.pack(side=TOP, fill=BOTH, expand=True)
  150. label = Label(root, textvariable=titleLabel, relief=RAISED)
  151. label.pack(in_=topFrame, fill=BOTH, side=TOP)
  152. textField = Text(root)
  153. textField.tag_configure("center", wrap=WORD)
  154. textField.pack(in_=topFrame, fill=BOTH, side=TOP)
  155. accept = Button(root, text ="Accept Paper", command = acceptButtonHandler)
  156. root.bind('<Right>', lambda e: acceptButtonHandler())
  157. accept.pack(in_=bottomFrame, side=LEFT)
  158. reject = Button(root, text ="Reject Paper", command = rejectButtonHandler)
  159. root.bind('<Down>', lambda e: rejectButtonHandler())
  160. reject.pack(in_=bottomFrame, side=LEFT)
  161. textField.insert(INSERT, text.get())
  162. text.trace('w', lambda *arg: updateAndClear(textField))
  163. textField.config(state=DISABLED)
  164. root.protocol("WM_DELETE_WINDOW", onClosing)
  165. root.mainloop()
  166. loadFiles()
  167. main()