generic trajectory services

This commit is contained in:
ngfrolov 2023-05-30 11:21:07 +05:00
parent 8c45b36623
commit be9be27bab
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
19 changed files with 285 additions and 389 deletions

View File

@ -1,9 +1,11 @@
namespace AsbCloudApp.Data
{
/// <summary>
/// Визуализация траектории 3D
/// </summary>
public class TrajectoryVisualizationFactDto
public class TrajectoryCartesianDto
{
/// <summary>
/// Координаты по оси X, в сторону востока (м)
@ -20,4 +22,9 @@
/// </summary>
public double Z { get; set; }
}
/// <summary>
/// Визуализация фактической траектории 3D
/// </summary>
public class TrajectoryCartesianFactDto : TrajectoryCartesianDto { }
}

View File

@ -3,7 +3,7 @@
/// <summary>
/// Визуализация траектории 3D для посторения радиуса цели
/// </summary>
public class TrajectoryVisualizationPlanDto : TrajectoryVisualizationFactDto
public class TrajectoryCartesianPlanDto : TrajectoryCartesianFactDto
{
/// <summary>
/// радиус цели

View File

@ -1,35 +0,0 @@
namespace AsbCloudApp.Data;
public class TrajectoryDto
{
public double WellboreDepth { get; set; }
public double ZenithAngle { get; set; }
public double AzimuthGeo { get; set; }
}
/// <summary>
/// Формирование визуализации траектории 3D
/// </summary>
/// <param name="WellboreDepth">Глубина ствола</param>
/// <param name="ZenithAngle">Зенитный угол</param>
/// <param name="AzimuthGeo">Азимут географиеский</param>
public class TrajectoryFactDto : TrajectoryDto
{
}
/// <summary>
///
/// </summary>
/// <param name="WellboreDepth"></param>
/// <param name="ZenithAngle"></param>
/// <param name="AzimuthGeo"></param>
/// <param name="Radius"></param>
/// <param name="Comment"></param>
public class TrajectoryPlanDto : TrajectoryDto
{
public double? Radius { get; set; }
public string? Comment { get; set; }
}

View File

@ -0,0 +1,30 @@
namespace AsbCloudApp.Data;
/// <summary>
/// Базовая географическая траектория
/// </summary>
public abstract class TrajectoryGeoDto
{
/// <summary>
/// Глубина по стволу
/// </summary>
public double WellboreDepth { get; set; }
/// <summary>
/// Угол зенитный
/// </summary>
public double ZenithAngle { get; set; }
/// <summary>
/// Азимут Географ.
/// </summary>
public double AzimuthGeo { get; set; }
}
/// <summary>
/// Формирование географической траектории
/// </summary>
public class TrajectoryGeoFactDto : TrajectoryGeoDto
{}

View File

@ -4,7 +4,7 @@ namespace AsbCloudApp.Data
/// <summary>
/// Формирование данных по плановой траектории
/// </summary>
public class PlannedTrajectoryDto
public class TrajectoryGeoPlanDto: TrajectoryGeoDto
{
/// <summary>
/// ИД строки с координатами
@ -15,28 +15,16 @@ namespace AsbCloudApp.Data
/// ИД скважины
/// </summary>
public int IdWell { get; set; }
/// <summary>
/// Дата загрузки
/// </summary>
public DateTime UpdateDate { get; set; }
/// <summary>
/// ИД пользователя
/// </summary>
public int IdUser { get; set; }
/// <summary>
/// Глубина по стволу
/// </summary>
public double WellboreDepth { get; set; }
/// <summary>
/// Угол зенитный
/// </summary>
public double ZenithAngle { get; set; }
/// <summary>
/// Азимут Географ.
/// </summary>
public double AzimuthGeo { get; set; }
/// <summary>
/// Азимут Магнитный
@ -93,6 +81,11 @@ namespace AsbCloudApp.Data
/// </summary>
public double OrificeOffset { get; set; }
/// <summary>
/// Радиус цели
/// </summary>
public double? Radius { get; set; }
/// <summary>
/// Комментарии
/// </summary>

View File

@ -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
{
/// <summary>
/// CRUD для работы с фактической траекторией из клиента
/// </summary>
/// <returns></returns>
public interface IActualTrajectoryRepository : ITrajectoryRepository
{
/// <summary>
/// Получение траектории для 3D-визуализации
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TrajectoryFactDto>> GetTrajectoryAsync(int idWell, CancellationToken token);
}
}

View File

@ -0,0 +1,16 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.WITS;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Repositories
{
/// <summary>
/// CRUD для работы с фактической траекторией из клиента
/// </summary>
/// <returns></returns>
public interface ITrajectoryFactRepository : ITrajectoryRepository<TrajectoryGeoFactDto>
{
}
}

View File

@ -9,23 +9,15 @@ namespace AsbCloudApp.Repositories
/// CRUD для работы с плановой траекторией из клиента
/// </summary>
/// <returns></returns>
public interface IPlannedTrajectoryRepository : ITrajectoryRepository
public interface ITrajectoryPlanRepository : ITrajectoryRepository<TrajectoryGeoPlanDto>
{
/// <summary>
/// Получить все добавленные по скважине координаты плановой траектории
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<PlannedTrajectoryDto>> GetAsync(int idWell, CancellationToken token);
/// <summary>
/// Добавить строки с координатами по одной скважине. Если в коллекции координаты для разных скважин получаем exception.
/// </summary>
/// <param name="plannedTrajectoryRows"></param>
/// <param name="token"></param>
/// <returns>количество записанных строк или exception с описанием</returns>
Task<int> AddRangeAsync(IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token);
Task<int> AddRangeAsync(IEnumerable<TrajectoryGeoPlanDto> plannedTrajectoryRows, CancellationToken token);
/// <summary>
/// Добавить одну строку с координатами
@ -33,7 +25,7 @@ namespace AsbCloudApp.Repositories
/// <param name="plannedTrajectoryRow"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> AddAsync(PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token);
Task<int> AddAsync(TrajectoryGeoPlanDto plannedTrajectoryRow, CancellationToken token);
/// <summary>
/// Обновить строку с координатами
@ -41,7 +33,7 @@ namespace AsbCloudApp.Repositories
/// <param name="row"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> UpdateAsync(PlannedTrajectoryDto row,
Task<int> UpdateAsync(TrajectoryGeoPlanDto row,
CancellationToken token);
/// <summary>
@ -59,13 +51,5 @@ namespace AsbCloudApp.Repositories
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteByIdWellAsync(int idWell, CancellationToken token);
/// <summary>
/// Получение траектории для 3D-визуализации
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TrajectoryPlanDto>> GetTrajectoryAsync(int idWell, CancellationToken token);
}
}

View File

@ -11,8 +11,15 @@ namespace AsbCloudApp.Repositories
/// <summary>
/// Репозиторий по работе с траекторией
/// </summary>
public interface ITrajectoryRepository
public interface ITrajectoryRepository<T>
where T : TrajectoryGeoDto
{
/// <summary>
/// Получить все добавленные по скважине координаты плановой траектории
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<T>> GetAsync(int idWell, CancellationToken token);
}
}

