2021-09-30 16:41:00 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-06-28 11:35:52 +05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2021-10-01 15:44:56 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Services.Analysis
|
2021-06-28 11:35:52 +05:00
|
|
|
|
{
|
2021-07-20 11:24:57 +05:00
|
|
|
|
public class InterpolationLine
|
2021-06-28 11:35:52 +05:00
|
|
|
|
{
|
2021-09-30 16:41:00 +05:00
|
|
|
|
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
|
|
|
|
|
2021-09-30 16:41:00 +05:00
|
|
|
|
public InterpolationLine(IEnumerable<(double Y, double X)> rawData)
|
2021-06-28 11:35:52 +05:00
|
|
|
|
{
|
2021-10-01 15:44:56 +05:00
|
|
|
|
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++;
|
|
|
|
|
}
|
2021-07-20 11:24:57 +05:00
|
|
|
|
}
|
2021-06-28 11:35:52 +05:00
|
|
|
|
|
2021-09-30 16:41:00 +05:00
|
|
|
|
public double A =>
|
|
|
|
|
(xSum * ySum - count * xySum) /
|
|
|
|
|
(xSum * xSum - count * x2Sum);
|
2021-06-28 11:35:52 +05:00
|
|
|
|
|
2021-09-30 16:41:00 +05:00
|
|
|
|
public double B =>
|
|
|
|
|
(xSum * xySum - x2Sum * ySum) /
|
|
|
|
|
(xSum * xSum - count * x2Sum);
|
2021-06-28 11:35:52 +05:00
|
|
|
|
|
2021-09-30 16:41:00 +05:00
|
|
|
|
public bool IsYNotChanges(double upperBound = 0d, double lowerBound = 0d) =>
|
|
|
|
|
A < upperBound && A > lowerBound;
|
2021-06-28 11:35:52 +05:00
|
|
|
|
|
2021-09-30 16:41:00 +05:00
|
|
|
|
public bool IsYIncreases(double bound = 0d) =>
|
|
|
|
|
A > bound;
|
2021-06-28 11:35:52 +05:00
|
|
|
|
|
2021-09-30 16:41:00 +05:00
|
|
|
|
public bool IsYDecreases(double bound = 0d) =>
|
|
|
|
|
A < bound;
|
2021-06-28 11:35:52 +05:00
|
|
|
|
|
2021-09-30 16:41:00 +05:00
|
|
|
|
public bool IsAverageYLessThanBound(double bound) =>
|
|
|
|
|
(ySum / count) < bound;
|
2021-06-28 11:35:52 +05:00
|
|
|
|
|
2021-09-30 16:41:00 +05:00
|
|
|
|
public bool IsAverageYMoreThanBound(double bound) =>
|
|
|
|
|
(ySum / count) >= bound;
|
2021-06-28 11:35:52 +05:00
|
|
|
|
}
|
|
|
|
|
}
|