| 
					
				 | 
			
			
				@@ -1,11 +1,9 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-from __future__ import print_function 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import sys 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import os 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 sys.path.extend(['.', '..']) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from pycparser import parse_file, c_ast 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-from Queue import Queue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import queue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from threading import Thread 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import re 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -13,6 +11,7 @@ import copy 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import files 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import analyser 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+from submissionFileReader import getSubmissionFile 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 COMMENT_REGEX = r"(//.*)|(/\*[\w\W\n\r]*?\*/)" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 USEFUL_REGEX = r"(//.*)|(/\*[\w\W\n\r]*?\*/)|(^\s*$)|(\{\s*\})|(^\s*\{\s*$)|(^\s*\}\s*$)" 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -40,7 +39,7 @@ class Worker (Thread): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         self.tasks = tasks 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         self.daemon = True 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         self.start() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     def run (self): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         while True: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             func, args, kargs = self.tasks.get() 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -52,7 +51,7 @@ class Worker (Thread): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class ThreadPool: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     """Pool of threads consuming tasks from a queue""" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     def __init__ (self, num_threads): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        self.tasks = Queue(num_threads) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        self.tasks = queue.Queue(num_threads) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for _ in range(num_threads): Worker(self.tasks) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     def add_task (self, func, *args, **kargs): 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -131,13 +130,103 @@ def saveToFile (filePath, data): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     file.write(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     file.close() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+def processDataFromCSV (parser, vplFolder): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    assingments = parser.exercises 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    data = {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for e in assingments: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        (allSubs, students) = parser.getSubmissions(e) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        studentData = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for student in students: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            submissions = parser.getStudentValidSubmissions(allSubs, student) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                assert len(submissions) > 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                submissions.sort(key = lambda x : x.submission_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                lastSub = submissions[-1] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                content = getSubmissionFile(vplFolder, e, lastSub.submission_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentData.append((student, content, len(submissions))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            except Exception: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentData.append((student, "", len(submissions))) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        data[e] = studentData[:] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pool = ThreadPool(10) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for a in data: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for studentData in data[a]: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pool.add_task(processStudentData, studentData, a) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pool.wait_completion() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    mainCSVFile = "" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    forCSVFile = "" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    condCSVFile = "" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    assignmentList = dict() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    constantInitCount = dict() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for data in finalDataList: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if data[0].assignment in assignmentList: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            assignmentList[data[0].assignment].append(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            assignmentList[data[0].assignment] = list() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            assignmentList[data[0].assignment].append(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for assignmentKey in assignmentList: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for studentData in assignmentList[assignmentKey]: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            astInfo = studentData[0] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for k in astInfo.constantInitCount: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if k in constantInitCount: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    constantInitCount[k] += astInfo.constantInitCount[k] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    constantInitCount[k] = astInfo.constantInitCount[k] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentOpData = initEmptyDict(analyser.VALID_OPS) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for key in astInfo.operatorsCount: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentOpData[key] = astInfo.operatorsCount[key] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentCommandData = initEmptyDict(COMMANDS) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for key in astInfo.commandCount: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentCommandData[key] = astInfo.commandCount[key] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentDeclarationData = initEmptyDict(DECLARATIONS) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for key in astInfo.declarations: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentDeclarationData[key] = astInfo.declarations[key] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for key in astInfo.declarationsPointers: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentDeclarationData["pointer_" + key] = astInfo.declarationsPointers[key] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for key in astInfo.declarationsVectors: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentDeclarationData["vector_" + key] = astInfo.declarationsVectors[key] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for key in astInfo.declarationsMatrixes: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentDeclarationData["matrix_" + key] = astInfo.declarationsMatrixes[key] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            mainCSVFile += "%s,%s,%s,%s,%s,%s" % (assignmentKey, astInfo.student, studentData[1], studentData[4], studentData[2], studentData[3]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            mainCSVFile += "," + ','.join([str(v) for v in studentOpData.values()]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            mainCSVFile += "," + ",".join([str(v) for v in studentCommandData.values()]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            mainCSVFile += "," + ",".join([str(v) for v in studentDeclarationData.values()]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            mainCSVFile += "\n" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            #For_structure.csv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for i in astInfo.forCommandData: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                forCSVFile += "%s,%s,%s,%s,%s,%s" % (assignmentKey, astInfo.student, i.cmdCount, i.condType, i.numLogicOps, i.numRelOps) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                opData = initEmptyDict(analyser.VALID_OPS) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for op in i.opList: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    opData[op] += 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                forCSVFile += "," + ','.join([str(v) for v in opData.values()]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                forCSVFile += ",%s,%s\n" % (i.useAssignment, i.useNext) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            #condition_structure.csv 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for i in astInfo.conditionCommandData: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                condCSVFile += "%s,%s,%s,%s,%s,%s" % (assignmentKey, astInfo.student, i.cmdCount, i.condType, i.numLogicOps, i.numRelOps) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                opData = initEmptyDict(analyser.VALID_OPS) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for op in i.opList: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    opData[op] += 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                condCSVFile += "," + ','.join([str(v) for v in opData.values()]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                condCSVFile += "\n" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    mainCSVFile = ','.join(CSV_HEADER) + '\n' + mainCSVFile 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    saveToFile("data.csv", mainCSVFile) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    forCSVFile = ','.join(FOR_CSV_HEADER) + '\n' + forCSVFile 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    saveToFile("for_structure.csv", forCSVFile) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    condCSVFile = ','.join(COND_CSV_HEADER) + '\n' + condCSVFile 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    saveToFile("cond_structure.csv", condCSVFile) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    constantInitFile = "constant,count\n" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    for k in constantInitCount: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        constantInitFile += "%s,%s\n" % (k, str(constantInitCount[k])) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    saveToFile("const_init.csv", constantInitFile) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    print("Entrada: {}, Saida: {}".format(analyser.PRINT_COUNT,analyser.SCAN_COUNT)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #--- run ---# 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 if __name__ == "__main__": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if len(sys.argv) > 1: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         file = sys.argv[1] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if file == "-f" and len(sys.argv) > 2: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             print(processFile(sys.argv[2])) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        elif file != "-f":     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        elif file != "-f": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             raiz = "./" + sys.argv[1] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             data = loadAssignments(raiz) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             pool = ThreadPool(10) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -209,8 +298,8 @@ if __name__ == "__main__": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             constantInitFile = "constant,count\n" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for k in constantInitCount: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 constantInitFile += "%s,%s\n" % (k, str(constantInitCount[k])) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            saveToFile("const_init.csv", constantInitFile)  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            saveToFile("const_init.csv", constantInitFile) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            print("cjson -f file | cjon folder/")     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            print("cjson -f file | cjon folder/") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         print("cjson -f file | cjon folder/") 
			 |