Skip to content

Commit

Permalink
stats computed, but very unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
cdriesler committed Jul 23, 2023
1 parent 2a18ec3 commit f08194e
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion packages/converters/models/NodePenDataTree.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Speckle.Core.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using Speckle.Newtonsoft.Json;

namespace NodePen.Converters
Expand Down Expand Up @@ -41,7 +42,8 @@ public void ComputeStats()
Stats = new NodePenDataTreeStats();

ComputeStructure();
// TODO: Compute other stats
ComputeTotalCounts();
ComputeTypes();
}

private void ComputeStructure()
Expand Down Expand Up @@ -72,6 +74,45 @@ private void ComputeStructure()
Stats.TreeStructure = "tree";
}

private void ComputeTotalCounts()
{
var valueCounts = new List<int>();

foreach (var branch in Branches)
{
valueCounts.Add(branch.Values.Count);
}

if (valueCounts.Count == 0)
{
Stats.BranchCount = Branches.Count;
Stats.ValueCount = 0;
return;
}

Stats.BranchCount = Branches.Count;
Stats.BranchValueCountDomain = new List<int>{
valueCounts.Min(),
valueCounts.Max()
};
Stats.ValueCount = valueCounts.Sum();
}

private void ComputeTypes()
{
var types = new HashSet<string>();

foreach (var branch in Branches)
{
foreach (var value in branch.Values)
{
types.Add(value.Type.ToLower());

Check warning on line 109 in packages/converters/models/NodePenDataTree.cs

View workflow job for this annotation

GitHub Actions / build

Expression value is never used

Check warning on line 109 in packages/converters/models/NodePenDataTree.cs

View workflow job for this annotation

GitHub Actions / build

Expression value is never used
}
}

Stats.ValueTypes = types.ToList();
}

}

/// <summary>
Expand Down

0 comments on commit f08194e

Please sign in to comment.