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

49 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
namespace AsbCloudInfrastructure.Services
{
2021-07-20 11:24:57 +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;
2021-07-20 11:24:57 +05:00
public InterpolationLine(IEnumerable<(double Y, double X)> rawData)
{
xSum = rawData.Sum(d => d.X);
ySum = rawData.Sum(d => d.Y);
xySum = rawData.Sum(d => d.X * d.Y);
x2Sum = rawData.Sum(d => d.X * d.X);
count = rawData.Count();
2021-07-20 11:24:57 +05:00
}
public double A =>
(xSum * ySum - count * xySum) /
(xSum * xSum - count * x2Sum);
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 IsAverageYLessThanBound(double bound) =>
(ySum / count) < bound;
public bool IsAverageYMoreThanBound(double bound) =>
(ySum / count) >= bound;
}
}