Merge branch 'operation_grouping' into dev

This commit is contained in:
ngfrolov 2022-06-14 15:35:59 +05:00
commit 9db7a7303a
31 changed files with 6511 additions and 69 deletions

View File

@ -6,4 +6,8 @@
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Linq" Version="4.3.0" />
</ItemGroup>
</Project>

View File

@ -2,6 +2,7 @@
namespace AsbCloudApp.Data
{
#nullable enable
/// <summary>
/// Автоматически определяемая операция
/// </summary>
@ -61,11 +62,17 @@ namespace AsbCloudApp.Data
/// <summary>
/// Бурильщик
/// </summary>
public DrillerDto Driller { get; set; }
public DrillerDto? Driller { get; set; }
/// <summary>
/// Целевые/нормативные показатели
/// </summary>
public OperationValueDto OperationValue { get; set; }
public OperationValueDto? OperationValue { get; set; }
/// <summary>
/// Ключевой параметр операции
/// </summary>
public double Value { get; set; }
}
#nullable disable
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace AsbCloudApp.Data
{
#nullable enable
/// <summary>
/// Статистика по операциям бурильщика
/// </summary>
public class DetectedOperationStatDto
{
/// <summary>
/// Бурильщик
/// </summary>
public DrillerDto? Driller { get; set; }
/// <summary>
/// Количество операции
/// </summary>
public int Count { get; set; }
/// <summary>
/// Среднее по ключевому показателю
/// </summary>
public double AverageValue { get; set; }
/// <summary>
/// Среднее целевого показателя
/// </summary>
public double? AverageTargetValue { get; set; }
/// <summary>
/// Коэффициент эффективности
/// </summary>
public double? Efficiency { get; set; }
/// <summary>
/// Коэффициент потерь
/// </summary>
public double? Loss { get; set; }
}
/// <summary>
/// Автоматически определяемая операция
/// </summary>
public class DetectedOperationListDto
{
/// <summary>
/// Список всех операций
/// </summary>
public IEnumerable<DetectedOperationDto> Operations { get; set; }
public IEnumerable<DetectedOperationStatDto> Stats { get; set; }
}
#nullable disable
}

View File

@ -1,18 +1,20 @@
namespace AsbCloudApp.Data
using System;
namespace AsbCloudApp.Data
{
/// <summary>
/// Описание целевых/нормативных показателей операций
/// </summary>
public class OperationValueDto : IId
public class OperationValueDto : IId, IWellRelated
{
/// <summary>
/// Идентификатор в БД
/// </summary>
public int Id { get; set; }
/// <summary>
/// Идентификатор скважины
/// </summary>
/// <summary>
/// Идентификатор скважины
/// </summary>
public int IdWell { get; set; }
/// <summary>

View File

@ -37,5 +37,10 @@ namespace AsbCloudApp.Data
/// Конец бурения
/// </summary>
public DateTime DrillEnd { get; set; }
/// <summary>
/// Бурильщик
/// </summary>
public DrillerDto Driller { get; set; }
}
}

View File

