From fcb1bb92d94d06fbd74244f3a5de7d2f06a8fd55 Mon Sep 17 00:00:00 2001 From: eugeniy_ivanov Date: Thu, 22 Sep 2022 16:26:17 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9A=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=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4=D0=BE=D0=B2=20=D1=80=D0=B0=D1=81=D1=87=D0=B5=D1=82=D0=B0?= =?UTF-8?q?=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D0=BD=D0=B0=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=D0=BC=20=D0=BF=D0=BE=D0=B4=D1=81=D0=B8=D1=81=D1=82?= =?UTF-8?q?=D0=B5=D0=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/IDetectedOperationService.cs | 9 ++ .../DetectedOperationService.cs | 2 +- .../SubsystemOperationTimeService.cs | 87 +++++++++---------- 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/AsbCloudApp/Services/IDetectedOperationService.cs b/AsbCloudApp/Services/IDetectedOperationService.cs index 0a0bd999..aaa5cc1c 100644 --- a/AsbCloudApp/Services/IDetectedOperationService.cs +++ b/AsbCloudApp/Services/IDetectedOperationService.cs @@ -30,6 +30,14 @@ namespace AsbCloudApp.Services /// /// Task GetAsync(DetectedOperationRequest request, CancellationToken token); + + /// + /// Получить автоматически определенные по телеметрии операции + /// + /// + /// + /// + Task?> GetOperationsAsync(DetectedOperationRequest request, CancellationToken token); /// /// Удалить операции @@ -37,6 +45,7 @@ namespace AsbCloudApp.Services /// /// /// + Task DeleteAsync(DetectedOperationRequest request, CancellationToken token); /// diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs index eecaebc0..3e8b3df2 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs @@ -64,7 +64,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations return result; } - private async Task?> GetOperationsAsync(DetectedOperationRequest request, CancellationToken token) + public async Task?> GetOperationsAsync(DetectedOperationRequest request, CancellationToken token) { var well = await wellService.GetOrDefaultAsync(request.IdWell, token); if (well?.IdTelemetry is null || well.Timezone is null) diff --git a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs index b2422ed0..35403caa 100644 --- a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs +++ b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs @@ -86,7 +86,20 @@ namespace AsbCloudInfrastructure.Services.Subsystems var data = await GetOperationTimeAsync(request, token); if (data is null) return null; - var statList = await CalcStatAsync(data, request, token); + + var detectedOperationsRequest = new DetectedOperationRequest() + { + IdWell = request.IdWell, + IdsCategories = new List() { + 1,3 + }, + LtDate = request.LtDate, + GtDate = request.GtDate, + }; + var detectedOperations = await detectedOperationService.GetOperationsAsync(detectedOperationsRequest, token); + var depthInterval = GetDepthInterval(detectedOperations); + + var statList = CalcStat(data,depthInterval,request, token); return statList; } @@ -110,73 +123,59 @@ namespace AsbCloudInfrastructure.Services.Subsystems return items; } - private async Task> CalcStatAsync(IEnumerable dtos, SubsystemOperationTimeRequest request, CancellationToken token) + private IEnumerable CalcStat(IEnumerable dtos, (double depthIntervalRotor, double depthIntervalSlide) depthInterval, SubsystemOperationTimeRequest request, CancellationToken token) { var groupedDataSubsystems = dtos .GroupBy(o => o.IdSubsystem); - - var detectedOperationsRequest = new DetectedOperationRequest() - { - IdWell = request.IdWell, - IdsCategories = new List() { - 1,3 - }, - LtDate = request.LtDate, - GtDate = request.GtDate, - }; - var detectedOperations = await detectedOperationService.GetAsync(detectedOperationsRequest, token); - var periodGroupTotal = dtos.Sum(o => (o.DateEnd - o.DateStart).TotalHours); - - var gtDate = request.GtDate ?? dtos.Min(o => o.DateStart); - var ltDate = request.LtDate ?? dtos.Max(o => o.DateEnd); - - - var periodRequest = (ltDate - gtDate).TotalHours; - var result = groupedDataSubsystems.Select(g => { + double depthIntervalSubsystem = 0; + //AKB - MSE + if (g.Key == 1 | g.Key == 2) + { + depthIntervalSubsystem = depthInterval.depthIntervalRotor + depthInterval.depthIntervalSlide; + } + //Spin + if (g.Key == 65536) + { + depthIntervalSubsystem = depthInterval.depthIntervalSlide; + } + //Torque + if (g.Key == 65537) + { + depthIntervalSubsystem = depthInterval.depthIntervalRotor; + } + var periodGroup = g.Sum(o => (o.DateEnd - o.DateStart).TotalHours); var periodGroupDepth = g.Sum(o => o.DepthEnd - o.DepthStart); - var depthInterval = GetDepthInterval(g.Key, detectedOperations.Operations); + // var subsystemStat = new SubsystemStatDto() { IdSubsystem = g.Key, SubsystemName = subsystemService.GetOrDefault(g.Key)?.Name ?? "unknown", UsedTimeHours = periodGroup, - KUsage = periodGroupDepth / depthInterval, + KUsage = periodGroupDepth / depthIntervalSubsystem, SumDepthInterval = periodGroupDepth, OperationCount = g.Count() }; + if(subsystemStat.KUsage > 100) + subsystemStat.KUsage = 100; return subsystemStat; }); return result; } - private double GetDepthInterval (int idSubsystem, IEnumerable? detectedOperations) + private (double,double) GetDepthInterval (IEnumerable? detectedOperations) { + var depthInterval = (depthIntervalRotor:(double)0, depthIntervalSlide: (double)0); if (detectedOperations is null) - return 0; - var depthIntervalRotor = detectedOperations.Where(o => o.IdCategory == 1) + return depthInterval; + depthInterval.depthIntervalRotor = detectedOperations.Where(o => o.IdCategory == 1) .Sum(o => o.DepthEnd - o.DepthStart); - var depthIntervalSlide = detectedOperations.Where(o => o.IdCategory == 3) - .Sum(o => o.DepthEnd - o.DepthStart); - //AKB - MSE - if (idSubsystem == 1 | idSubsystem ==2) - { - return depthIntervalRotor + depthIntervalSlide; - } - //Spin - if (idSubsystem == 65536) - { - return depthIntervalSlide; - } - //Torque - if (idSubsystem == 65537) - { - return depthIntervalRotor; - } - return 0; + depthInterval.depthIntervalSlide = detectedOperations.Where(o => o.IdCategory == 3) + .Sum(o => o.DepthEnd - o.DepthStart); + return depthInterval; } private IQueryable? BuildQuery(SubsystemOperationTimeRequest request)