DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/DetectOperations/InterpolationLine.cs

58 lines
1.6 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2022-04-22 17:17:38 +05:00
namespace AsbCloudInfrastructure.Services.DetectOperations
{
2022-04-22 17:17:38 +05:00
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) =>
2022-04-22 17:17:38 +05:00
(ySum / count) < bound;
public bool IsAverageYGreaterThan(double bound) =>
2022-04-22 17:17:38 +05:00
(ySum / count) >= bound;
}
2022-04-22 17:17:38 +05:00
}