-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
83 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Randomizer.Statistics; | ||
|
||
internal static class HistogramDrawer { | ||
|
||
public static void DrawHistogram(string title, int height, ulong[] data, ulong[]? additionalData = null, char character = '#') { | ||
var width = data.Length; | ||
var outputHeight = additionalData == null ? height : height * 2; | ||
var output = new char[outputHeight + 1, width]; | ||
|
||
// Initialize the array with spaces | ||
for (var y = 0; y < outputHeight + 1; ++y) | ||
for (var x = 0; x < width; ++x) | ||
output[y, x] = ' '; | ||
|
||
// Write the bin index row | ||
for (var i = 0; i < width; ++i) | ||
output[height, i] = i % 10 == 0 ? i == 0 ? '0' : (char)('A' - 1 + i / 10) : (char)('0' + i % 10); | ||
|
||
// Find max to normalize | ||
var max = data.Max(); | ||
if (additionalData != null) | ||
max = Math.Max(max, additionalData.Max()); | ||
|
||
// Calculate and write the histogram bars for data | ||
for (var i = 0; i < width; ++i) { | ||
var binHeight = data[i] * (ulong)height / max; | ||
for (ulong j = 0; j < binHeight; ++j) | ||
output[height - 1 - (int)j, i] = character; | ||
} | ||
|
||
// Calculate and write the histogram bars for additionalData if provided | ||
if (additionalData != null) { | ||
for (var i = 0; i < width; ++i) { | ||
var binHeight = additionalData[i] * (ulong)height / max; | ||
for (ulong j = 0; j < binHeight; ++j) | ||
output[height + 1 + (int)j, i] = character; | ||
} | ||
} | ||
|
||
// Convert the array to a string and print it | ||
Console.WriteLine($"{title}:"); | ||
for (var i = 0; i < outputHeight + 1; ++i) { | ||
for (var j = 0; j < width; ++j) | ||
Console.Write(output[i, j]); | ||
|
||
Console.WriteLine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Randomizer.Statistics; | ||
|
||
internal class RepetitionHistogram : IValueTracker { | ||
private const int NumBins = 64; | ||
private const double ScaleFactor = NumBins / (double)ulong.MaxValue; | ||
private readonly ulong[] _bins = new ulong[NumBins]; | ||
|
||
#region Implementation of IValueTracker | ||
|
||
public void Feed(ulong value) => ++this._bins[(int)(value * ScaleFactor)]; | ||
|
||
public void Print() => HistogramDrawer.DrawHistogram("Repetition Histogram", 10, this._bins); | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters