style: format code with dotnet-format

This commit fixes the style issues introduced in ed45c9e according to the output
from dotnet-format.

Details: None
This commit is contained in:
deepsource-autofix[bot]
2024-10-06 07:24:57 +00:00
committed by GitHub
parent ed45c9e5b8
commit 40842ba5fc
116 changed files with 1773 additions and 2748 deletions
+19 -9
View File
@@ -9,7 +9,8 @@ namespace QuanTAlib;
/// efficiently. Before the specified period is reached, it returns the average of
/// the available values as an approximation.
/// </remarks>
public class Mode : AbstractBase {
public class Mode : AbstractBase
{
private readonly int Period;
private readonly CircularBuffer _buffer;
@@ -20,8 +21,10 @@ public class Mode : AbstractBase {
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when period is less than 1.
/// </exception>
public Mode(int period) : base() {
if (period < 1) {
public Mode(int period) : base()
{
if (period < 1)
{
throw new ArgumentOutOfRangeException(nameof(period), "Period must be greater than or equal to 1.");
}
Period = period;
@@ -36,7 +39,8 @@ public class Mode : AbstractBase {
/// </summary>
/// <param name="source">The source object to subscribe to for value updates.</param>
/// <param name="period">The period over which to calculate the mode.</param>
public Mode(object source, int period) : this(period) {
public Mode(object source, int period) : this(period)
{
var pubEvent = source.GetType().GetEvent("Pub");
pubEvent?.AddEventHandler(source, new ValueSignal(Sub));
}
@@ -45,8 +49,10 @@ public class Mode : AbstractBase {
/// Manages the state of the Mode instance based on whether a new value is being processed.
/// </summary>
/// <param name="isNew">Indicates whether the current input is a new value.</param>
protected override void ManageState(bool isNew) {
if (isNew) {
protected override void ManageState(bool isNew)
{
if (isNew)
{
_lastValidValue = Input.Value;
_index++;
}
@@ -64,12 +70,14 @@ public class Mode : AbstractBase {
/// the available values as an approximation of the mode. Once the period is
/// reached, it calculates the true mode by grouping and counting the values.
/// </remarks>
protected override double Calculation() {
protected override double Calculation()
{
ManageState(Input.IsNew);
_buffer.Add(Input.Value, Input.IsNew);
double mode;
if (_index >= Period) {
if (_index >= Period)
{
var values = _buffer.GetSpan().ToArray();
var groupedValues = values.GroupBy(v => v)
.OrderByDescending(g => g.Count())
@@ -82,7 +90,9 @@ public class Mode : AbstractBase {
.ToList();
mode = modes.Average(); // If there are multiple modes, we return their average
} else {
}
else
{
mode = _buffer.Average(); // Use average until we have enough data points
}