View File

@ -137,9 +137,7 @@ namespace AsbCloudInfrastructure
services.AddTransient<IProcessMapReportMakerService, ProcessMapReportMakerService>();
services.AddTransient<IProcessMapReportService, ProcessMapReportService>();
services.AddTransient<TrajectoryVisualizationBaseService>();
services.AddTransient<ITrajectoryVisualizationService<TrajectoryVisualizationPlanDto>, TrajectoryVisualizationPlanService>();
services.AddTransient<ITrajectoryVisualizationService<TrajectoryVisualizationFactDto>, TrajectoryVisualizationFactService>();
services.AddTransient<TrajectoryService>();
services.AddTransient<IGtrRepository, GtrWitsRepository>();
@ -179,8 +177,8 @@ namespace AsbCloudInfrastructure
services.AddTransient<ILimitingParameterRepository, LimitingParameterRepository>();
services.AddTransient<ITelemetryWirelineRunOutRepository, TelemetryWirelineRunOutRepository>();
services.AddTransient<IWellFinalDocumentsRepository, WellFinalDocumentsRepository>();
services.AddTransient<IPlannedTrajectoryRepository, PlannedTrajectoryRepository>();
services.AddTransient<IActualTrajectoryRepository, ActualTrajectoryRepository>();
services.AddTransient<ITrajectoryPlanRepository, TrajectoryPlanRepository>();
services.AddTransient<ITrajectoryFactRepository, TrajectoryFactRepository>();
services.AddTransient<IFaqRepository, FaqRepository>();
// Subsystem service

View File

@ -11,19 +11,18 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
internal class ActualTrajectoryRepository : IActualTrajectoryRepository
internal class TrajectoryFactRepository : ITrajectoryFactRepository
{
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
public ActualTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService)
public TrajectoryFactRepository(IAsbCloudDbContext db, IWellService wellService)
{
this.db = db;
this.wellService = wellService;
}
public async Task<IEnumerable<TrajectoryFactDto>> GetTrajectoryAsync(int idWell, CancellationToken token)
public async Task<IEnumerable<TrajectoryGeoFactDto>> 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));
@ -37,7 +36,12 @@ namespace AsbCloudInfrastructure.Repository
.ToArrayAsync(token);
var result = entities
.Select(coord => new TrajectoryFactDto(coord.Deptsvym!.Value, coord.Svyinc!.Value, coord.Svyazc!.Value))
.Select(coord => new TrajectoryGeoFactDto
{
WellboreDepth = coord.Deptsvym!.Value,
ZenithAngle = coord.Svyinc!.Value,
AzimuthGeo = coord.Svyazc!.Value
})
.ToArray();
return result;

