forked from ddrilling/AsbCloudServer
eugeniy_ivanov
abd0008615
изменение алгоритма формирования списка СПИН изменение алгоритма поиска глубины
43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudInfrastructure.Services.Subsystems.Utils
|
|
{
|
|
#nullable enable
|
|
internal class DepthInterpolation
|
|
{
|
|
private List<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> collection;
|
|
(DateTimeOffset x, float y) lastValue = default;
|
|
public DepthInterpolation(List<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> collection)
|
|
{
|
|
this.collection = collection;
|
|
}
|
|
|
|
public float GetDepth(DateTimeOffset date)
|
|
{
|
|
for (int i = 0; i < collection.Count; i++)
|
|
{
|
|
if (date <= collection[i].dateMax && date >= collection[i].dateMin)
|
|
{
|
|
lastValue.x = date;
|
|
lastValue.y = CalcValue(collection[i], (date - collection[i].dateMin).TotalSeconds);
|
|
}
|
|
}
|
|
return lastValue.y;
|
|
}
|
|
|
|
private float CalcValue((DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax) item, double timestamp)
|
|
{
|
|
if (item.depthMin == item.depthMax)
|
|
{
|
|
return item.depthMin;
|
|
}
|
|
var w = timestamp / (item.dateMax - item.dateMin).TotalSeconds;
|
|
var d = ((item.depthMax - item.depthMin) * w) + item.depthMin;
|
|
return (float)d;
|
|
}
|
|
}
|
|
#nullable disable
|
|
}
|