forked from ddrilling/AsbCloudServer
Правки по результатам ревью
This commit is contained in:
parent
f4cc1d1bdf
commit
b95250a0dd
@ -19,6 +19,6 @@ namespace AsbCloudApp.Repositories
|
||||
/// <param name="idWell">ключ скважины</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<TrajectoryDto[]> GetTrajectoryAsync(int idWell, CancellationToken token);
|
||||
Task<IEnumerable<TrajectoryDto>> GetTrajectoryAsync(int idWell, CancellationToken token);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -20,7 +21,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
this.wellService = wellService;
|
||||
}
|
||||
|
||||
public async Task<TrajectoryDto[]> GetTrajectoryAsync(int idWell, CancellationToken token)
|
||||
public async Task<IEnumerable<TrajectoryDto>> GetTrajectoryAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
|
||||
var well = wellService.GetOrDefault(idWell);
|
||||
|
@ -86,7 +86,7 @@ namespace AsbCloudInfrastructure.Repository
|
||||
.Where(x => x.IdWell == idWell);
|
||||
var entities = await query
|
||||
.OrderBy(e => e.WellboreDepth)
|
||||
.ToListAsync(token);
|
||||
.ToArrayAsync(token);
|
||||
var result = entities
|
||||
.Select(r => Convert(r, offsetHours));
|
||||
return result;
|
||||
@ -116,11 +116,20 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<TrajectoryDto[]> GetTrajectoryAsync(int idWell, CancellationToken token)
|
||||
public async Task<IEnumerable<TrajectoryDto>> GetTrajectoryAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
return (await GetAsync(idWell, 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 TrajectoryDto(coord.WellboreDepth, coord.ZenithAngle, coord.AzimuthGeo))
|
||||
.ToArray();
|
||||
.ToArrayAsync()
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,19 +45,20 @@ namespace AsbCloudInfrastructure.Services.Trajectory
|
||||
/// </summary>
|
||||
/// <param name="geoCoordinates"></param>
|
||||
/// <returns></returns>
|
||||
private List<TrajectoryVisualizationDto> GetTrajectoryVisualisation(TrajectoryDto[] geoCoordinates)
|
||||
private IEnumerable<TrajectoryVisualizationDto> GetTrajectoryVisualisation(IEnumerable<TrajectoryDto> geoCoordinates)
|
||||
{
|
||||
if(geoCoordinates.Length < 2)
|
||||
return new List<TrajectoryVisualizationDto>();
|
||||
var geoCoordinatesLength = geoCoordinates.Count();
|
||||
if (geoCoordinatesLength < 2)
|
||||
return new TrajectoryVisualizationDto[0];
|
||||
|
||||
var cartesianCoordinates = new List<TrajectoryVisualizationDto>(geoCoordinates.Length) {
|
||||
new (),
|
||||
};
|
||||
var cartesianCoordinates = new TrajectoryVisualizationDto[geoCoordinatesLength];
|
||||
cartesianCoordinates[0] = new();
|
||||
|
||||
for (var i = 1; i < geoCoordinates.Length; i++)
|
||||
var geoCoordinatesArray = geoCoordinates.ToArray();
|
||||
for (var i = 1; i < geoCoordinatesLength; i++)
|
||||
{
|
||||
var intervalGeoParams = geoCoordinates[i - 1];
|
||||
var deltaWellLength = geoCoordinates[i].WellboreDepth - intervalGeoParams.WellboreDepth;
|
||||
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);
|
||||
@ -72,7 +73,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
|
||||
Y = preCoordinates.Y + dy,
|
||||
};
|
||||
|
||||
cartesianCoordinates.Add(coordinates);
|
||||
cartesianCoordinates[i] = coordinates;
|
||||
}
|
||||
|
||||
return cartesianCoordinates;
|
||||
|
@ -13,7 +13,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
{
|
||||
public class TrajectoryVisualizationServiceTest
|
||||
{
|
||||
private Mock<T> MakeTrajectoryRepositoryMock<T>(TrajectoryDto[] dateForGetMethod)
|
||||
private Mock<T> MakeTrajectoryRepositoryMock<T>(IEnumerable<TrajectoryDto> dateForGetMethod)
|
||||
where T : class, ITrajectoryRepository
|
||||
{
|
||||
var mock = new Mock<T>();
|
||||
@ -55,28 +55,18 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
[Fact]
|
||||
public async Task GetTrajectoryAsync_StraigthBore()
|
||||
{
|
||||
var plannedTrajectory = new TrajectoryDto[]
|
||||
var trajectory = new TrajectoryDto[]
|
||||
{
|
||||
new(0, 0, 0),
|
||||
new(0, 0, 0),
|
||||
new(0, 0, 20),
|
||||
new(0, 0, 20),
|
||||
new(0, 0, 30),
|
||||
new(0, 0, 50),
|
||||
new(20, 0, 0),
|
||||
new(20, 0, 0),
|
||||
new(30, 0, 0),
|
||||
new(50, 0, 0),
|
||||
};
|
||||
|
||||
var factualTrajectory = new TrajectoryDto[]
|
||||
{
|
||||
new(0, 0, 0),
|
||||
new(0, 0, 0),
|
||||
new(0, 0, 20),
|
||||
new(0, 0, 20),
|
||||
new(0, 0, 30),
|
||||
new(0, 0, 50),
|
||||
};
|
||||
|
||||
var mockPlan = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(plannedTrajectory);
|
||||
var mockFact = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(factualTrajectory);
|
||||
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 lastPointPlan = result.Plan!.Last();
|
||||
@ -94,22 +84,15 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
[Fact]
|
||||
public async Task GetTrajectoryAsync_Match()
|
||||
{
|
||||
var plannedTrajectory = new TrajectoryDto[]
|
||||
var trajectory = new TrajectoryDto[]
|
||||
{
|
||||
new(0, 0, 0),
|
||||
new(30, 30, 10),
|
||||
new(0, 0, 20),
|
||||
new(10, 30, 30),
|
||||
new(20, 0, 0),
|
||||
};
|
||||
|
||||
var factualTrajectory = new TrajectoryDto[]
|
||||
{
|
||||
new(0, 0, 0),
|
||||
new(30, 30, 10),
|
||||
new(0, 0, 20),
|
||||
};
|
||||
|
||||
var mockPlanned = MakeTrajectoryRepositoryMock<IPlannedTrajectoryRepository>(plannedTrajectory);
|
||||
var mockFactual = MakeTrajectoryRepositoryMock<IActualTrajectoryRepository>(factualTrajectory);
|
||||
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 lastPointPlan = result.Plan!.Last();
|
||||
|
Loading…
Reference in New Issue
Block a user