DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/Trajectory/TrajectoryVisualizationService.cs

84 lines
3.5 KiB
C#

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 TrajectoryVisualizationService : ITrajectoryVisualizationService
{
private readonly IPlannedTrajectoryRepository plannedRepository;
private readonly IActualTrajectoryRepository factualRepository;
public TrajectoryVisualizationService(IPlannedTrajectoryRepository plannedRepository, IActualTrajectoryRepository factualRepository)
{
this.plannedRepository = plannedRepository;
this.factualRepository = factualRepository;
}
/// <summary>
/// Получение плановой и фактической траектории по скважине
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="token"></param>
/// <returns></returns>
public async Task<PlanFactBase<IEnumerable<TrajectoryVisualizationDto>>> GetTrajectoryAsync(int idWell, CancellationToken token)
{
var result = new PlanFactBase<IEnumerable<TrajectoryVisualizationDto>>();
var geoPlanCoordinates = await plannedRepository.GetTrajectoryAsync(idWell, token);
var geoFactCoordinates = await factualRepository.GetTrajectoryAsync(idWell, token);
result.Plan = GetTrajectoryVisualisation(geoPlanCoordinates);
result.Fact = GetTrajectoryVisualisation(geoFactCoordinates);
return result;
}
/// <summary>
/// Формирует список координат для визуализации трактории 3D
/// </summary>
/// <param name="geoCoordinates"></param>
/// <returns></returns>
private IEnumerable<TrajectoryVisualizationDto> GetTrajectoryVisualisation(IEnumerable<TrajectoryDto> geoCoordinates)
{
var geoCoordinatesLength = geoCoordinates.Count();
if (geoCoordinatesLength < 2)
return new TrajectoryVisualizationDto[0];
var cartesianCoordinates = new TrajectoryVisualizationDto[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 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[i] = coordinates;
}
return cartesianCoordinates;
}
}
}