forked from ddrilling/AsbCloudServer
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
{
|
|
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)
|
|
{
|
|
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();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|