From b95250a0ddeb5f21fb64ca875014d80d44a85869 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 17 May 2023 11:42:14 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82?= =?UTF-8?q?=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();