forked from ddrilling/AsbCloudServer
56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace AsbCloudInfrastructure.Services.DetectOperations;
|
|
|
|
|
|
public class InterpolationLine
|
|
{
|
|
private readonly double xSum;
|
|
private readonly double ySum;
|
|
private readonly double xySum;
|
|
private readonly double x2Sum;
|
|
private readonly int count;
|
|
|
|
public InterpolationLine(IEnumerable<(double Y, double X)> rawData)
|
|
{
|
|
var iterator = rawData.GetEnumerator();
|
|
while (iterator.MoveNext())
|
|
{
|
|
xSum += iterator.Current.X;
|
|
ySum += iterator.Current.Y;
|
|
xySum += iterator.Current.X * iterator.Current.Y;
|
|
x2Sum += iterator.Current.X * iterator.Current.X;
|
|
count++;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// tan(alpha)
|
|
/// </summary>
|
|
public double A =>
|
|
(xSum * ySum - count * xySum) /
|
|
(xSum * xSum - count * x2Sum);
|
|
|
|
/// <summary>
|
|
/// y offset
|
|
/// </summary>
|
|
public double B =>
|
|
(xSum * xySum - x2Sum * ySum) /
|
|
(xSum * xSum - count * x2Sum);
|
|
|
|
public bool IsYNotChanges(double upperBound = 0d, double lowerBound = 0d) =>
|
|
A < upperBound && A > lowerBound;
|
|
|
|
public bool IsYIncreases(double bound = 0d) =>
|
|
A > bound;
|
|
|
|
public bool IsYDecreases(double bound = 0d) =>
|
|
A < bound;
|
|
|
|
public bool IsAverageYLessThan(double bound) =>
|
|
(ySum / count) < bound;
|
|
|
|
public bool IsAverageYGreaterThan(double bound) =>
|
|
(ySum / count) >= bound;
|
|
}
|