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

56 lines
1.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2022-04-22 17:17:38 +05:00
2024-08-19 10:01:07 +05:00
namespace AsbCloudInfrastructure.Services.DetectOperations;
public class InterpolationLine
2022-04-22 17:17:38 +05:00
{
2024-08-19 10:01:07 +05:00
private readonly double xSum;
private readonly double ySum;
private readonly double xySum;
private readonly double x2Sum;
private readonly int count;
2024-08-19 10:01:07 +05:00
public InterpolationLine(IEnumerable<(double Y, double X)> rawData)
2022-04-22 17:17:38 +05:00
{
2024-08-19 10:01:07 +05:00
var iterator = rawData.GetEnumerator();
while (iterator.MoveNext())
2022-04-22 17:17:38 +05:00
{
2024-08-19 10:01:07 +05:00
xSum += iterator.Current.X;
ySum += iterator.Current.Y;
xySum += iterator.Current.X * iterator.Current.Y;
x2Sum += iterator.Current.X * iterator.Current.X;
count++;
2022-04-22 17:17:38 +05:00
}
2024-08-19 10:01:07 +05:00
}
2022-04-22 17:17:38 +05:00
2024-08-19 10:01:07 +05:00
/// <summary>
/// tan(alpha)
/// </summary>
public double A =>
(xSum * ySum - count * xySum) /
(xSum * xSum - count * x2Sum);
2022-04-22 17:17:38 +05:00
2024-08-19 10:01:07 +05:00
/// <summary>
/// y offset
/// </summary>
public double B =>
(xSum * xySum - x2Sum * ySum) /
(xSum * xSum - count * x2Sum);
2022-04-22 17:17:38 +05:00
2024-08-19 10:01:07 +05:00
public bool IsYNotChanges(double upperBound = 0d, double lowerBound = 0d) =>
A < upperBound && A > lowerBound;
2022-04-22 17:17:38 +05:00
2024-08-19 10:01:07 +05:00
public bool IsYIncreases(double bound = 0d) =>
A > bound;
2022-04-22 17:17:38 +05:00
2024-08-19 10:01:07 +05:00
public bool IsYDecreases(double bound = 0d) =>
A < bound;
2022-04-22 17:17:38 +05:00
2024-08-19 10:01:07 +05:00
public bool IsAverageYLessThan(double bound) =>
(ySum / count) < bound;
2024-08-19 10:01:07 +05:00
public bool IsAverageYGreaterThan(double bound) =>
(ySum / count) >= bound;
2022-04-22 17:17:38 +05:00
}