From 09c69fcf75a88930566398cf695af4e3ce934c38 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 4 May 2023 16:54:09 +0500 Subject: [PATCH 01/10] =?UTF-8?q?=D0=92=D1=8B=D1=87=D0=B8=D1=81=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B0=D0=BA=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=BE=D0=B9=20=D1=82=D1=80=D0=B0=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IFactualTrajectoryRepository.cs | 23 +++++ .../ITrajectoryVisualizationService.cs | 6 +- AsbCloudDb/Model/WITS/Record7.cs | 3 + AsbCloudInfrastructure/DependencyInjection.cs | 1 + .../Repository/FactualTrajectoryRepository.cs | 47 +++++++++ .../TrajectoryVisualizationService.cs | 96 +++++++++++++++---- .../TrajectoryVisualizationServiceTest.cs | 32 +++---- .../PlannedTrajectoryController.cs | 4 +- 8 files changed, 172 insertions(+), 40 deletions(-) create mode 100644 AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs create mode 100644 AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs diff --git a/AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs b/AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs new file mode 100644 index 00000000..692c53dd --- /dev/null +++ b/AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs @@ -0,0 +1,23 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Data.WITS; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudApp.Repositories +{ + /// + /// CRUD для работы с фактической траекторией из клиента + /// + /// + public interface IFactualTrajectoryRepository + { + /// + /// Получить все добавленные по скважине координаты фактической траектории + /// + /// + /// + /// + Task> GetAsync(int idWell, CancellationToken token); + } +} diff --git a/AsbCloudApp/Services/ITrajectoryVisualizationService.cs b/AsbCloudApp/Services/ITrajectoryVisualizationService.cs index 31d77271..286a81d5 100644 --- a/AsbCloudApp/Services/ITrajectoryVisualizationService.cs +++ b/AsbCloudApp/Services/ITrajectoryVisualizationService.cs @@ -11,11 +11,11 @@ namespace AsbCloudApp.Services public interface ITrajectoryVisualizationService { /// - /// Получение траектории по скважине + /// Получение плановой и фактической траектории по скважине /// - /// + /// ключ скважины /// /// - Task> GetTrajectoryAsync(int idWell, CancellationToken token); + Task>> GetTrajectoryAsync(int idWell, CancellationToken token); } } diff --git a/AsbCloudDb/Model/WITS/Record7.cs b/AsbCloudDb/Model/WITS/Record7.cs index d856f8a7..f2ebd2e0 100644 --- a/AsbCloudDb/Model/WITS/Record7.cs +++ b/AsbCloudDb/Model/WITS/Record7.cs @@ -12,6 +12,7 @@ namespace AsbCloudDb.Model.WITS { /// + /// /// RecordId = 7, /// ItemId = 8, /// LongMnemonic = "DEPTSVYM", @@ -87,6 +88,7 @@ namespace AsbCloudDb.Model.WITS public string? Svytype { get; set; } /// + /// /// RecordId = 7, /// ItemId = 13, /// LongMnemonic = "SVYINC", @@ -117,6 +119,7 @@ namespace AsbCloudDb.Model.WITS public float? Svyazu { get; set; } /// + /// /// RecordId = 7, /// ItemId = 15, /// LongMnemonic = "SVYAZC", diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 7952b1f4..96051f7e 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -180,6 +180,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); // Subsystem service diff --git a/AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs b/AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs new file mode 100644 index 00000000..d140775d --- /dev/null +++ b/AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs @@ -0,0 +1,47 @@ +using AsbCloudApp.Data.WITS; +using AsbCloudApp.Exceptions; +using AsbCloudApp.Repositories; +using AsbCloudApp.Services; +using AsbCloudDb.Model; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudInfrastructure.Repository +{ + internal class FactualTrajectoryRepository : IFactualTrajectoryRepository + { + private readonly IAsbCloudDbContext db; + private readonly IWellService wellService; + public FactualTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService) + { + this.db = db; + this.wellService = wellService; + } + + public async Task> GetAsync(int idWell, CancellationToken token) + { + var well = wellService.GetOrDefault(idWell); + if (well is null || well.Timezone is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); + + var query = db.Record7 + .AsNoTracking() + .Where(x => x.IdTelemetry == well.IdTelemetry); + var entities = await query + .OrderBy(e => e.Deptsvym) + .ToListAsync(token); + var result = entities + .Select(r => new Record7Dto() + { + IdTelemetry = r.IdTelemetry, + Deptsvym = r.Deptsvym, + Svyinc = r.Svyinc, + Svyazc = r.Svyazc + }); + return result; + } + } +} diff --git a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs index 8eb94b5a..1ef563f9 100644 --- a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs @@ -1,6 +1,8 @@ using AsbCloudApp.Data; using AsbCloudApp.Repositories; using AsbCloudApp.Services; +using AsbCloudDb.Model; +using AsbCloudDb.Model.WITS; using System; using System.Collections.Generic; using System.Linq; @@ -12,20 +14,45 @@ namespace AsbCloudInfrastructure.Services.Trajectory public class TrajectoryVisualizationService : ITrajectoryVisualizationService { - private readonly IPlannedTrajectoryRepository repository; + private readonly IPlannedTrajectoryRepository plannedRepository; + private readonly IFactualTrajectoryRepository factualRepository; - public TrajectoryVisualizationService(IPlannedTrajectoryRepository repository) + public TrajectoryVisualizationService(IPlannedTrajectoryRepository plannedRepository, IFactualTrajectoryRepository factualRepository) { - this.repository = repository; + this.plannedRepository = plannedRepository; + this.factualRepository = factualRepository; } - public async Task> GetTrajectoryAsync(int idWell, CancellationToken token) + /// + /// Получение плановой и фактической траектории по скважине + /// + /// ключ скважины + /// + /// + public async Task>> GetTrajectoryAsync(int idWell, CancellationToken token) { - var geoCoordinates = (await repository.GetAsync(idWell, token)).ToArray(); + var result = new PlanFactBase>(); - if (geoCoordinates.Length < 2) - return Enumerable.Empty(); + var geoPlanCoordinates = (await plannedRepository.GetAsync(idWell, token)) + .Select(coord => new TrajectoryDto(coord.WellboreDepth, coord.ZenithAngle, coord.AzimuthGeo)) + .ToArray(); + var geoFactCoordinates = (await factualRepository.GetAsync(idWell, token)) + .Select(coord => new TrajectoryDto(coord.Deptsvym, coord.Svyinc, coord.Svyazc)) + .ToArray(); + result.Plan = GetTrajectoryVisualisation(geoPlanCoordinates); + result.Fact = GetTrajectoryVisualisation(geoFactCoordinates); + + return result; + } + + /// + /// Формирует список координат для визуализации трактории 3D + /// + /// + /// + private List GetTrajectoryVisualisation(TrajectoryDto[] geoCoordinates) + { var cartesianCoordinates = new List(geoCoordinates.Length) { new (), }; @@ -34,25 +61,56 @@ namespace AsbCloudInfrastructure.Services.Trajectory { var intervalGeoParams = geoCoordinates[i - 1]; var deltaWellLength = geoCoordinates[i].WellboreDepth - intervalGeoParams.WellboreDepth; - var projectionLengthToXYSurface = deltaWellLength * Math.Sin(intervalGeoParams.ZenithAngle * Math.PI / 180); - var dz = deltaWellLength * Math.Cos(intervalGeoParams.ZenithAngle * Math.PI / 180); - var dx = projectionLengthToXYSurface * Math.Sin(intervalGeoParams.AzimuthGeo * Math.PI / 180); - var dy = projectionLengthToXYSurface * Math.Cos(intervalGeoParams.AzimuthGeo * Math.PI / 180); + if (intervalGeoParams.ZenithAngle != null && intervalGeoParams.AzimuthGeo != null && deltaWellLength != null) { + + var projectionLengthToXYSurface = deltaWellLength.Value * Math.Sin(intervalGeoParams.ZenithAngle.Value * Math.PI / 180); - var preCoordinates = cartesianCoordinates[i - 1]; - var coordinates = new TrajectoryVisualizationDto - { - Z = preCoordinates.Z + dz, - X = preCoordinates.X + dx, - Y = preCoordinates.Y + dy, - }; + var dz = deltaWellLength.Value * Math.Cos(intervalGeoParams.ZenithAngle.Value * Math.PI / 180); + var dx = projectionLengthToXYSurface * Math.Sin(intervalGeoParams.AzimuthGeo.Value * Math.PI / 180); + var dy = projectionLengthToXYSurface * Math.Cos(intervalGeoParams.AzimuthGeo.Value * Math.PI / 180); - cartesianCoordinates.Add(coordinates); + var preCoordinates = cartesianCoordinates[i - 1]; + var coordinates = new TrajectoryVisualizationDto + { + Z = preCoordinates.Z + dz, + X = preCoordinates.X + dx, + Y = preCoordinates.Y + dy, + }; + + cartesianCoordinates.Add(coordinates); + } } return cartesianCoordinates; } } + /// + /// Класс для формирования визуализации траектории 3D + /// + internal class TrajectoryDto + { + /// + /// Глубина ствола + /// + public double? WellboreDepth { get; } + + /// + /// Зенитный угол + /// + public double? ZenithAngle { get; } + + /// + /// Азимут географиеский + /// + public double? AzimuthGeo { get; } + + public TrajectoryDto(double? wellboreDepth, double? zenithAngle, double? azimuthGeo) + { + WellboreDepth = wellboreDepth; + ZenithAngle = zenithAngle; + AzimuthGeo = azimuthGeo; + } + } } diff --git a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs index f4532d7c..b8d40a3b 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs @@ -38,10 +38,10 @@ namespace AsbCloudWebApi.Tests.ServicesTests }; var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); - var service = new TrajectoryVisualizationService(mock.Object); - var result = await service.GetTrajectoryAsync(1, CancellationToken.None); + //var service = new TrajectoryVisualizationService(mock.Object); + //ar result = await service.GetTrajectoryAsync(1, CancellationToken.None); - Assert.Equal(plannedTrajectory.Length, result.Count()); + //Assert.Equal(plannedTrajectory.Length, result.Count()); } [Fact] @@ -58,13 +58,13 @@ namespace AsbCloudWebApi.Tests.ServicesTests }; var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); - var service = new TrajectoryVisualizationService(mock.Object); - var result = await service.GetTrajectoryAsync(1, CancellationToken.None); - var lastPoint = result.Last(); + //var service = new TrajectoryVisualizationService(mock.Object); + //var result = await service.GetTrajectoryAsync(1, CancellationToken.None); + //var lastPoint = result.Last(); - Assert.Equal(0d, lastPoint.X, 0.1d); - Assert.Equal(0d, lastPoint.Y, 0.1d); - Assert.Equal(50d, lastPoint.Z, 0.1d); + //Assert.Equal(0d, lastPoint.X, 0.1d); + //Assert.Equal(0d, lastPoint.Y, 0.1d); + //Assert.Equal(50d, lastPoint.Z, 0.1d); } [Fact] @@ -78,14 +78,14 @@ namespace AsbCloudWebApi.Tests.ServicesTests }; var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); - var service = new TrajectoryVisualizationService(mock.Object); - var result = await service.GetTrajectoryAsync(1, CancellationToken.None); - var lastPoint = result.Last(); - var tolerance = 0.001d; + //var service = new TrajectoryVisualizationService(mock.Object); + //var result = await service.GetTrajectoryAsync(1, CancellationToken.None); + //var lastPoint = result.Last(); + //var tolerance = 0.001d; - Assert.InRange(lastPoint.Z, 10 + tolerance, 20 - tolerance); - Assert.InRange(lastPoint.Y, 0 + tolerance, 10 - tolerance); - Assert.InRange(lastPoint.X, 0 + tolerance, 10 - tolerance); + //Assert.InRange(lastPoint.Z, 10 + tolerance, 20 - tolerance); + //Assert.InRange(lastPoint.Y, 0 + tolerance, 10 - tolerance); + //Assert.InRange(lastPoint.X, 0 + tolerance, 10 - tolerance); } } } diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs index df564558..28c14c54 100644 --- a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs +++ b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs @@ -225,14 +225,14 @@ namespace AsbCloudWebApi.Controllers } /// - /// Получение координат для визуализации траектории + /// Получение координат для визуализации траектории (плановой и фактической) /// /// /// /// [HttpGet] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task GetTrajectoryAsync(int idWell, CancellationToken token) + public async Task GetPlanFactTrajectoryAsync(int idWell, CancellationToken token) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) From 83fcf738b9a2550149bcc53bf2368df938c28095 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 5 May 2023 16:19:35 +0500 Subject: [PATCH 02/10] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D0=B9=20producesResponseType=20=D0=B2=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B5=20GetPlanFactTrajectoryAsy?= =?UTF-8?q?nc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs index 28c14c54..5d019e18 100644 --- a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs +++ b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs @@ -231,7 +231,7 @@ namespace AsbCloudWebApi.Controllers /// /// [HttpGet] - [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + [ProducesResponseType(typeof(PlanFactBase>), (int)System.Net.HttpStatusCode.OK)] public async Task GetPlanFactTrajectoryAsync(int idWell, CancellationToken token) { if (!await CanUserAccessToWellAsync(idWell, From e1228ef6bf08554bd9945cdbf040f2e5a5fdedb8 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 10 May 2023 11:31:40 +0500 Subject: [PATCH 03/10] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=8E=D0=BD=D0=B8=D1=82-=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D1=82=D1=80=D0=B0=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrajectoryVisualizationServiceTest.cs | 74 ++++++++++++++----- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs index b8d40a3b..30bcf172 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data; +using AsbCloudApp.Data.WITS; using AsbCloudApp.Repositories; using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.Trajectory; @@ -24,6 +25,16 @@ namespace AsbCloudWebApi.Tests.ServicesTests return mock; } + private Mock MakeFactualTrajectoryRepositoryMock(IEnumerable dateForGetMethod) + { + var mock = new Mock(); + + mock.Setup(r => r.GetAsync(It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(dateForGetMethod)); + + return mock; + } + [Fact] public async Task GetTrajectoryAsync_SameCounts() { @@ -37,11 +48,19 @@ namespace AsbCloudWebApi.Tests.ServicesTests new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 50d}, }; - var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); - //var service = new TrajectoryVisualizationService(mock.Object); - //ar result = await service.GetTrajectoryAsync(1, CancellationToken.None); + var actualTrajectory = new Record7Dto[] + { + new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0}, + new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10}, + new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20}, + }; - //Assert.Equal(plannedTrajectory.Length, result.Count()); + var mockPlan = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); + var mockFact = MakeFactualTrajectoryRepositoryMock(actualTrajectory); + var service = new TrajectoryVisualizationService(mockPlan.Object, mockFact.Object); + var result = await service.GetTrajectoryAsync(1, CancellationToken.None); + Assert.Equal(plannedTrajectory.Length, result.Plan?.Count()); + Assert.Equal(actualTrajectory.Length, result.Fact?.Count()); } [Fact] @@ -57,14 +76,23 @@ namespace AsbCloudWebApi.Tests.ServicesTests new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 50d}, }; - var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); - //var service = new TrajectoryVisualizationService(mock.Object); - //var result = await service.GetTrajectoryAsync(1, CancellationToken.None); - //var lastPoint = result.Last(); + var factualTrajectory = new Record7Dto[] + { + new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0}, + new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10}, + new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20}, + }; - //Assert.Equal(0d, lastPoint.X, 0.1d); - //Assert.Equal(0d, lastPoint.Y, 0.1d); - //Assert.Equal(50d, lastPoint.Z, 0.1d); + var mockPlan = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); + var mockFact = MakeFactualTrajectoryRepositoryMock(factualTrajectory); + var service = new TrajectoryVisualizationService(mockPlan.Object, mockFact.Object); + var result = await service.GetTrajectoryAsync(1, CancellationToken.None); + var lastPointPlan = result.Plan!.Last(); + var lastPointFact = result.Fact!.Last(); + + Assert.Equal(0d, lastPointPlan.X, 0.1d); + Assert.Equal(0d, lastPointPlan.Y, 0.1d); + Assert.Equal(50d, lastPointPlan.Z, 0.1d); } [Fact] @@ -77,15 +105,23 @@ namespace AsbCloudWebApi.Tests.ServicesTests new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d}, }; - var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); - //var service = new TrajectoryVisualizationService(mock.Object); - //var result = await service.GetTrajectoryAsync(1, CancellationToken.None); - //var lastPoint = result.Last(); - //var tolerance = 0.001d; + var factualTrajectory = new Record7Dto[] + { + new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0}, + new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10}, + new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20}, + }; - //Assert.InRange(lastPoint.Z, 10 + tolerance, 20 - tolerance); - //Assert.InRange(lastPoint.Y, 0 + tolerance, 10 - tolerance); - //Assert.InRange(lastPoint.X, 0 + tolerance, 10 - tolerance); + var mockPlanned = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); + var mockFactual = MakeFactualTrajectoryRepositoryMock(factualTrajectory); + var service = new TrajectoryVisualizationService(mockPlanned.Object, mockFactual.Object); + var result = await service.GetTrajectoryAsync(1, CancellationToken.None); + var lastPointPlan = result.Plan!.Last(); + var tolerancePlan = 0.001d; + + Assert.InRange(lastPointPlan.Z, 10 + tolerancePlan, 20 - tolerancePlan); + Assert.InRange(lastPointPlan.Y, 0 + tolerancePlan, 10 - tolerancePlan); + Assert.InRange(lastPointPlan.X, 0 + tolerancePlan, 10 - tolerancePlan); } } } From 19d30d74ce71450bac54e95b4043d46647056866 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 10 May 2023 12:20:18 +0500 Subject: [PATCH 04/10] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=B4=D0=B8=D1=80=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudDb/Model/WITS/Record7.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AsbCloudDb/Model/WITS/Record7.cs b/AsbCloudDb/Model/WITS/Record7.cs index f2ebd2e0..0b768243 100644 --- a/AsbCloudDb/Model/WITS/Record7.cs +++ b/AsbCloudDb/Model/WITS/Record7.cs @@ -12,7 +12,7 @@ namespace AsbCloudDb.Model.WITS { /// - /// + /// /// RecordId = 7, /// ItemId = 8, /// LongMnemonic = "DEPTSVYM", @@ -88,7 +88,7 @@ namespace AsbCloudDb.Model.WITS public string? Svytype { get; set; } /// - /// + /// /// RecordId = 7, /// ItemId = 13, /// LongMnemonic = "SVYINC", @@ -119,7 +119,7 @@ namespace AsbCloudDb.Model.WITS public float? Svyazu { get; set; } /// - /// + /// /// RecordId = 7, /// ItemId = 15, /// LongMnemonic = "SVYAZC", From 2201b6582d353d7966a810f315a2eb0bf9a65124 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 10 May 2023 15:05:05 +0500 Subject: [PATCH 05/10] =?UTF-8?q?=D0=AE=D0=BD=D0=B8=D1=82-=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D1=84=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=BE=D0=B9=20=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrajectoryVisualizationServiceTest.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs index 30bcf172..c8f4baae 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs @@ -1,10 +1,8 @@ using AsbCloudApp.Data; using AsbCloudApp.Data.WITS; using AsbCloudApp.Repositories; -using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.Trajectory; using Moq; -using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -79,8 +77,11 @@ namespace AsbCloudWebApi.Tests.ServicesTests var factualTrajectory = new Record7Dto[] { new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0}, - new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10}, + new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0}, new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20}, + new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20}, + new() { Svyazc = 0, Svyinc = 0, Deptsvym = 30}, + new() { Svyazc = 0, Svyinc = 0, Deptsvym = 50}, }; var mockPlan = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); @@ -93,6 +94,10 @@ namespace AsbCloudWebApi.Tests.ServicesTests Assert.Equal(0d, lastPointPlan.X, 0.1d); Assert.Equal(0d, lastPointPlan.Y, 0.1d); Assert.Equal(50d, lastPointPlan.Z, 0.1d); + + Assert.Equal(0d, lastPointFact.X, 0.1d); + Assert.Equal(0d, lastPointFact.Y, 0.1d); + Assert.Equal(50d, lastPointFact.Z, 0.1d); } [Fact] @@ -117,11 +122,17 @@ namespace AsbCloudWebApi.Tests.ServicesTests var service = new TrajectoryVisualizationService(mockPlanned.Object, mockFactual.Object); var result = await service.GetTrajectoryAsync(1, CancellationToken.None); var lastPointPlan = result.Plan!.Last(); + var lastPointFact = result.Fact!.Last(); var tolerancePlan = 0.001d; + var toleranceFact = 0.001d; Assert.InRange(lastPointPlan.Z, 10 + tolerancePlan, 20 - tolerancePlan); Assert.InRange(lastPointPlan.Y, 0 + tolerancePlan, 10 - tolerancePlan); Assert.InRange(lastPointPlan.X, 0 + tolerancePlan, 10 - tolerancePlan); + + Assert.InRange(lastPointFact.Z, 10 + toleranceFact, 20 - toleranceFact); + Assert.InRange(lastPointFact.Y, 0 + toleranceFact, 10 - toleranceFact); + Assert.InRange(lastPointFact.X, 0 + toleranceFact, 10 - toleranceFact); } } } From 37399f74a78d33773dd464fa0a30213bc4d2ad64 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 11 May 2023 11:50:45 +0500 Subject: [PATCH 06/10] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB=20=D0=B4=D0=BB=D1=8F=20Trajec?= =?UTF-8?q?toryDto,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=20ITraje?= =?UTF-8?q?ctoryRepository=20=D0=B8=20=D0=B5=D0=B3=D0=BE=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BB=D0=B0=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=B8=20=D1=84=D0=B0=D0=BA=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=82=D1=80=D0=B0=D0=B5=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/TrajectoryDto.cs | 13 ++++ .../IFactualTrajectoryRepository.cs | 2 +- .../IPlannedTrajectoryRepository.cs | 2 +- .../Repositories/ITrajectoryRepository.cs | 24 +++++++ .../Repository/FactualTrajectoryRepository.cs | 20 +++--- .../Repository/PlannedTrajectoryRepository.cs | 7 +++ .../TrajectoryVisualizationService.cs | 63 +++++-------------- 7 files changed, 72 insertions(+), 59 deletions(-) create mode 100644 AsbCloudApp/Data/TrajectoryDto.cs create mode 100644 AsbCloudApp/Repositories/ITrajectoryRepository.cs diff --git a/AsbCloudApp/Data/TrajectoryDto.cs b/AsbCloudApp/Data/TrajectoryDto.cs new file mode 100644 index 00000000..80c965f4 --- /dev/null +++ b/AsbCloudApp/Data/TrajectoryDto.cs @@ -0,0 +1,13 @@ +namespace AsbCloudApp.Data +{ + /// + /// Формирование визуализации траектории 3D + /// + /// Глубина ствола + /// Зенитный угол + /// Азимут географиеский + public record TrajectoryDto( + double WellboreDepth, + double ZenithAngle, + double AzimuthGeo); +} diff --git a/AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs b/AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs index 692c53dd..536419ed 100644 --- a/AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs +++ b/AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs @@ -10,7 +10,7 @@ namespace AsbCloudApp.Repositories /// CRUD для работы с фактической траекторией из клиента /// /// - public interface IFactualTrajectoryRepository + public interface IFactualTrajectoryRepository : ITrajectoryRepository { /// /// Получить все добавленные по скважине координаты фактической траектории diff --git a/AsbCloudApp/Repositories/IPlannedTrajectoryRepository.cs b/AsbCloudApp/Repositories/IPlannedTrajectoryRepository.cs index 94f19162..85362f9f 100644 --- a/AsbCloudApp/Repositories/IPlannedTrajectoryRepository.cs +++ b/AsbCloudApp/Repositories/IPlannedTrajectoryRepository.cs @@ -9,7 +9,7 @@ namespace AsbCloudApp.Repositories /// CRUD для работы с плановой траекторией из клиента /// /// - public interface IPlannedTrajectoryRepository + public interface IPlannedTrajectoryRepository : ITrajectoryRepository { /// /// Получить все добавленные по скважине координаты плановой траектории diff --git a/AsbCloudApp/Repositories/ITrajectoryRepository.cs b/AsbCloudApp/Repositories/ITrajectoryRepository.cs new file mode 100644 index 00000000..ad4ee0f4 --- /dev/null +++ b/AsbCloudApp/Repositories/ITrajectoryRepository.cs @@ -0,0 +1,24 @@ +using AsbCloudApp.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudApp.Repositories +{ + /// + /// Репозиторий по работе с траекторией + /// + public interface ITrajectoryRepository + { + /// + /// Получение траектории для 3D-визуализации + /// + /// ключ скважины + /// + /// + Task GetTrajectoryAsync(int idWell, CancellationToken token); + } +} diff --git a/AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs b/AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs index d140775d..67126227 100644 --- a/AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs +++ b/AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs @@ -1,8 +1,10 @@ -using AsbCloudApp.Data.WITS; +using AsbCloudApp.Data; +using AsbCloudApp.Data.WITS; using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudDb.Model; +using Mapster; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; @@ -34,14 +36,16 @@ namespace AsbCloudInfrastructure.Repository .OrderBy(e => e.Deptsvym) .ToListAsync(token); var result = entities - .Select(r => new Record7Dto() - { - IdTelemetry = r.IdTelemetry, - Deptsvym = r.Deptsvym, - Svyinc = r.Svyinc, - Svyazc = r.Svyazc - }); + .Select(r => r.Adapt()); return result; } + + public async Task GetTrajectoryAsync(int idWell, CancellationToken token) + { + return (await GetAsync(idWell, token)) + .Where(coord => coord.Deptsvym != null && coord.Svyinc != null && coord.Svyazc != null) + .Select(coord => new TrajectoryDto(coord.Deptsvym!.Value, coord.Svyinc!.Value, coord.Svyazc!.Value)) + .ToArray(); + } } } diff --git a/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs b/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs index 0db7022d..9b4873f0 100644 --- a/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs +++ b/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs @@ -115,6 +115,13 @@ namespace AsbCloudInfrastructure.Repository entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(offsetHours); return entity; } + + public async Task GetTrajectoryAsync(int idWell, CancellationToken token) + { + return (await GetAsync(idWell, token)) + .Select(coord => new TrajectoryDto(coord.WellboreDepth, coord.ZenithAngle, coord.AzimuthGeo)) + .ToArray(); + } } } diff --git a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs index 1ef563f9..cc1557bc 100644 --- a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs @@ -33,12 +33,8 @@ namespace AsbCloudInfrastructure.Services.Trajectory { var result = new PlanFactBase>(); - var geoPlanCoordinates = (await plannedRepository.GetAsync(idWell, token)) - .Select(coord => new TrajectoryDto(coord.WellboreDepth, coord.ZenithAngle, coord.AzimuthGeo)) - .ToArray(); - var geoFactCoordinates = (await factualRepository.GetAsync(idWell, token)) - .Select(coord => new TrajectoryDto(coord.Deptsvym, coord.Svyinc, coord.Svyazc)) - .ToArray(); + var geoPlanCoordinates = await plannedRepository.GetTrajectoryAsync(idWell, token); + var geoFactCoordinates = await factualRepository.GetTrajectoryAsync(idWell, token); result.Plan = GetTrajectoryVisualisation(geoPlanCoordinates); result.Fact = GetTrajectoryVisualisation(geoFactCoordinates); @@ -61,56 +57,25 @@ namespace AsbCloudInfrastructure.Services.Trajectory { var intervalGeoParams = geoCoordinates[i - 1]; var deltaWellLength = geoCoordinates[i].WellboreDepth - intervalGeoParams.WellboreDepth; + var projectionLengthToXYSurface = deltaWellLength * Math.Sin(intervalGeoParams.ZenithAngle * Math.PI / 180); - if (intervalGeoParams.ZenithAngle != null && intervalGeoParams.AzimuthGeo != null && deltaWellLength != null) { - - var projectionLengthToXYSurface = deltaWellLength.Value * Math.Sin(intervalGeoParams.ZenithAngle.Value * Math.PI / 180); + var dz = deltaWellLength * Math.Cos(intervalGeoParams.ZenithAngle * Math.PI / 180); + var dx = projectionLengthToXYSurface * Math.Sin(intervalGeoParams.AzimuthGeo * Math.PI / 180); + var dy = projectionLengthToXYSurface * Math.Cos(intervalGeoParams.AzimuthGeo * Math.PI / 180); - var dz = deltaWellLength.Value * Math.Cos(intervalGeoParams.ZenithAngle.Value * Math.PI / 180); - var dx = projectionLengthToXYSurface * Math.Sin(intervalGeoParams.AzimuthGeo.Value * Math.PI / 180); - var dy = projectionLengthToXYSurface * Math.Cos(intervalGeoParams.AzimuthGeo.Value * Math.PI / 180); + var preCoordinates = cartesianCoordinates[i - 1]; + var coordinates = new TrajectoryVisualizationDto + { + Z = preCoordinates.Z + dz, + X = preCoordinates.X + dx, + Y = preCoordinates.Y + dy, + }; - var preCoordinates = cartesianCoordinates[i - 1]; - var coordinates = new TrajectoryVisualizationDto - { - Z = preCoordinates.Z + dz, - X = preCoordinates.X + dx, - Y = preCoordinates.Y + dy, - }; - - cartesianCoordinates.Add(coordinates); - } + cartesianCoordinates.Add(coordinates); } return cartesianCoordinates; } } - /// - /// Класс для формирования визуализации траектории 3D - /// - internal class TrajectoryDto - { - /// - /// Глубина ствола - /// - public double? WellboreDepth { get; } - - /// - /// Зенитный угол - /// - public double? ZenithAngle { get; } - - /// - /// Азимут географиеский - /// - public double? AzimuthGeo { get; } - - public TrajectoryDto(double? wellboreDepth, double? zenithAngle, double? azimuthGeo) - { - WellboreDepth = wellboreDepth; - ZenithAngle = zenithAngle; - AzimuthGeo = azimuthGeo; - } - } } From a1b4b1b9bb8120e12b939e07f5f5cf2ee01cc478 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 11 May 2023 15:36:49 +0500 Subject: [PATCH 07/10] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8,=20I?= =?UTF-8?q?FactualRepository=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=BD=D0=B0=20IActualReposito?= =?UTF-8?q?ry,=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2=20=D1=8E?= =?UTF-8?q?=D0=BD=D0=B8=D1=82-=D1=82=D0=B5=D1=81=D1=82=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IActualTrajectoryRepository.cs | 17 ++++ .../IFactualTrajectoryRepository.cs | 23 ----- ...itory.cs => ActualTrajectoryRepository.cs} | 32 +++---- .../TrajectoryVisualizationService.cs | 7 +- .../TrajectoryVisualizationServiceTest.cs | 95 +++++++++---------- 5 files changed, 75 insertions(+), 99 deletions(-) create mode 100644 AsbCloudApp/Repositories/IActualTrajectoryRepository.cs delete mode 100644 AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs rename AsbCloudInfrastructure/Repository/{FactualTrajectoryRepository.cs => ActualTrajectoryRepository.cs} (65%) diff --git a/AsbCloudApp/Repositories/IActualTrajectoryRepository.cs b/AsbCloudApp/Repositories/IActualTrajectoryRepository.cs new file mode 100644 index 00000000..76c1648d --- /dev/null +++ b/AsbCloudApp/Repositories/IActualTrajectoryRepository.cs @@ -0,0 +1,17 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Data.WITS; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudApp.Repositories +{ + /// + /// CRUD для работы с фактической траекторией из клиента + /// + /// + public interface IActualTrajectoryRepository : ITrajectoryRepository + { + + } +} diff --git a/AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs b/AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs deleted file mode 100644 index 536419ed..00000000 --- a/AsbCloudApp/Repositories/IFactualTrajectoryRepository.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AsbCloudApp.Data; -using AsbCloudApp.Data.WITS; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace AsbCloudApp.Repositories -{ - /// - /// CRUD для работы с фактической траекторией из клиента - /// - /// - public interface IFactualTrajectoryRepository : ITrajectoryRepository - { - /// - /// Получить все добавленные по скважине координаты фактической траектории - /// - /// - /// - /// - Task> GetAsync(int idWell, CancellationToken token); - } -} diff --git a/AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs b/AsbCloudInfrastructure/Repository/ActualTrajectoryRepository.cs similarity index 65% rename from AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs rename to AsbCloudInfrastructure/Repository/ActualTrajectoryRepository.cs index 67126227..cf4b551a 100644 --- a/AsbCloudInfrastructure/Repository/FactualTrajectoryRepository.cs +++ b/AsbCloudInfrastructure/Repository/ActualTrajectoryRepository.cs @@ -1,51 +1,45 @@ using AsbCloudApp.Data; -using AsbCloudApp.Data.WITS; using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudDb.Model; -using Mapster; using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace AsbCloudInfrastructure.Repository { - internal class FactualTrajectoryRepository : IFactualTrajectoryRepository + internal class ActualTrajectoryRepository : IActualTrajectoryRepository { private readonly IAsbCloudDbContext db; private readonly IWellService wellService; - public FactualTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService) + public ActualTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService) { this.db = db; this.wellService = wellService; } - public async Task> GetAsync(int idWell, CancellationToken token) + public async Task GetTrajectoryAsync(int idWell, CancellationToken token) { + var well = wellService.GetOrDefault(idWell); if (well is null || well.Timezone is null) throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); - var query = db.Record7 + var entities = await db.Record7 .AsNoTracking() - .Where(x => x.IdTelemetry == well.IdTelemetry); - var entities = await query - .OrderBy(e => e.Deptsvym) - .ToListAsync(token); - var result = entities - .Select(r => r.Adapt()); - return result; - } - - public async Task GetTrajectoryAsync(int idWell, CancellationToken token) - { - return (await GetAsync(idWell, token)) + .Where(x => x.IdTelemetry == well.IdTelemetry) .Where(coord => coord.Deptsvym != null && coord.Svyinc != null && coord.Svyazc != null) + .OrderBy(e => e.Deptsvym) + .Select(x => new { x.Deptsvym, x.Svyinc, x.Svyazc }) + .ToArrayAsync(token); + + var result = entities .Select(coord => new TrajectoryDto(coord.Deptsvym!.Value, coord.Svyinc!.Value, coord.Svyazc!.Value)) .ToArray(); + + return result; } } } diff --git a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs index cc1557bc..ba7f9990 100644 --- a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs @@ -1,11 +1,8 @@ using AsbCloudApp.Data; using AsbCloudApp.Repositories; using AsbCloudApp.Services; -using AsbCloudDb.Model; -using AsbCloudDb.Model.WITS; using System; using System.Collections.Generic; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -15,9 +12,9 @@ namespace AsbCloudInfrastructure.Services.Trajectory public class TrajectoryVisualizationService : ITrajectoryVisualizationService { private readonly IPlannedTrajectoryRepository plannedRepository; - private readonly IFactualTrajectoryRepository factualRepository; + private readonly IActualTrajectoryRepository factualRepository; - public TrajectoryVisualizationService(IPlannedTrajectoryRepository plannedRepository, IFactualTrajectoryRepository factualRepository) + public TrajectoryVisualizationService(IPlannedTrajectoryRepository plannedRepository, IActualTrajectoryRepository factualRepository) { this.plannedRepository = plannedRepository; this.factualRepository = factualRepository; diff --git a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs index c8f4baae..2b7011fa 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs @@ -13,21 +13,12 @@ namespace AsbCloudWebApi.Tests.ServicesTests { public class TrajectoryVisualizationServiceTest { - private Mock MakePlannedTrajectoryRepositoryMock(IEnumerable dateForGetMethod) + private Mock MakeTrajectoryRepositoryMock(TrajectoryDto[] dateForGetMethod) + where T : class, ITrajectoryRepository { - var mock = new Mock(); + var mock = new Mock(); - mock.Setup(r => r.GetAsync(It.IsAny(), It.IsAny())) - .Returns(Task.FromResult(dateForGetMethod)); - - return mock; - } - - private Mock MakeFactualTrajectoryRepositoryMock(IEnumerable dateForGetMethod) - { - var mock = new Mock(); - - mock.Setup(r => r.GetAsync(It.IsAny(), It.IsAny())) + mock.Setup(r => r.GetTrajectoryAsync(It.IsAny(), It.IsAny())) .Returns(Task.FromResult(dateForGetMethod)); return mock; @@ -36,25 +27,25 @@ namespace AsbCloudWebApi.Tests.ServicesTests [Fact] public async Task GetTrajectoryAsync_SameCounts() { - var plannedTrajectory = new PlannedTrajectoryDto[] + var plannedTrajectory = new TrajectoryDto[] { - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 10d}, - new() { AzimuthGeo = 0d, ZenithAngle = 30d, WellboreDepth = 20d}, - new() { AzimuthGeo = 30d, ZenithAngle = 0d, WellboreDepth = 30d}, - new() { AzimuthGeo = 30d, ZenithAngle = 90d, WellboreDepth = 40d}, - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 50d}, + new(0d, 0d, 0d), + new(0d, 0d, 10d), + new(0d, 30d, 20d), + new(30d, 0d, 30d), + new(30d, 90d, 40d), + new(0d, 0d, 50d), }; - var actualTrajectory = new Record7Dto[] + var actualTrajectory = new TrajectoryDto[] { - new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0}, - new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10}, - new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20}, + new(0, 0, 0), + new(30,30,10), + new(0, 0, 20), }; - var mockPlan = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); - var mockFact = MakeFactualTrajectoryRepositoryMock(actualTrajectory); + var mockPlan = MakeTrajectoryRepositoryMock(plannedTrajectory); + var mockFact = MakeTrajectoryRepositoryMock(actualTrajectory); var service = new TrajectoryVisualizationService(mockPlan.Object, mockFact.Object); var result = await service.GetTrajectoryAsync(1, CancellationToken.None); Assert.Equal(plannedTrajectory.Length, result.Plan?.Count()); @@ -64,28 +55,28 @@ namespace AsbCloudWebApi.Tests.ServicesTests [Fact] public async Task GetTrajectoryAsync_StraigthBore() { - var plannedTrajectory = new PlannedTrajectoryDto[] + var plannedTrajectory = new TrajectoryDto[] { - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d}, - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d}, - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 30d}, - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 50d}, + new(0, 0, 0), + new(0, 0, 0), + new(0, 0, 20), + new(0, 0, 20), + new(0, 0, 30), + new(0, 0, 50), }; - var factualTrajectory = new Record7Dto[] + var factualTrajectory = new TrajectoryDto[] { - new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0}, - new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0}, - new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20}, - new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20}, - new() { Svyazc = 0, Svyinc = 0, Deptsvym = 30}, - new() { Svyazc = 0, Svyinc = 0, Deptsvym = 50}, + new(0, 0, 0), + new(0, 0, 0), + new(0, 0, 20), + new(0, 0, 20), + new(0, 0, 30), + new(0, 0, 50), }; - var mockPlan = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); - var mockFact = MakeFactualTrajectoryRepositoryMock(factualTrajectory); + var mockPlan = MakeTrajectoryRepositoryMock(plannedTrajectory); + var mockFact = MakeTrajectoryRepositoryMock(factualTrajectory); var service = new TrajectoryVisualizationService(mockPlan.Object, mockFact.Object); var result = await service.GetTrajectoryAsync(1, CancellationToken.None); var lastPointPlan = result.Plan!.Last(); @@ -103,22 +94,22 @@ namespace AsbCloudWebApi.Tests.ServicesTests [Fact] public async Task GetTrajectoryAsync_Match() { - var plannedTrajectory = new PlannedTrajectoryDto[] + var plannedTrajectory = new TrajectoryDto[] { - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, - new() { AzimuthGeo = 30d, ZenithAngle = 30d, WellboreDepth = 10d}, - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d}, + new(0, 0, 0), + new(30, 30, 10), + new(0, 0, 20), }; - var factualTrajectory = new Record7Dto[] + var factualTrajectory = new TrajectoryDto[] { - new() { Svyazc = 0, Svyinc = 0, Deptsvym = 0}, - new() { Svyazc = 30, Svyinc = 30, Deptsvym = 10}, - new() { Svyazc = 0, Svyinc = 0, Deptsvym = 20}, + new(0, 0, 0), + new(30, 30, 10), + new(0, 0, 20), }; - var mockPlanned = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); - var mockFactual = MakeFactualTrajectoryRepositoryMock(factualTrajectory); + var mockPlanned = MakeTrajectoryRepositoryMock(plannedTrajectory); + var mockFactual = MakeTrajectoryRepositoryMock(factualTrajectory); var service = new TrajectoryVisualizationService(mockPlanned.Object, mockFactual.Object); var result = await service.GetTrajectoryAsync(1, CancellationToken.None); var lastPointPlan = result.Plan!.Last(); From b659cbc93460a8572d21f128fd38c3755144c2a1 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 11 May 2023 17:58:26 +0500 Subject: [PATCH 08/10] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0,=20=D1=87=D1=82=D0=BE=20=D1=82=D0=BE=D1=87=D0=B5?= =?UTF-8?q?=D0=BA=20=D0=BF=D1=80=D0=B8=20=D0=BF=D0=BE=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BD=D0=B8=D0=B8=20=D1=82=D1=80=D0=B0=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=B8=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B1=D1=8B=D1=82=D1=8C=20=D0=BC=D0=B8=D0=BD=D0=B8?= =?UTF-8?q?=D0=BC=D1=83=D0=BC=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Trajectory/TrajectoryVisualizationService.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs index ba7f9990..0da2851d 100644 --- a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs @@ -3,6 +3,7 @@ using AsbCloudApp.Repositories; using AsbCloudApp.Services; using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -46,6 +47,9 @@ namespace AsbCloudInfrastructure.Services.Trajectory /// private List GetTrajectoryVisualisation(TrajectoryDto[] geoCoordinates) { + if(geoCoordinates.Length < 2) + return new List(); + var cartesianCoordinates = new List(geoCoordinates.Length) { new (), }; From f4cc1d1bdfae995ae639d9760510c9c422a4e606 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 15 May 2023 10:17:56 +0500 Subject: [PATCH 09/10] =?UTF-8?q?=D0=9F=D1=83=D1=88=20=D0=BD=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D1=8E=D1=89=D0=B5=D0=B3=D0=BE=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/DependencyInjection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 96051f7e..1911d5a8 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -180,7 +180,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); // Subsystem service From b95250a0ddeb5f21fb64ca875014d80d44a85869 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 17 May 2023 11:42:14 +0500 Subject: [PATCH 10/10] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D0=B0=D0=BC=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/ITrajectoryRepository.cs | 2 +- .../Repository/ActualTrajectoryRepository.cs | 3 +- .../Repository/PlannedTrajectoryRepository.cs | 17 ++++++-- .../TrajectoryVisualizationService.cs | 21 ++++----- .../TrajectoryVisualizationServiceTest.cs | 43 ++++++------------- 5 files changed, 40 insertions(+), 46 deletions(-) diff --git a/AsbCloudApp/Repositories/ITrajectoryRepository.cs b/AsbCloudApp/Repositories/ITrajectoryRepository.cs index ad4ee0f4..123f1669 100644 --- a/AsbCloudApp/Repositories/ITrajectoryRepository.cs +++ b/AsbCloudApp/Repositories/ITrajectoryRepository.cs @@ -19,6 +19,6 @@ namespace AsbCloudApp.Repositories /// ключ скважины /// /// - Task GetTrajectoryAsync(int idWell, CancellationToken token); + Task> GetTrajectoryAsync(int idWell, CancellationToken token); } } diff --git a/AsbCloudInfrastructure/Repository/ActualTrajectoryRepository.cs b/AsbCloudInfrastructure/Repository/ActualTrajectoryRepository.cs index cf4b551a..b89c9cf8 100644 --- a/AsbCloudInfrastructure/Repository/ActualTrajectoryRepository.cs +++ b/AsbCloudInfrastructure/Repository/ActualTrajectoryRepository.cs @@ -4,6 +4,7 @@ using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudDb.Model; using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -20,7 +21,7 @@ namespace AsbCloudInfrastructure.Repository this.wellService = wellService; } - public async Task GetTrajectoryAsync(int idWell, CancellationToken token) + public async Task> GetTrajectoryAsync(int idWell, CancellationToken token) { var well = wellService.GetOrDefault(idWell); diff --git a/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs b/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs index 9b4873f0..d09b9690 100644 --- a/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs +++ b/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs @@ -86,7 +86,7 @@ namespace AsbCloudInfrastructure.Repository .Where(x => x.IdWell == idWell); var entities = await query .OrderBy(e => e.WellboreDepth) - .ToListAsync(token); + .ToArrayAsync(token); var result = entities .Select(r => Convert(r, offsetHours)); return result; @@ -116,11 +116,20 @@ namespace AsbCloudInfrastructure.Repository return entity; } - public async Task GetTrajectoryAsync(int idWell, CancellationToken token) + public async Task> GetTrajectoryAsync(int idWell, CancellationToken token) { - return (await GetAsync(idWell, token)) + var well = wellService.GetOrDefault(idWell); + if (well is null || well.Timezone is null) + throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); + + var query = db.PlannedTrajectories + .AsNoTracking() + .Where(x => x.IdWell == idWell); + + return await query .Select(coord => new TrajectoryDto(coord.WellboreDepth, coord.ZenithAngle, coord.AzimuthGeo)) - .ToArray(); + .ToArrayAsync() + .ConfigureAwait(false); } } diff --git a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs index 0da2851d..6e298a37 100644 --- a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs @@ -45,19 +45,20 @@ namespace AsbCloudInfrastructure.Services.Trajectory /// /// /// - private List GetTrajectoryVisualisation(TrajectoryDto[] geoCoordinates) + private IEnumerable GetTrajectoryVisualisation(IEnumerable geoCoordinates) { - if(geoCoordinates.Length < 2) - return new List(); + var geoCoordinatesLength = geoCoordinates.Count(); + if (geoCoordinatesLength < 2) + return new TrajectoryVisualizationDto[0]; - var cartesianCoordinates = new List(geoCoordinates.Length) { - new (), - }; + var cartesianCoordinates = new TrajectoryVisualizationDto[geoCoordinatesLength]; + cartesianCoordinates[0] = new(); - for (var i = 1; i < geoCoordinates.Length; i++) + var geoCoordinatesArray = geoCoordinates.ToArray(); + for (var i = 1; i < geoCoordinatesLength; i++) { - var intervalGeoParams = geoCoordinates[i - 1]; - var deltaWellLength = geoCoordinates[i].WellboreDepth - intervalGeoParams.WellboreDepth; + var intervalGeoParams = geoCoordinatesArray[i - 1]; + var deltaWellLength = geoCoordinatesArray[i].WellboreDepth - intervalGeoParams.WellboreDepth; var projectionLengthToXYSurface = deltaWellLength * Math.Sin(intervalGeoParams.ZenithAngle * Math.PI / 180); var dz = deltaWellLength * Math.Cos(intervalGeoParams.ZenithAngle * Math.PI / 180); @@ -72,7 +73,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory Y = preCoordinates.Y + dy, }; - cartesianCoordinates.Add(coordinates); + cartesianCoordinates[i] = coordinates; } return cartesianCoordinates; diff --git a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs index 2b7011fa..1a0dab1b 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs @@ -13,7 +13,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests { public class TrajectoryVisualizationServiceTest { - private Mock MakeTrajectoryRepositoryMock(TrajectoryDto[] dateForGetMethod) + private Mock MakeTrajectoryRepositoryMock(IEnumerable dateForGetMethod) where T : class, ITrajectoryRepository { var mock = new Mock(); @@ -55,28 +55,18 @@ namespace AsbCloudWebApi.Tests.ServicesTests [Fact] public async Task GetTrajectoryAsync_StraigthBore() { - var plannedTrajectory = new TrajectoryDto[] + var trajectory = new TrajectoryDto[] { new(0, 0, 0), new(0, 0, 0), - new(0, 0, 20), - new(0, 0, 20), - new(0, 0, 30), - new(0, 0, 50), + new(20, 0, 0), + new(20, 0, 0), + new(30, 0, 0), + new(50, 0, 0), }; - var factualTrajectory = new TrajectoryDto[] - { - new(0, 0, 0), - new(0, 0, 0), - new(0, 0, 20), - new(0, 0, 20), - new(0, 0, 30), - new(0, 0, 50), - }; - - var mockPlan = MakeTrajectoryRepositoryMock(plannedTrajectory); - var mockFact = MakeTrajectoryRepositoryMock(factualTrajectory); + var mockPlan = MakeTrajectoryRepositoryMock(trajectory); + var mockFact = MakeTrajectoryRepositoryMock(trajectory); var service = new TrajectoryVisualizationService(mockPlan.Object, mockFact.Object); var result = await service.GetTrajectoryAsync(1, CancellationToken.None); var lastPointPlan = result.Plan!.Last(); @@ -94,22 +84,15 @@ namespace AsbCloudWebApi.Tests.ServicesTests [Fact] public async Task GetTrajectoryAsync_Match() { - var plannedTrajectory = new TrajectoryDto[] + var trajectory = new TrajectoryDto[] { new(0, 0, 0), - new(30, 30, 10), - new(0, 0, 20), + new(10, 30, 30), + new(20, 0, 0), }; - var factualTrajectory = new TrajectoryDto[] - { - new(0, 0, 0), - new(30, 30, 10), - new(0, 0, 20), - }; - - var mockPlanned = MakeTrajectoryRepositoryMock(plannedTrajectory); - var mockFactual = MakeTrajectoryRepositoryMock(factualTrajectory); + var mockPlanned = MakeTrajectoryRepositoryMock(trajectory); + var mockFactual = MakeTrajectoryRepositoryMock(trajectory); var service = new TrajectoryVisualizationService(mockPlanned.Object, mockFactual.Object); var result = await service.GetTrajectoryAsync(1, CancellationToken.None); var lastPointPlan = result.Plan!.Last();