@ -5,7 +5,7 @@ namespace AsbCloudApp.Data
/// <summary>
/// DTO времени
/// </summary>
public class TimeDto
public class TimeDto: IComparable<TimeDto>
{
private int hour = 0;
private int minute = 0;
@ -51,6 +51,11 @@ namespace AsbCloudApp.Data
}
}
/// <summary>
/// Кол-во секунд с начала суток
/// </summary>
public int TotalSeconds => (Hour * 60 + minute) * 60 + second;
/// <inheritdoc/>
public TimeDto()
{ }
@ -71,6 +76,14 @@ namespace AsbCloudApp.Data
second = time.Second;
}
/// <inheritdoc/>
public TimeDto(DateTime fullDate)
{
hour = fullDate.Hour;
minute = fullDate.Minute;
second = fullDate.Second;
}
/// <summary>
/// Makes System.TimeOnly
/// </summary>
@ -83,5 +96,27 @@ namespace AsbCloudApp.Data
var str = $"{Hour:00}:{Minute:00}:{Second:00}";
return str;
}
/// <inheritdoc/>
public static bool operator ==(TimeDto a, TimeDto b) => a?.TotalSeconds == b?.TotalSeconds;
/// <inheritdoc/>
public static bool operator !=(TimeDto a, TimeDto b) => !(a == b);
/// <inheritdoc/>
public static bool operator <=(TimeDto a, TimeDto b) => a.TotalSeconds <= b.TotalSeconds;
/// <inheritdoc/>
public static bool operator >=(TimeDto a, TimeDto b) => a.TotalSeconds >= b.TotalSeconds;
/// <inheritdoc/>
public static bool operator <(TimeDto a, TimeDto b) => a.TotalSeconds < b.TotalSeconds;
/// <inheritdoc/>
public static bool operator >(TimeDto a, TimeDto b) => a.TotalSeconds > b.TotalSeconds;
/// <inheritdoc/>
public int CompareTo(TimeDto other)
=> TotalSeconds - other.TotalSeconds;
}
}

View File

@ -19,7 +19,7 @@ namespace AsbCloudApp.Services
/// <param name="idWell">id скважины</param>
/// <param name="token"></param>
/// <returns>emptyList if nothing found</returns>
Task<IEnumerable<Tdto>> GetAllAsync(int idWell, CancellationToken token);
Task<IEnumerable<Tdto>> GetByIdWellAsync(int idWell, CancellationToken token);
/// <summary>
/// Получение всех записей по нескольким скважинам
@ -27,7 +27,7 @@ namespace AsbCloudApp.Services
/// <param name="idsWells">id скважин</param>
/// <param name="token"></param>
/// <returns>emptyList if nothing found</returns>
Task<IEnumerable<Tdto>> GetAllAsync(IEnumerable<int> idsWells, CancellationToken token);
Task<IEnumerable<Tdto>> GetByIdWellAsync(IEnumerable<int> idsWells, CancellationToken token);
}
#nullable disable
}

View File

@ -9,7 +9,7 @@ namespace AsbCloudApp.Services
public interface IDetectedOperationService
{
Task<IEnumerable<WellOperationCategoryDto>> GetCategoriesAsync(CancellationToken token);
Task<IEnumerable<DetectedOperationDto>> GetAsync(int idWell, Requests.DetectedOperationRequest request, CancellationToken token);
Task<DetectedOperationListDto> GetAsync(int idWell, Requests.DetectedOperationRequest request, CancellationToken token);
Task<int> DeleteAsync(int idWell, DetectedOperationRequest request, CancellationToken token);
}
}

View File

@ -2,7 +2,7 @@
namespace AsbCloudApp.Services
{
public interface IOperationValueService : ICrudService<OperationValueDto>
public interface IOperationValueService : ICrudWellRelatedService<OperationValueDto>
{
}
}

View File

@ -6,9 +6,8 @@ using System.Threading.Tasks;
namespace AsbCloudApp.Services
{
public interface IScheduleService : ICrudService<ScheduleDto>
public interface IScheduleService : ICrudWellRelatedService<ScheduleDto>
{
Task<IEnumerable<ScheduleDto>> GetByIdWellAsync(int idWell, CancellationToken token = default);
Task<DrillerDto> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default);
Task<DrillerDto> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class AddValToOp : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<double>(
name: "value",
table: "t_detected_operation",
type: "double precision",
nullable: false,
defaultValue: 0.0,
comment: "Ключевой показатель операции");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "value",
table: "t_detected_operation");
}
}
}

View File

