forked from ddrilling/AsbCloudServer
изменение формулы расчета глубины
изменение алгоритма формирования списка СПИН изменение алгоритма поиска глубины
This commit is contained in:
parent
af6eea370c
commit
abd0008615
@ -7,40 +7,34 @@ 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)
|
||||
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)
|
||||
{
|
||||
enumerator = collection.GetEnumerator();
|
||||
enumerator.MoveNext();
|
||||
dateMin = enumerator.Current.dateMin;
|
||||
this.collection = collection;
|
||||
}
|
||||
|
||||
public float GetDepth(DateTimeOffset date)
|
||||
{
|
||||
var isNotEnd = true;
|
||||
while (isOnInterval(date) && isNotEnd)
|
||||
{
|
||||
for (int i = 0; i < collection.Count; i++)
|
||||
{
|
||||
lastValue.x = date;
|
||||
lastValue.y = CalcValue(enumerator.Current, (date- enumerator.Current.dateMin).TotalSeconds);
|
||||
isNotEnd = enumerator.MoveNext();
|
||||
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 bool isOnInterval(DateTimeOffset date)
|
||||
=> date >= enumerator.Current.dateMin && date <= enumerator.Current.dateMax;
|
||||
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;
|
||||
var d = ((item.depthMax - item.depthMin) * w) + item.depthMin;
|
||||
return (float)d;
|
||||
}
|
||||
}
|
||||
|
@ -284,6 +284,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
dataSpinList.Add(dateRowItem);
|
||||
}
|
||||
await resultSpin.DisposeAsync();
|
||||
dataSpinList.OrderBy(s => s.Date);
|
||||
using var resultDepthFromSaub = await GetResultFromQueryAsync(queryDepthFromSaub, begin, idTelemetry, db, token);
|
||||
var dataDepthFromSaub = new List<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)>();
|
||||
while (resultDepthFromSaub.Read())
|
||||
@ -294,22 +295,26 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
resultDepthFromSaub.GetFieldValue<float>(1),
|
||||
resultDepthFromSaub.GetFieldValue<DateTimeOffset>(2),
|
||||
resultDepthFromSaub.GetFieldValue<float>(3)
|
||||
|
||||
);
|
||||
dataDepthFromSaub.Add(dateRowItem);
|
||||
}
|
||||
var interp = new DepthInterpolation(dataDepthFromSaub.OrderBy(t => t.dateMin));
|
||||
dataDepthFromSaub.OrderBy(o => o.dateMin);
|
||||
var depthInterpolation = new DepthInterpolation(dataDepthFromSaub);
|
||||
foreach (var item in dataSpinList)
|
||||
{
|
||||
item.Depth = depthInterpolation.GetDepth(item.Date);
|
||||
}
|
||||
if (dataSpinList.Any())
|
||||
{
|
||||
var mode = dataSpinList[0].Mode;
|
||||
var state = dataSpinList[0].State;
|
||||
var idSubsystem = GetSubsytemId(mode, state);
|
||||
var dateStart = dataSpinList[0].Date;
|
||||
var depthStart = interp.GetDepth(dateStart);
|
||||
var depthStart = dataSpinList[0].Depth;
|
||||
for (int i = 1; i < dataSpinList.Count; i++)
|
||||
{
|
||||
var dateEnd = dataSpinList[i].Date;
|
||||
var depthEnd = interp.GetDepth(dateEnd);
|
||||
var depthEnd = dataSpinList[i].Depth;
|
||||
if (idSubsystem.HasValue)
|
||||
{
|
||||
var operationTimeItem = new SubsystemOperationTime()
|
||||
@ -319,7 +324,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
DateStart = dateStart,
|
||||
DateEnd = dateEnd,
|
||||
DepthEnd = depthEnd,
|
||||
DepthStart = depthStart,
|
||||
DepthStart = depthStart
|
||||
};
|
||||
subsystemOperationTime.Add(operationTimeItem);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user