From d47fa1b09ce46c8ef0ec7f3609dcb63f107f4c8e Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Fri, 10 Feb 2023 11:12:16 +0500 Subject: [PATCH 01/12] =?UTF-8?q?#8636739=20=D0=92=D0=B8=D0=B7=D1=83=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B8=203D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/TrajectoryVisualizationDataDto.cs | 41 ++++++++++++ .../Data/TrajectoryVisualizationDto.cs | 32 ++++++++++ .../ITrajectoryVisualizationRepository.cs | 23 +++++++ .../ITrajectoryVisualizationService.cs | 23 +++++++ .../AsbCloudInfrastructure.csproj | 4 ++ AsbCloudInfrastructure/DependencyInjection.cs | 2 + .../TrajectoryVisualizationRepository.cs | 44 +++++++++++++ .../TrajectoryVisualizationService.cs | 63 +++++++++++++++++++ .../TrajectoryVisualizationController.cs | 34 ++++++++++ 9 files changed, 266 insertions(+) create mode 100644 AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs create mode 100644 AsbCloudApp/Data/TrajectoryVisualizationDto.cs create mode 100644 AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs create mode 100644 AsbCloudApp/Services/ITrajectoryVisualizationService.cs create mode 100644 AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs create mode 100644 AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs create mode 100644 AsbCloudWebApi/Controllers/TrajectoryVisualizationController.cs diff --git a/AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs b/AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs new file mode 100644 index 00000000..7fbce489 --- /dev/null +++ b/AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs @@ -0,0 +1,41 @@ +namespace AsbCloudDb.Model +{ +#nullable enable + /// + /// Данные для визуализации траектории + /// + public class TrajectoryVisualizationDataDto + { + + /// + /// Глубина по стволу + /// + public double WellboreDepth { get; set; } + + /// + /// Зенит + /// + public double Zenith { get; set; } + + /// + /// Азимут + /// + public double Azimuth { get; set; } + + /// + /// Координаты по оси X + /// + public double X { get; set; } + + /// + /// Координаты по оси Y + /// + public double Y { get; set; } + + /// + /// Координаты по оси Z + /// + public double Z { get; set; } + } +#nullable disable +} diff --git a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs new file mode 100644 index 00000000..3d8cbe8c --- /dev/null +++ b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs @@ -0,0 +1,32 @@ +namespace AsbCloudApp.Data +{ + /// + /// Визуализация траектории 3D + /// + public class TrajectoryVisualizationDto : IWellRelated + { + + /// + public int IdWell { get; set; } + + /// + /// Плоскость + /// + public double Flat { get; set; } + + /// + /// Координаты по оси X + /// + public double X { get; set; } + + /// + /// Координаты по оси Y + /// + public double Y { get; set; } + + /// + /// Координаты по оси Z + /// + public double Z { get; set; } + } +} diff --git a/AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs b/AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs new file mode 100644 index 00000000..24cb646b --- /dev/null +++ b/AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs @@ -0,0 +1,23 @@ +using AsbCloudDb.Model; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudApp.Repositories +{ +#nullable enable + /// + /// Визуализация траектории 3D + /// + public interface ITrajectoryVisualizationRepository + { + /// + /// Получение данных для расчета + /// + /// + /// + /// + Task> GetAllAsync(int idWell, CancellationToken token); + } +#nullable disable +} diff --git a/AsbCloudApp/Services/ITrajectoryVisualizationService.cs b/AsbCloudApp/Services/ITrajectoryVisualizationService.cs new file mode 100644 index 00000000..a387e501 --- /dev/null +++ b/AsbCloudApp/Services/ITrajectoryVisualizationService.cs @@ -0,0 +1,23 @@ +using AsbCloudApp.Data; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudApp.Services +{ +#nullable enable + /// + /// Сервис "Визуализация траектории 3D" + /// + public interface ITrajectoryVisualizationService + { + /// + /// Получение траектории по скважине + /// + /// + /// + /// + Task> GetTrajectoryAsync(int idWell, CancellationToken token); + } +#nullable disable +} diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index 1a8e2432..3e674968 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -72,4 +72,8 @@ + + + + diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index dcc2eb70..32a6f490 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -140,6 +140,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); // admin crud services: services.AddTransient, CrudCacheRepositoryBase>(s => @@ -177,6 +178,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); // Subsystem service services.AddTransient, CrudCacheRepositoryBase>(); diff --git a/AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs b/AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs new file mode 100644 index 00000000..76b11e7a --- /dev/null +++ b/AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs @@ -0,0 +1,44 @@ +using AsbCloudApp.Repositories; +using AsbCloudDb.Model; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudInfrastructure.Repository +{ +#nullable enable + public class TrajectoryVisualizationRepository : ITrajectoryVisualizationRepository + { + private readonly IAsbCloudDbContext context; + + public TrajectoryVisualizationRepository(IAsbCloudDbContext context) + { + this.context = context; + } + + /// + public async Task> GetAllAsync(int idWell, CancellationToken token) + { + var dtos = await context.PlannedTrajectories + .Where(t => t.IdWell == idWell) + .OrderBy(x => x.UpdateDate) + .Select(x => Convert(x)) + .ToListAsync(token) + .ConfigureAwait(false); + + return dtos; + } + + private static TrajectoryVisualizationDataDto Convert(PlannedTrajectory dto) + { + return new TrajectoryVisualizationDataDto { + WellboreDepth = dto.WellboreDepth, + Azimuth = dto.AzimuthGeo, + Zenith = dto.ZenithAngle + }; + } + } +#nullable disable +} diff --git a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs new file mode 100644 index 00000000..97aae641 --- /dev/null +++ b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs @@ -0,0 +1,63 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Repositories; +using AsbCloudApp.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudInfrastructure.Services +{ + public class TrajectoryVisualizationService : ITrajectoryVisualizationService + { + private readonly ITrajectoryVisualizationRepository repository; + + public TrajectoryVisualizationService(ITrajectoryVisualizationRepository repository) + { + this.repository = repository; + } + + public async Task> GetTrajectoryAsync(int idWell, CancellationToken token) + { + var result = new List(); + var dto = (await repository.GetAllAsync(idWell, token)).ToArray(); + + var prevData = dto[0]; + for (var i = 1; i < dto.Length; i++) + { + var data = dto[i]; + var flat = GetFlat(data.WellboreDepth, prevData.WellboreDepth, data.Zenith); + var x = data.X = GetX(data.Azimuth, flat, prevData.X); + var y = data.Y = GetY(data.Azimuth, flat, prevData.Y); + var z = data.Z = GetZ(data.WellboreDepth, prevData.WellboreDepth, data.Zenith, prevData.Z); + prevData = data; + + var coordinates = new TrajectoryVisualizationDto + { + IdWell = idWell, + Flat = flat, + X = x, + Y = y, + Z = z + }; + + result.Add(coordinates); + } + + return result; + } + + private double GetFlat(double depthEnd, double depthStart, double zenit) => + (depthEnd - depthStart) * Math.Sin(zenit * Math.PI / 180); + + private double GetX(double azimuth, double flat, double prev) => + (prev + flat) * Math.Sin(azimuth * Math.PI / 180); + + private double GetY(double azimuth, double flat, double prev) => + prev + flat * Math.Cos(azimuth * Math.PI / 180); + + private double GetZ(double depthEnd, double depthStart, double zenit, double prev) => + prev - (depthEnd - depthStart) * Math.Cos(zenit * Math.PI / 180); + } +} diff --git a/AsbCloudWebApi/Controllers/TrajectoryVisualizationController.cs b/AsbCloudWebApi/Controllers/TrajectoryVisualizationController.cs new file mode 100644 index 00000000..1ba99178 --- /dev/null +++ b/AsbCloudWebApi/Controllers/TrajectoryVisualizationController.cs @@ -0,0 +1,34 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; +using System.Threading; +using System.Collections.Generic; + +namespace AsbCloudWebApi.Controllers +{ + /// + /// Визуализация траектории 3D + /// + [Route("api/[controller]")] + [ApiController] + [Authorize] + public class TrajectoryVisualizationController : ControllerBase + { + private readonly ITrajectoryVisualizationService service; + + public TrajectoryVisualizationController(ITrajectoryVisualizationService service) + { + this.service = service; + } + + [HttpGet] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public async Task GetTrajectoryAsync(int idWell, CancellationToken token) + { + var result = await service.GetTrajectoryAsync(idWell, token); + return Ok(result); + } + } +} From 7127dfd9bbd31eb1286f07fcd2b579a91db8ff7e Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Mon, 13 Feb 2023 09:10:48 +0500 Subject: [PATCH 02/12] =?UTF-8?q?#8636739=20=D0=92=D0=B8=D0=B7=D1=83=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B8=203D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/TrajectoryVisualizationDataDto.cs | 41 ----------------- .../Data/TrajectoryVisualizationDto.cs | 14 +----- .../IPlannedTrajectoryRepository.cs} | 4 +- .../ITrajectoryVisualizationRepository.cs | 23 ---------- AsbCloudInfrastructure/DependencyInjection.cs | 3 +- .../PlannedTrajectoryRepository.cs} | 39 ++++++++-------- .../TrajectoryVisualizationRepository.cs | 44 ------------------- .../PlannedTrajectoryImportService.cs | 5 ++- .../TrajectoryVisualizationService.cs | 17 ++++--- .../PlannedTrajectoryController.cs | 17 +++---- 10 files changed, 46 insertions(+), 161 deletions(-) delete mode 100644 AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs rename AsbCloudApp/{Services/IPlannedTrajectoryService.cs => Repositories/IPlannedTrajectoryRepository.cs} (96%) delete mode 100644 AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs rename AsbCloudInfrastructure/{Services/PlannedTrajectory/PlannedTrajectoryService.cs => Repository/PlannedTrajectoryRepository.cs} (79%) delete mode 100644 AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs diff --git a/AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs b/AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs deleted file mode 100644 index 7fbce489..00000000 --- a/AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace AsbCloudDb.Model -{ -#nullable enable - /// - /// Данные для визуализации траектории - /// - public class TrajectoryVisualizationDataDto - { - - /// - /// Глубина по стволу - /// - public double WellboreDepth { get; set; } - - /// - /// Зенит - /// - public double Zenith { get; set; } - - /// - /// Азимут - /// - public double Azimuth { get; set; } - - /// - /// Координаты по оси X - /// - public double X { get; set; } - - /// - /// Координаты по оси Y - /// - public double Y { get; set; } - - /// - /// Координаты по оси Z - /// - public double Z { get; set; } - } -#nullable disable -} diff --git a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs index 3d8cbe8c..bc67f9c0 100644 --- a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs +++ b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs @@ -3,18 +3,8 @@ /// /// Визуализация траектории 3D /// - public class TrajectoryVisualizationDto : IWellRelated - { - - /// - public int IdWell { get; set; } - - /// - /// Плоскость - /// - public double Flat { get; set; } - - /// + public class TrajectoryVisualizationDto + {/// /// Координаты по оси X /// public double X { get; set; } diff --git a/AsbCloudApp/Services/IPlannedTrajectoryService.cs b/AsbCloudApp/Repositories/IPlannedTrajectoryRepository.cs similarity index 96% rename from AsbCloudApp/Services/IPlannedTrajectoryService.cs rename to AsbCloudApp/Repositories/IPlannedTrajectoryRepository.cs index 31fc1130..b18f72cf 100644 --- a/AsbCloudApp/Services/IPlannedTrajectoryService.cs +++ b/AsbCloudApp/Repositories/IPlannedTrajectoryRepository.cs @@ -3,14 +3,14 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudApp.Services +namespace AsbCloudApp.Repositories { #nullable enable /// /// CRUD для работы с плановой траекторией из клиента /// /// - public interface IPlannedTrajectoryService + public interface IPlannedTrajectoryRepository { /// /// Получить все добавленные по скважине координаты плановой траектории diff --git a/AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs b/AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs deleted file mode 100644 index 24cb646b..00000000 --- a/AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AsbCloudDb.Model; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace AsbCloudApp.Repositories -{ -#nullable enable - /// - /// Визуализация траектории 3D - /// - public interface ITrajectoryVisualizationRepository - { - /// - /// Получение данных для расчета - /// - /// - /// - /// - Task> GetAllAsync(int idWell, CancellationToken token); - } -#nullable disable -} diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 32a6f490..cfa4d8ac 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -126,7 +126,6 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -178,7 +177,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); // Subsystem service services.AddTransient, CrudCacheRepositoryBase>(); diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs b/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs similarity index 79% rename from AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs rename to AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs index d00a9563..dba77d7b 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs +++ b/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs @@ -1,5 +1,6 @@ using AsbCloudApp.Data; using AsbCloudApp.Exceptions; +using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudDb.Model; using Mapster; @@ -10,31 +11,33 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudInfrastructure.Services.PlannedTrajectory +namespace AsbCloudInfrastructure.Repository { #nullable enable - public class PlannedTrajectoryService : IPlannedTrajectoryService + public class PlannedTrajectoryRepository : IPlannedTrajectoryRepository { private readonly IAsbCloudDbContext db; private readonly IWellService wellService; - public PlannedTrajectoryService(IAsbCloudDbContext db, IWellService wellService) + public PlannedTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService) { this.db = db; this.wellService = wellService; } /// public async Task AddRangeAsync(IEnumerable plannedTrajectoryRows, CancellationToken token) - { + { var idWell = plannedTrajectoryRows.First().IdWell; if (!plannedTrajectoryRows.All(r => r.IdWell == idWell)) throw new ArgumentInvalidException("Все строки должны относиться к одной скважине", nameof(plannedTrajectoryRows)); var offsetHours = wellService.GetTimezone(idWell).Hours; var entities = plannedTrajectoryRows - .Select(e => { + .Select(e => + { var entity = Convert(e, offsetHours); entity.Id = 0; - return entity;}); - + return entity; + }); + db.PlannedTrajectories.AddRange(entities); return await db.SaveChangesAsync(token) .ConfigureAwait(false); @@ -46,7 +49,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory var offsetHours = wellService.GetTimezone(plannedTrajectoryRow.IdWell).Hours; var entity = Convert(plannedTrajectoryRow, offsetHours); entity.Id = 0; - db.PlannedTrajectories.Add(entity); + db.PlannedTrajectories.Add(entity); return await db.SaveChangesAsync(token) .ConfigureAwait(false); } @@ -77,13 +80,13 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory var well = wellService.GetOrDefault(idWell); if (well is null || well.Timezone is null) throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); - var offsetHours = well.Timezone.Hours; + var offsetHours = well.Timezone.Hours; var query = db.PlannedTrajectories .AsNoTracking() - .Where(x => x.IdWell == idWell); + .Where(x => x.IdWell == idWell); var entities = await query .OrderBy(e => e.WellboreDepth) - .ToListAsync(token); + .ToListAsync(token); var result = entities .Select(r => Convert(r, offsetHours)); return result; @@ -99,19 +102,19 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory .ConfigureAwait(false); } - private PlannedTrajectoryDto Convert(AsbCloudDb.Model.PlannedTrajectory entity, double offsetHours) - { - var dto = entity.Adapt(); + private PlannedTrajectoryDto Convert(PlannedTrajectory entity, double offsetHours) + { + var dto = entity.Adapt(); dto.UpdateDate = entity.UpdateDate.ToRemoteDateTime(offsetHours); return dto; } - private AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto, double offsetHours) - { - var entity = dto.Adapt(); + private PlannedTrajectory Convert(PlannedTrajectoryDto dto, double offsetHours) + { + var entity = dto.Adapt(); entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(offsetHours); return entity; - } + } } #nullable disable } diff --git a/AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs b/AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs deleted file mode 100644 index 76b11e7a..00000000 --- a/AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs +++ /dev/null @@ -1,44 +0,0 @@ -using AsbCloudApp.Repositories; -using AsbCloudDb.Model; -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace AsbCloudInfrastructure.Repository -{ -#nullable enable - public class TrajectoryVisualizationRepository : ITrajectoryVisualizationRepository - { - private readonly IAsbCloudDbContext context; - - public TrajectoryVisualizationRepository(IAsbCloudDbContext context) - { - this.context = context; - } - - /// - public async Task> GetAllAsync(int idWell, CancellationToken token) - { - var dtos = await context.PlannedTrajectories - .Where(t => t.IdWell == idWell) - .OrderBy(x => x.UpdateDate) - .Select(x => Convert(x)) - .ToListAsync(token) - .ConfigureAwait(false); - - return dtos; - } - - private static TrajectoryVisualizationDataDto Convert(PlannedTrajectory dto) - { - return new TrajectoryVisualizationDataDto { - WellboreDepth = dto.WellboreDepth, - Azimuth = dto.AzimuthGeo, - Zenith = dto.ZenithAngle - }; - } - } -#nullable disable -} diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs index 8e2278fa..0bf97365 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs +++ b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data; +using AsbCloudApp.Repositories; using AsbCloudApp.Services; using ClosedXML.Excel; using System; @@ -18,7 +19,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory */ private readonly IWellService wellService; - private readonly IPlannedTrajectoryService plannedTrajectoryService; + private readonly IPlannedTrajectoryRepository plannedTrajectoryService; private const string templateFileName = "PlannedTrajectoryTemplate.xlsx"; private const string usingTemplateFile = "AsbCloudInfrastructure.Services.PlannedTrajectory"; @@ -40,7 +41,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory private const int ColumnOrificeOffset = 14; private const int ColumnComment = 15; - public PlannedTrajectoryImportService(IWellService wellService, IPlannedTrajectoryService plannedTrajectoryService) + public PlannedTrajectoryImportService(IWellService wellService, IPlannedTrajectoryRepository plannedTrajectoryService) { this.wellService = wellService; diff --git a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs index 97aae641..c6ad3b4b 100644 --- a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs @@ -11,9 +11,9 @@ namespace AsbCloudInfrastructure.Services { public class TrajectoryVisualizationService : ITrajectoryVisualizationService { - private readonly ITrajectoryVisualizationRepository repository; + private readonly IPlannedTrajectoryRepository repository; - public TrajectoryVisualizationService(ITrajectoryVisualizationRepository repository) + public TrajectoryVisualizationService(IPlannedTrajectoryRepository repository) { this.repository = repository; } @@ -21,22 +21,21 @@ namespace AsbCloudInfrastructure.Services public async Task> GetTrajectoryAsync(int idWell, CancellationToken token) { var result = new List(); - var dto = (await repository.GetAllAsync(idWell, token)).ToArray(); + var dto = (await repository.GetAsync(idWell, token)).ToArray(); var prevData = dto[0]; + var prevCoordinates = new TrajectoryVisualizationDto(); for (var i = 1; i < dto.Length; i++) { var data = dto[i]; - var flat = GetFlat(data.WellboreDepth, prevData.WellboreDepth, data.Zenith); - var x = data.X = GetX(data.Azimuth, flat, prevData.X); - var y = data.Y = GetY(data.Azimuth, flat, prevData.Y); - var z = data.Z = GetZ(data.WellboreDepth, prevData.WellboreDepth, data.Zenith, prevData.Z); + var flat = GetFlat(data.WellboreDepth, prevData.WellboreDepth, data.ZenithAngle); + var x = prevCoordinates.X = GetX(data.AzimuthGeo, flat, prevCoordinates.X); + var y = prevCoordinates.Y = GetY(data.AzimuthGeo, flat, prevCoordinates.Y); + var z = prevCoordinates.Z = GetZ(data.WellboreDepth, prevData.WellboreDepth, data.ZenithAngle, prevCoordinates.Z); prevData = data; var coordinates = new TrajectoryVisualizationDto { - IdWell = idWell, - Flat = flat, X = x, Y = y, Z = z diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs index cd1c1ed6..d396618f 100644 --- a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs +++ b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data; +using AsbCloudApp.Repositories; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -21,13 +22,13 @@ namespace AsbCloudWebApi.Controllers { private readonly IWellService wellService; private readonly IPlannedTrajectoryImportService plannedTrajectoryImportService; - private readonly IPlannedTrajectoryService plannedTrajectoryService; + private readonly IPlannedTrajectoryRepository plannedTrajectoryRepository; - public PlannedTrajectoryController(IWellService wellService, IPlannedTrajectoryImportService plannedTrajectoryImportService, IPlannedTrajectoryService plannedTrajectoryService) + public PlannedTrajectoryController(IWellService wellService, IPlannedTrajectoryImportService plannedTrajectoryImportService, IPlannedTrajectoryRepository plannedTrajectoryRepository) { this.plannedTrajectoryImportService = plannedTrajectoryImportService; this.wellService = wellService; - this.plannedTrajectoryService = plannedTrajectoryService; + this.plannedTrajectoryRepository = plannedTrajectoryRepository; } /// @@ -121,7 +122,7 @@ namespace AsbCloudWebApi.Controllers if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); - var result = await plannedTrajectoryService.GetAsync(idWell, token); + var result = await plannedTrajectoryRepository.GetAsync(idWell, token); return Ok(result); } @@ -146,7 +147,7 @@ namespace AsbCloudWebApi.Controllers return Forbid(); row.IdUser = idUser.Value; row.IdWell = idWell; - var result = await plannedTrajectoryService.AddAsync(row, token); + var result = await plannedTrajectoryRepository.AddAsync(row, token); return Ok(result); } @@ -174,7 +175,7 @@ namespace AsbCloudWebApi.Controllers item.IdUser = idUser.Value; item.IdWell = idWell; } - var result = await plannedTrajectoryService.AddRangeAsync(rows, token); + var result = await plannedTrajectoryRepository.AddRangeAsync(rows, token); return Ok(result); } @@ -200,7 +201,7 @@ namespace AsbCloudWebApi.Controllers row.Id = idRow; row.IdUser = idUser.Value; row.IdWell = idWell; - var result = await plannedTrajectoryService.UpdateAsync(row, token); + var result = await plannedTrajectoryRepository.UpdateAsync(row, token); return Ok(result); } @@ -220,7 +221,7 @@ namespace AsbCloudWebApi.Controllers token).ConfigureAwait(false)) return Forbid(); - var result = await plannedTrajectoryService.DeleteRangeAsync(new int[] { idRow }, token); + var result = await plannedTrajectoryRepository.DeleteRangeAsync(new int[] { idRow }, token); return Ok(result); } From 41922540726feb64a13c7108035f7c1aee95b3dd Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Mon, 13 Feb 2023 09:11:28 +0500 Subject: [PATCH 03/12] =?UTF-8?q?#8636739=20=D0=92=D0=B8=D0=B7=D1=83=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B8=203D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/TrajectoryVisualizationService.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs index c6ad3b4b..36ed5106 100644 --- a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs @@ -21,13 +21,13 @@ namespace AsbCloudInfrastructure.Services public async Task> GetTrajectoryAsync(int idWell, CancellationToken token) { var result = new List(); - var dto = (await repository.GetAsync(idWell, token)).ToArray(); + var dtos = (await repository.GetAsync(idWell, token)).ToArray(); - var prevData = dto[0]; + var prevData = dtos[0]; var prevCoordinates = new TrajectoryVisualizationDto(); - for (var i = 1; i < dto.Length; i++) + for (var i = 1; i < dtos.Length; i++) { - var data = dto[i]; + var data = dtos[i]; var flat = GetFlat(data.WellboreDepth, prevData.WellboreDepth, data.ZenithAngle); var x = prevCoordinates.X = GetX(data.AzimuthGeo, flat, prevCoordinates.X); var y = prevCoordinates.Y = GetY(data.AzimuthGeo, flat, prevCoordinates.Y); From 7d94945c9f54e93dd6bc0aa10adcfa6700841437 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Mon, 13 Feb 2023 09:19:11 +0500 Subject: [PATCH 04/12] =?UTF-8?q?#8636739=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlannedTrajectoryController.cs | 22 +++++++++++- .../TrajectoryVisualizationController.cs | 34 ------------------- 2 files changed, 21 insertions(+), 35 deletions(-) delete mode 100644 AsbCloudWebApi/Controllers/TrajectoryVisualizationController.cs diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs index d396618f..258dae7a 100644 --- a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs +++ b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs @@ -4,6 +4,7 @@ using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using ProtoBuf.Meta; using System.Collections.Generic; using System.IO; using System.Threading; @@ -23,12 +24,17 @@ namespace AsbCloudWebApi.Controllers private readonly IWellService wellService; private readonly IPlannedTrajectoryImportService plannedTrajectoryImportService; private readonly IPlannedTrajectoryRepository plannedTrajectoryRepository; + private readonly ITrajectoryVisualizationService trajectoryVisualizationService; - public PlannedTrajectoryController(IWellService wellService, IPlannedTrajectoryImportService plannedTrajectoryImportService, IPlannedTrajectoryRepository plannedTrajectoryRepository) + public PlannedTrajectoryController(IWellService wellService, + IPlannedTrajectoryImportService plannedTrajectoryImportService, + IPlannedTrajectoryRepository plannedTrajectoryRepository, + ITrajectoryVisualizationService trajectoryVisualizationService) { this.plannedTrajectoryImportService = plannedTrajectoryImportService; this.wellService = wellService; this.plannedTrajectoryRepository = plannedTrajectoryRepository; + this.trajectoryVisualizationService = trajectoryVisualizationService; } /// @@ -226,6 +232,20 @@ namespace AsbCloudWebApi.Controllers return Ok(result); } + /// + /// Получение координат для визуализации траектории + /// + /// + /// + /// + [HttpGet] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public async Task GetTrajectoryAsync(int idWell, CancellationToken token) + { + var result = await trajectoryVisualizationService.GetTrajectoryAsync(idWell, token); + return Ok(result); + } + private async Task CanUserAccessToWellAsync(int idWell, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); diff --git a/AsbCloudWebApi/Controllers/TrajectoryVisualizationController.cs b/AsbCloudWebApi/Controllers/TrajectoryVisualizationController.cs deleted file mode 100644 index 1ba99178..00000000 --- a/AsbCloudWebApi/Controllers/TrajectoryVisualizationController.cs +++ /dev/null @@ -1,34 +0,0 @@ -using AsbCloudApp.Data; -using AsbCloudApp.Services; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using System.Threading.Tasks; -using System.Threading; -using System.Collections.Generic; - -namespace AsbCloudWebApi.Controllers -{ - /// - /// Визуализация траектории 3D - /// - [Route("api/[controller]")] - [ApiController] - [Authorize] - public class TrajectoryVisualizationController : ControllerBase - { - private readonly ITrajectoryVisualizationService service; - - public TrajectoryVisualizationController(ITrajectoryVisualizationService service) - { - this.service = service; - } - - [HttpGet] - [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task GetTrajectoryAsync(int idWell, CancellationToken token) - { - var result = await service.GetTrajectoryAsync(idWell, token); - return Ok(result); - } - } -} From 3f2febc0225dd4e1f463e33174174ffeae5e6d2c Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Mon, 13 Feb 2023 12:39:45 +0500 Subject: [PATCH 05/12] =?UTF-8?q?#8636739=20=D0=92=D0=B8=D0=B7=D1=83=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B8=203D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/TrajectoryVisualizationDto.cs | 3 ++- AsbCloudInfrastructure/AsbCloudInfrastructure.csproj | 5 ----- .../Services/TrajectoryVisualizationService.cs | 6 +++--- AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs | 4 ++++ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs index bc67f9c0..8c92470a 100644 --- a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs +++ b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs @@ -4,7 +4,8 @@ /// Визуализация траектории 3D /// public class TrajectoryVisualizationDto - {/// + { + /// /// Координаты по оси X /// public double X { get; set; } diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index 3e674968..d5ec4e0a 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -71,9 +71,4 @@ CommonLibs\AsbWitsInfo.dll - - - - - diff --git a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs index 36ed5106..ee40b693 100644 --- a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs @@ -28,9 +28,9 @@ namespace AsbCloudInfrastructure.Services for (var i = 1; i < dtos.Length; i++) { var data = dtos[i]; - var flat = GetFlat(data.WellboreDepth, prevData.WellboreDepth, data.ZenithAngle); + var flat = GetFlat(data.WellboreDepth, prevData.WellboreDepth, prevData.ZenithAngle); var x = prevCoordinates.X = GetX(data.AzimuthGeo, flat, prevCoordinates.X); - var y = prevCoordinates.Y = GetY(data.AzimuthGeo, flat, prevCoordinates.Y); + var y = prevCoordinates.Y = GetY(data.AzimuthGeo, flat, prevCoordinates.X); var z = prevCoordinates.Z = GetZ(data.WellboreDepth, prevData.WellboreDepth, data.ZenithAngle, prevCoordinates.Z); prevData = data; @@ -51,7 +51,7 @@ namespace AsbCloudInfrastructure.Services (depthEnd - depthStart) * Math.Sin(zenit * Math.PI / 180); private double GetX(double azimuth, double flat, double prev) => - (prev + flat) * Math.Sin(azimuth * Math.PI / 180); + prev + flat * Math.Sin(azimuth * Math.PI / 180); private double GetY(double azimuth, double flat, double prev) => prev + flat * Math.Cos(azimuth * Math.PI / 180); diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs index 258dae7a..ef50518c 100644 --- a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs +++ b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs @@ -242,6 +242,10 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public async Task GetTrajectoryAsync(int idWell, CancellationToken token) { + if (!await CanUserAccessToWellAsync(idWell, + token).ConfigureAwait(false)) + return Forbid(); + var result = await trajectoryVisualizationService.GetTrajectoryAsync(idWell, token); return Ok(result); } From 5759388713340d7f15ef4700f9f35aaa598cc6e0 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Wed, 15 Feb 2023 10:49:55 +0500 Subject: [PATCH 06/12] #8636739 dto --- AsbCloudApp/Data/TrajectoryVisualizationDto.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs index 8c92470a..8e47ccd5 100644 --- a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs +++ b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs @@ -6,17 +6,17 @@ public class TrajectoryVisualizationDto { /// - /// Координаты по оси X + /// Координаты по оси X, в сторону севера (м) /// public double X { get; set; } /// - /// Координаты по оси Y + /// Координаты по оси Y, в сторону востока (м) /// public double Y { get; set; } /// - /// Координаты по оси Z + /// Координаты по оси Z, глубина (м) /// public double Z { get; set; } } From 2e59d97dcd7069e30eb29c3e5b8bc3c37b7f28c3 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 15 Feb 2023 13:35:18 +0500 Subject: [PATCH 07/12] Add test --- .../TrajectoryVisualizationServiceTest.cs | 104 ++++++++++++++++++ .../PlannedTrajectoryController.cs | 1 - 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs diff --git a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs new file mode 100644 index 00000000..ab57843e --- /dev/null +++ b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs @@ -0,0 +1,104 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Repositories; +using AsbCloudInfrastructure.Services; +using Moq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace AsbCloudWebApi.Tests.ServicesTests +{ + public class TrajectoryVisualizationServiceTest + { + private Mock MakePlannedTrajectoryRepositoryMock(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() + { + var plannedTrajectory = new PlannedTrajectoryDto[] + { + 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}, + }; + + var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); + var service = new TrajectoryVisualizationService(mock.Object); + var result = await service.GetTrajectoryAsync(1, CancellationToken.None); + + Assert.Equal(plannedTrajectory.Length, result.Count()); + } + + [Fact] + public async Task GetTrajectoryAsync_StraigthBore() + { + var plannedTrajectory = new PlannedTrajectoryDto[] + { + 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}, + }; + + var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); + 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); + } + + + [Fact] + public async Task GetTrajectoryAsync_Match() + { + var plannedTrajectory = new PlannedTrajectoryDto[] + { + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, + new() { AzimuthGeo = 30d, ZenithAngle = 30d, WellboreDepth = 10d}, + 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 deltaLength = plannedTrajectory[2].WellboreDepth - plannedTrajectory[1].WellboreDepth; + var zenith = plannedTrajectory[1].ZenithAngle * Math.PI / 1800; + var azimuth = plannedTrajectory[1].AzimuthGeo * Math.PI / 1800; + + var dz = deltaLength * Math.Cos(zenith); + var xySurfaceSegmentProjectionLength = deltaLength * Math.Sin(zenith); + var dx = xySurfaceSegmentProjectionLength * Math.Cos(azimuth); + var dy = xySurfaceSegmentProjectionLength * Math.Sin(azimuth); + + var Z = plannedTrajectory[1].WellboreDepth + dz; + var X = dx; + var Y = dy; + + Assert.Equal(0d, lastPoint.X, 1d); + Assert.Equal(0d, lastPoint.Y, 1d); + Assert.Equal(50d, lastPoint.Z, 1d); + } + + } +} diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs index ef50518c..f44f1600 100644 --- a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs +++ b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs @@ -4,7 +4,6 @@ using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using ProtoBuf.Meta; using System.Collections.Generic; using System.IO; using System.Threading; From 5070863ed43b2c978458dc48ad9a5d1d812d7d71 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 15 Feb 2023 13:46:17 +0500 Subject: [PATCH 08/12] TrajectoryVisualizationServiceTest. Update test --- .../TrajectoryVisualizationServiceTest.cs | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs index ab57843e..7ba99ce0 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs @@ -66,7 +66,6 @@ namespace AsbCloudWebApi.Tests.ServicesTests Assert.Equal(50d, lastPoint.Z, 0.1d); } - [Fact] public async Task GetTrajectoryAsync_Match() { @@ -81,24 +80,11 @@ namespace AsbCloudWebApi.Tests.ServicesTests var service = new TrajectoryVisualizationService(mock.Object); var result = await service.GetTrajectoryAsync(1, CancellationToken.None); var lastPoint = result.Last(); + var tolerance = 0.001d; - var deltaLength = plannedTrajectory[2].WellboreDepth - plannedTrajectory[1].WellboreDepth; - var zenith = plannedTrajectory[1].ZenithAngle * Math.PI / 1800; - var azimuth = plannedTrajectory[1].AzimuthGeo * Math.PI / 1800; - - var dz = deltaLength * Math.Cos(zenith); - var xySurfaceSegmentProjectionLength = deltaLength * Math.Sin(zenith); - var dx = xySurfaceSegmentProjectionLength * Math.Cos(azimuth); - var dy = xySurfaceSegmentProjectionLength * Math.Sin(azimuth); - - var Z = plannedTrajectory[1].WellboreDepth + dz; - var X = dx; - var Y = dy; - - Assert.Equal(0d, lastPoint.X, 1d); - Assert.Equal(0d, lastPoint.Y, 1d); - Assert.Equal(50d, lastPoint.Z, 1d); + Assert.InRange(lastPoint.Z, 10 + tolerance, 20 - tolerance); + Assert.InRange(lastPoint.Y, 0 + tolerance, 10 - tolerance); + Assert.InRange(lastPoint.X, 0 + tolerance, 10 - tolerance); } - } } From bd5260edd176b6c3b838ffe99d3a726b530ca328 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Thu, 16 Feb 2023 11:54:05 +0500 Subject: [PATCH 09/12] #8636739 tests --- .../Services/TrajectoryVisualizationService.cs | 7 +++++-- .../ServicesTests/TrajectoryVisualizationServiceTest.cs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs index ee40b693..56e02565 100644 --- a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs @@ -20,11 +20,14 @@ namespace AsbCloudInfrastructure.Services public async Task> GetTrajectoryAsync(int idWell, CancellationToken token) { - var result = new List(); + var result = new List { + new () + }; var dtos = (await repository.GetAsync(idWell, token)).ToArray(); var prevData = dtos[0]; var prevCoordinates = new TrajectoryVisualizationDto(); + for (var i = 1; i < dtos.Length; i++) { var data = dtos[i]; @@ -38,7 +41,7 @@ namespace AsbCloudInfrastructure.Services { X = x, Y = y, - Z = z + Z = z * -1 }; result.Add(coordinates); diff --git a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs index 7ba99ce0..914a374c 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs @@ -73,7 +73,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests { new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, new() { AzimuthGeo = 30d, ZenithAngle = 30d, WellboreDepth = 10d}, - new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d}, + new() { AzimuthGeo = 20d, ZenithAngle = 20d, WellboreDepth = 20d}, }; var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); From d852fb36405665126ad8375deb30086ab86c5457 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Mon, 20 Feb 2023 11:12:39 +0500 Subject: [PATCH 10/12] #8636739 data --- .../Services/TrajectoryVisualizationService.cs | 8 ++++---- .../ServicesTests/TrajectoryVisualizationServiceTest.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs index 56e02565..1c90e8d8 100644 --- a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs @@ -32,9 +32,9 @@ namespace AsbCloudInfrastructure.Services { var data = dtos[i]; var flat = GetFlat(data.WellboreDepth, prevData.WellboreDepth, prevData.ZenithAngle); - var x = prevCoordinates.X = GetX(data.AzimuthGeo, flat, prevCoordinates.X); - var y = prevCoordinates.Y = GetY(data.AzimuthGeo, flat, prevCoordinates.X); - var z = prevCoordinates.Z = GetZ(data.WellboreDepth, prevData.WellboreDepth, data.ZenithAngle, prevCoordinates.Z); + var x = prevCoordinates.X = GetX(prevData.AzimuthGeo, flat, prevCoordinates.X); + var y = prevCoordinates.Y = GetY(prevData.AzimuthGeo, flat, prevCoordinates.X); + var z = prevCoordinates.Z = GetZ(data.WellboreDepth, prevData.WellboreDepth, prevData.ZenithAngle, prevCoordinates.Z); prevData = data; var coordinates = new TrajectoryVisualizationDto @@ -50,7 +50,7 @@ namespace AsbCloudInfrastructure.Services return result; } - private double GetFlat(double depthEnd, double depthStart, double zenit) => + private double GetFlat(double depthEnd, double depthStart, double zenit) => (depthEnd - depthStart) * Math.Sin(zenit * Math.PI / 180); private double GetX(double azimuth, double flat, double prev) => diff --git a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs index 914a374c..7ba99ce0 100644 --- a/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs +++ b/AsbCloudWebApi.Tests/ServicesTests/TrajectoryVisualizationServiceTest.cs @@ -73,7 +73,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests { new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 0d}, new() { AzimuthGeo = 30d, ZenithAngle = 30d, WellboreDepth = 10d}, - new() { AzimuthGeo = 20d, ZenithAngle = 20d, WellboreDepth = 20d}, + new() { AzimuthGeo = 0d, ZenithAngle = 0d, WellboreDepth = 20d}, }; var mock = MakePlannedTrajectoryRepositoryMock(plannedTrajectory); From 25cbdc911c23b7032237a08c75cc825f18824e35 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Mon, 20 Feb 2023 11:16:24 +0500 Subject: [PATCH 11/12] #8636739 --- .../Services/TrajectoryVisualizationService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs index 1c90e8d8..dc54f49d 100644 --- a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs @@ -41,7 +41,7 @@ namespace AsbCloudInfrastructure.Services { X = x, Y = y, - Z = z * -1 + Z = z }; result.Add(coordinates); @@ -60,6 +60,6 @@ namespace AsbCloudInfrastructure.Services prev + flat * Math.Cos(azimuth * Math.PI / 180); private double GetZ(double depthEnd, double depthStart, double zenit, double prev) => - prev - (depthEnd - depthStart) * Math.Cos(zenit * Math.PI / 180); + prev + (depthEnd - depthStart) * Math.Cos(zenit * Math.PI / 180); } } From ada2b36310a76c429a69f9b495dc737c2b5f1ebf Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Mon, 20 Feb 2023 15:57:08 +0500 Subject: [PATCH 12/12] Refactor trajectory --- .../Data/TrajectoryVisualizationDto.cs | 1 + .../AsbCloudInfrastructure.csproj | 4 +- AsbCloudInfrastructure/DependencyInjection.cs | 2 +- .../PlannedTrajectoryImportService.cs | 24 +++---- .../PlannedTrajectoryTemplate.xlsx | Bin .../TrajectoryVisualizationService.cs | 57 +++++++++++++++ .../TrajectoryVisualizationService.cs | 65 ------------------ 7 files changed, 73 insertions(+), 80 deletions(-) rename AsbCloudInfrastructure/Services/{PlannedTrajectory => Trajectory}/PlannedTrajectoryImportService.cs (96%) rename AsbCloudInfrastructure/Services/{PlannedTrajectory => Trajectory}/PlannedTrajectoryTemplate.xlsx (100%) create mode 100644 AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs delete mode 100644 AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs diff --git a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs index 8e47ccd5..1deb4fbd 100644 --- a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs +++ b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs @@ -1,5 +1,6 @@ namespace AsbCloudApp.Data { +#nullable enable /// /// Визуализация траектории 3D /// diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index 48b0a009..ffc380f4 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -12,7 +12,7 @@ - + @@ -30,7 +30,7 @@ - + diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index cfa4d8ac..2da84cc4 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -12,10 +12,10 @@ using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.DailyReport; using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.DrillingProgram; -using AsbCloudInfrastructure.Services.PlannedTrajectory; using AsbCloudInfrastructure.Services.ProcessMap; using AsbCloudInfrastructure.Services.SAUB; using AsbCloudInfrastructure.Services.Subsystems; +using AsbCloudInfrastructure.Services.Trajectory; using AsbCloudInfrastructure.Services.WellOperationService; using AsbCloudInfrastructure.Validators; using FluentValidation.AspNetCore; diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs b/AsbCloudInfrastructure/Services/Trajectory/PlannedTrajectoryImportService.cs similarity index 96% rename from AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs rename to AsbCloudInfrastructure/Services/Trajectory/PlannedTrajectoryImportService.cs index 0bf97365..810530d5 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs +++ b/AsbCloudInfrastructure/Services/Trajectory/PlannedTrajectoryImportService.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudInfrastructure.Services.PlannedTrajectory +namespace AsbCloudInfrastructure.Services.Trajectory { #nullable enable public class PlannedTrajectoryImportService : IPlannedTrajectoryImportService @@ -17,7 +17,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory /* * password for PlannedTrajectoryTemplate.xlsx is Drill2022 */ - + private readonly IWellService wellService; private readonly IPlannedTrajectoryRepository plannedTrajectoryService; @@ -43,7 +43,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory public PlannedTrajectoryImportService(IWellService wellService, IPlannedTrajectoryRepository plannedTrajectoryService) { - + this.wellService = wellService; this.plannedTrajectoryService = plannedTrajectoryService; } @@ -57,21 +57,21 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory return stream; } - public async Task GetFileNameAsync (int idWell, CancellationToken token) + public async Task GetFileNameAsync(int idWell, CancellationToken token) { var fileName = await wellService.GetWellCaptionByIdAsync(idWell, token) + "_plannedTrajectory.xlsx"; return fileName; } public async Task ExportAsync(int idWell, CancellationToken token) - { - var plannedTrajectorys = await plannedTrajectoryService.GetAsync(idWell, token); + { + var plannedTrajectorys = await plannedTrajectoryService.GetAsync(idWell, token); return MakeExelFileStream(plannedTrajectorys); } private Stream MakeExelFileStream(IEnumerable plannedTrajectories) { - using Stream ecxelTemplateStream = GetTemplateFile(); + using Stream ecxelTemplateStream = GetTemplateFile(); using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled); AddPlannedTrajecoryToWorkbook(workbook, plannedTrajectories); MemoryStream memoryStream = new MemoryStream(); @@ -124,12 +124,12 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled); var trajectoryRows = ParseFileStream(stream); foreach (var row in trajectoryRows) - { - row.IdWell = idWell; + { + row.IdWell = idWell; row.IdUser = idUser; } - var rowsCount = await SavePlannedTrajectoryAsync(idWell,trajectoryRows, deletePrevRows, token); + var rowsCount = await SavePlannedTrajectoryAsync(idWell, trajectoryRows, deletePrevRows, token); return rowsCount; } @@ -206,9 +206,9 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory var _comment = row.Cell(ColumnComment).Value; var trajectoryRow = new PlannedTrajectoryDto(); - + static double getDoubleValue(object value, string nameParam, IXLRow row) - { + { if (value is double _value) return _value; throw new FileFormatException($"Лист {row.Worksheet.Name}. Строка {row.RowNumber()} - некорректные данные - {nameParam}"); diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryTemplate.xlsx b/AsbCloudInfrastructure/Services/Trajectory/PlannedTrajectoryTemplate.xlsx similarity index 100% rename from AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryTemplate.xlsx rename to AsbCloudInfrastructure/Services/Trajectory/PlannedTrajectoryTemplate.xlsx diff --git a/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs new file mode 100644 index 00000000..d8a30c7d --- /dev/null +++ b/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs @@ -0,0 +1,57 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Repositories; +using AsbCloudApp.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudInfrastructure.Services.Trajectory +{ +#nullable enable + public class TrajectoryVisualizationService : ITrajectoryVisualizationService + { + private readonly IPlannedTrajectoryRepository repository; + + public TrajectoryVisualizationService(IPlannedTrajectoryRepository repository) + { + this.repository = repository; + } + + public async Task> GetTrajectoryAsync(int idWell, CancellationToken token) + { + var geoCoordinates = (await repository.GetAsync(idWell, token)).ToArray(); + + if (geoCoordinates.Length < 2) + return Enumerable.Empty(); + + var cartesianCoordinates = new List(geoCoordinates.Length) { + new (), + }; + + for (var i = 1; i < geoCoordinates.Length; i++) + { + 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); + + 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; + } + } +} diff --git a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs deleted file mode 100644 index dc54f49d..00000000 --- a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs +++ /dev/null @@ -1,65 +0,0 @@ -using AsbCloudApp.Data; -using AsbCloudApp.Repositories; -using AsbCloudApp.Services; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace AsbCloudInfrastructure.Services -{ - public class TrajectoryVisualizationService : ITrajectoryVisualizationService - { - private readonly IPlannedTrajectoryRepository repository; - - public TrajectoryVisualizationService(IPlannedTrajectoryRepository repository) - { - this.repository = repository; - } - - public async Task> GetTrajectoryAsync(int idWell, CancellationToken token) - { - var result = new List { - new () - }; - var dtos = (await repository.GetAsync(idWell, token)).ToArray(); - - var prevData = dtos[0]; - var prevCoordinates = new TrajectoryVisualizationDto(); - - for (var i = 1; i < dtos.Length; i++) - { - var data = dtos[i]; - var flat = GetFlat(data.WellboreDepth, prevData.WellboreDepth, prevData.ZenithAngle); - var x = prevCoordinates.X = GetX(prevData.AzimuthGeo, flat, prevCoordinates.X); - var y = prevCoordinates.Y = GetY(prevData.AzimuthGeo, flat, prevCoordinates.X); - var z = prevCoordinates.Z = GetZ(data.WellboreDepth, prevData.WellboreDepth, prevData.ZenithAngle, prevCoordinates.Z); - prevData = data; - - var coordinates = new TrajectoryVisualizationDto - { - X = x, - Y = y, - Z = z - }; - - result.Add(coordinates); - } - - return result; - } - - private double GetFlat(double depthEnd, double depthStart, double zenit) => - (depthEnd - depthStart) * Math.Sin(zenit * Math.PI / 180); - - private double GetX(double azimuth, double flat, double prev) => - prev + flat * Math.Sin(azimuth * Math.PI / 180); - - private double GetY(double azimuth, double flat, double prev) => - prev + flat * Math.Cos(azimuth * Math.PI / 180); - - private double GetZ(double depthEnd, double depthStart, double zenit, double prev) => - prev + (depthEnd - depthStart) * Math.Cos(zenit * Math.PI / 180); - } -}