public SnapshotMethod Generate(AbstractSyntaxTreeNode studentNode, AbstractSyntaxTreeNode solutionNode, MethodDeclaration method) { var studentMethod = GetMethodOrDefault(studentNode, method); var solutionMethod = GetMethodOrDefault(solutionNode, method); if (studentMethod == null || solutionMethod == null) { return new SnapshotMethod() { Declared = false, MethodDeclaration = method, } } ; return(new SnapshotMethod() { Declared = true, CodeAnalysisMetric = new CodeAnalysisMetric() { AbstractSyntaxTreeMetric = AbstractSyntaxTreeMetricCreator.Create(solutionMethod, studentMethod), BagOfWordsMetric = BagOfWordsMetricCreator.Create(solutionMethod, studentMethod), }, MethodDeclaration = method }); }
private double CalculateMetricDistance(AbstractSyntaxTreeNode leftRoot, AbstractSyntaxTreeNode rightRoot, DevAssignment assignment, MarkovModelOptions options) { if (leftRoot == null && rightRoot == null) { return(0.0d); } var accumlator = 0.0d; foreach (var methodDeclarration in assignment.Solution.MethodDeclarations) { var leftNode = leftRoot == null ? null : GetMethodOrDefault(leftRoot, methodDeclarration); var rightNode = rightRoot == null ? null : GetMethodOrDefault(leftRoot, methodDeclarration); if (leftNode != null && rightNode != null) { var abstractSyntaxTreeMetric = AbstractSyntaxTreeMetricCreator.Create(leftNode, rightNode); var bagOfWordsMetric = BagOfWordsMetricCreator.Create(leftNode, rightNode); accumlator += Math.Pow(abstractSyntaxTreeMetric.Rotations * options.AbstractSyntaxTreeWeight, 2); accumlator += Math.Pow(abstractSyntaxTreeMetric.Insertations * options.AbstractSyntaxTreeWeight, 2); accumlator += Math.Pow(abstractSyntaxTreeMetric.Deletions * options.AbstractSyntaxTreeWeight, 2); accumlator += Math.Pow(bagOfWordsMetric.Difference * options.BagOfWordsWeight, 2); } else if (leftNode != null) { var amount = leftNode.NumberOfNodes(); accumlator += Math.Pow(amount * options.AbstractSyntaxTreeWeight, 2); accumlator += Math.Pow(amount * options.BagOfWordsWeight, 2); } else if (rightNode != null) { var amount = rightNode.NumberOfNodes(); accumlator += Math.Pow(amount * options.AbstractSyntaxTreeWeight, 2); accumlator += Math.Pow(amount * options.BagOfWordsWeight, 2); } } return(accumlator); }