private void OnStats(object sender, RoutedEventArgs ev)
        {
            // method change paths
            CommitDescription.Text = "";
            var graph = this.currentGraph;

            var subGraph = new Graph();

            subGraph.Nodes.AddRange(graph.Nodes.Where(n => n.IsMethodDeclartionNode()));
            subGraph.Edges.AddRange(graph.Edges.Where(e => e.from.IsMethodDeclartionNode() && e.to.IsMethodDeclartionNode()));

            var disconnectedSubGraphs = subGraph.GetConnectedSubGraphs(true, false).ToList();

            var sinks = subGraph.SinkVertexs();
            ConcurrentBag <int> changes = new ConcurrentBag <int>();
            ConcurrentBag <Tuple <int, string> > allChanges = new ConcurrentBag <Tuple <int, string> >();

            foreach (var methodHistory in  subGraph.GetConnectedSubGraphs(true, false))
            {
                var s = methodHistory.Nodes.Where(n => methodHistory.Edges.All(e => e.from != n)).FirstOrDefault();
                if (methodHistory.Edges.Count == methodHistory.Nodes.Count - 1)
                {
                    var changeEdges = methodHistory.Edges.Where(e => e.type != Edge.EdgeType.NoCodeChange).Count();
                    allChanges.Add(new Tuple <int, string>(changeEdges, NodeDescriber.Decribe(s) + " had " + changeEdges + " changes \n"));
                    changes.Add(changeEdges);
                }
                else
                {
                    var foo = graph.Edges.Where(e => e.to == s).ToList();
                    allChanges.Add(new Tuple <int, string>(methodHistory.Edges.Count, NodeDescriber.Decribe(s) + " had " + methodHistory.Edges.Count + " changes \n"));
                }
            }

            CommitDescription.Text += "Overall " + changes.Count + " Methods changed " + changes.Min() + " - " + changes.Max() + " avrg. " + changes.Average() + "\n";
            var tmp = allChanges.ToList();

            tmp.Sort((s1, s2) => s2.Item1.CompareTo(s1.Item1)); // desending
            foreach (var t in tmp.Take(20))
            {
                CommitDescription.Text += t.Item2;
            }
        }
        private void CommitButtonPressed(object o, Node n)
        {
            HighlightSingleToggleButton(o);

            this.GraphDisplay.Graph = AddNodeToDisplay(n);
            ViewCode(this.CodeDisplay, n);

            CommitDescription.Text = "";
            if (n.Type == Node.NodeType.Commit)
            {
                BuildFileTreeForNode(n);

                var changesInThisCommit = currentGraph.GetConnectedSubGraph(n, new Edge.EdgeType[] { Edge.EdgeType.SyntaxHierarchialyAbove, Edge.EdgeType.HierarchialyAbove, Edge.EdgeType.InFile }, false, false);

                foreach (var node in changesInThisCommit.Nodes)
                {
                    switch (node.Type)
                    {
                    case Node.NodeType.Commit:
                        CommitDescription.Text += " Summery for commit " + node.Content + "\n";
                        break;

                    case Node.NodeType.Syntax:
                    {
                        var toNode = currentGraph.Edges.Where(e => e.to == node && e.type.IsCodeModificationEdge());
                        if (toNode.Any())
                        {
                            CommitDescription.Text += " Changed " + NodeDescriber.Decribe(node) + "\n";
                        }
                        else
                        {
                            CommitDescription.Text += " Created " + NodeDescriber.Decribe(node) + "\n";
                        }
                    }
                    break;

                    default: break;
                    }
                }
            }
        }
예제 #3
0
 public void Setup()
 {
     _nodeDescriber = new NodeDescriber(Indentation);
 }
        public void NodeDescriberTest()
        {
            // Traverse down and across tree
            INodeDescriber implementation = new NodeDescriber(new NodesHelper());
            var            testData       = new SingleChildNode("root",
                                                                new TwoChildrenNode("child1",
                                                                                    new NoChildrenNode("leaf1"),
                                                                                    new SingleChildNode("child2",
                                                                                                        new NoChildrenNode("leaf2"))));

            var result = implementation.Describe(testData);

            StringBuilder sb = new StringBuilder();

            sb.Append("new SingleChildNode(\"root\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append("new TwoChildrenNode(\"child1\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append(tab); sb.Append("new NoChildrenNode(\"leaf1\"),"); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append(tab); sb.Append("new SingleChildNode(\"child2\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append(tab); sb.Append(tab); sb.Append("new NoChildrenNode(\"leaf2\"))));");
            string expectedResult = sb.ToString();

            Assert.AreEqual(expectedResult, result);


            // Traverse down tree, back up, then back down
            implementation = new NodeDescriber(new NodesHelper());
            testData       = new SingleChildNode("root",
                                                 new ManyChildrenNode("child1",
                                                                      new SingleChildNode("child2",
                                                                                          new NoChildrenNode("leaf1")),
                                                                      new NoChildrenNode("leaf2")));

            result = implementation.Describe(testData);

            sb = new StringBuilder();
            sb.Append("new SingleChildNode(\"root\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append("new ManyChildrenNode(\"child1\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append(tab); sb.Append("new SingleChildNode(\"child2\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append(tab); sb.Append(tab); sb.Append("new NoChildrenNode(\"leaf1\")),"); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append(tab); sb.Append("new NoChildrenNode(\"leaf2\")));");
            expectedResult = sb.ToString();

            Assert.AreEqual(expectedResult, result);


            // Traverse tree, removing null nodes
            implementation = new NodeDescriber(new NodesHelper());
            var testDataWithNulls = new ManyChildrenNode("root",
                                                         new TwoChildrenNode("child1",
                                                                             null,
                                                                             new SingleChildNode("leaf1",
                                                                                                 null)));

            result = implementation.Describe(testDataWithNulls);

            sb = new StringBuilder();
            sb.Append("new ManyChildrenNode(\"root\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append("new TwoChildrenNode(\"child1\","); sb.Append(Environment.NewLine);
            sb.Append(tab); sb.Append(tab); sb.Append("new SingleChildNode(\"leaf1\")));");
            expectedResult = sb.ToString();

            Assert.AreEqual(expectedResult, result);
        }