forked from ddrilling/AsbCloudServer
64 lines
2.3 KiB
C#
64 lines
2.3 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
|
|
{
|
|
public class TrajectoryVisualizationService : ITrajectoryVisualizationService
|
|
{
|
|
private readonly ITrajectoryVisualizationRepository repository;
|
|
|
|
public TrajectoryVisualizationService(ITrajectoryVisualizationRepository repository)
|
|
{
|
|
this.repository = repository;
|
|
}
|
|
|
|
public async Task<IEnumerable<TrajectoryVisualizationDto>> GetTrajectoryAsync(int idWell, CancellationToken token)
|
|
{
|
|
var result = new List<TrajectoryVisualizationDto>();
|
|
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);
|
|
}
|
|
}
|