forked from ddrilling/AsbCloudServer
корректировка класса интерполяции глубин
This commit is contained in:
parent
37e29e003c
commit
cb2a8dfdeb
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.Subsystems.Utils
|
||||
{
|
||||
#nullable enable
|
||||
internal class DepthInterpolation
|
||||
{
|
||||
private IEnumerator<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> enumerator;
|
||||
(DateTimeOffset x, float? y) lastValue = default;
|
||||
|
||||
private DateTimeOffset dateMin;
|
||||
public DepthInterpolation(IOrderedEnumerable<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> collection)
|
||||
{
|
||||
enumerator = collection.GetEnumerator();
|
||||
enumerator.MoveNext();
|
||||
dateMin = enumerator.Current.dateMin;
|
||||
}
|
||||
|
||||
public float GetDepth(DateTimeOffset date)
|
||||
{
|
||||
{
|
||||
while (isLess(date))
|
||||
{
|
||||
lastValue.x = date;
|
||||
lastValue.y = CalcValue(enumerator.Current, (date - dateMin).TotalSeconds);
|
||||
enumerator.MoveNext();
|
||||
}
|
||||
}
|
||||
return (float)lastValue.y;
|
||||
}
|
||||
|
||||
private bool isLess(DateTimeOffset date)
|
||||
{
|
||||
if (date >= enumerator.Current.dateMin)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
private float CalcValue((DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax) item, double timestamp)
|
||||
{
|
||||
var a = (item.depthMax - item.depthMin) / (item.dateMax - item.dateMin).TotalSeconds;
|
||||
var b = item.depthMin * (item.dateMax.Second - (item.depthMax - item.depthMin) / (item.dateMax.Second - item.dateMin.Second));
|
||||
var resultDepth = a * timestamp + b;
|
||||
return (float)resultDepth;
|
||||
}
|
||||
|
||||
}
|
||||
#nullable disable
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.Subsystems.Utils
|
||||
{
|
||||
#nullable enable
|
||||
internal class Interpolation
|
||||
{
|
||||
private IEnumerator<(DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax)> enumerator;
|
||||
(DateTimeOffset x, float? y) lastValue = default;
|
||||
|
||||
public Interpolation(IOrderedEnumerable<(DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax)> collection)
|
||||
{
|
||||
enumerator = collection.GetEnumerator();
|
||||
enumerator.MoveNext();
|
||||
}
|
||||
|
||||
public float GetDepth(DateTimeOffset date)
|
||||
{
|
||||
{
|
||||
while (date >= enumerator.Current.dateMax)
|
||||
{
|
||||
if (isLess(date))
|
||||
{
|
||||
lastValue.x = date;
|
||||
lastValue.y = CalcValue(enumerator.Current, date.Second);
|
||||
}
|
||||
enumerator.MoveNext();
|
||||
}
|
||||
}
|
||||
return (float)lastValue.y;
|
||||
}
|
||||
|
||||
private bool isLess(DateTimeOffset date)
|
||||
{
|
||||
if (date <= enumerator.Current.dateMax && date >= enumerator.Current.dateMin)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
private float CalcValue((DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax) item, int x)
|
||||
{
|
||||
|
||||
var a = (item.depthMax - item.depthMin) / (item.dateMax.Second - item.dateMin.Second);
|
||||
var b = item.depthMin * (item.dateMax.Second - (item.depthMax - item.depthMin) / (item.dateMax.Second - item.dateMin.Second));
|
||||
var resultDepth = a * x + b;
|
||||
return (float)resultDepth;
|
||||
}
|
||||
|
||||
}
|
||||
#nullable disable
|
||||
}
|
@ -284,24 +284,21 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
dataSpinList.Add(dateRowItem);
|
||||
}
|
||||
await resultSpin.DisposeAsync();
|
||||
|
||||
|
||||
using var resultDepthFromSaub = await GetResultFromQueryAsync(queryDepthFromSaub, begin, idTelemetry, db, token);
|
||||
|
||||
var dataDepthFromSaub = new List<(DateTimeOffset dateMin, float? depthMin, DateTimeOffset dateMax, float? depthMax)>();
|
||||
var dataDepthFromSaub = new List<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)>();
|
||||
while (resultDepthFromSaub.Read())
|
||||
{
|
||||
var dateRowItem =
|
||||
(
|
||||
resultDepthFromSaub.GetFieldValue<DateTimeOffset>(0),
|
||||
resultDepthFromSaub.GetFieldValue<float?>(1),
|
||||
resultDepthFromSaub.GetFieldValue<float>(1),
|
||||
resultDepthFromSaub.GetFieldValue<DateTimeOffset>(2),
|
||||
resultDepthFromSaub.GetFieldValue<float?>(3)
|
||||
resultDepthFromSaub.GetFieldValue<float>(3)
|
||||
|
||||
);
|
||||
dataDepthFromSaub.Add(dateRowItem);
|
||||
}
|
||||
var interp = new Interpolation(dataDepthFromSaub.OrderBy(t => t.depthMin));
|
||||
var interp = new DepthInterpolation(dataDepthFromSaub.OrderBy(t => t.depthMin));
|
||||
if (dataSpinList.Any())
|
||||
{
|
||||
var mode = dataSpinList[0].Mode;
|
||||
|
Loading…
Reference in New Issue
Block a user