From f570e82b410ecc8f5f254c4d5b061b666bfc59ae Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 28 Feb 2024 13:11:44 +0500 Subject: [PATCH 01/12] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=BE=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=80=D1=82=D0=BA-=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Clients/IProcessMapReportDrilling.cs | 16 ++ .../ProcessMapReportDrillingControllerTest.cs | 237 ++++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs create mode 100644 AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs new file mode 100644 index 00000000..b721df75 --- /dev/null +++ b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs @@ -0,0 +1,16 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Data.ProcessMaps; +using AsbCloudApp.Data.ProcessMaps.Report; +using AsbCloudApp.Requests; +using Microsoft.AspNetCore.Mvc; +using Refit; + +namespace AsbCloudWebApi.IntegrationTests.Clients; + +public interface IProcessMapReportDrilling +{ + private const string BaseRoute = "/api/well/{idWell}/ProcessMapReportDrilling"; + + [Get($"{BaseRoute}/report")] + Task>> GetReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); +} diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs new file mode 100644 index 00000000..2d08b0c8 --- /dev/null +++ b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs @@ -0,0 +1,237 @@ +using AsbCloudApp.Requests; +using AsbCloudDb.Model.ProcessMapPlan; +using AsbCloudWebApi.IntegrationTests.Clients; +using Mapster; +using Microsoft.EntityFrameworkCore; +using System.Net; +using System.Reflection; +using AsbCloudDb.Model.ProcessMaps; +using AsbCloudWebApi.IntegrationTests.Data; +using Refit; +using Xunit; +using AsbCloudApp.Data.ProcessMaps; +using AsbCloudDb.Model; + +namespace AsbCloudWebApi.IntegrationTests.Controllers.ProcessMapPlan; + +public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest +{ + + private readonly WellSectionType wellSection = new WellSectionType() + { + Id = 1, + Caption = "Секция 1", + Order = 1 + }; + + private readonly WellOperationCategory wellOperationCategory = new WellOperationCategory() + { + Id = 1, + IdParent = null, + KeyValueName = "Name", + Name = "Name" + }; + + private readonly WellOperation wellOperation = new WellOperation() + { + CategoryInfo= "CategoryInfo", + Id = 10, + Comment = "Comment", + DateStart = DateTimeOffset.UtcNow, + DepthEnd = 1, + DepthStart = 0.6, + DurationHours = 10, + IdCategory = 1, + IdPlan = null, + IdType = 1, + IdUser = 1, + IdWell = 1, + IdWellSectionType = 1, + LastUpdateDate = DateTimeOffset.UtcNow + }; + + private readonly List dataSaubStats = new List() + { + + new DataSaubStat() + { + AxialLoad = 0, + AxialLoadLimitMax = 10, + AxialLoadSp = 8, + BlockSpeedSp = 50.0, + DateEnd = DateTimeOffset.UtcNow, + DateStart = DateTimeOffset.UtcNow.AddDays(-1), + DepthEnd = 85.99299621582031, + DepthStart = 85.9260025024414, + EnabledSubsystems = 0, + Flow = 10, + HasOscillation = true, + Id = 1, + IdCategory = 1, + IdFeedRegulator = 0, + IdTelemetry = 1, + Pressure = 24, + PressureIdle = 0, + PressureSp = 40, + RotorSpeed = 11.3, + RotorTorque = 1, + RotorTorqueLimitMax = 26.5, + RotorTorqueSp = 5, + Speed = 80.3924560546875 + }, + new DataSaubStat() + { + AxialLoad = 2, + AxialLoadLimitMax = 10.0, + AxialLoadSp = 8, + BlockSpeedSp = 20, + DateEnd = DateTimeOffset.UtcNow.AddDays(-1), + DateStart = DateTimeOffset.UtcNow.AddDays(-2), + DepthEnd = 86.28099822998047, + DepthStart = 86.21900177001953, + EnabledSubsystems = 1, + Flow = 20, + HasOscillation = true, + Id = 2, + IdCategory = 1, + IdFeedRegulator = 1, + IdTelemetry = 1, + Pressure = 30, + PressureIdle = 20, + PressureSp = 40, + RotorSpeed = 11.251153300212916, + RotorTorque = 7, + RotorTorqueLimitMax = 26.5, + RotorTorqueSp = 9, + Speed = 74.395751953125 + }, + new DataSaubStat() + { + AxialLoad = 4, + AxialLoadLimitMax = 15.0, + AxialLoadSp = 8, + BlockSpeedSp = 110.0, + DateEnd = DateTimeOffset.UtcNow.AddDays(-2), + DateStart = DateTimeOffset.UtcNow.AddDays(-3), + DepthEnd = 106.7490005493164, + DepthStart = 106.47899627685547, + EnabledSubsystems = 1, + Flow = 30, + HasOscillation = true, + Id = 3, + IdCategory = 1, + IdFeedRegulator = 1, + IdTelemetry = 1, + Pressure = 36, + PressureIdle = 23.0, + PressureSp = 63.0, + RotorSpeed = 11.334207942999628, + RotorTorque = 14, + RotorTorqueLimitMax = 15.0, + RotorTorqueSp = 13, + Speed = 108.001708984375 + } + }; + + + + + private readonly ProcessMapPlanDrilling entity = new () + { + Id = 0, + IdAuthor = 1, + IdEditor = null, + Creation = DateTimeOffset.UtcNow, + Obsolete = null, + IdState = AsbCloudDb.Model.ChangeLogAbstract.IdStateActual, + IdPrevious = null, + + IdWell = 1, + IdWellSectionType = 1, + DepthStart = 0.5, + DepthEnd = 1.5, + + IdMode = 1, + AxialLoadPlan = 2.718281, + AxialLoadLimitMax = 3.1415926, + DeltaPressurePlan = 4, + DeltaPressureLimitMax = 5, + TopDriveTorquePlan = 6, + TopDriveTorqueLimitMax = 7, + TopDriveSpeedPlan = 8, + TopDriveSpeedLimitMax = 9, + FlowPlan = 10, + FlowLimitMax = 11, + RopPlan = 12, + UsageSaub = 13, + UsageSpin = 14, + Comment = "это тестовая запись", + }; + + private IProcessMapReportDrilling client; + + public ProcessMapReportDrillingControllerTest(WebAppFactoryFixture factory) : base(factory) + { + dbContext.CleanupDbSet(); + client = factory.GetAuthorizedHttpClient(); + } + + + + [Fact] + public async Task Get_rtk_report_returns_success() + { + //arrange + var dbset = dbContext.Set(); + dbset.Add(entity); + entity.Id = 1; + dbset.Add(entity); + entity.Id = 2; + dbset.Add(entity); + + var dbSetWellOperationCategory = dbContext.Set(); + dbSetWellOperationCategory.Add(wellOperationCategory); + + var dbSetWellOperation = dbContext.Set(); + dbSetWellOperation.Add(wellOperation); + + var dbSetDataSaubStat = dbContext.Set(); + dbSetDataSaubStat.AddRange(dataSaubStats); + + dbContext.SaveChanges(); + + //act + var request = new DataSaubStatRequest(); + var response = await client.GetReportAsync(1, request, CancellationToken.None); + + //assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(response.Content); + Assert.Equal(dataSaubStats.Count() - 1, response.Content.Count()); + + //act + request = new DataSaubStatRequest() { + DeltaAxialLoad = 5, + DeltaPressure = 15, + DeltaRotorTorque = 10 + }; + response = await client.GetReportAsync(1, request, CancellationToken.None); + + //assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(response.Content); + Assert.Equal(1, response.Content.Count()); + + //act + request = new DataSaubStatRequest() + { + DeltaAxialLoad = 15, + DeltaPressure = 25, + DeltaRotorTorque = 20 + }; + response = await client.GetReportAsync(1, request, CancellationToken.None); + + //assert + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); + } +} From b389b181d5dd18379823dec7df08b0fd69bad6e0 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 29 Feb 2024 09:10:15 +0500 Subject: [PATCH 02/12] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=BE=D0=BD=D0=BD=D1=8B=D0=B5=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=20=D0=BD=D0=B0=20=D1=81=D0=BA=D0=B0=D0=B8=D1=87?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=A0=D0=A2=D0=9A-=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Clients/IProcessMapReportDrilling.cs | 4 ++ .../ProcessMapReportDrillingControllerTest.cs | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs index b721df75..12adac91 100644 --- a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs +++ b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs @@ -13,4 +13,8 @@ public interface IProcessMapReportDrilling [Get($"{BaseRoute}/report")] Task>> GetReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); + + [Get($"{BaseRoute}/report/export")] + Task> ExportReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); + } diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs index 2d08b0c8..77951c23 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs @@ -172,7 +172,6 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest public ProcessMapReportDrillingControllerTest(WebAppFactoryFixture factory) : base(factory) { - dbContext.CleanupDbSet(); client = factory.GetAuthorizedHttpClient(); } @@ -181,6 +180,9 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest [Fact] public async Task Get_rtk_report_returns_success() { + //clear + dbContext.CleanupDbSet(); + //arrange var dbset = dbContext.Set(); dbset.Add(entity); @@ -234,4 +236,38 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest //assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } + + [Fact] + public async Task Export_rtk_report_returns_success() + { + //clear + dbContext.CleanupDbSet(); + + //arrange + var dbset = dbContext.Set(); + dbset.Add(entity); + entity.Id = 1; + dbset.Add(entity); + entity.Id = 2; + dbset.Add(entity); + + var dbSetWellOperationCategory = dbContext.Set(); + dbSetWellOperationCategory.Add(wellOperationCategory); + + var dbSetWellOperation = dbContext.Set(); + dbSetWellOperation.Add(wellOperation); + + var dbSetDataSaubStat = dbContext.Set(); + dbSetDataSaubStat.AddRange(dataSaubStats); + + dbContext.SaveChanges(); + + //act + var request = new DataSaubStatRequest(); + var response = await client.ExportReportAsync(1, request, CancellationToken.None); + + //assert + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(response.Content); + } } From 2ece8cdb9f6d1055ce45db6a30aeab80f9fe2b72 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 29 Feb 2024 13:08:53 +0500 Subject: [PATCH 03/12] =?UTF-8?q?=D0=94=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BE=D0=B4=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B0=20=D1=81=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D1=80=D1=82=D0=BA-=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=82=D0=B0=20=D0=BD=D0=B0=20=D0=BD=D0=B5?= =?UTF-8?q?=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Clients/IProcessMapReportDrilling.cs | 2 +- .../ProcessMapReportDrillingControllerTest.cs | 114 ++++++++++++------ 2 files changed, 79 insertions(+), 37 deletions(-) diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs index 12adac91..92a4353b 100644 --- a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs +++ b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapReportDrilling.cs @@ -15,6 +15,6 @@ public interface IProcessMapReportDrilling Task>> GetReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); [Get($"{BaseRoute}/report/export")] - Task> ExportReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); + Task> ExportReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken); } diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs index 77951c23..3083d514 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapReportDrillingControllerTest.cs @@ -1,27 +1,22 @@ using AsbCloudApp.Requests; -using AsbCloudDb.Model.ProcessMapPlan; -using AsbCloudWebApi.IntegrationTests.Clients; -using Mapster; -using Microsoft.EntityFrameworkCore; -using System.Net; -using System.Reflection; -using AsbCloudDb.Model.ProcessMaps; -using AsbCloudWebApi.IntegrationTests.Data; -using Refit; -using Xunit; -using AsbCloudApp.Data.ProcessMaps; using AsbCloudDb.Model; +using AsbCloudDb.Model.ProcessMaps; +using AsbCloudWebApi.IntegrationTests.Clients; +using Org.BouncyCastle.Asn1.Ocsp; +using System.Net; +using System.Net.Http.Headers; +using Xunit; namespace AsbCloudWebApi.IntegrationTests.Controllers.ProcessMapPlan; -public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest +public class ProcessMapReportDrillingControllerTest : BaseIntegrationTest { private readonly WellSectionType wellSection = new WellSectionType() { - Id = 1, - Caption = "Секция 1", - Order = 1 + Id = 1, + Caption = "Секция 1", + Order = 1 }; private readonly WellOperationCategory wellOperationCategory = new WellOperationCategory() @@ -29,12 +24,12 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest Id = 1, IdParent = null, KeyValueName = "Name", - Name = "Name" + Name = "Name" }; private readonly WellOperation wellOperation = new WellOperation() { - CategoryInfo= "CategoryInfo", + CategoryInfo = "CategoryInfo", Id = 10, Comment = "Comment", DateStart = DateTimeOffset.UtcNow, @@ -59,8 +54,8 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest AxialLoadLimitMax = 10, AxialLoadSp = 8, BlockSpeedSp = 50.0, - DateEnd = DateTimeOffset.UtcNow, - DateStart = DateTimeOffset.UtcNow.AddDays(-1), + DateEnd = DateTimeOffset.UtcNow.AddMinutes(40), + DateStart = DateTimeOffset.UtcNow.AddMinutes(30), DepthEnd = 85.99299621582031, DepthStart = 85.9260025024414, EnabledSubsystems = 0, @@ -85,8 +80,8 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest AxialLoadLimitMax = 10.0, AxialLoadSp = 8, BlockSpeedSp = 20, - DateEnd = DateTimeOffset.UtcNow.AddDays(-1), - DateStart = DateTimeOffset.UtcNow.AddDays(-2), + DateEnd = DateTimeOffset.UtcNow.AddMinutes(30), + DateStart = DateTimeOffset.UtcNow.AddMinutes(20), DepthEnd = 86.28099822998047, DepthStart = 86.21900177001953, EnabledSubsystems = 1, @@ -111,8 +106,8 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest AxialLoadLimitMax = 15.0, AxialLoadSp = 8, BlockSpeedSp = 110.0, - DateEnd = DateTimeOffset.UtcNow.AddDays(-2), - DateStart = DateTimeOffset.UtcNow.AddDays(-3), + DateEnd = DateTimeOffset.UtcNow.AddMinutes(20), + DateStart = DateTimeOffset.UtcNow.AddMinutes(10), DepthEnd = 106.7490005493164, DepthStart = 106.47899627685547, EnabledSubsystems = 1, @@ -136,7 +131,7 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest - private readonly ProcessMapPlanDrilling entity = new () + private readonly ProcessMapPlanDrilling entity = new() { Id = 0, IdAuthor = 1, @@ -172,18 +167,15 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest public ProcessMapReportDrillingControllerTest(WebAppFactoryFixture factory) : base(factory) { - client = factory.GetAuthorizedHttpClient(); + client = factory.GetAuthorizedHttpClient(string.Empty); } - [Fact] - public async Task Get_rtk_report_returns_success() + public async Task Get_rtk_report_by_default_request_returns_success() { - //clear - dbContext.CleanupDbSet(); - //arrange + dbContext.CleanupDbSet(); var dbset = dbContext.Set(); dbset.Add(entity); entity.Id = 1; @@ -210,28 +202,77 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); Assert.Equal(dataSaubStats.Count() - 1, response.Content.Count()); + } + + [Fact] + public async Task Get_rtk_report_by_parametrize_request_returns_success() + { + //arrange + dbContext.CleanupDbSet(); + var dbset = dbContext.Set(); + dbset.Add(entity); + entity.Id = 1; + dbset.Add(entity); + entity.Id = 2; + dbset.Add(entity); + + var dbSetWellOperationCategory = dbContext.Set(); + dbSetWellOperationCategory.Add(wellOperationCategory); + + var dbSetWellOperation = dbContext.Set(); + dbSetWellOperation.Add(wellOperation); + + var dbSetDataSaubStat = dbContext.Set(); + dbSetDataSaubStat.AddRange(dataSaubStats); + + dbContext.SaveChanges(); //act - request = new DataSaubStatRequest() { + var request = new DataSaubStatRequest() + { DeltaAxialLoad = 5, DeltaPressure = 15, DeltaRotorTorque = 10 }; - response = await client.GetReportAsync(1, request, CancellationToken.None); + var response = await client.GetReportAsync(1, request, CancellationToken.None); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Content); - Assert.Equal(1, response.Content.Count()); + Assert.Equal(1, response.Content.Count()); + } + + [Fact] + public async Task Get_rtk_report_returns_BadRequest() + { + //arrange + dbContext.CleanupDbSet(); + var dbset = dbContext.Set(); + dbset.Add(entity); + entity.Id = 1; + dbset.Add(entity); + entity.Id = 2; + dbset.Add(entity); + + var dbSetWellOperationCategory = dbContext.Set(); + dbSetWellOperationCategory.Add(wellOperationCategory); + + var dbSetWellOperation = dbContext.Set(); + dbSetWellOperation.Add(wellOperation); + + var dbSetDataSaubStat = dbContext.Set(); + dbSetDataSaubStat.AddRange(dataSaubStats); + + dbContext.SaveChanges(); //act - request = new DataSaubStatRequest() + var request = new DataSaubStatRequest() { DeltaAxialLoad = 15, DeltaPressure = 25, DeltaRotorTorque = 20 }; - response = await client.GetReportAsync(1, request, CancellationToken.None); + var response = await client.GetReportAsync(1, request, CancellationToken.None); //assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); @@ -268,6 +309,7 @@ public class ProcessMapReportDrillingControllerTest: BaseIntegrationTest //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.NotNull(response.Content); + Assert.Equal("application/octet-stream", response.ContentHeaders?.ContentType?.MediaType); + Assert.True(response.ContentHeaders?.ContentLength > 0); } } From d55b9b41386e2506b914b0c0ec25d69a43b4e569 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 29 Feb 2024 13:45:28 +0500 Subject: [PATCH 04/12] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=B0=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20WellOpera?= =?UTF-8?q?tionExportServiceTest=20(=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B8?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B8=D1=81=D1=8C=20=D0=B4=D0=B0=D1=82=D1=8B?= =?UTF-8?q?=20=D1=81=D0=BE=20=D1=81=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B8=20=D0=B1=D0=B5=D0=B7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WellOperationExportServiceTest.cs | 102 ++++++++++-------- 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs b/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs index 0c8523c4..ad3d3895 100644 --- a/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs +++ b/AsbCloudWebApi.Tests/Services/WellOperationExport/WellOperationExportServiceTest.cs @@ -5,11 +5,9 @@ using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudApp.Services.WellOperationImport; using AsbCloudDb.Model; -using AsbCloudInfrastructure.Repository; using AsbCloudInfrastructure.Services.WellOperationImport; using AsbCloudInfrastructure.Services.WellOperationImport.FileParser; using NSubstitute; -using SignalRSwaggerGen.Enums; using System; using System.Collections.Generic; using System.Linq; @@ -34,41 +32,6 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport private WellOperationImportService wellOperationImportService; private IWellOperationExcelParser wellOperationDefaultExcelParser; - private readonly WellOperationDto[] operations = new WellOperationDto[2] { - new WellOperationDto() { - Id = 5, - IdWell = idWell, - IdUser = 1, - IdType = 0, - IdWellSectionType = 1, - WellSectionTypeName = "1", - IdCategory = 1, - CategoryName = "1", - CategoryInfo = "CategoryInfo 1", - DepthStart = 10, - DepthEnd = 20, - DateStart = GetDate(days: 0), - DurationHours = 10, - Comment = "Комментарий 1", - }, - new WellOperationDto() { - Id = 6, - IdWell = idWell, - IdUser = 1, - IdType = 0, - IdWellSectionType = 2, - WellSectionTypeName = "2", - IdCategory = 2, - CategoryName = "2", - CategoryInfo = "CategoryInfo 2", - DepthStart = 20, - DepthEnd = 30, - DateStart = GetDate(days: 1), - DurationHours = 20, - Comment = "Комментарий 2", - } - }; - private readonly WellSectionTypeDto[] sectionTypes = new WellSectionTypeDto[2] { new WellSectionTypeDto() @@ -106,12 +69,6 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport }; private readonly ITestOutputHelper output; - private static DateTime GetDate(int days) - { - var date = DateTime.Now.AddDays(days); - return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second); - } - public WellOperationExportServiceTest(ITestOutputHelper output) { wellService = Substitute.For(); @@ -123,17 +80,20 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport wellOperationImportService = new WellOperationImportService(wellService, wellOperationRepository, wellOperationCategoryRepository); wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser(); this.output = output; + + wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto() + { + Hours = 5 + }); } [Fact] public async Task Check_Exported_WellOperations_With_Operations_In_Db() { - wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto() - { - Hours = 5 - }); + var operations = getOperations(); var localOperations = operations.ToArray(); + foreach (var operation in localOperations) operation.Id = 0; @@ -161,6 +121,7 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport public void TestDataContainsNotDefaultProps() { var initOk = true; + var operations = getOperations(); for (int i = 0; i < operations.Length; i++) { var operation = operations[i]; @@ -204,5 +165,52 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport yield return prop.Name; } } + + private WellOperationDto[] getOperations() + { + + var timezone = wellService.GetTimezone(idWell); + + DateTimeOffset GetDate(int days) + { + var date = DateTimeOffset.UtcNow.AddDays(days); + return new DateTimeOffset(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, TimeSpan.FromHours(timezone.Hours)); + } + + return new WellOperationDto[2] { + new WellOperationDto() { + Id = 5, + IdWell = idWell, + IdUser = 1, + IdType = 0, + IdWellSectionType = 1, + WellSectionTypeName = "1", + IdCategory = 1, + CategoryName = "1", + CategoryInfo = "CategoryInfo 1", + DepthStart = 10, + DepthEnd = 20, + DateStart = GetDate(days: 0), + DurationHours = 10, + Comment = "Комментарий 1", + }, + new WellOperationDto() { + Id = 6, + IdWell = idWell, + IdUser = 1, + IdType = 0, + IdWellSectionType = 2, + WellSectionTypeName = "2", + IdCategory = 2, + CategoryName = "2", + CategoryInfo = "CategoryInfo 2", + DepthStart = 20, + DepthEnd = 30, + DateStart = GetDate(days: 1), + DurationHours = 20, + Comment = "Комментарий 2", + } + }; + } } } From 3176e89236fac6c921721febae5d75c32c30f408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 1 Mar 2024 07:32:02 +0300 Subject: [PATCH 05/12] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=B0?= =?UTF-8?q?=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC=20=D1=83=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D1=8C=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DetectedOperation/DetectedOperationDto.cs | 8 ++- .../DetectOperations/DetectableTelemetry.cs | 3 +- .../DetectedOperationExportService.cs | 11 ++-- .../Detectors/DetectorAbstract.cs | 26 +++----- .../Detectors/DetectorSlipsTime.cs | 59 +++++++++++++++---- .../Specifications/Удержание в клиньях.md | 27 ++++++--- 6 files changed, 88 insertions(+), 46 deletions(-) diff --git a/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs b/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs index e81a45fb..ce433aff 100644 --- a/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs +++ b/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs @@ -77,7 +77,13 @@ public class DetectedOperationDto: IId /// [Required] public WellOperationCategoryDto OperationCategory { get; set; } = null!; - + + /// + /// Положение долота на момент окончания операции + /// + [Required] + public float BitDepth { get; set; } + /// /// Ключевой параметр операции /// diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs index 9c72c4e8..aeb18fe2 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectableTelemetry.cs @@ -13,4 +13,5 @@ public class DetectableTelemetry public float BlockPosition { get; set; } public float BitDepth { get; set; } public float RotorSpeed { get; set; } -} + public float AxialLoad { get; set; } +} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs index 3ba4350a..fd33c32a 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationExportService.cs @@ -118,13 +118,14 @@ public class DetectedOperationExportService for (int i = 0; i < operations.Count; i++) { var current = operations[i]; - var dateStart = current.DateStart.ToRemoteDateTime(well.Timezone.Hours); - var dateEnd = current.DateEnd.ToRemoteDateTime(well.Timezone.Hours); + var dateStart = current.DateStart.DateTime; + var dateEnd = current.DateEnd.DateTime; var row = sheet.Row(5 + i + headerRowsCount); var categoryName = GetCategoryName(wellOperationCategories, current); + row.Cell(columnDateStart).SetCellValue(dateStart); row.Cell(columnOperationName).SetCellValue(categoryName); row.Cell(columnDateEnd).SetCellValue(dateEnd); row.Cell(columnDuration).SetCellValue((dateEnd - dateStart).TotalMinutes); @@ -143,9 +144,7 @@ public class DetectedOperationExportService query.Add("end", dateStart.AddSeconds(1800 * 0.9).ToString("yyyy-MM-ddTHH:mm:ss.fff")); query.Add("range", "1800"); - row.Cell(columnDateStart).SetCellValue(dateStart); - - var link = $"{host}/well/{well.Id}/telemetry/monitoring{query}"; + var link = $"{host}/well/{well.Id}/telemetry/monitoring{query}"; row.Cell(columnDateStart).SetHyperlink(link); var deltaDepth = i > 0 && i + 1 < operations.Count @@ -180,6 +179,8 @@ public class DetectedOperationExportService 1 => "Не определено начало операции", 101 => "Разница глубин забоя и положением долота", 300 => "Низкое давление", + 301 => "Высокое давление", + 700 => "Изменение глубины долота и осевая нагрузка < веса на крюке", _ => idReasonOfEnd.ToString($"Причина № {idReasonOfEnd}"), }; diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs index 6c5b99de..ec05be39 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs @@ -1,5 +1,4 @@ -using AsbCloudDb.Model; -using System; +using System; using System.Collections.Generic; using AsbCloudApp.Data.DetectedOperation; @@ -7,8 +6,6 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors { public abstract class DetectorAbstract { - private readonly int stepLength = 3; - protected const int IdReasonOfEnd_NotDetected = 0; protected const int IdReasonOfEnd_NotDetectBegin = 1; @@ -33,7 +30,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors protected const int IdReasonOfEnd_Drilling = 600; - protected const int IdReasonOfEnd_Custom1 = 10_000; + protected const int IdReasonOfEnd_ChangeBithDepthAndAxiloadLessHookWeight = 700; public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end, DetectedOperationDto? previousOperation, out OperationDetectorResult? result) @@ -44,9 +41,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors // Поиск окончания соответствия критерию int idReasonOfEnd = 0; var positionEnd = begin; + while (positionEnd < end) { - positionEnd += stepLength; + positionEnd += 1; if (positionEnd > end) break; @@ -55,15 +53,9 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors if (idReasonOfEnd != IdReasonOfEnd_NotDetected) break; } - + var (Begin, End) = RefineEdges(telemetry, begin, positionEnd); - - if (!IsValidTelemetryRange(telemetry, Begin, End)) - { - result = null; - return false; - } - + result = MakeOperationDetectorResult(idTelemetry, telemetry, Begin, End, idReasonOfEnd); return IsValidOperationDetectorResult(result); @@ -72,10 +64,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors result = null; return false; } - - protected virtual bool IsValidTelemetryRange(DetectableTelemetry[] telemetry, int begin, int end) - => end - begin > 1; - + protected virtual (int Begin, int End) RefineEdges(DetectableTelemetry[] telemetry, int begin, int end) => (begin, end); @@ -125,6 +114,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors DepthStart = (double)pBegin.WellDepth, DepthEnd = (double)pEnd.WellDepth, ExtraData = ExtraData, + BitDepth = pEnd.BitDepth, Value = CalcValue(telemetry, begin, end), EnabledSubsystems = DetectEnabledSubsystems(telemetry, begin, end, ExtraData) }; diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs index 9388918d..4d06365a 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs @@ -12,29 +12,64 @@ public class DetectorSlipsTime : DetectorAbstract protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation) { - var point0 = telemetry[position]; - var delta = point0.WellDepth - point0.BitDepth; - if (delta > 2.5d) + var currentPoint = telemetry[position]; + var delta = Math.Abs(currentPoint.WellDepth - currentPoint.BitDepth); + + if (delta < 0.1d) return false; - if (point0.Pressure > 15) + if (currentPoint.Pressure > 20) return false; - if (point0.BlockPosition > 8) + var nextIndexPoint = telemetry.Length <= position ? position : position + 1; + + var nextPoint = telemetry[nextIndexPoint]; + var deltaBitDepth = Math.Abs(currentPoint.BitDepth - nextPoint.BitDepth); + var deltaBlockPosition = Math.Abs(currentPoint.BlockPosition - nextPoint.BlockPosition); + + if (deltaBitDepth > 0.001d) return false; - if (point0.HookWeight > 20) + if (deltaBlockPosition < 0.001d) return false; return true; } - protected override (int IdCategory, IDictionary ExtraData) GetSpecificInformation(DetectableTelemetry[] telemetry, int begin, int end) - { + protected override int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation) + { + var currentPoint = telemetry[position]; + + if (currentPoint.Pressure > 20) + return IdReasonOfEnd_PressureIsHi; + + var prevPointIndex = position <= 0 ? 0 : position - 1; + + var prevPoint = telemetry[prevPointIndex]; + + var deltaBitDepth = Math.Abs(currentPoint.BitDepth - prevPoint.BitDepth); + + if (deltaBitDepth > 0.001d && currentPoint.AxialLoad < currentPoint.HookWeight) + return IdReasonOfEnd_ChangeBithDepthAndAxiloadLessHookWeight; + + return IdReasonOfEnd_NotDetected; + } + + protected override (int IdCategory, IDictionary ExtraData) GetSpecificInformation(DetectableTelemetry[] telemetry, + int begin, + int end) + { return (WellOperationCategory.IdSlipsTime, new Dictionary()); - } + } - protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) => - Math.Abs(operationDetectorResult.Operation.DepthStart - operationDetectorResult.Operation.DepthEnd) > 0.01; -} + protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) + { + if (Math.Abs((operationDetectorResult.Operation.DateStart - operationDetectorResult.Operation.DateEnd).TotalMinutes) > 30) + return false; + if (operationDetectorResult.Operation.BitDepth <= 150d) + return false; + + return true; + } +} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md b/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md index fee75476..eda6b993 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md +++ b/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md @@ -3,19 +3,28 @@ Наращивание бурильного инструмента – операция, во время которой после добуривания очередной трубы/ свечи циркуляция выключается, инструмент разгружается в клиньях (остается только вес крюкоблока и ВСП), происходит развинчивание трубы от верхнего силового привода, берется очередная труба/ свеча, свинчивается с инструментом в клиньях, свинчивается с верхним силовым приводом, происходит подъем инструмента, вес на крюке увеличивается. Далее включается циркуляция и происходит механическое бурение. - Наращивается определяется как время между: -- разгрузкой инструмента на клинья (остается только вес крюкоблока и ВСП). При этом давление менее 15 атм. В случае давления более 15 атм считать началом операции как снижение давления менее 15 атм и началом движения талевого блока вверх. -- снятие инструмента с клиньев (вес увеличивается более, чем на 1т). При этом движение талевого блока происходит вверх. +Наращивание определяется как время между: +- началом разгрузки инструмента на клинья (остается только вес крюкоблока и ВСП). При этом расстояние от долота до забоя в диапазоне от 0.1 до 3м., давление менее 20 атм. В случае Если происходит движение блока без изменения глубины долота—-> идем назад и ищем падение давления ниже 20атм. +- снятие инструмента с клиньев (вес увеличивается более, чем на 1т). При этом движение талевого блока происходит вверх ИЛИ увеличение давления больше 20 атм. + ## Метод определения Признак начала операции = - ( расстояние от долота до забоя < 2.5м ) И - ( положение талевого блока < 8 ) И - ( вес на крюке < 20 тонн ) И - ( давление < 15 атм ); + ( Расстояние от долота до забоя > 0.1 м) И + ( давление < 20атм) И + ( движение блока без изменения глубины долота) И + ( глубина долота > 150 м); + + Признак окончания операции = + ( давление > 20атм) ИЛИ + ( время продолжительности > 30 мин) ИЛИ + ( глубина долота < 150 м) ИЛИ + ( изменение глубины долота) И + ( осевая нагрузка < веса на крюке); - Признак окончания операции = НЕ выполняется признак начала операции; ## Ключевой параметр -Продолжительность операции. \ No newline at end of file +Продолжительность операции. + +Предел времени операции 30 минут, всё что больше 30 минут это уже не наращивание - а НПВ. \ No newline at end of file From 47e9c9f2cd042fdb5a19c709ba7db84772524d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 1 Mar 2024 07:33:39 +0300 Subject: [PATCH 06/12] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D1=8B=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=82=D0=BC=D0=B0=20"=D0=A3=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B2=20=D0=BA=D0=BB=D0=B8=D0=BD?= =?UTF-8?q?=D1=8C=D1=8F=D1=85"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Builders/DetectableTelemetryBuilder.cs | 69 +++++++++++ .../Detectors/DetectorSlipsTimeTests.cs | 109 ++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs create mode 100644 AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs diff --git a/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs b/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs new file mode 100644 index 00000000..f0acdc09 --- /dev/null +++ b/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs @@ -0,0 +1,69 @@ +using System; +using AsbCloudInfrastructure.Services.DetectOperations; + +namespace AsbCloudWebApi.Tests.Builders; + +public class DetectableTelemetryBuilder +{ + private DateTimeOffset dateTime = DateTimeOffset.UtcNow; + private float wellDepth = 300; + private float pressure = 15; + private float hookWeight = 20; + private float blockPosition = 20; + private float bitDepth = 151; + private float axialLoad = 19; + + public DetectableTelemetryBuilder WithDateTime(DateTimeOffset newDateTime) + { + dateTime = newDateTime; + return this; + } + + public DetectableTelemetryBuilder WithWellDepth(float newWllDepth) + { + wellDepth = newWllDepth; + return this; + } + + public DetectableTelemetryBuilder WithPressure(float newPressure) + { + pressure = newPressure; + return this; + } + + public DetectableTelemetryBuilder WithHookWeight(float newHookWeight) + { + hookWeight = newHookWeight; + return this; + } + + public DetectableTelemetryBuilder WithBlockPosition(float newBlockPosition) + { + blockPosition = newBlockPosition; + return this; + } + + public DetectableTelemetryBuilder WithBitDepth(float newBitDepth) + { + bitDepth = newBitDepth; + return this; + } + + public DetectableTelemetryBuilder WithAxialLoad(float newAxialLoad) + { + axialLoad = newAxialLoad; + return this; + } + + public DetectableTelemetry Build() => + new() + { + DateTime = dateTime, + WellDepth = wellDepth, + Pressure = pressure, + HookWeight = hookWeight, + BlockPosition = blockPosition, + BitDepth = bitDepth, + AxialLoad = axialLoad + }; +} \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs new file mode 100644 index 00000000..ac8c373c --- /dev/null +++ b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs @@ -0,0 +1,109 @@ +using System; +using AsbCloudInfrastructure.Services.DetectOperations.Detectors; +using AsbCloudWebApi.Tests.Builders; +using Xunit; + +namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors; + +public class DetectorSlipsTimeTests +{ + private const int IdSlipsTime = 5011; + + private readonly DetectableTelemetryBuilder telemetryBuilder = new(); + + private readonly DetectorSlipsTime sut = new(); + + [Fact] + public void DetectOperation_by_change_block_position_and_axial_load_less_hook_weight_is_success() + { + //arrange + var point0 = telemetryBuilder + .Build(); + + var point1 = telemetryBuilder + .WithBlockPosition(21) + .Build(); + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.True(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } + + [Fact] + public void DetectOperation_by_high_pressure_is_success() + { + //arrange + var point0 = telemetryBuilder + .Build(); + + var point1 = telemetryBuilder + .WithBlockPosition(21) + .WithAxialLoad(30) + .WithHookWeight(20) + .WithPressure(23) + .Build(); + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.True(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } + + [Fact] + public void ValidateOperation_with_well_depth_before_150_meters_is_invalid() + { + //arrange + var point0 = telemetryBuilder + .WithBitDepth(149) + .Build(); + + var point1 = telemetryBuilder + .WithBitDepth(149) + .WithBlockPosition(21) + .Build(); + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.False(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } + + [Fact] + public void ValidateOperation_with_duration_more_30_minutes_is_invalid() + { + //arrange + var point0 = telemetryBuilder + .Build(); + + var point1 = telemetryBuilder + .WithDateTime(DateTimeOffset.UtcNow.AddMinutes(30)) + .WithBlockPosition(21) + .Build(); + + var telemetries = new[] { point0, point1 }; + + //act + var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); + + //assert + Assert.False(isDetectOperation); + Assert.NotNull(result); + Assert.Equal(IdSlipsTime, result.Operation.IdCategory); + } +} \ No newline at end of file From 4af7868430fc3514f90ad6c2f7f5bcdc82176367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 1 Mar 2024 07:41:55 +0300 Subject: [PATCH 07/12] fix naming test --- .../DetectedOperations/Detectors/DetectorSlipsTimeTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs index ac8c373c..947161ac 100644 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs +++ b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs @@ -61,7 +61,7 @@ public class DetectorSlipsTimeTests } [Fact] - public void ValidateOperation_with_well_depth_before_150_meters_is_invalid() + public void ValidateOperation_with_bit_depth_before_150_meters_is_invalid() { //arrange var point0 = telemetryBuilder From 93f22c5b5b39d5d6054c309946219457709a8c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 1 Mar 2024 07:59:26 +0300 Subject: [PATCH 08/12] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B2=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DetectedOperation/DetectedOperationDto.cs | 8 +------ .../Detectors/DetectorAbstract.cs | 1 - .../Detectors/DetectorSlipsTime.cs | 15 ++++-------- .../Specifications/Удержание в клиньях.md | 6 ++--- .../Detectors/DetectorSlipsTimeTests.cs | 24 ------------------- 5 files changed, 8 insertions(+), 46 deletions(-) diff --git a/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs b/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs index ce433aff..e81a45fb 100644 --- a/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs +++ b/AsbCloudApp/Data/DetectedOperation/DetectedOperationDto.cs @@ -77,13 +77,7 @@ public class DetectedOperationDto: IId /// [Required] public WellOperationCategoryDto OperationCategory { get; set; } = null!; - - /// - /// Положение долота на момент окончания операции - /// - [Required] - public float BitDepth { get; set; } - + /// /// Ключевой параметр операции /// diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs index ec05be39..559e1dc4 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorAbstract.cs @@ -114,7 +114,6 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors DepthStart = (double)pBegin.WellDepth, DepthEnd = (double)pEnd.WellDepth, ExtraData = ExtraData, - BitDepth = pEnd.BitDepth, Value = CalcValue(telemetry, begin, end), EnabledSubsystems = DetectEnabledSubsystems(telemetry, begin, end, ExtraData) }; diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs index 4d06365a..315583f6 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs @@ -15,6 +15,9 @@ public class DetectorSlipsTime : DetectorAbstract var currentPoint = telemetry[position]; var delta = Math.Abs(currentPoint.WellDepth - currentPoint.BitDepth); + if (currentPoint.BitDepth < 150) + return false; + if (delta < 0.1d) return false; @@ -62,14 +65,6 @@ public class DetectorSlipsTime : DetectorAbstract return (WellOperationCategory.IdSlipsTime, new Dictionary()); } - protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) - { - if (Math.Abs((operationDetectorResult.Operation.DateStart - operationDetectorResult.Operation.DateEnd).TotalMinutes) > 30) - return false; - - if (operationDetectorResult.Operation.BitDepth <= 150d) - return false; - - return true; - } + protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) => + Math.Abs((operationDetectorResult.Operation.DateStart - operationDetectorResult.Operation.DateEnd).TotalMinutes) < 30; } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md b/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md index eda6b993..c3bcab51 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md +++ b/AsbCloudInfrastructure/Services/DetectOperations/Specifications/Удержание в клиньях.md @@ -16,14 +16,12 @@ ( движение блока без изменения глубины долота) И ( глубина долота > 150 м); - Признак окончания операции = + Признак окончания операции = ( давление > 20атм) ИЛИ - ( время продолжительности > 30 мин) ИЛИ - ( глубина долота < 150 м) ИЛИ + ( время продолжительности > 30 мин) ИЛИ ( изменение глубины долота) И ( осевая нагрузка < веса на крюке); - ## Ключевой параметр Продолжительность операции. diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs index 947161ac..86c1b3ae 100644 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs +++ b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs @@ -60,30 +60,6 @@ public class DetectorSlipsTimeTests Assert.Equal(IdSlipsTime, result.Operation.IdCategory); } - [Fact] - public void ValidateOperation_with_bit_depth_before_150_meters_is_invalid() - { - //arrange - var point0 = telemetryBuilder - .WithBitDepth(149) - .Build(); - - var point1 = telemetryBuilder - .WithBitDepth(149) - .WithBlockPosition(21) - .Build(); - - var telemetries = new[] { point0, point1 }; - - //act - var isDetectOperation = sut.TryDetect(0, telemetries, 0, telemetries.Length - 1, null, out var result); - - //assert - Assert.False(isDetectOperation); - Assert.NotNull(result); - Assert.Equal(IdSlipsTime, result.Operation.IdCategory); - } - [Fact] public void ValidateOperation_with_duration_more_30_minutes_is_invalid() { From 9ba05d6650cc64d8e40b1b71bec02ada05c61338 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 1 Mar 2024 10:35:43 +0500 Subject: [PATCH 09/12] DetectorSlipsTime.DetectBegin reorder conditions --- .../DetectOperations/Detectors/DetectorSlipsTime.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs index 315583f6..a9996a1b 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/Detectors/DetectorSlipsTime.cs @@ -13,26 +13,23 @@ public class DetectorSlipsTime : DetectorAbstract protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperationDto? previousOperation) { var currentPoint = telemetry[position]; - var delta = Math.Abs(currentPoint.WellDepth - currentPoint.BitDepth); - if (currentPoint.BitDepth < 150) return false; - if (delta < 0.1d) - return false; - if (currentPoint.Pressure > 20) return false; - var nextIndexPoint = telemetry.Length <= position ? position : position + 1; + var delta = currentPoint.WellDepth - currentPoint.BitDepth; + if (delta < 0.1d) + return false; + var nextIndexPoint = telemetry.Length <= position ? position : position + 1; var nextPoint = telemetry[nextIndexPoint]; var deltaBitDepth = Math.Abs(currentPoint.BitDepth - nextPoint.BitDepth); - var deltaBlockPosition = Math.Abs(currentPoint.BlockPosition - nextPoint.BlockPosition); - if (deltaBitDepth > 0.001d) return false; + var deltaBlockPosition = Math.Abs(currentPoint.BlockPosition - nextPoint.BlockPosition); if (deltaBlockPosition < 0.001d) return false; From e4a5ca69fb0a71ea588b168d1db2db3f2dd312e5 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 1 Mar 2024 11:06:37 +0500 Subject: [PATCH 10/12] DetectedOperationService.DetectOperationsAsync() Add AxialLoad to select --- .../Services/DetectOperations/DetectedOperationService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs index 06415870..b53b1cd0 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs @@ -164,6 +164,7 @@ public class DetectedOperationService : IDetectedOperationService BlockPosition = t.BlockPosition, BitDepth = t.BitDepth, RotorSpeed = t.RotorSpeed, + AxialLoad = t.AxialLoad, }).ToArray(); if (detectableTelemetries.Length < gap) From fb6126260fedda01766500ffa3369ca51687ace2 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 1 Mar 2024 11:07:19 +0500 Subject: [PATCH 11/12] Replace DetectableTelemetryBuilder by CommonExtensions.Copy() --- .../Builders/DetectableTelemetryBuilder.cs | 69 ------------------- AsbCloudWebApi.Tests/CommonExtensions.cs | 19 +++++ .../Detectors/DetectorSlipsTimeTests.cs | 47 ++++++------- 3 files changed, 43 insertions(+), 92 deletions(-) delete mode 100644 AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs create mode 100644 AsbCloudWebApi.Tests/CommonExtensions.cs diff --git a/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs b/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs deleted file mode 100644 index f0acdc09..00000000 --- a/AsbCloudWebApi.Tests/Builders/DetectableTelemetryBuilder.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using AsbCloudInfrastructure.Services.DetectOperations; - -namespace AsbCloudWebApi.Tests.Builders; - -public class DetectableTelemetryBuilder -{ - private DateTimeOffset dateTime = DateTimeOffset.UtcNow; - private float wellDepth = 300; - private float pressure = 15; - private float hookWeight = 20; - private float blockPosition = 20; - private float bitDepth = 151; - private float axialLoad = 19; - - public DetectableTelemetryBuilder WithDateTime(DateTimeOffset newDateTime) - { - dateTime = newDateTime; - return this; - } - - public DetectableTelemetryBuilder WithWellDepth(float newWllDepth) - { - wellDepth = newWllDepth; - return this; - } - - public DetectableTelemetryBuilder WithPressure(float newPressure) - { - pressure = newPressure; - return this; - } - - public DetectableTelemetryBuilder WithHookWeight(float newHookWeight) - { - hookWeight = newHookWeight; - return this; - } - - public DetectableTelemetryBuilder WithBlockPosition(float newBlockPosition) - { - blockPosition = newBlockPosition; - return this; - } - - public DetectableTelemetryBuilder WithBitDepth(float newBitDepth) - { - bitDepth = newBitDepth; - return this; - } - - public DetectableTelemetryBuilder WithAxialLoad(float newAxialLoad) - { - axialLoad = newAxialLoad; - return this; - } - - public DetectableTelemetry Build() => - new() - { - DateTime = dateTime, - WellDepth = wellDepth, - Pressure = pressure, - HookWeight = hookWeight, - BlockPosition = blockPosition, - BitDepth = bitDepth, - AxialLoad = axialLoad - }; -} \ No newline at end of file diff --git a/AsbCloudWebApi.Tests/CommonExtensions.cs b/AsbCloudWebApi.Tests/CommonExtensions.cs new file mode 100644 index 00000000..ac32b59f --- /dev/null +++ b/AsbCloudWebApi.Tests/CommonExtensions.cs @@ -0,0 +1,19 @@ +using Mapster; +using System; + +namespace AsbCloudWebApi.Tests; + +public static class CommonExtensions +{ + public static T Copy(this T obj) + { + var copy = obj.Adapt(); + return copy; + } + + public static T Mutate(this T obj, Action mutation) + { + var copy = obj.Copy(); + return copy; + } +} diff --git a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs index 86c1b3ae..30d8da83 100644 --- a/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs +++ b/AsbCloudWebApi.Tests/Services/DetectedOperations/Detectors/DetectorSlipsTimeTests.cs @@ -1,6 +1,6 @@ using System; +using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.DetectOperations.Detectors; -using AsbCloudWebApi.Tests.Builders; using Xunit; namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors; @@ -9,7 +9,14 @@ public class DetectorSlipsTimeTests { private const int IdSlipsTime = 5011; - private readonly DetectableTelemetryBuilder telemetryBuilder = new(); + private readonly DetectableTelemetry telemetry = new() { + WellDepth = 300, + Pressure = 15, + HookWeight = 20, + BlockPosition = 20, + BitDepth = 151, + AxialLoad = 19, + }; private readonly DetectorSlipsTime sut = new(); @@ -17,12 +24,10 @@ public class DetectorSlipsTimeTests public void DetectOperation_by_change_block_position_and_axial_load_less_hook_weight_is_success() { //arrange - var point0 = telemetryBuilder - .Build(); + var point0 = telemetry.Copy(); - var point1 = telemetryBuilder - .WithBlockPosition(21) - .Build(); + var point1 = telemetry.Copy(); + point1.BlockPosition = 21; var telemetries = new[] { point0, point1 }; @@ -38,16 +43,14 @@ public class DetectorSlipsTimeTests [Fact] public void DetectOperation_by_high_pressure_is_success() { - //arrange - var point0 = telemetryBuilder - .Build(); + //arrange + var point0 = telemetry.Copy(); - var point1 = telemetryBuilder - .WithBlockPosition(21) - .WithAxialLoad(30) - .WithHookWeight(20) - .WithPressure(23) - .Build(); + var point1 = telemetry.Copy(); + point1.BlockPosition = 21; + point1.AxialLoad = 30; + point1.HookWeight = 20; + point1.Pressure = 23; var telemetries = new[] { point0, point1 }; @@ -63,14 +66,12 @@ public class DetectorSlipsTimeTests [Fact] public void ValidateOperation_with_duration_more_30_minutes_is_invalid() { - //arrange - var point0 = telemetryBuilder - .Build(); + //arrange + var point0 = telemetry.Copy(); - var point1 = telemetryBuilder - .WithDateTime(DateTimeOffset.UtcNow.AddMinutes(30)) - .WithBlockPosition(21) - .Build(); + var point1 = telemetry.Copy(); + point1.BlockPosition = 21; + point1.DateTime = DateTimeOffset.UtcNow.AddMinutes(30); var telemetries = new[] { point0, point1 }; From 9b61706f557136b9a026b810130371b27ab42fed Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 1 Mar 2024 12:06:42 +0500 Subject: [PATCH 12/12] =?UTF-8?q?SmtpException=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B5=20=D1=83=D0=B2?= =?UTF-8?q?=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D0=B0=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D1=8F=D1=82=D1=8C=D1=81=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Notifications/NotificationService.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/AsbCloudApp/Services/Notifications/NotificationService.cs b/AsbCloudApp/Services/Notifications/NotificationService.cs index d0414213..d703ffb4 100644 --- a/AsbCloudApp/Services/Notifications/NotificationService.cs +++ b/AsbCloudApp/Services/Notifications/NotificationService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Mail; using System.Threading; using System.Threading.Tasks; using AsbCloudApp.Data; @@ -60,7 +61,15 @@ public class NotificationService var notificationTransportService = GetTransportService(request.IdTransportType); - await notificationTransportService.SendAsync(notification, cancellationToken); + //todo Добавить задачу в WorkToSendEmail + try + { + await notificationTransportService.SendAsync(notification, cancellationToken); + } + catch (SmtpException ex) + { + Console.WriteLine(ex.Message); + } notification.SentDate = DateTime.UtcNow; await notificationRepository.UpdateAsync(notification, cancellationToken);