|  | @@ -9,6 +9,7 @@ from Queue import Queue
 | 
	
		
			
				|  |  |  from threading import Thread
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import re
 | 
	
		
			
				|  |  | +import copy
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import files
 | 
	
		
			
				|  |  |  import analyser
 | 
	
	
		
			
				|  | @@ -17,12 +18,19 @@ COMMENT_REGEX = r"(//.*)|(/\*[\w\W\n\r]*?\*/)"
 | 
	
		
			
				|  |  |  USEFUL_REGEX = r"(//.*)|(/\*[\w\W\n\r]*?\*/)|(^\s*$)|(\{\s*\})|(^\s*\{\s*$)|(^\s*\}\s*$)"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  CSV_HEADER = ['assignment_id', 'student_id', 'total_submissions', 'code_lines','total_lines','comments']
 | 
	
		
			
				|  |  | -CSV_HEADER.extend(['!', '<=', '%', '>=', '++', '+', '*', '-', '/', '<', '--', '&&', 'p++', '\'==\'', 'p--', '!=', '||', '>'])
 | 
	
		
			
				|  |  | +OP_HEADER = ['!', '<=', '%', '>=', '++', '+', '*', '-', '/', '<', '--', '&&', 'p++', '\'==\'', 'p--', '!=', '||', '>']
 | 
	
		
			
				|  |  | +CSV_HEADER.extend(OP_HEADER)
 | 
	
		
			
				|  |  |  COMMANDS = ['Return', 'For', 'FuncCall', 'Assignment', 'Switch', 'DoWhile', 'While', 'FuncDef', 'If']
 | 
	
		
			
				|  |  |  CSV_HEADER.extend(COMMANDS)
 | 
	
		
			
				|  |  |  DECLARATIONS = ['vector_int', 'vector_float', 'matrix_string', 'string', 'int', 'pointer_int', 'float', 'matrix_int', 'pointer_float', 'matrix_float']
 | 
	
		
			
				|  |  |  CSV_HEADER.extend(DECLARATIONS)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +COND_CSV_HEADER = ['assignment_id', 'student_id', 'commands_count', 'cond_type', 'logic_op_count', 'rel_op_count']
 | 
	
		
			
				|  |  | +COND_CSV_HEADER.extend(OP_HEADER)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +FOR_CSV_HEADER = copy.deepcopy(COND_CSV_HEADER)
 | 
	
		
			
				|  |  | +FOR_CSV_HEADER.extend(['use_assignment','use_next_loop'])
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  finalDataList = list()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class Worker (Thread):
 | 
	
	
		
			
				|  | @@ -118,6 +126,11 @@ def initEmptyDict (list):
 | 
	
		
			
				|  |  |          result[k] = 0
 | 
	
		
			
				|  |  |      return result
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +def saveToFile (filePath, data):
 | 
	
		
			
				|  |  | +    file = open(filePath, "w+")
 | 
	
		
			
				|  |  | +    file.write(data)
 | 
	
		
			
				|  |  | +    file.close()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  #--- run ---#
 | 
	
		
			
				|  |  |  if __name__ == "__main__":
 | 
	
		
			
				|  |  |      if len(sys.argv) > 1:
 | 
	
	
		
			
				|  | @@ -132,8 +145,11 @@ if __name__ == "__main__":
 | 
	
		
			
				|  |  |                  for studentData in data[a]:
 | 
	
		
			
				|  |  |                      pool.add_task(processStudentData, studentData, a)
 | 
	
		
			
				|  |  |              pool.wait_completion()
 | 
	
		
			
				|  |  | -            csvfile = ""
 | 
	
		
			
				|  |  | +            mainCSVFile = ""
 | 
	
		
			
				|  |  | +            forCSVFile = ""
 | 
	
		
			
				|  |  | +            condCSVFile = ""
 | 
	
		
			
				|  |  |              assignmentList = dict()
 | 
	
		
			
				|  |  | +            constantInitCount = dict()
 | 
	
		
			
				|  |  |              for data in finalDataList:
 | 
	
		
			
				|  |  |                  if data[0].assignment in assignmentList:
 | 
	
		
			
				|  |  |                      assignmentList[data[0].assignment].append(data)
 | 
	
	
		
			
				|  | @@ -143,6 +159,11 @@ if __name__ == "__main__":
 | 
	
		
			
				|  |  |              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]
 | 
	
	
		
			
				|  | @@ -158,16 +179,38 @@ if __name__ == "__main__":
 | 
	
		
			
				|  |  |                          studentDeclarationData["vector_" + key] = astInfo.declarationsVectors[key]
 | 
	
		
			
				|  |  |                      for key in astInfo.declarationsMatrixes:
 | 
	
		
			
				|  |  |                          studentDeclarationData["matrix_" + key] = astInfo.declarationsMatrixes[key]
 | 
	
		
			
				|  |  | -                    csvfile += "%s,%s,%s,%s,%s,%s" % (assignmentKey, astInfo.student, studentData[1], studentData[4], studentData[2], studentData[3])
 | 
	
		
			
				|  |  | -                    csvfile += "," + ','.join([str(v) for v in studentOpData.values()])
 | 
	
		
			
				|  |  | -                    csvfile += "," + ",".join([str(v) for v in studentCommandData.values()])
 | 
	
		
			
				|  |  | -                    csvfile += "," + ",".join([str(v) for v in studentDeclarationData.values()])
 | 
	
		
			
				|  |  | -                    csvfile += "\n"
 | 
	
		
			
				|  |  | -            csvfile = ','.join(CSV_HEADER) + '\n' + csvfile
 | 
	
		
			
				|  |  | -            file = open("data.csv", "w+")
 | 
	
		
			
				|  |  | -            file.write(csvfile)
 | 
	
		
			
				|  |  | -            file.close()
 | 
	
		
			
				|  |  | +                    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) 
 | 
	
		
			
				|  |  |          else:
 | 
	
		
			
				|  |  |              print("cjson -f file | cjon folder/")    
 | 
	
		
			
				|  |  |      else:
 | 
	
		
			
				|  |  | -        print("cjson -f file | cjon folder/")
 | 
	
		
			
				|  |  | +        print("cjson -f file | cjon folder/")
 |