View File

@ -14,17 +14,17 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
public class PlannedTrajectoryRepository : IPlannedTrajectoryRepository
public class TrajectoryPlanRepository : ITrajectoryPlanRepository
{
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
public PlannedTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService)
public TrajectoryPlanRepository(IAsbCloudDbContext db, IWellService wellService)
{
this.db = db;
this.wellService = wellService;
}
/// <inheritdoc/>
public async Task<int> AddRangeAsync(IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token)
public async Task<int> AddRangeAsync(IEnumerable<TrajectoryGeoPlanDto> plannedTrajectoryRows, CancellationToken token)
{
var idWell = plannedTrajectoryRows.First().IdWell;
if (!plannedTrajectoryRows.All(r => r.IdWell == idWell))
@ -44,7 +44,7 @@ namespace AsbCloudInfrastructure.Repository
}
/// <inheritdoc/>
public async Task<int> AddAsync(PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token)
public async Task<int> AddAsync(TrajectoryGeoPlanDto plannedTrajectoryRow, CancellationToken token)
{
var offsetHours = wellService.GetTimezone(plannedTrajectoryRow.IdWell).Hours;
var entity = Convert(plannedTrajectoryRow, offsetHours);
@ -75,7 +75,7 @@ namespace AsbCloudInfrastructure.Repository
}
/// <inheritdoc/>
public async Task<IEnumerable<PlannedTrajectoryDto>> GetAsync(int idWell, CancellationToken token)
public async Task<IEnumerable<TrajectoryGeoPlanDto>> GetAsync(int idWell, CancellationToken token)
{
var well = wellService.GetOrDefault(idWell);
if (well is null || well.Timezone is null)
@ -93,7 +93,7 @@ namespace AsbCloudInfrastructure.Repository
}
/// <inheritdoc/>
public async Task<int> UpdateAsync(PlannedTrajectoryDto row, CancellationToken token)
public async Task<int> UpdateAsync(TrajectoryGeoPlanDto row, CancellationToken token)
{
var offsetHours = wellService.GetTimezone(row.IdWell).Hours;
var entity = Convert(row, offsetHours);
@ -102,35 +102,18 @@ namespace AsbCloudInfrastructure.Repository
.ConfigureAwait(false);
}
private PlannedTrajectoryDto Convert(PlannedTrajectory entity, double offsetHours)
private TrajectoryGeoPlanDto Convert(PlannedTrajectory entity, double offsetHours)
{
var dto = entity.Adapt<PlannedTrajectoryDto>();
var dto = entity.Adapt<TrajectoryGeoPlanDto>();
dto.UpdateDate = entity.UpdateDate.ToRemoteDateTime(offsetHours);
return dto;
}
private PlannedTrajectory Convert(PlannedTrajectoryDto dto, double offsetHours)
private PlannedTrajectory Convert(TrajectoryGeoPlanDto dto, double offsetHours)
{
var entity = dto.Adapt<PlannedTrajectory>();
entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(offsetHours);
return entity;
}
public async Task<IEnumerable<TrajectoryPlanDto>> 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.PlannedTrajectories
.AsNoTracking()
.Where(x => x.IdWell == idWell);
return await query
.Select(coord => new TrajectoryPlanDto(coord.WellboreDepth, coord.ZenithAngle, coord.AzimuthGeo, coord.RadiusTarget, coord.Comment))
.ToArrayAsync()
.ConfigureAwait(false);
}
}
}

View File

