From 58d7c11940773438df68e66dbe2701c538e6398b Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 2 Oct 2024 12:10:01 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=B8=D0=BD?= =?UTF-8?q?=D0=B8=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D0=B8=20?= =?UTF-8?q?=D0=BC=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=B3=D0=BB=D1=83=D0=B1=D0=B8=D0=BD=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E?= =?UTF-8?q?=D1=89=D0=B5=D0=B3=D0=BE=20=D1=80=D0=B0=D1=81=D1=87=D0=B5=D1=82?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/ITelemetryDataSaubService.cs | 14 ++++++-- .../Services/DataSaubStatServiceTest.cs | 2 +- .../Services/DataSaubStatService.cs | 2 +- .../Services/SAUB/TelemetryDataSaubService.cs | 36 +++++++++++++------ .../Services/Subsystems/SubsystemService.cs | 18 ++++------ 5 files changed, 45 insertions(+), 27 deletions(-) diff --git a/AsbCloudApp/Services/ITelemetryDataSaubService.cs b/AsbCloudApp/Services/ITelemetryDataSaubService.cs index 4a23ee87..72aee988 100644 --- a/AsbCloudApp/Services/ITelemetryDataSaubService.cs +++ b/AsbCloudApp/Services/ITelemetryDataSaubService.cs @@ -15,14 +15,24 @@ public interface ITelemetryDataSaubService : ITelemetryDataService /// Получение телеметрии для РТК статистики /// - /// + /// /// /// /// /// /// /// - Task> Get(IEnumerable idsTelemetries, bool isBitOnBottom, DateTimeOffset geDate, DateTimeOffset leDate, int take, CancellationToken token); + Task> Get(int idTelemetry, bool isBitOnBottom, DateTimeOffset geDate, DateTimeOffset leDate, int take, CancellationToken token); + + /// + /// Получение минимальных и максимальных глубин скважин на определенную дату для заданных телеметрий + /// + /// + /// + /// + /// + /// + Task> GetMinAndMaxWellDepths(IEnumerable idsTelemetries, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token); /// /// усредненная статистика по 1м за весь период diff --git a/AsbCloudInfrastructure.Tests/Services/DataSaubStatServiceTest.cs b/AsbCloudInfrastructure.Tests/Services/DataSaubStatServiceTest.cs index 80783c73..486ddc97 100644 --- a/AsbCloudInfrastructure.Tests/Services/DataSaubStatServiceTest.cs +++ b/AsbCloudInfrastructure.Tests/Services/DataSaubStatServiceTest.cs @@ -220,7 +220,7 @@ public class DataSaubStatServiceTest } dataSaubServiceMock - .Get(Arg.Any>(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()) + .Get(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()) .Returns(telemetryDataSaubDtos); dataSaubStatService = new DataSaubStatService( diff --git a/AsbCloudInfrastructure/Services/DataSaubStatService.cs b/AsbCloudInfrastructure/Services/DataSaubStatService.cs index 82ee0416..bdeaf6eb 100644 --- a/AsbCloudInfrastructure/Services/DataSaubStatService.cs +++ b/AsbCloudInfrastructure/Services/DataSaubStatService.cs @@ -78,7 +78,7 @@ public class DataSaubStatService : IDataSaubStatService var geDate = detectedOperations.First().DateStart; var leDate = detectedOperations.OrderByDescending(d => d.DateEnd).First().DateEnd; - var dataSaub = await dataSaubService.Get([idTelemetry], true, geDate, leDate, 100_000, token); + var dataSaub = await dataSaubService.Get(idTelemetry, true, geDate, leDate, 100_000, token); if (!dataSaub.Any()) return 0; diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSaubService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSaubService.cs index 0abd8fdf..4405d026 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSaubService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSaubService.cs @@ -13,8 +13,6 @@ using System.Linq; using System.Text.Csv; using System.Threading; using System.Threading.Tasks; -using AsbCloudApp.Data; -using AsbCloudApp.Requests; namespace AsbCloudInfrastructure.Services.SAUB; @@ -37,19 +35,14 @@ public class TelemetryDataSaubService : TelemetryDataBaseService> Get(IEnumerable idsTelemetries, bool isBitOnBottom, DateTimeOffset geDate, DateTimeOffset leDate, int take, CancellationToken token) + public async Task> Get(int idTelemetry, bool isBitOnBottom, DateTimeOffset geDate, DateTimeOffset leDate, int take, CancellationToken token) { - var offsetDict = new Dictionary(); - foreach (var idTelemetry in idsTelemetries) - { - offsetDict.Add(idTelemetry, telemetryService.GetTimezone(idTelemetry).Offset); - } - + var offset = telemetryService.GetTimezone(idTelemetry).Offset; var geDateUtc = geDate.ToUniversalTime(); var leDateUtc = leDate.ToUniversalTime(); var query = db.Set() - .Where(t => idsTelemetries.Contains(t.IdTelemetry)) + .Where(t => t.IdTelemetry == idTelemetry) .Where(t => t.DateTime >= geDateUtc) .Where(t => t.DateTime <= leDateUtc); @@ -61,10 +54,31 @@ public class TelemetryDataSaubService : TelemetryDataBaseService Convert(e, offsetDict.GetValueOrDefault(e.IdTelemetry).TotalHours)); + + var dtos = entities.Select(e => Convert(e, offset.TotalHours)); return dtos; } + public async Task> GetMinAndMaxWellDepths(IEnumerable idsTelemetries, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token) + { + var geDateUtc = geDate.ToUniversalTime(); + var leDateUtc = leDate.ToUniversalTime(); + + var query = db.Set() + .Where(t => idsTelemetries.Contains(t.IdTelemetry)) + .Where(t => t.DateTime >= geDateUtc) + .Where(t => t.DateTime <= leDateUtc) + .GroupBy(t => t.IdTelemetry); + + var result = await query + .ToDictionaryAsync(t => t.Key, t => ( + t.MinBy(x => x.WellDepth)!.WellDepth, + t.MaxBy(x => x.WellDepth)!.WellDepth + )); + + return result; + } + public async Task> GetTelemetryDataStatAsync(int idTelemetry, CancellationToken token) { var timezone = telemetryService.GetTimezone(idTelemetry); diff --git a/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs b/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs index f5acee31..0292d126 100644 --- a/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs +++ b/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs @@ -141,26 +141,20 @@ public class SubsystemService : ISubsystemService .GetOrDefaultTelemetriesByIdsWells(request.IdsWell) .ToDictionary(t => t.Id, t => t.IdWell); - var dtNow = DateTimeOffset.UtcNow; var geDate = request.GeDate ?? SubsystemPlanFactRequest.ValidationMinDate; var leDate = request.LeDate ?? DateTimeOffset.UtcNow; - var telemetryDataSaub = await telemetryDataSaubService.Get(telemetriesDict.Keys, false, geDate, leDate, 100_000, token); - - var groupedTelemetryDataSaub = telemetryDataSaub - .GroupBy(t => t.IdTelemetry) - .ToDictionary(t => t.Key, t => new - { - IdWell = telemetriesDict.GetValueOrDefault(t.Key)!, - MinDepth = t.MinBy(x => x.WellDepth)!.WellDepth, - MaxDepth = t.MaxBy(x => x.WellDepth)!.WellDepth - }); + var groupedTelemetryDataSaub = await telemetryDataSaubService.GetMinAndMaxWellDepths(telemetriesDict.Keys, geDate, leDate, token); var result = new List(); foreach (var telemetryDataSaubItem in groupedTelemetryDataSaub) { + var idWell = telemetriesDict.GetValueOrDefault(telemetryDataSaubItem.Key); + if (!idWell.HasValue) + continue; + var telemetryDataSaubInfo = telemetryDataSaubItem.Value; - var requestProcessMapPlan = new ProcessMapPlanBaseRequestWithWell(telemetryDataSaubInfo.IdWell!.Value, telemetryDataSaubInfo.MinDepth, telemetryDataSaubInfo.MaxDepth); + var requestProcessMapPlan = new ProcessMapPlanBaseRequestWithWell(idWell.Value, telemetryDataSaubInfo.MinDepth, telemetryDataSaubInfo.MaxDepth); var processMapPlanSubsystems = await processMapPlanRepository.GetCurrent(requestProcessMapPlan, token); foreach (var processMapPlanSubsystem in processMapPlanSubsystems)