From cb2a8dfdeb6ef5a9ecbd6907025f2e27b5b8e9ed Mon Sep 17 00:00:00 2001 From: eugeniy_ivanov Date: Tue, 11 Oct 2022 17:25:59 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B0=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8F=D1=86=D0=B8=D0=B8=20=D0=B3=D0=BB=D1=83=D0=B1=D0=B8=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Subsystems/DepthInterpolation.cs | 50 ++++++++++++++++++ .../Services/Subsystems/Interpolation.cs | 52 ------------------- ...SubsystemOperationTimeBackgroundService.cs | 11 ++-- 3 files changed, 54 insertions(+), 59 deletions(-) create mode 100644 AsbCloudInfrastructure/Services/Subsystems/DepthInterpolation.cs delete mode 100644 AsbCloudInfrastructure/Services/Subsystems/Interpolation.cs diff --git a/AsbCloudInfrastructure/Services/Subsystems/DepthInterpolation.cs b/AsbCloudInfrastructure/Services/Subsystems/DepthInterpolation.cs new file mode 100644 index 00000000..def5886a --- /dev/null +++ b/AsbCloudInfrastructure/Services/Subsystems/DepthInterpolation.cs @@ -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 +} diff --git a/AsbCloudInfrastructure/Services/Subsystems/Interpolation.cs b/AsbCloudInfrastructure/Services/Subsystems/Interpolation.cs deleted file mode 100644 index cf87da98..00000000 --- a/AsbCloudInfrastructure/Services/Subsystems/Interpolation.cs +++ /dev/null @@ -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 -} diff --git a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeBackgroundService.cs b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeBackgroundService.cs index b2cf39fc..def85fa4 100644 --- a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeBackgroundService.cs +++ b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeBackgroundService.cs @@ -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(0), - resultDepthFromSaub.GetFieldValue(1), + resultDepthFromSaub.GetFieldValue(1), resultDepthFromSaub.GetFieldValue(2), - resultDepthFromSaub.GetFieldValue(3) + resultDepthFromSaub.GetFieldValue(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;