forked from ddrilling/AsbCloudServer
# correction DepthInterval
This commit is contained in:
parent
cb2a8dfdeb
commit
af6eea370c
@ -8,43 +8,41 @@ namespace AsbCloudInfrastructure.Services.Subsystems.Utils
|
|||||||
internal class DepthInterpolation
|
internal class DepthInterpolation
|
||||||
{
|
{
|
||||||
private IEnumerator<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> enumerator;
|
private IEnumerator<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> enumerator;
|
||||||
(DateTimeOffset x, float? y) lastValue = default;
|
(DateTimeOffset x, float y) lastValue = default;
|
||||||
|
|
||||||
private DateTimeOffset dateMin;
|
private DateTimeOffset dateMin;
|
||||||
public DepthInterpolation(IOrderedEnumerable<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> collection)
|
public DepthInterpolation(IOrderedEnumerable<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> collection)
|
||||||
{
|
{
|
||||||
enumerator = collection.GetEnumerator();
|
enumerator = collection.GetEnumerator();
|
||||||
enumerator.MoveNext();
|
enumerator.MoveNext();
|
||||||
dateMin = enumerator.Current.dateMin;
|
dateMin = enumerator.Current.dateMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetDepth(DateTimeOffset date)
|
public float GetDepth(DateTimeOffset date)
|
||||||
{
|
{
|
||||||
|
var isNotEnd = true;
|
||||||
|
while (isOnInterval(date) && isNotEnd)
|
||||||
{
|
{
|
||||||
while (isLess(date))
|
lastValue.x = date;
|
||||||
{
|
lastValue.y = CalcValue(enumerator.Current, (date- enumerator.Current.dateMin).TotalSeconds);
|
||||||
lastValue.x = date;
|
isNotEnd = enumerator.MoveNext();
|
||||||
lastValue.y = CalcValue(enumerator.Current, (date - dateMin).TotalSeconds);
|
|
||||||
enumerator.MoveNext();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (float)lastValue.y;
|
return lastValue.y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isLess(DateTimeOffset date)
|
private bool isOnInterval(DateTimeOffset date)
|
||||||
{
|
=> date >= enumerator.Current.dateMin && date <= enumerator.Current.dateMax;
|
||||||
if (date >= enumerator.Current.dateMin)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private float CalcValue((DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax) item, double timestamp)
|
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;
|
if (item.depthMin == item.depthMax)
|
||||||
var b = item.depthMin * (item.dateMax.Second - (item.depthMax - item.depthMin) / (item.dateMax.Second - item.dateMin.Second));
|
{
|
||||||
var resultDepth = a * timestamp + b;
|
return item.depthMin;
|
||||||
return (float)resultDepth;
|
}
|
||||||
|
var w = timestamp / (item.dateMax - item.dateMin).TotalSeconds;
|
||||||
|
var d = ((item.depthMax - item.depthMin) * w)+ item.depthMin;
|
||||||
|
return (float)d;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -298,7 +298,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
);
|
);
|
||||||
dataDepthFromSaub.Add(dateRowItem);
|
dataDepthFromSaub.Add(dateRowItem);
|
||||||
}
|
}
|
||||||
var interp = new DepthInterpolation(dataDepthFromSaub.OrderBy(t => t.depthMin));
|
var interp = new DepthInterpolation(dataDepthFromSaub.OrderBy(t => t.dateMin));
|
||||||
if (dataSpinList.Any())
|
if (dataSpinList.Any())
|
||||||
{
|
{
|
||||||
var mode = dataSpinList[0].Mode;
|
var mode = dataSpinList[0].Mode;
|
||||||
|
Loading…
Reference in New Issue
Block a user