From a1b4b1b9bb8120e12b939e07f5f5cf2ee01cc478 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 11 May 2023 15:36:49 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8,=20IFactua?= =?UTF-8?q?lRepository=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=BD=D0=B0=20IActualRepository,=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2=20=D1=8E=D0=BD?= =?UTF-8?q?=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();