public void Should_GraphXY() { var width = 20; var height = 18; var startTime = DateTime.Now; var data = new Dictionary <DateTime, double>() { { startTime.Add(TimeSpan.FromSeconds(0)), 0 }, { startTime.Add(TimeSpan.FromSeconds(1)), 1 }, { startTime.Add(TimeSpan.FromSeconds(2)), 3 }, { startTime.Add(TimeSpan.FromSeconds(3)), 13 }, { startTime.Add(TimeSpan.FromSeconds(4)), 18 }, { startTime.Add(TimeSpan.FromSeconds(5)), 15 }, { startTime.Add(TimeSpan.FromSeconds(6)), 15 }, { startTime.Add(TimeSpan.FromSeconds(7)), 15 }, { startTime.Add(TimeSpan.FromSeconds(8)), 7 }, { startTime.Add(TimeSpan.FromSeconds(9)), 2 }, { startTime.Add(TimeSpan.FromSeconds(10)), 0 }, { startTime.Add(TimeSpan.FromSeconds(11)), 1 }, { startTime.Add(TimeSpan.FromSeconds(12)), 3 }, { startTime.Add(TimeSpan.FromSeconds(13)), 13 }, { startTime.Add(TimeSpan.FromSeconds(14)), 18 }, { startTime.Add(TimeSpan.FromSeconds(15)), 15 }, { startTime.Add(TimeSpan.FromSeconds(16)), 15 }, { startTime.Add(TimeSpan.FromSeconds(17)), 15 }, { startTime.Add(TimeSpan.FromSeconds(18)), 7 }, { startTime.Add(TimeSpan.FromSeconds(19)), 2 }, }; var chart = new AsciiChart(width, height); var result = chart.GraphXY(data); Assert.NotNull(result); Assert.AreEqual(width, result.IndexOf('\n') - 1); Assert.AreEqual(height, result.Count(c => c == '\n') - 1); }
public override ColorTextBuilder Write(object parameters = null) { var builder = new ColorTextBuilder(); var chartWidth = 30; var chartHeight = 10; var chartSpacing = 3; var testConcurrency = new ColorTextBuilder(); var testData = _runContext.Runs.SelectMany(x => x.Key.PerformanceLog.GetAll(PerformanceLog.PerformanceType.TestConcurrency)); if (testData.Sum(x => x.Value) > 0) { WriteRoundBox(testConcurrency, $"Test Concurrency", 8); var testConcurrencyChart = new AsciiChart(chartWidth, chartHeight); var testChartData = testData.ToDictionary(key => key.TimeSlot, value => value.Value); testConcurrency.Append(testConcurrencyChart.GraphXY(testChartData, _colorScheme.DarkSuccess, _colorScheme.DarkDefault)); testConcurrency.AppendLine(); } var testFixtureConcurrency = new ColorTextBuilder(); var testFixtureData = _runContext.Runs.SelectMany(x => x.Key.PerformanceLog.GetAll(PerformanceLog.PerformanceType.TestFixtureConcurrency)); if (testFixtureData.Sum(x => x.Value) > 0) { WriteRoundBox(testFixtureConcurrency, "Test Fixture Concurrency"); var testFixtureConcurrencyChart = new AsciiChart(chartWidth, chartHeight); var testFixtureChartData = testFixtureData.ToDictionary(key => key.TimeSlot, value => value.Value); testFixtureConcurrency.Append(testFixtureConcurrencyChart.GraphXY(testFixtureChartData, _colorScheme.DarkHighlight, _colorScheme.DarkDefault)); testFixtureConcurrency.AppendLine(); } var assemblyConcurrency = new ColorTextBuilder(); var assemblyData = _runContext.Runs.SelectMany(x => x.Key.PerformanceLog.GetAll(PerformanceLog.PerformanceType.AssemblyConcurrency)); if (assemblyData.Sum(x => x.Value) > 0) { WriteRoundBox(assemblyConcurrency, "Assembly Concurrency", 4); var assemblyConcurrencyChart = new AsciiChart(chartWidth, chartHeight); var assemblyChartData = assemblyData.ToDictionary(key => key.TimeSlot, value => value.Value); assemblyConcurrency.Append(assemblyConcurrencyChart.GraphXY(assemblyChartData, _colorScheme.DarkError, _colorScheme.DarkDefault)); assemblyConcurrency.AppendLine(); } var cpuUsage = new ColorTextBuilder(); var cpuUsageData = _runContext.Runs.SelectMany(x => x.Key.PerformanceLog.GetAll(PerformanceLog.PerformanceType.CpuUsed)); if (cpuUsageData.Sum(x => x.Value) > 0) { WriteRoundBox(cpuUsage, "CPU Usage"); var cpuUsageChart = new AsciiChart(chartWidth, chartHeight); var cpuUsageChartData = cpuUsageData.ToDictionary(key => key.TimeSlot, value => value.Value); cpuUsage.Append(cpuUsageChart.GraphXY(cpuUsageChartData, _colorScheme.Default, _colorScheme.DarkDefault)); cpuUsage.AppendLine(); } // stack the graphs horizontally, until they won't fit on the console var chartRows = new List <ColorTextBuilder>(); var isNewRow = false; var charts = testConcurrency; chartRows.Add(charts); chartRows[chartRows.Count - 1] = StackGraph(chartRows.Last(), testFixtureConcurrency, chartSpacing, out isNewRow); if (isNewRow) { chartRows.Add(ColorTextBuilder.Create.Append(testFixtureConcurrency)); } chartRows[chartRows.Count - 1] = StackGraph(chartRows.Last(), assemblyConcurrency, chartSpacing, out isNewRow); if (isNewRow) { chartRows.Add(ColorTextBuilder.Create.Append(assemblyConcurrency)); } chartRows[chartRows.Count - 1] = StackGraph(chartRows.Last(), cpuUsage, chartSpacing, out isNewRow); if (isNewRow) { chartRows.Add(ColorTextBuilder.Create.Append(cpuUsage)); } foreach (var chartRow in chartRows) { builder.AppendLine(chartRow); } return(builder); }