@ -239,6 +239,11 @@ namespace AsbCloudDb.Migrations
.HasColumnName("id_user")
.HasComment("Id пользователя по телеметрии на момент начала операции");
b.Property<double>("Value")
.HasColumnType("double precision")
.HasColumnName("value")
.HasComment("Ключевой показатель операции");
b.HasKey("Id");
b.HasIndex("IdCategory");
@ -868,6 +873,57 @@ namespace AsbCloudDb.Migrations
});
});
modelBuilder.Entity("AsbCloudDb.Model.OperationValue", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id")
.HasComment("Идентификатор");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<double>("DepthEnd")
.HasColumnType("double precision")
.HasColumnName("depth_end")
.HasComment("Конечная глубина");
b.Property<double>("DepthStart")
.HasColumnType("double precision")
.HasColumnName("depth_start")
.HasComment("Старотовая глубина");
b.Property<int>("IdOperationCategory")
.HasColumnType("integer")
.HasColumnName("id_operation_category")
.HasComment("Ид категории операции");
b.Property<int>("IdWell")
.HasColumnType("integer")
.HasColumnName("id_well")
.HasComment("Ид скважины");
b.Property<double>("StandardValue")
.HasColumnType("double precision")
.HasColumnName("standard_value")
.HasComment("Нормативный показатель");
b.Property<double>("TargetValue")
.HasColumnType("double precision")
.HasColumnName("target_value")
.HasComment("Целевой показатель");
b.HasKey("Id");
b.HasIndex("IdOperationCategory");
b.HasIndex("IdWell");
b.ToTable("t_operationvalue");
b.HasComment("Целевые/нормативные показатели операции");
});
modelBuilder.Entity("AsbCloudDb.Model.Permission", b =>
{
b.Property<int>("Id")
@ -5468,6 +5524,25 @@ namespace AsbCloudDb.Migrations
b.Navigation("Well");
});
modelBuilder.Entity("AsbCloudDb.Model.OperationValue", b =>
{
b.HasOne("AsbCloudDb.Model.WellOperationCategory", "OperationCategory")
.WithMany()
.HasForeignKey("IdOperationCategory")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AsbCloudDb.Model.Well", "Well")
.WithMany()
.HasForeignKey("IdWell")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("OperationCategory");
b.Navigation("Well");
});
modelBuilder.Entity("AsbCloudDb.Model.RelationCompanyWell", b =>
{
b.HasOne("AsbCloudDb.Model.Company", "Company")

View File

@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
@ -38,6 +39,9 @@ namespace AsbCloudDb.Model
[Column("depth_end"), Comment("Глубина после завершения операции, м")]
public double DepthEnd { get; set; }
[Column("value"), Comment("Ключевой показатель операции")]
public double Value { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdTelemetry))]
public virtual Telemetry Telemetry { get; set; }

View File

