def writeGradesFromTurningPoint(self): # This is where the work is done. Need to read in the xml # files that have the sections information in them. Then read # the grade files. The create the xml files for output. #print("Write grades") self.moodleIDNumbers = {} itemScores = TurningPointFile(self) itemScores.setRegradeState(self.overwriteOld.get()) itemScores.setNumericState(self.numericGrade.get()) itemScores.setCSVOutfile(self.writeCSV.get()) # See http://docs.moodle.org/en/Development:Grades for the # details on the xml format. # Go through each xml file that has the section information in it. defaultXMLFileName = None writtenSections = self.specifySectionClassLists(itemScores) # ,[('tpzx files', '.tpzx')]) if(not writtenSections): tkMessageBox.showinfo( "OK", "No section files have been specified. Please choose a default file name for the one xml output file."); if(self.writeCSV.get()): fileExtensions = [('csv files', '.csv')] else: fileExtensions = [('xml files', '.xml')] fileExtensions.append(('all files', '.*')) #fileExtensions.append(('tpzx files', '.tpzx')) defaultXMLFileName = tkFileDialog.asksaveasfile(mode='w',filetypes=fileExtensions); if(defaultXMLFileName): itemScores.addSection(None,defaultXMLFileName,None) else: tkMessageBox.showinfo( "OK", "No section file was given. No action taken") return # Get the clicker ID information clickerIDs = self.getClickerIDResponses() # Prepare to start the process of going through the grade files. numberGradeRows = self.gradeListBox.size() if(self.saveGradeList.get()) : completeOutput = "ID,section,score\n" else : completeOutput = "" # Go through each grade data file and read it in. for row in range(numberGradeRows) : if(self.DEBUG): print(" reading turning point file: {0}".format(self.gradeListBox.get(row))) # Open the file. If it cannot be opened move on to the next one. if(self.csvExtension.search(self.gradeListBox.get(row))): # This is a csv file. Read it as the output from turning point. #print("{0} is a csv file.".format(self.gradeListBox.get(row))) completeOutput += self.readTurningPointCSVFile( \ self.gradeListBox.get(row), itemScores,clickerIDs) elif(self.tpzxExtension.search(self.gradeListBox.get(row))): # This is a session file from a turning point class. #print("{0} is a zipped set of xml files.".format( # self.gradeListBox.get(row))) completeOutput += itemScores.readTurningPointXMLFile( \ self.gradeListBox.get(row), itemScores,self.leadingZero.get(),clickerIDs, self.moodleIDNumbers) if(self.DEBUG): print("Output:\n{0}\n{1}".format(completeOutput,len(completeOutput))) #print("item scores: {0}".format(itemScores)) # There is some output from the grade parsing routines. if(len(completeOutput)>0) : if(self.DEBUG): print("Creating text output") newTextViewer = TextOutput(self) newTextViewer.setDocument(completeOutput) self.textWindows.append(newTextViewer) ## Write the results to their respective xml files. itemScores.writeOutputFiles(self.moodleIDNumbers,None)
def writeGrades(self): # This is where the work is done. Need to read in the xml # files that have the sections information in them. Then read # the grade files. The create the xml files for output. self.moodleIDNumbers = {} itemScores = AllScores() itemScores.setRegradeState(self.overwriteOld.get()) itemScores.setNumericState(self.numericGrade.get()) itemScores.setCSVOutfile(self.writeCSV.get()) # See http://docs.moodle.org/en/Development:Grades for the # details on the xml format. # Go through each xml file that has the section information in it. defaultXMLFileName = None writtenSections = self.specifySectionClassLists(itemScores) if(not writtenSections): tkMessageBox.showinfo( "OK", "No section files have been specified. Please choose a default file name for the one xml output file."); defaultXMLFileName = tkFileDialog.asksaveasfile(mode='w', filetypes= [('xml files', '.xml'), ('all files', '.*')]); itemScores.addSection(None,defaultXMLFileName,None) # Prepare to start the process of going through the grade files. numberGradeRows = self.gradeListBox.size() if(self.saveGradeList.get()) : completeOutput = "ID,section,score\n" else : completeOutput = "" # Go through each grade data file and read it in. for row in range(numberGradeRows) : if(self.DEBUG): print(" reading grade file: {0}".format(self.gradeListBox.get(row))) # Open the file. If it cannot be opened move on to the next one. try: csvFile = open(self.gradeListBox.get(row),'r') except OSError: tkMessageBox.showerror( "Error Reading File", "There was an error reading file: {0}".format(self.gradeListBox.get(row))) continue rowReader = csv.reader(csvFile,delimiter=',') lineNumber = 0 if(self.gradeListBox.get(row) in self.headerLineSkip): # Skip the requisite number of lines in the header. lineNumber = self.headerLineSkip[self.gradeListBox.get(row)] for lupe in range(lineNumber): try: header = rowReader.next() except: # There are not enough rows in this file. break # Read in the header line and determine which fields are # known. try: header = rowReader.next() except: # The file was not recognized as a valid grade file. header = None if(header): # The header for the file was recognized. Move ahead full speed. self.determineIDNumbers(header) results = itemScores.parseOneFile(csvFile,rowReader,header, self.moodleIDNumbers, self.leadingZero.get(), self.saveGradeList.get(), self.getStudentIDColumn(), lineNumber-1) if(self.DEBUG): print("Results:\n{0}".format(results)) completeOutput += results if(self.DEBUG): print("Output:\n{0}\n{1}".format(completeOutput,len(completeOutput))) # There is some output from the grade parsing routines. if(len(completeOutput)>0) : if(self.DEBUG): print("Creating text output") newTextViewer = TextOutput(self) newTextViewer.setDocument(completeOutput) self.textWindows.append(newTextViewer) ## Write the results to their respective xml files. itemScores.writeOutputFiles(self.moodleIDNumbers)