123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- import hashlib
- import sys
- from tkinter import *
- import helpers
- root = Tk()
- titleLabel = StringVar()
- text = StringVar()
- filesInfo = None
- csvFiles = None
- state = None
- acceptedDataCSV = None
- rejectedDataCSV = None
- nextCount = 0
- def findDuplicate (hashDict, title):
- if title in hashDict:
- return True
- else:
- return False
- def acceptPaper (file, csvRow, index):
- global state
- global acceptedDataCSV
- fileFilter = helpers.getFilter(file)
- data = fileFilter.getCSVData(csvRow)
- digest = hashlib.sha256(str.encode(fileFilter.getTitle(csvRow))).hexdigest()
- duplicate = findDuplicate(rejectedDataCSV, digest) or findDuplicate(acceptedDataCSV, digest)
- if duplicate:
- state['duplicate'] += 1
- else:
- data.append("{0} - {1}".format(file['path'],index))
- acceptedDataCSV[digest] = data
- state['accepted'] += 1
- return
- def rejectPaper (file, csvRow, index):
- global rejectedDataCSV
- global state
- fileFilter = helpers.getFilter(file)
- data = fileFilter.getCSVData(csvRow)
- digest = hashlib.sha256(str.encode(fileFilter.getTitle(csvRow))).hexdigest()
- duplicate = findDuplicate(rejectedDataCSV, digest) or findDuplicate(acceptedDataCSV, digest)
- if duplicate:
- state['duplicate'] += 1
- else:
- data.append("{0} - {1}".format(file['path'],index))
- rejectedDataCSV[digest] = data
- state['rejected'] += 1
- return
- def rejectButtonHandler (*arg):
- global state
- global csvFiles
- index = state['row_index']
- fileIndex = state['file_index']
- fileTuple = csvFiles[fileIndex]
- rejectPaper(fileTuple[1], fileTuple[0][index], index)
- nextPaper()
- return
- def acceptButtonHandler (*arg):
- global state
- global csvFiles
- index = state['row_index']
- fileIndex = state['file_index']
- fileTuple = csvFiles[fileIndex]
- acceptPaper(fileTuple[1], fileTuple[0][index], index)
- nextPaper()
- return
- def updateAndClear (textField, *args):
- textField.config(state=NORMAL)
- textField.delete('1.0', END)
- textField.insert(INSERT, text.get())
- textField.tag_add("center", '1.0', END)
- textField.config(state=DISABLED)
- def loadFiles ():
- global filesInfo
- global csvFiles
- global state
- global root
- global acceptedDataCSV
- global rejectedDataCSV
- filesInfo = helpers.loadConfigFile()
- if len(filesInfo) == 0:
- sys.exit("csvconfig.txt not found. You need this file to run the program")
- state = helpers.loadState(root)
- acceptedDataCSV = helpers.restoreAcceptedCSV() #load default file, if present append else create new one
- rejectedDataCSV = helpers.restoreRejectedCSV()
- if len(acceptedDataCSV) == 0:
- acceptedDataCSV['header'] = helpers.FINAL_CSV_HEADERS
- if len(rejectedDataCSV) == 0:
- rejectedDataCSV['header'] = helpers.FINAL_CSV_HEADERS
- csvFiles = [(list(f[0]), f[1]) for f in helpers.loadFiles(filesInfo)]
- def setPaperFromState ():
- global titleLabel
- global text
- fileIndex = state['file_index']
- if fileIndex >= len(filesInfo):
- return #finished processing
- fileList = csvFiles[fileIndex][0]
- index = state['row_index']
- if index >= len(fileList):
- state['file_index'] += 1
- state['row_index'] = 0
- setPaperFromState()
- else:
- file = fileList[index]
- fileFilter = helpers.getFilter(csvFiles[fileIndex][1])
- title = fileFilter.getTitle(file)
- abstract = fileFilter.getAbstract(file)
- titleLabel.set(title)
- text.set(abstract)
- def nextPaper ():
- global titleLabel
- global text
- global root
- global nextCount
- fileIndex = state['file_index']
- if fileIndex >= len(filesInfo):
- helpers.removeStateFile()
- helpers.writeFinalLog(state)
- helpers.saveAcceptedCSV(acceptedDataCSV)
- helpers.saveRejectedCSV(rejectedDataCSV)
- root.destroy()#acabou, fecha essa porra
- return
- fileList = csvFiles[fileIndex][0]
- index = state['row_index'] = state['row_index'] + 1
- if index >= len(fileList):
- state['file_index'] += 1
- state['row_index'] = -1
- nextPaper()
- else:
- nextCount += 1
- if nextCount%10 == 0:
- saveCurrentData()
- file = fileList[index]
- fileFilter = helpers.getFilter(csvFiles[fileIndex][1])
- title = fileFilter.getTitle(file)
- abstract = fileFilter.getAbstract(file)
- titleLabel.set(title)
- text.set(abstract)
- def onClosing ():
- global root
- saveCurrentData()
- root.destroy()
- def saveCurrentData ():
- global state
- global acceptedDataCSV
- global rejectedDataCSV
- helpers.saveState(state)
- helpers.saveAcceptedCSV(acceptedDataCSV)
- helpers.saveRejectedCSV(rejectedDataCSV)
- def updateDup ():
- global acceptedDataCSV
- global rejectedDataCSV
- global state
- tempA = {}
- tempR = {}
- dataR = list(rejectedDataCSV.values())
- for i in range(1,len(dataR)):
- digest = hashlib.sha256(str.encode(dataR[i][0].lower())).hexdigest()
- if digest in tempR:
- print("Found duplicate in rejected: {0}".format(dataR[i][0]))
- state['duplicate'] += 1
- else:
- tempR[digest] = dataR[i]
- dataA = list(acceptedDataCSV.values())
- for i in range(1, len(dataA)):
- digest = hashlib.sha256(str.encode(dataA[i][0].lower())).hexdigest()
- if digest in tempA or digest in tempR:
- print("Found duplicate in accepted: {0}".format(dataA[i][0]))
- state['duplicate'] += 1
- else:
- tempA[digest] = dataA[i]
- state['accepted'] = len(tempA)
- state['rejected'] = len(tempR)
- tempA['header'] = dataA[0]
- tempR['header'] = dataR[0]
- acceptedDataCSV = tempA
- rejectedDataCSV = tempR
- saveCurrentData()
- def main ():
- global root
- root.title('Reviewer')
- root.geometry('800x600')
- topFrame = Frame(root)
- bottomFrame = Frame(root)
- bottomFrame.pack(side=BOTTOM)
- topFrame.pack(side=TOP, fill=BOTH, expand=True)
- label = Label(root, textvariable=titleLabel, relief=RAISED)
- label.pack(in_=topFrame, fill=BOTH, side=TOP)
- textField = Text(root)
- textField.tag_configure("center", wrap=WORD)
- textField.pack(in_=topFrame, fill=BOTH, side=TOP)
- accept = Button(root, text ="Accept Paper", command = acceptButtonHandler)
- root.bind('<Right>', lambda e: acceptButtonHandler())
- accept.pack(in_=bottomFrame, side=LEFT)
- reject = Button(root, text ="Reject Paper", command = rejectButtonHandler)
- root.bind('<Down>', lambda e: rejectButtonHandler())
- reject.pack(in_=bottomFrame, side=LEFT)
- textField.insert(INSERT, text.get())
- text.trace('w', lambda *arg: updateAndClear(textField))
- textField.config(state=DISABLED)
- root.protocol("WM_DELETE_WINDOW", onClosing)
- setPaperFromState()
- #updateDup()
- print("Duplicate count {0}".format(state['duplicate']))
- print("Accepted count {0}".format(state['accepted']))
- print("Rejected count {0}".format(state['rejected']))
- root.mainloop()
- if __name__ == '__main__':
- loadFiles()
- main()
|