@ -1,16 +1,11 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsbCloudDb.Model
{
[Table("t_operationvalue"), Comment("Целевые/нормативные показатели операции")]
public class OperationValue:IId
public class OperationValue: IId, IWellRelated
{
[Key]
[Column("id"), Comment("Идентификатор")]

View File

@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model
{
[Table("t_schedule"), Comment("График работы бурильщика")]
public class Schedule: IId
public class Schedule: IId, IWellRelated
{
[Key]
[Column("id"),Comment("Идентификатор")]

View File

@ -23,7 +23,7 @@ namespace AsbCloudInfrastructure.Services
public CrudWellRelatedServiceBase(IAsbCloudDbContext context, Func<DbSet<TEntity>, IQueryable<TEntity>> makeQuery)
: base(context, makeQuery) { }
public async Task<IEnumerable<TDto>> GetAllAsync(int idWell, CancellationToken token)
public async Task<IEnumerable<TDto>> GetByIdWellAsync(int idWell, CancellationToken token)
{
var entities = await GetQuery()
.Where(e => e.IdWell == idWell)
@ -32,7 +32,7 @@ namespace AsbCloudInfrastructure.Services
return dtos;
}
public async Task<IEnumerable<TDto>> GetAllAsync(IEnumerable<int> idsWells, CancellationToken token)
public async Task<IEnumerable<TDto>> GetByIdWellAsync(IEnumerable<int> idsWells, CancellationToken token)
{
if (!idsWells.Any())
return Enumerable.Empty<TDto>();

View File

@ -15,13 +15,15 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
{
public class DetectedOperationService: IDetectedOperationService
{
public const int IdOperationRotor = 1;
public const int IdOperationSlide = 3;
public const int IdOperationSlipsTime = 14;
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
private readonly IOperationValueService operationValueService;
private readonly IScheduleService scheduleService;
private IEnumerable<OperationValueDto> operationValues;
public DetectedOperationService(IAsbCloudDbContext db, IWellService wellService,
IOperationValueService operationValueService, IScheduleService scheduleService)
{
@ -31,7 +33,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
this.scheduleService = scheduleService;
}
public async Task<IEnumerable<DetectedOperationDto>> GetAsync(int idWell, DetectedOperationRequest request, CancellationToken token)
public async Task<DetectedOperationListDto> GetAsync(int idWell, DetectedOperationRequest request, CancellationToken token)
{
var well = await wellService.GetAsync(idWell, token);
if (well?.IdTelemetry is null || well.Timezone is null)
@ -42,15 +44,38 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
var data = await query.ToListAsync(token);
operationValues = await operationValueService.GetAllAsync(token);
operationValues = operationValues.Where(o => o.IdWell == idWell);
var operationValues = await operationValueService.GetByIdWellAsync(idWell, token);
var schedules = await scheduleService.GetByIdWellAsync(idWell, token);
var dtos = data.Select(o => Convert(o, well, operationValues, schedules));
var groups = dtos.GroupBy(o => o.Driller);
var dtos = data.Select(o => Convert(o, well, operationValues));
foreach (var item in dtos)
var stats = new List<DetectedOperationStatDto>(groups.Count());
foreach (var group in groups)
{
item.Driller = await scheduleService.GetDrillerAsync(idWell, item.DateStart);
var itemsWithTarget = group.Where(i => i.OperationValue is not null);
var stat = new DetectedOperationStatDto
{
Driller = group.Key,
AverageValue = group.Sum(e => e.Value) / group.Count(),
Count = group.Count(),
};
if (itemsWithTarget.Any())
{
var itemsOutOfTarget = itemsWithTarget.Where(o => !IsTargetOk(o));
stat.AverageTargetValue = itemsWithTarget.Average(e => e.OperationValue.TargetValue);
stat.Efficiency = 100d * itemsOutOfTarget.Count() / itemsWithTarget.Count();
stat.Loss = itemsOutOfTarget.Sum(DeltaToTarget);
}
stats.Add(stat);
}
return dtos;
var result = new DetectedOperationListDto
{
Operations = dtos,
Stats = stats
};
return result;
}
public async Task<int> DeleteAsync(int idWell, DetectedOperationRequest request, CancellationToken token)
@ -64,6 +89,28 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
return await db.SaveChangesAsync(token);
}
private static bool IsTargetOk(DetectedOperationDto op)
{
return (op.IdCategory) switch
{
IdOperationRotor => op.Value > op.OperationValue.TargetValue,
IdOperationSlide => op.Value > op.OperationValue.TargetValue,
IdOperationSlipsTime => op.Value > op.OperationValue.TargetValue,
_ => op.Value > op.OperationValue.TargetValue,
};
}
private static double DeltaToTarget(DetectedOperationDto op)
{
return (op.IdCategory) switch
{
IdOperationRotor => 0,
IdOperationSlide => 0,
IdOperationSlipsTime => op.Value - op.OperationValue.TargetValue,
_ => 0,
};
}
private IQueryable<DetectedOperation> BuildQuery(WellDto well, DetectedOperationRequest request)
{
if (well?.IdTelemetry is null || well.Timezone is null)
@ -112,14 +159,26 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
return query;
}
private static DetectedOperationDto Convert(DetectedOperation operation, WellDto well, IEnumerable<OperationValueDto> operationValues)
private DetectedOperationDto Convert(DetectedOperation operation, WellDto well, IEnumerable<OperationValueDto> operationValues, IEnumerable<ScheduleDto> schedules)
{
var dto = operation.Adapt<DetectedOperationDto>();
dto.IdWell = well.Id;
dto.DateStart = operation.DateStart.ToRemoteDateTime(well.Timezone.Hours);
var dateStart = operation.DateStart.ToRemoteDateTime(well.Timezone.Hours);
dto.DateStart = dateStart;
dto.DateEnd = operation.DateEnd.ToRemoteDateTime(well.Timezone.Hours);
dto.OperationValue = operationValues.FirstOrDefault(e => e.IdOperationCategory == dto.IdCategory
&& e.DepthStart <= dto.DepthStart);
var timeStart = new TimeDto(dateStart);
var driller = schedules.FirstOrDefault(s =>
s.DrillStart <= dateStart &&
s.DrillEnd > dateStart && (
s.ShiftStart > s.ShiftEnd
) ^ (s.ShiftStart <= timeStart &&
s.ShiftEnd > timeStart
))
?.Driller;
dto.Driller = driller;
return dto;
}

View File

@ -49,6 +49,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
DepthStart = telemetry[position].WellDepth ?? -1d,
DepthEnd = telemetry[skip].WellDepth ?? -1d,
};
CalcValue(ref result);
position = skip + FragmentLength;
return result;
}
@ -59,6 +60,8 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
return null;
}
protected abstract void CalcValue(ref DetectedOperation result);
protected abstract bool DetectStart(DetectableTelemetry[] telemetry, int position);
protected abstract bool DetectEnd(DetectableTelemetry[] telemetry, int position);

View File

@ -1,4 +1,5 @@
using System.Linq;
using AsbCloudDb.Model;
using System.Linq;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{
@ -43,6 +44,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position)
=> !DetectStart(telemetry, position);
protected override void CalcValue(ref DetectedOperation result)
{
throw new System.NotImplementedException();
}
}
#nullable disable
}

View File

@ -1,4 +1,5 @@
using System.Linq;
using AsbCloudDb.Model;
using System.Linq;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{
@ -42,6 +43,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position)
=> !DetectStart(telemetry, position);
protected override void CalcValue(ref DetectedOperation result)
{
throw new System.NotImplementedException();
}
}
#nullable disable
}

