изменение формулы расчета глубины

изменение алгоритма формирования списка СПИН
изменение алгоритма поиска глубины
This commit is contained in:
eugeniy_ivanov 2022-10-14 15:12:30 +05:00
parent af6eea370c
commit abd0008615
2 changed files with 23 additions and 24 deletions

View File

@ -7,32 +7,26 @@ namespace AsbCloudInfrastructure.Services.Subsystems.Utils
#nullable enable
internal class DepthInterpolation
{
private IEnumerator<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> enumerator;
private List<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> collection;
(DateTimeOffset x, float y) lastValue = default;
private DateTimeOffset dateMin;
public DepthInterpolation(IOrderedEnumerable<(DateTimeOffset dateMin, float depthMin, DateTimeOffset dateMax, float depthMax)> collection)
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++)
{
if (date <= collection[i].dateMax && date >= collection[i].dateMin)
{
lastValue.x = date;
lastValue.y = CalcValue(enumerator.Current, (date- enumerator.Current.dateMin).TotalSeconds);
isNotEnd = enumerator.MoveNext();
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)
@ -40,7 +34,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems.Utils
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;
}
}

View File

@ -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);
}