public List <Stats> MergeStatistics(List <Stats> stats) { var allStats = new List <Stats>(); foreach (var stat in stats) { var finalStats = new Stats() { Parameters = stat.Parameters }; allStats.Add(finalStats); foreach (var key in stat.Times.Keys) { finalStats.Times[key] = TreeStatistics.AverageStd(stat.Times[key]); } finalStats.Edges = TreeStatistics.AverageStd(stat.Edges); foreach (var key in stat.Output.Keys) { finalStats.Output[key] = TreeStatistics.AverageStd(stat.Output[key]); } finalStats.CliqueTrees = TreeStatistics.AvgStdTreeStats(stat.CliqueTrees); } return(allStats); }
private static void PopulateDateStatistics(TreeStatistics treeStatistics, List <WhoWhatWhereWhen> whoWhatWhereWhen) { var peopleGrouped = whoWhatWhereWhen .GroupBy(g => g.Who.Id) .ToList(); treeStatistics.PeopleNotFound = !peopleGrouped.Any(); treeStatistics.NumberOfPeople = peopleGrouped.Count(); var allDates = whoWhatWhereWhen .Select(p => p.When.DateRange) .ToList(); var dateStatusEnums = Enum.GetValues(typeof(DateQualityStatus)); foreach (DateQualityStatus dateEnumStatus in dateStatusEnums) { var dateSummary = new DateSummary { Count = allDates.Count(d => d.Status == dateEnumStatus), Status = dateEnumStatus, }; treeStatistics.DateCountsByStatus.Add(dateSummary); } treeStatistics.DateIssuesExist = treeStatistics .DateCountsByStatus .Where(d => d.Status != DateQualityStatus.OK) .Any(d => d.Count > 0); }
public void OutputToConsole(TreeStatistics treeStatistics) { var originalColour = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("GeneGenie.Sawmill.Console - report on status of processed trees."); Console.WriteLine(); Console.Write("{0,-25}", "Number of trees"); Console.WriteLine($"{treeStatistics.NumberOfTrees,5}"); Console.Write("{0,-25}", "Number of people"); Console.WriteLine($"{treeStatistics.NumberOfPeople,5}"); if (treeStatistics.TreesAreEmpty) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"No trees were found."); } else if (treeStatistics.PeopleNotFound) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"No people were found in any of the trees."); } OutputDates(treeStatistics); OutputLocations(treeStatistics); Console.WriteLine(); Console.ForegroundColor = originalColour; }
private void BuildTree() { treXmiStructure.BeginUpdate(); treXmiStructure.Nodes.Clear(); TreeStatistics stats = new TreeStatistics(); BuildTree(null, eaModel.Root, stats); lblElementCount.Text = string.Format("Nodes: {0}", stats.Nodes); lblMaxAlias.Text = string.Format("Last Alias: {0}", stats.MaxAlias); treXmiStructure.EndUpdate(); }
public TreeStatistics GenerateStatistics(List <WhoWhatWhereWhen> whoWhatWhereWhen) { var treeStatistics = new TreeStatistics(); if (whoWhatWhereWhen == null) { treeStatistics.TreesAreEmpty = true; return(treeStatistics); } treeStatistics.TreesAreEmpty = !whoWhatWhereWhen.Any(); treeStatistics.NumberOfTrees = whoWhatWhereWhen.GroupBy(g => g.Who.TreeId).Count(); PopulateDateStatistics(treeStatistics, whoWhatWhereWhen); PopulateLocationStatistics(treeStatistics, whoWhatWhereWhen); return(treeStatistics); }
private static void OutputLocations(TreeStatistics treeStatistics) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"**** Locations ****"); foreach (var locationSummary in treeStatistics.LocationCountsByStatus) { Console.ForegroundColor = ConsoleColor.Green; Console.Write($"{locationSummary.Status,-25}"); Console.ForegroundColor = ColourForLocationSummary(locationSummary); Console.WriteLine($"{locationSummary.Count,5}"); } Console.ForegroundColor = ConsoleColor.Green; Console.Write("{0,-25}", "Total"); Console.WriteLine($"{treeStatistics.LocationCountsByStatus.Sum(l => l.Count),5}"); Console.WriteLine($"**** Locations ****"); }
private static void OutputDates(TreeStatistics treeStatistics) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"**** Dates ****"); foreach (var dateSummary in treeStatistics.DateCountsByStatus) { Console.ForegroundColor = ConsoleColor.Green; Console.Write($"{dateSummary.Status,-25}"); Console.ForegroundColor = ColourForDateSummary(dateSummary); Console.WriteLine($"{dateSummary.Count,5}"); } Console.ForegroundColor = ConsoleColor.Green; Console.Write("{0,-25}", "Total"); Console.WriteLine($"{treeStatistics.DateCountsByStatus.Sum(l => l.Count),5}"); Console.WriteLine($"**** Dates ****"); }
private static void PopulateLocationStatistics(TreeStatistics treeStatistics, List <WhoWhatWhereWhen> whoWhatWhereWhen) { var allLocations = whoWhatWhereWhen .Select(p => p.Where.Location) .ToList(); var locationStatusEnums = Enum.GetValues(typeof(SawmillStatus)); foreach (SawmillStatus locationEnumStatus in locationStatusEnums) { var locationSummary = new LocationSummary { Count = allLocations.Count(d => d.Status == locationEnumStatus), Status = locationEnumStatus, }; treeStatistics.LocationCountsByStatus.Add(locationSummary); } treeStatistics.LocationIssuesExist = treeStatistics .LocationCountsByStatus .Where(d => d.Status != SawmillStatus.Geocoded) .Any(d => d.Count > 0); }
private void BuildTree(TreeNode parent, Model.EATree element, TreeStatistics statistics) { TreeNode node; StringBuilder heading = new StringBuilder(); if (!string.IsNullOrWhiteSpace(element.Stereotype)) { heading.Append("«").Append(element.Stereotype).Append("» "); } heading.Append(element.Heading); if (!string.IsNullOrWhiteSpace(element.Alias)) { heading.Append(" (").Append(element.Alias).Append(")"); } node = new TreeNode(heading.ToString()) { Tag = element }; if (parent == null) { treXmiStructure.Nodes.Add(node); } else { parent.Nodes.Add(node); } statistics.Nodes++; if (string.Compare(element.Alias, statistics.MaxAlias) > 0) { statistics.MaxAlias = element.Alias; } if (element.Id.StartsWith("MX_EAID_")) { node.ImageKey = "Model"; } else if (element.Id.StartsWith("EAPK")) { node.ImageKey = "Specification"; } else if (element.Status != null) { if (element.Status.Equals("Approved", StringComparison.InvariantCultureIgnoreCase)) { node.ImageKey = "RequirementApproved"; } else if (element.Status.Equals("Implemented", StringComparison.InvariantCultureIgnoreCase)) { node.ImageKey = "RequirementImplemented"; } else if (element.Status.Equals("Mandatory", StringComparison.InvariantCultureIgnoreCase)) { node.ImageKey = "RequirementMandatory"; } else if (element.Status.Equals("Proposed", StringComparison.InvariantCultureIgnoreCase)) { node.ImageKey = "RequirementProposed"; } else if (element.Status.Equals("Validated", StringComparison.InvariantCultureIgnoreCase)) { node.ImageKey = "RequirementValidated"; } else { node.ImageKey = "Requirement"; } } else { node.ImageKey = "Requirement"; } node.SelectedImageKey = node.ImageKey; foreach (Model.EATree child in element.Children) { BuildTree(node, child, statistics); } }
public TreeStatistics SHETBFSStatistics(long edges, IEnumerable <TreeNode> tree) { var count = tree.Count(); var avgDegree = 2.0 * (count - 1) / count; var tStats = new TreeStatistics(); var visited = new HashSet <TreeNode>(); var stack = new Stack <TreeNode>(); var root = tree.First(); var farthestNode = root; stack.Push(root); while (stack.Count > 0) { var clique = stack.Pop(); visited.Add(clique); var degree = 0; foreach (var child in clique.Adjoint.Where(c => (c.State == NodeState.Valid || c.State == NodeState.NewCC) && !visited.Contains(c))) { child.Height = clique.Height + 1; degree++; stack.Push(child); // calculate for each edge tStats.NumEdges++; var seperatorCount = clique.CliqueList.Intersect(child.CliqueList).Count(); tStats.SumWeight += seperatorCount; tStats.MaxWeight = Math.Max(tStats.MaxWeight, seperatorCount); tStats.MinWeight = tStats.MinWeight == 0 ? seperatorCount : Math.Min(tStats.MinWeight, seperatorCount); if (!tStats.DistributionWeight.ContainsKey(seperatorCount)) { tStats.DistributionWeight[seperatorCount] = 1; } else { tStats.DistributionWeight[seperatorCount] += 1; } } var size = clique.CliqueList.Count; tStats.Num++; tStats.Width = Math.Max(tStats.Width, degree); tStats.Height = Math.Max(tStats.Height, clique.Height); tStats.DegreesVar += (degree - avgDegree) * (degree - avgDegree); tStats.MaxSize = Math.Max(tStats.MaxSize, size); tStats.MinSize = tStats.MinSize == 0 ? clique.CliqueList.Count : Math.Min(tStats.MinSize, clique.CliqueList.Count); tStats.SumSize += clique.CliqueList.Count; if (!tStats.DistributionSize.ContainsKey(size)) { tStats.DistributionSize[size] = 1; } else { tStats.DistributionSize[size] += 1; } if (clique.Height > farthestNode.Height) { farthestNode = clique; } } tStats.MaxCliqueDistribution = ((tStats.MaxSize * (tStats.MaxSize - 1)) / 2.0) / edges; tStats.AvgSize = tStats.SumSize / (double)tStats.Num; tStats.AvgWeight = tStats.SumWeight / (double)tStats.NumEdges; // run a second bfs from farthest vertex to get the diameter farthestNode.Height = 0; visited = new HashSet <TreeNode>(); stack = new Stack <TreeNode>(); stack.Push(farthestNode); while (stack.Count > 0) { var clique = stack.Pop(); visited.Add(clique); foreach (var child in clique.Adjoint.Where(c => (c.State == NodeState.Valid || c.State == NodeState.NewCC) && !visited.Contains(c))) { child.Height = clique.Height + 1; stack.Push(child); } tStats.Diameter = Math.Max(tStats.Diameter, clique.Height); } return(tStats); }