예제 #1
0
        static void Render(TallyCount tally, int?top = null)
        {
            var bins   = tally.GetBinInfos().ToList();
            int others = 0;

            if (top < bins.Count)
            {
                bins   = bins.OrderByDescending(b => b.Count).ToList();
                others = bins.Skip(top.Value).Sum(b => b.Count);
                bins   = bins.Take(top.Value).ToList();
            }

            Console.WriteLine(tally.Definition.Caption + (others > 0 ? $" (Top {top})" : ""));
            Console.WriteLine();
            foreach (var bin in bins)
            {
                Console.WriteLine($"\u001b[32m\t{bin.Caption,-15} {bin.Count,10:N0} [{PercentBar(bin.Percentage)}]\u001b[0m");
            }
            if (others > 0)
            {
                Console.WriteLine($"\u001b[34m\t{$"({tally.Counts.Length - top} other)",-15} {others,10:N0} [{PercentBar((double)others / tally.Count)}]\u001b[0m");
            }
            Console.WriteLine($"\u001b[97m\t{"TOTAL",-15} {tally.Count,10:N0}\u001b[0m");
            Console.WriteLine();
        }
예제 #2
0
        public void Add()
        {
            var c1  = new TallyCount(null, new[] { 1, 2, 3 });
            var c2  = new TallyCount(null, new[] { 1, 2, 3 });
            var sum = c1 + c2;

            Assert.AreEqual(2, sum.Counts[0]);
            Assert.AreEqual(4, sum.Counts[1]);
            Assert.AreEqual(6, sum.Counts[2]);
        }
예제 #3
0
 static void RenderCompletion(TallyCount count)
 {
     Console.WriteLine(count.Definition.Caption);
     Console.WriteLine();
     foreach (var line in BigLetters.Render($"{count.Percentages[^1]:P2}"))