@ -19,7 +19,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
*/
private readonly IWellService wellService;
private readonly IPlannedTrajectoryRepository plannedTrajectoryService;
private readonly ITrajectoryPlanRepository plannedTrajectoryService;
private const string templateFileName = "PlannedTrajectoryTemplate.xlsx";
private const string usingTemplateFile = "AsbCloudInfrastructure.Services.Trajectory";
@ -41,7 +41,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
private const int ColumnOrificeOffset = 14;
private const int ColumnComment = 15;
public PlannedTrajectoryImportService(IWellService wellService, IPlannedTrajectoryRepository plannedTrajectoryService)
public PlannedTrajectoryImportService(IWellService wellService, ITrajectoryPlanRepository plannedTrajectoryService)
{
this.wellService = wellService;
@ -69,7 +69,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
return MakeExelFileStream(plannedTrajectorys);
}
private Stream MakeExelFileStream(IEnumerable<PlannedTrajectoryDto> plannedTrajectories)
private Stream MakeExelFileStream(IEnumerable<TrajectoryGeoPlanDto> plannedTrajectories)
{
using Stream ecxelTemplateStream = GetTemplateFile();
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
@ -80,7 +80,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
return memoryStream;
}
private static void AddPlannedTrajecoryToWorkbook(XLWorkbook workbook, IEnumerable<PlannedTrajectoryDto> plannedTrajectories)
private static void AddPlannedTrajecoryToWorkbook(XLWorkbook workbook, IEnumerable<TrajectoryGeoPlanDto> plannedTrajectories)
{
if (plannedTrajectories.Any())
{
@ -91,7 +91,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
}
}
private static void AddPlannedTrajecoryToSheet(IXLWorksheet sheet, IEnumerable<PlannedTrajectoryDto> plannedTrajectories)
private static void AddPlannedTrajecoryToSheet(IXLWorksheet sheet, IEnumerable<TrajectoryGeoPlanDto> plannedTrajectories)
{
var rowList = plannedTrajectories.ToList();
for (int i = 0; i < rowList.Count; i++)
@ -100,7 +100,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
AddCoordinatesToRow(row, rowList[i]);
}
}
private static void AddCoordinatesToRow(IXLRow row, PlannedTrajectoryDto trajectory)
private static void AddCoordinatesToRow(IXLRow row, TrajectoryGeoPlanDto trajectory)
{
row.Cell(ColumnWellboreDepth).Value = trajectory.WellboreDepth;
row.Cell(ColumnZenithAngle).Value = trajectory.ZenithAngle;
@ -133,7 +133,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
return rowsCount;
}
private async Task<int> SavePlannedTrajectoryAsync(int idWell, IEnumerable<PlannedTrajectoryDto> newRows, bool deletePrevRow, CancellationToken token)
private async Task<int> SavePlannedTrajectoryAsync(int idWell, IEnumerable<TrajectoryGeoPlanDto> newRows, bool deletePrevRow, CancellationToken token)
{
if (deletePrevRow)
await plannedTrajectoryService.DeleteByIdWellAsync(idWell, token);
@ -141,13 +141,13 @@ namespace AsbCloudInfrastructure.Services.Trajectory
return rowsCount;
}
private IEnumerable<PlannedTrajectoryDto> ParseFileStream(Stream stream)
private IEnumerable<TrajectoryGeoPlanDto> ParseFileStream(Stream stream)
{
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
return ParseWorkbook(workbook);
}
private IEnumerable<PlannedTrajectoryDto> ParseWorkbook(IXLWorkbook workbook)
private IEnumerable<TrajectoryGeoPlanDto> ParseWorkbook(IXLWorkbook workbook)
{
var sheetPlannedTrajectory = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlannedTrajectory);
if (sheetPlannedTrajectory is null)
@ -156,7 +156,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
return plannedTrajectoryRows;
}
private IEnumerable<PlannedTrajectoryDto> ParseSheet(IXLWorksheet sheet)
private IEnumerable<TrajectoryGeoPlanDto> ParseSheet(IXLWorksheet sheet)
{
if (sheet.RangeUsed().RangeAddress.LastAddress.ColumnNumber < 15)
throw new FileFormatException($"Лист {sheet.Name} содержит меньшее количество столбцов.");
@ -169,7 +169,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
if (count <= 0)
throw new FileFormatException($"Лист {sheet.Name} некорректного формата либо пустой");
var trajectoryRows = new List<PlannedTrajectoryDto>(count);
var trajectoryRows = new List<TrajectoryGeoPlanDto>(count);
var parseErrors = new List<string>();
for (int i = 0; i < count; i++)
{
@ -187,7 +187,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
return trajectoryRows;
}
private PlannedTrajectoryDto ParseRow(IXLRow row)
private TrajectoryGeoPlanDto ParseRow(IXLRow row)
{
var _wellboreDepth = row.Cell(ColumnWellboreDepth).Value;
var _zenithAngle = row.Cell(ColumnZenithAngle).Value;
@ -205,7 +205,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
var _orificeOffset = row.Cell(ColumnOrificeOffset).Value;
var _comment = row.Cell(ColumnComment).Value;
var trajectoryRow = new PlannedTrajectoryDto();
var trajectoryRow = new TrajectoryGeoPlanDto();
static double getDoubleValue(object value, string nameParam, IXLRow row)
{

View File

@ -0,0 +1,145 @@
using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.Trajectory;
abstract class TrajectoryBaseService<TGeo, TCartesian>
where TGeo : TrajectoryGeoDto
where TCartesian : TrajectoryCartesianDto, new()
{
ITrajectoryRepository<TGeo> repository;
public TrajectoryBaseService(ITrajectoryRepository<TGeo> repository)
{
this.repository = repository;
}
protected class Location
{
public double North { get; set; }
public double East { get; set; }
public double Depth { get; set; }
public TrajectoryGeoDto Trajectory { get; set; } = null!;
}
public async Task<IEnumerable<TCartesian>?> GetAsync(int idWell, CancellationToken token)
{
var geoCoords = await repository.GetAsync(idWell, token);
var locs = GetTrajectoryVisualisation(geoCoords);
var dtos = locs.Select(l => Convert(l));
return dtos;
}
private IEnumerable<Location> GetTrajectoryVisualisation(IEnumerable<TrajectoryGeoDto> geoCoordinates)
{
var geoCoordinatesLength = geoCoordinates.Count();
if (geoCoordinatesLength < 2)
return new Location[0];
var cartesianCoordinates = new Location[geoCoordinatesLength];
cartesianCoordinates[0] = new();
var geoCoordinatesArray = geoCoordinates.OrderBy(c => c.WellboreDepth).ToArray();
for (var i = 1; i < geoCoordinatesLength; i++)
{
var preCoordinates = cartesianCoordinates[i - 1];
var coordinates = Calculate(cartesianCoordinates[i - 1],
geoCoordinatesArray[i - 1],
geoCoordinatesArray[i]);
cartesianCoordinates[i] = coordinates;
}
return cartesianCoordinates;
}
protected Location Calculate(Location prevlocation, TrajectoryGeoDto prev, TrajectoryGeoDto current)
{
var intervalGeoParams = prev;
var deltaWellLength = current.WellboreDepth - intervalGeoParams.WellboreDepth;
var projectionLengthToXYSurface = deltaWellLength * Math.Sin(intervalGeoParams.ZenithAngle * Math.PI / 180);
var dDepth = deltaWellLength * Math.Cos(intervalGeoParams.ZenithAngle * Math.PI / 180);
var dNorth = projectionLengthToXYSurface * Math.Sin(intervalGeoParams.AzimuthGeo * Math.PI / 180);
var dEast = projectionLengthToXYSurface * Math.Cos(intervalGeoParams.AzimuthGeo * Math.PI / 180);
return new()
{
North = prevlocation.North + dNorth,
East = prevlocation.East + dEast,
Depth = prevlocation.Depth + dDepth,
Trajectory = current,
};
}
protected virtual TCartesian Convert(Location location)
{
var result = new TCartesian()
{
X = location.East,
Y = -location.Depth,
Z = -location.North,
};
return result;
}
}
class TrajectoryPlanService: TrajectoryBaseService<TrajectoryGeoPlanDto, TrajectoryCartesianPlanDto>
{
public TrajectoryPlanService(ITrajectoryPlanRepository repository)
:base(repository)
{}
protected override TrajectoryCartesianPlanDto Convert(Location location)
{
var result = base.Convert(location);
if (location.Trajectory is TrajectoryGeoPlanDto trajectoryPlan)
{
result.Radius = trajectoryPlan.Radius;
result.Comment = trajectoryPlan.Comment;
}
return result;
}
}
class TrajectoryFactService : TrajectoryBaseService<TrajectoryGeoFactDto, TrajectoryCartesianFactDto>
{
public TrajectoryFactService(ITrajectoryFactRepository repository)
: base(repository)
{ }
}
public class TrajectoryService
{
private TrajectoryPlanService trajectoryPlanService;
private TrajectoryFactService trajectoryFactService;
public TrajectoryService(ITrajectoryPlanRepository plannedRepository, ITrajectoryFactRepository factRepository)
{
trajectoryPlanService = new TrajectoryPlanService(plannedRepository);
trajectoryFactService = new TrajectoryFactService(factRepository);
}
/// <summary>
/// Получение плановой и фактической траектории по скважине
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="token"></param>
/// <returns></returns>
public async Task<PlanFactBase<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>> GetTrajectoryCartesianAsync(int idWell, CancellationToken token)
{
var result = new PlanFactBase<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>();
result.Plan = await trajectoryPlanService.GetAsync(idWell, token);
result.Fact = await trajectoryFactService.GetAsync(idWell, token);
return result;
}
}

View File

@ -1,53 +0,0 @@
using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using DocumentFormat.OpenXml.Spreadsheet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.Trajectory
{
public class TrajectoryVisualizationBaseService
{
private ITrajectoryVisualizationService<TrajectoryVisualizationPlanDto> planTrajectoryVisualizationService;
private ITrajectoryVisualizationService<TrajectoryVisualizationFactDto> factTrajectoryVisualizationService;
public TrajectoryVisualizationBaseService(
ITrajectoryVisualizationService<TrajectoryVisualizationPlanDto> _planTrajectoryVisualizationService,
ITrajectoryVisualizationService<TrajectoryVisualizationFactDto> _factTrajectoryVisualizationService)
{
this.planTrajectoryVisualizationService = _planTrajectoryVisualizationService;
this.factTrajectoryVisualizationService = _factTrajectoryVisualizationService;
}
/// <summary>
/// Получение плановой и фактической траектории по скважине
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="token"></param>
/// <returns></returns>
public async Task<PlanFactBase<IEnumerable<TrajectoryVisualizationPlanDto>, IEnumerable<TrajectoryVisualizationFactDto>>> GetTrajectoryAsync(int idWell, CancellationToken token)
{
var result = new PlanFactBase<IEnumerable<TrajectoryVisualizationPlanDto>, IEnumerable<TrajectoryVisualizationFactDto>>();
result.Plan = await planTrajectoryVisualizationService.GetVisualizationAsync(idWell, token);
result.Fact = await factTrajectoryVisualizationService.GetVisualizationAsync(idWell, token);
return result;
}
protected void Calculate(TrajectoryDto prev, TrajectoryDto current) {
var intervalGeoParams = prev;
var deltaWellLength = current.WellboreDepth - intervalGeoParams.WellboreDepth;
var projectionLengthToXYSurface = deltaWellLength * Math.Sin(intervalGeoParams.ZenithAngle* Math.PI / 180);
var dDepth = deltaWellLength * Math.Cos(intervalGeoParams.ZenithAngle * Math.PI / 180);
var dNorth = projectionLengthToXYSurface * Math.Sin(intervalGeoParams.AzimuthGeo * Math.PI / 180);
var dEast = projectionLengthToXYSurface * Math.Cos(intervalGeoParams.AzimuthGeo * Math.PI / 180);
}
}
}

View File

@ -1,76 +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.Trajectory
{
public class TrajectoryVisualizationFactService : ITrajectoryVisualizationService<TrajectoryVisualizationFactDto>
{
private readonly IActualTrajectoryRepository actualRepository;
public TrajectoryVisualizationFactService(IActualTrajectoryRepository actualRepository)
{
this.actualRepository = actualRepository;
}
/// <summary>
/// Визуализация для фактической траектории по скважине
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="token"></param>
/// <returns></returns>
public async Task<IEnumerable<TrajectoryVisualizationFactDto>> GetVisualizationAsync(int idWell, CancellationToken token)
{
var geoFactCoordinates = await actualRepository.GetTrajectoryAsync(idWell, token);
var visualization = GetTrajectoryVisualisation(geoFactCoordinates);
return visualization;
}
record struct Location(double North, double East, double Depth);
/// <summary>
/// Формирует список координат для визуализации трактории 3D
/// </summary>
/// <param name="geoCoordinates"></param>
/// <returns></returns>
private IEnumerable<TrajectoryVisualizationFactDto> GetTrajectoryVisualisation(IEnumerable<TrajectoryFactDto> geoCoordinates)
{
var geoCoordinatesLength = geoCoordinates.Count();
if (geoCoordinatesLength < 2)
return new TrajectoryVisualizationFactDto[0];
var cartesianCoordinates = new Location[geoCoordinatesLength];
cartesianCoordinates[0] = new();
var geoCoordinatesArray = geoCoordinates.OrderBy(c => c.WellboreDepth).ToArray();
for (var i = 1; i < geoCoordinatesLength; i++)
{
var intervalGeoParams = geoCoordinatesArray[i - 1];
var deltaWellLength = geoCoordinatesArray[i].WellboreDepth - intervalGeoParams.WellboreDepth;
var projectionLengthToXYSurface = deltaWellLength * Math.Sin(intervalGeoParams.ZenithAngle * Math.PI / 180);
var dDepth = deltaWellLength * Math.Cos(intervalGeoParams.ZenithAngle * Math.PI / 180);
var dNorth = projectionLengthToXYSurface * Math.Sin(intervalGeoParams.AzimuthGeo * Math.PI / 180);
var dEast = projectionLengthToXYSurface * Math.Cos(intervalGeoParams.AzimuthGeo * Math.PI / 180);
var preCoordinates = cartesianCoordinates[i - 1];
var coordinates = new Location(
preCoordinates.North + dNorth,
preCoordinates.East + dEast,
preCoordinates.Depth + dDepth);
cartesianCoordinates[i] = coordinates;
}
return cartesianCoordinates.Select(location => new TrajectoryVisualizationFactDto { X = location.East, Y = - location.Depth, Z = - location.North});
}
}
}

View File

@ -1,84 +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.Trajectory
{
public class TrajectoryVisualizationPlanService : ITrajectoryVisualizationService<TrajectoryVisualizationPlanDto>
{
private readonly IPlannedTrajectoryRepository plannedRepository;
public TrajectoryVisualizationPlanService(IPlannedTrajectoryRepository plannedRepository)
{
this.plannedRepository = plannedRepository;
}
/// <summary>
/// Визуализация для плановой траектории по скважине
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="token"></param>
/// <returns></returns>
public async Task<IEnumerable<TrajectoryVisualizationPlanDto>> GetVisualizationAsync(int idWell, CancellationToken token)
{
var coords = await plannedRepository.GetTrajectoryAsync(idWell, token);
return GetTrajectoryVisualisation(coords);
}
/// <summary>
/// Формирует список координат для визуализации трактории 3D
/// </summary>
/// <param name="geoCoordinates"></param>
/// <returns></returns>
private IEnumerable<TrajectoryVisualizationPlanDto> GetTrajectoryVisualisation(IEnumerable<TrajectoryPlanDto> geoCoordinates)
{
var geoCoordinatesLength = geoCoordinates.Count();
if (geoCoordinatesLength < 2)
return new TrajectoryVisualizationPlanDto[0];
var cartesianCoordinates = new Location[geoCoordinatesLength];
cartesianCoordinates[0] = new();
var geoCoordinatesArray = geoCoordinates.OrderBy(c => c.WellboreDepth).ToArray();
for (var i = 1; i < geoCoordinatesLength; i++)
{
var intervalGeoParams = geoCoordinatesArray[i - 1];
var deltaWellLength = geoCoordinatesArray[i].WellboreDepth - intervalGeoParams.WellboreDepth;
var projectionLengthToXYSurface = deltaWellLength * Math.Sin(intervalGeoParams.ZenithAngle * Math.PI / 180);
var dDepth = deltaWellLength * Math.Cos(intervalGeoParams.ZenithAngle * Math.PI / 180);
var dNorth = projectionLengthToXYSurface * Math.Sin(intervalGeoParams.AzimuthGeo * Math.PI / 180);
var dEast = projectionLengthToXYSurface * Math.Cos(intervalGeoParams.AzimuthGeo * Math.PI / 180);
var preCoordinates = cartesianCoordinates[i - 1];
var coordinates = new Location(
preCoordinates.North + dNorth,
preCoordinates.East + dEast,
preCoordinates.Depth + dDepth,
geoCoordinatesArray[i].Radius,
geoCoordinatesArray[i].Comment
);
cartesianCoordinates[i] = coordinates;
}
return cartesianCoordinates.Select(location => new TrajectoryVisualizationPlanDto {
X = location.East,
Y = -location.Depth,
Z = -location.North,
Comment = location.Comment,
Radius = location.Radius
});
}
}
}

View File

@ -13,12 +13,12 @@ namespace AsbCloudWebApi.Tests.ServicesTests
{
public class TrajectoryVisualizationServiceTest
{
private Mock<T> MakeTrajectoryRepositoryMock<T>(IEnumerable<TrajectoryFactDto> dateForGetMethod)
where T : class, ITrajectoryRepository
private Mock<T> MakeTrajectoryRepositoryMock<T>(IEnumerable<TrajectoryGeoFactDto> dateForGetMethod)
where T : class, ITrajectoryPlanRepository
{
var mock = new Mock<T>();
mock.Setup(r => r.GetTrajectoryAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
mock.Setup(r => r.GetAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(dateForGetMethod));
return mock;
@ -27,7 +27,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
[Fact]
public async Task GetTrajectoryAsync_SameCounts()
{
var plannedTrajectory = new TrajectoryFactDto[]
var plannedTrajectory = new TrajectoryGeoFactDto[]
{
new(0d, 0d, 0d),
new(0d, 0d, 10d),
@ -37,17 +37,17 @@ namespace AsbCloudWebApi.Tests.ServicesTests
new(0d, 0d, 50d),
};
var actualTrajectory = new TrajectoryFactDto[]
var actualTrajectory = new TrajectoryGeoFactDto[]
{
new(0, 0, 0),
new(30,30,10),
new(0, 0, 20),
};
var mockPlan = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(plannedTrajectory);
var mockFact = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(actualTrajectory);
var service = new TrajectoryVisualizationService(mockPlan.Object, mockFact.Object);
var result = await service.GetTrajectoryAsync(1, CancellationToken.None);
var mockPlan = MakeTrajectoryRepositoryMock<ITrajectoryPlanRepository>(plannedTrajectory);
var mockFact = MakeTrajectoryRepositoryMock<ITrajectoryFactRepository>(actualTrajectory);
var service = new TrajectoryService(mockPlan.Object, mockFact.Object);
var result = await service.GetTrajectoryCartesianAsync(1, CancellationToken.None);
Assert.Equal(plannedTrajectory.Length, result.Plan?.Count());
Assert.Equal(actualTrajectory.Length, result.Fact?.Count());
}
@ -55,7 +55,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
[Fact]
public async Task GetTrajectoryAsync_StraigthBore()
{
var trajectory = new TrajectoryFactDto[]
var trajectory = new TrajectoryGeoFactDto[]
{
new(0, 0, 0),
new(0, 0, 0),
@ -65,10 +65,10 @@ namespace AsbCloudWebApi.Tests.ServicesTests
new(50, 0, 0),
};
var mockPlan = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(trajectory);
var mockFact = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(trajectory);
var service = new TrajectoryVisualizationService(mockPlan.Object, mockFact.Object);
var result = await service.GetTrajectoryAsync(1, CancellationToken.None);
var mockPlan = MakeTrajectoryRepositoryMock<ITrajectoryPlanRepository>(trajectory);
var mockFact = MakeTrajectoryRepositoryMock<ITrajectoryFactRepository>(trajectory);
var service = new TrajectoryService(mockPlan.Object, mockFact.Object);
var result = await service.GetTrajectoryCartesianAsync(1, CancellationToken.None);
var lastPointPlan = result.Plan!.Last();
var lastPointFact = result.Fact!.Last();
@ -84,17 +84,17 @@ namespace AsbCloudWebApi.Tests.ServicesTests
[Fact]
public async Task GetTrajectoryAsync_Match()
{
var trajectory = new TrajectoryFactDto[]
var trajectory = new TrajectoryGeoFactDto[]
{
new(0, 0, 0),
new(10, 30, 30),
new(20, 0, 0),
};
var mockPlanned = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(trajectory);
var mockFactual = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(trajectory);
var service = new TrajectoryVisualizationService(mockPlanned.Object, mockFactual.Object);
var result = await service.GetTrajectoryAsync(1, CancellationToken.None);
var mockPlanned = MakeTrajectoryRepositoryMock<ITrajectoryPlanRepository>(trajectory);
var mockFactual = MakeTrajectoryRepositoryMock<ITrajectoryFactRepository>(trajectory);
var service = new TrajectoryService(mockPlanned.Object, mockFactual.Object);
var result = await service.GetTrajectoryCartesianAsync(1, CancellationToken.None);
var lastPointPlan = result.Plan!.Last();
var lastPointFact = result.Fact!.Last();
var tolerancePlan = 0.001d;

View File

@ -23,13 +23,13 @@ namespace AsbCloudWebApi.Controllers
{
private readonly IWellService wellService;
private readonly IPlannedTrajectoryImportService plannedTrajectoryImportService;
private readonly IPlannedTrajectoryRepository plannedTrajectoryRepository;
private readonly TrajectoryVisualizationBaseService trajectoryVisualizationService;
private readonly ITrajectoryPlanRepository plannedTrajectoryRepository;
private readonly TrajectoryService trajectoryVisualizationService;
public PlannedTrajectoryController(IWellService wellService,
IPlannedTrajectoryImportService plannedTrajectoryImportService,
IPlannedTrajectoryRepository plannedTrajectoryRepository,
TrajectoryVisualizationBaseService trajectoryVisualizationService)
ITrajectoryPlanRepository plannedTrajectoryRepository,
TrajectoryService trajectoryVisualizationService)
{
this.plannedTrajectoryImportService = plannedTrajectoryImportService;
this.wellService = wellService;
@ -119,7 +119,7 @@ namespace AsbCloudWebApi.Controllers
/// <returns>Список добавленных координат плановой траектории</returns>
[HttpGet]
[Route("getRows")]
[ProducesResponseType(typeof(IEnumerable<PlannedTrajectoryDto>), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(IEnumerable<TrajectoryGeoPlanDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync([FromRoute] int idWell, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell,
@ -139,7 +139,7 @@ namespace AsbCloudWebApi.Controllers
[HttpPost]
[Route("addRow")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> AddAsync(int idWell, [FromBody] PlannedTrajectoryDto row,
public async Task<IActionResult> AddAsync(int idWell, [FromBody] TrajectoryGeoPlanDto row,
CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
@ -163,7 +163,7 @@ namespace AsbCloudWebApi.Controllers
[HttpPost]
[Route("addRangeRows")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> AddRangeAsync(int idWell, [FromBody] IEnumerable<PlannedTrajectoryDto> rows,
public async Task<IActionResult> AddRangeAsync(int idWell, [FromBody] IEnumerable<TrajectoryGeoPlanDto> rows,
CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
@ -191,7 +191,7 @@ namespace AsbCloudWebApi.Controllers
[HttpPut("{idRow}")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> UpdateAsync(int idWell, int idRow,
[FromBody] PlannedTrajectoryDto row, CancellationToken token = default)
[FromBody] TrajectoryGeoPlanDto row, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
@ -232,14 +232,14 @@ namespace AsbCloudWebApi.Controllers
/// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(typeof(PlanFactBase<IEnumerable<TrajectoryVisualizationPlanDto>, IEnumerable<TrajectoryVisualizationFactDto>>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetPlanFactTrajectoryAsync(int idWell, CancellationToken token)
[ProducesResponseType(typeof(PlanFactBase<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetTrajectoryCartesianPlanFactAsync(int idWell, CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell,
token).ConfigureAwait(false))
return Forbid();
var result = await trajectoryVisualizationService.GetTrajectoryAsync(idWell, token);
var result = await trajectoryVisualizationService.GetTrajectoryCartesianAsync(idWell, token);
return Ok(result);
}