View File

@ -1,4 +1,6 @@
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
using AsbCloudDb.Model;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{
#nullable enable
class DetectorSlipsTime : DetectorAbstract
@ -31,6 +33,11 @@
return result;
}
protected override void CalcValue(ref DetectedOperation result)
{
result.Value = result.DurationMinutes;
}
}
#nullable disable
}

View File

@ -97,15 +97,17 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
IdTelemetry = outer,
LastDate = inner.SingleOrDefault()?.LastDate ,
});
var affected = 0;
foreach (var item in JounedlastDetectedDates)
{
var newOperations = await DetectOperationsAsync(item.IdTelemetry, item.LastDate??DateTimeOffset.MinValue, db, token);
if (newOperations.Any())
{
db.DetectedOperations.AddRange(newOperations);
affected += await db.SaveChangesAsync(token);
}
}
return await db.SaveChangesAsync(token);
return affected;
}
private async Task<IEnumerable<DetectedOperation>> DetectOperationsAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
@ -131,7 +133,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
var dbRequests_ = 0;
var dbTime_ = 0d;
var sw_ = new System.Diagnostics.Stopwatch();
var sw_ = new Stopwatch();
var otherTime_ = 0d;
while (true)

View File

@ -4,7 +4,7 @@ using AsbCloudDb.Model;
namespace AsbCloudInfrastructure.Services
{
public class OperationValueService : CrudServiceBase<OperationValueDto, OperationValue>, IOperationValueService
public class OperationValueService : CrudWellRelatedServiceBase<OperationValueDto, OperationValue>, IOperationValueService
{
public OperationValueService(IAsbCloudDbContext context) : base(context)
{

View File

@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
#nullable enable
public class ScheduleService : CrudServiceBase<ScheduleDto, Schedule>, IScheduleService
public class ScheduleService : CrudWellRelatedServiceBase<ScheduleDto, Schedule>, IScheduleService
{
private readonly IWellService wellService;
@ -22,16 +22,7 @@ namespace AsbCloudInfrastructure.Services
this.wellService = wellService;
}
public async Task<IEnumerable<ScheduleDto>> GetByIdWellAsync(int idWell, CancellationToken token = default)
{
var entities = await GetQuery()
.Where(s => s.IdWell == idWell)
.ToListAsync(token);
var dtos = entities.Select(Convert);
return dtos;
}
public async Task<DrillerDto?> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default)
public async Task<DrillerDto?> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token)
{
var hoursOffset = wellService.GetTimezone(idWell).Hours;
var date = workTime.ToUtcDateTimeOffset(hoursOffset);

View File

@ -0,0 +1,97 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.Cache;
using AsbCloudInfrastructure.Services.DetectOperations;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace AsbCloudWebApi.Tests.ServicesTests
{
public class DetectedOperationServiceTest
{
private readonly AsbCloudDbContext context;
private readonly CacheDb cacheDb;
private readonly DetectedOperationService service;
#region Задача данных
private Deposit deposit = new Deposit { Id = 1, Caption = "Депозит 1" };
private Cluster cluster = new Cluster { Id = 1, Caption = "Кластер 1", IdDeposit = 1, Timezone = new SimpleTimezone() };
private Well well = new Well
{
Id = 1,
Caption = "Test well 1",
IdTelemetry=1,
IdCluster = 1,
Timezone = new SimpleTimezone { Hours = 5 }
};
private Driller driller = new Driller
{
Id = 1,
Name = "Тестовый",
Patronymic = "Тест",
Surname = "Тестович"
};
private DetectedOperation do1 = new DetectedOperation
{
Id = 1,
IdCategory = 1,
IdTelemetry = 1,
DateStart = DateTimeOffset.Parse("2022-05-16T10:00:00.286Z"),
DateEnd = DateTimeOffset.Parse("2022-05-16T18:00:00.286Z"),
DepthStart = 100,
DepthEnd = 1000
};
private Telemetry telemetry = new Telemetry
{
Id=1,
RemoteUid = Guid.NewGuid().ToString()
};
#endregion
public DetectedOperationServiceTest()
{
context = TestHelpter.MakeTestContext();
context.SaveChanges();
context.Telemetries.Add(telemetry);
context.Deposits.Add(deposit);
context.Clusters.Add(cluster);
context.Wells.Add(well);
context.Drillers.Add(driller);
context.DetectedOperations.Add(do1);
context.SaveChanges();
var timezone = new SimpleTimezoneDto { Hours = 5 };
var wellServiceMock = new Mock<IWellService>();
wellServiceMock.Setup(s => s.GetTimezone(It.IsAny<int>())).Returns(timezone);
var operationValueService = new OperationValueService(context);
var scheduleService = new ScheduleService(context, wellServiceMock.Object);
service = new DetectedOperationService(context, wellServiceMock.Object, operationValueService, scheduleService);
AsbCloudInfrastructure.DependencyInjection.MapsterSetup();
}
~DetectedOperationServiceTest()
{
}
[Fact]
public async Task Count_grouping_by_driller()
{
var count = 10;
var list = await service.GetAsync(1, null, CancellationToken.None);
Assert.Equal(3, count);
}
}
}

View File

@ -34,8 +34,8 @@ namespace AsbCloudWebApi.Tests.ServicesTests
{
IdWell = dto?.IdWell ?? 1,
IdDriller = dto?.IdDriller ?? 1,
ShiftStart = dto?.ShiftStart ?? new TimeDto(10, 00),
ShiftEnd = dto?.ShiftEnd ?? new TimeDto(18, 00),
//ShiftStart = dto?.ShiftStart ?? new TimeOnly(10, 00),
//ShiftEnd = dto?.ShiftEnd ?? new TimeOnly(18, 00),
DrillStart = dto?.DrillStart ?? DateTime.Parse("2022-05-16T10:00:00.286Z"),
DrillEnd = dto?.DrillEnd ?? DateTime.Parse("2022-05-16T18:00:00.286Z")
};
@ -114,8 +114,8 @@ namespace AsbCloudWebApi.Tests.ServicesTests
public async Task GetDriller_by_workTime_shift1()
{
var dto = MakeScheduleDto();
dto.ShiftStart = new TimeDto(8, 00);
dto.ShiftEnd = new TimeDto(20, 00);
dto.ShiftStart = new TimeOnly(8, 00);
dto.ShiftEnd = new TimeOnly(20, 00);
var id = await scheduleService.InsertAsync(dto, CancellationToken.None);
var drillerWorkTime = new DateTime(
dto.DrillStart.Year,
@ -130,8 +130,8 @@ namespace AsbCloudWebApi.Tests.ServicesTests
public async Task GetDriller_by_workTime_shift2()
{
var dto = MakeScheduleDto();
dto.ShiftStart = new TimeDto(20, 00);
dto.ShiftEnd = new TimeDto(8, 00);
dto.ShiftStart = new TimeOnly(20, 00);
dto.ShiftEnd = new TimeOnly(8, 00);
var id = await scheduleService.InsertAsync(dto, CancellationToken.None);
var drillerWorkTime = new DateTime(
dto.DrillStart.Year,

View File

@ -48,7 +48,7 @@ namespace AsbCloudWebApi.Controllers
return NoContent();
var idsWells = wells.Select(w => w.Id);
var result = await service.GetAllAsync(idsWells, token);
var result = await service.GetByIdWellAsync(idsWells, token);
return Ok(result);
}
@ -59,12 +59,12 @@ namespace AsbCloudWebApi.Controllers
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("well/{idWell}")]
public async Task<ActionResult<IEnumerable<T>>> GetAllAsync(int idWell, CancellationToken token)
public async Task<ActionResult<IEnumerable<T>>> GetByIdWellAsync(int idWell, CancellationToken token)
{
if (!await UserHasAccesToWellAsync(idWell, token))
return Forbid();
var result = await service.GetAllAsync(idWell, token);
var result = await service.GetByIdWellAsync(idWell, token);
return Ok(result);
}
@ -108,6 +108,7 @@ namespace AsbCloudWebApi.Controllers
return await base.UpdateAsync(value, token);
}
/// <inheritdoc/>
[HttpDelete("{id}")]
public override async Task<ActionResult<int>> DeleteAsync(int id, CancellationToken token)
{

View File

@ -5,12 +5,12 @@ using Microsoft.AspNetCore.Mvc;
namespace AsbCloudWebApi.Controllers
{
[Route("api/operationvalue")]
[Route("api/operationValue")]
[ApiController]
[Authorize]
public class OperationValueController : CrudController<OperationValueDto, IOperationValueService>
public class OperationValueController : CrudWellRelatedController<OperationValueDto, IOperationValueService>
{
public OperationValueController(IOperationValueService service) : base(service)
public OperationValueController(IOperationValueService service, IWellService wellService) : base(wellService, service)
{
}
}

View File

@ -45,7 +45,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
/// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<DetectedOperationDto>), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(DetectedOperationListDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync(
int idWell,
[FromQuery] DetectedOperationRequest request,

View File

@ -0,0 +1,8 @@
{
"profiles": {
"WSL": {
"commandName": "WSL2",
"distributionName": ""
}
}
}