65 lines
1.2 KiB
C#
65 lines
1.2 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
|
|
namespace FrostFS.SDK.Client.Models.Netmap.Placement;
|
|
|
|
internal struct MeanIQRAgg : IAggregator
|
|
{
|
|
private const int minLn = 4;
|
|
internal Collection<double> arr = [];
|
|
|
|
public MeanIQRAgg()
|
|
{
|
|
}
|
|
|
|
public readonly void Add(double d)
|
|
{
|
|
arr.Add(d);
|
|
}
|
|
|
|
public readonly double Compute()
|
|
{
|
|
var length = arr.Count;
|
|
if (length == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
var sorted = arr.OrderBy(p => p).ToArray();
|
|
|
|
double minV, maxV;
|
|
|
|
if (arr.Count < minLn)
|
|
{
|
|
minV = sorted[0];
|
|
maxV = sorted[length - 1];
|
|
}
|
|
else
|
|
{
|
|
var start = length / minLn;
|
|
var end = length * 3 / minLn - 1;
|
|
|
|
minV = sorted[start];
|
|
maxV = sorted[end];
|
|
}
|
|
|
|
var count = 0;
|
|
double sum = 0;
|
|
|
|
foreach (var e in sorted)
|
|
{
|
|
if (e >= minV && e <= maxV)
|
|
{
|
|
sum += e;
|
|
count++;
|
|
}
|
|
}
|
|
|
|
return sum / count;
|
|
}
|
|
|
|
internal readonly void Clear()
|
|
{
|
|
arr.Clear();
|
|
}
|
|
}
|