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

163 lines
5.6 KiB
C#
Raw Normal View History

2023-11-28 15:54:47 +05:00
using AsbCloudApp.Data.Trajectory;
2023-05-30 11:21:07 +05:00
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
2023-05-30 11:21:07 +05:00
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 request = new TrajectoryRequest()
{
IdWell = idWell
};
var geoCoords = await repository.GetAsync(request, token);
2023-05-30 11:21:07 +05:00
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 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(ITrajectoryEditableRepository<TrajectoryGeoPlanDto> repository)
2023-05-30 11:21:07 +05:00
: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(ITrajectoryEditableRepository<TrajectoryGeoFactDto> repository)
: base(repository)
{ }
}
class TrajectoryNnbService : TrajectoryBaseService<TrajectoryGeoFactDto, TrajectoryCartesianFactDto>
{
public TrajectoryNnbService(ITrajectoryNnbRepository repository)
2023-05-30 11:21:07 +05:00
: base(repository)
{ }
}
public class TrajectoryService
{
private TrajectoryPlanService trajectoryPlanService;
private TrajectoryFactService trajectoryFactService;
private TrajectoryNnbService trajectoryNnbService;
2023-05-30 11:21:07 +05:00
public TrajectoryService(
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> plannedRepository,
ITrajectoryEditableRepository<TrajectoryGeoFactDto> factRepository,
ITrajectoryNnbRepository nnbRepository)
2023-05-30 11:21:07 +05:00
{
trajectoryPlanService = new TrajectoryPlanService(plannedRepository);
trajectoryFactService = new TrajectoryFactService(factRepository);
trajectoryNnbService = new TrajectoryNnbService(nnbRepository);
2023-05-30 11:21:07 +05:00
}
/// <summary>
/// Получение плановой и фактической траектории по скважине
/// </summary>
/// <param name="idWell">ключ скважины</param>
/// <param name="token"></param>
/// <returns></returns>
2023-11-28 15:54:47 +05:00
public async Task<TrajectoryPlanFactDto<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>> GetTrajectoryCartesianAsync(int idWell, CancellationToken token)
2023-05-30 11:21:07 +05:00
{
2023-11-28 15:54:47 +05:00
var result = new TrajectoryPlanFactDto<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>();
2023-05-30 11:21:07 +05:00
result.Plan = await trajectoryPlanService.GetAsync(idWell, token);
2023-11-28 15:54:47 +05:00
result.FactManual = await trajectoryFactService.GetAsync(idWell, token);
result.FactNnb = await trajectoryNnbService.GetAsync(idWell, token);
2023-05-30 11:21:07 +05:00
return result;
}
}