forked from ddrilling/AsbCloudServer
merge dev to well_operation_import
This commit is contained in:
commit
e97f8494ca
32
AsbCloudApp/Data/DetectedOperation/OperationsSummaryDto.cs
Normal file
32
AsbCloudApp/Data/DetectedOperation/OperationsSummaryDto.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
namespace AsbCloudApp.Data.DetectedOperation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Статистика по операциям
|
||||||
|
/// </summary>
|
||||||
|
public class OperationsSummaryDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Id телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public int IdTelemetry { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Id названия/описания операции
|
||||||
|
/// </summary>
|
||||||
|
public int IdCategory { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Количество операций
|
||||||
|
/// </summary>
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cумма проходок операций
|
||||||
|
/// </summary>
|
||||||
|
public double SumDepthIntervals { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cумма продолжительностей операций
|
||||||
|
/// </summary>
|
||||||
|
public double SumDurationHours { get; set; }
|
||||||
|
}
|
@ -14,7 +14,7 @@ namespace AsbCloudApp.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// дата появления события
|
/// дата появления события
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime Date { get; set; }
|
public DateTime DateTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// категория события
|
/// категория события
|
||||||
|
44
AsbCloudApp/Data/SlipsStatDto.cs
Normal file
44
AsbCloudApp/Data/SlipsStatDto.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Data
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// DTO, описывающая аналитику удержания в клиньях
|
||||||
|
/// </summary>
|
||||||
|
public class SlipsStatDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ФИО бурильщика
|
||||||
|
/// </summary>
|
||||||
|
public string DrillerName { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Количество скважин
|
||||||
|
/// </summary>
|
||||||
|
public int WellCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Название секции
|
||||||
|
/// </summary>
|
||||||
|
public string SectionCaption { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Количество удержаний в клиньях, шт.
|
||||||
|
/// </summary>
|
||||||
|
public int SlipsCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Время удержания в клиньях, мин.
|
||||||
|
/// </summary>
|
||||||
|
public double SlipsTimeInMinutes { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проходка, м.
|
||||||
|
/// </summary>
|
||||||
|
public double SectionDepth { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -23,13 +23,20 @@ namespace AsbCloudApp.Data.Subsystems
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public double KUsage { get; set; }
|
public double KUsage { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// сумма изменения глубин
|
/// сумма изменения глубин при включеной подсистеме
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double SumDepthInterval { get; set; }
|
public double SumDepthInterval { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// количество операций
|
/// сумма проходок автоопределенных операций выполняемых подсистемой
|
||||||
|
/// </summary>
|
||||||
|
public double SumOperationDepthInterval { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// сумма продолжительности автоопределенных операций выполняемых подсистемой
|
||||||
|
/// </summary>
|
||||||
|
public double SumOperationDurationHours { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// количество включений подсистемы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int OperationCount { get; set; }
|
public int OperationCount { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
53
AsbCloudApp/Requests/DetectedOperationSummaryRequest.cs
Normal file
53
AsbCloudApp/Requests/DetectedOperationSummaryRequest.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Requests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Запрос на получение обобщенных данных по операцим
|
||||||
|
/// </summary>
|
||||||
|
public class DetectedOperationSummaryRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Список id телеметрий
|
||||||
|
/// пустой список - нет фильтрации
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<int> IdsTelemetries { get;set;} = Enumerable.Empty<int>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Список id категорий операций
|
||||||
|
/// пустой список - нет фильтрации
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<int> IdsOperationCategories { get; set; } = Enumerable.Empty<int>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Больше или равно даты начала операции
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset? GeDateStart {get;set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Меньше или равно даты начала операции
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset? LeDateStart { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Меньше или равно даты окончания операции
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset? LeDateEnd { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Больше или равно глубины начала операции
|
||||||
|
/// </summary>
|
||||||
|
public double? GeDepthStart { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Меньше или равно глубины начала операции
|
||||||
|
/// </summary>
|
||||||
|
public double? LeDepthStart { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Меньше или равно глубины окончания операции
|
||||||
|
/// </summary>
|
||||||
|
public double? LeDepthEnd { get; set; }
|
||||||
|
}
|
30
AsbCloudApp/Requests/OperationStatRequest.cs
Normal file
30
AsbCloudApp/Requests/OperationStatRequest.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Requests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры фильтра операции
|
||||||
|
/// </summary>
|
||||||
|
public class OperationStatRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Дата начала операции в UTC
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? DateStartUTC { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Дата окончания операции в UTC
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? DateEndUTC { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Минимальная продолжительность операции, мин
|
||||||
|
/// </summary>
|
||||||
|
public double? DurationMinutesMin { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Максимальная продолжительность операции, мин
|
||||||
|
/// </summary>
|
||||||
|
public double? DurationMinutesMax { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,7 @@ namespace AsbCloudApp.Requests
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Больше или равно дате
|
/// Больше или равно дате
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? GtDate { get; set; }
|
public DateTime? GtDate { get; set; }//TODO: its Ge*
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Меньше или равно дате
|
/// Меньше или равно дате
|
||||||
@ -43,6 +43,7 @@ namespace AsbCloudApp.Requests
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public double? LtDepth { get; set; }
|
public double? LtDepth { get; set; }
|
||||||
|
|
||||||
|
//TODO: Replace modes by DateTimeOffset LeDateStart, LeDateEnd
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// информация попадает в выборку, если интервал выборки частично или полностью пересекается с запрашиваемым интервалом
|
/// информация попадает в выборку, если интервал выборки частично или полностью пересекается с запрашиваемым интервалом
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -42,12 +42,10 @@ namespace AsbCloudApp.Services
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить интервалы глубин по всем скважинам
|
/// Получить интервалы глубин по всем скважинам
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="telemetryIds">список ИД телеметрий активных скважин</param>
|
/// <param name="request"></param>
|
||||||
/// <param name="gtDate"></param>
|
|
||||||
/// <param name="ltDate"></param>
|
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns>кортеж - ид телеметрии, интервалы глубины забоя (ротор,слайд) </returns>
|
/// <returns>кортеж - ид телеметрии, интервалы глубины забоя (ротор,слайд) </returns>
|
||||||
Task<IEnumerable<(int idTelemetry,double depthIntervalRotor, double depthIntervalSlide)>> GetDepthIntervalAllOperationsAsync(IEnumerable<int?> telemetryIds,DateTimeOffset gtDate, DateTimeOffset ltDate, CancellationToken token);
|
Task<IEnumerable<OperationsSummaryDto>> GetOperationSummaryAsync(DetectedOperationSummaryRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удалить операции
|
/// Удалить операции
|
||||||
|
23
AsbCloudApp/Services/ISlipsStatService.cs
Normal file
23
AsbCloudApp/Services/ISlipsStatService.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Сервис для получения аналитики удержания в клиньях
|
||||||
|
/// </summary>
|
||||||
|
public interface ISlipsStatService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получение записей для построения аналитики удержания в клиньях
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">параметры запроса</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<SlipsStatDto>> GetAllAsync(OperationStatRequest request, CancellationToken token);
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,7 @@ namespace AsbCloudApp.Services.Subsystems
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<SubsystemStatDto>?> GetStatAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
Task<IEnumerable<SubsystemStatDto>> GetStatAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление наработки по подсистемам.
|
/// Удаление наработки по подсистемам.
|
||||||
@ -37,7 +37,7 @@ namespace AsbCloudApp.Services.Subsystems
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<SubsystemOperationTimeDto>?> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
Task<IEnumerable<SubsystemOperationTimeDto>> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Временной диапазон за который есть статистика работы подсистем
|
/// Временной диапазон за который есть статистика работы подсистем
|
||||||
|
@ -26,13 +26,13 @@ using System;
|
|||||||
using AsbCloudApp.Data.Manuals;
|
using AsbCloudApp.Data.Manuals;
|
||||||
using AsbCloudApp.Services.AutoGeneratedDailyReports;
|
using AsbCloudApp.Services.AutoGeneratedDailyReports;
|
||||||
using AsbCloudApp.Services.Notifications;
|
using AsbCloudApp.Services.Notifications;
|
||||||
using AsbCloudApp.Services.WellOperationImport;
|
|
||||||
using AsbCloudDb.Model.Manuals;
|
using AsbCloudDb.Model.Manuals;
|
||||||
using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
|
using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
|
||||||
|
using AsbCloudApp.Services.WellOperationImport;
|
||||||
using AsbCloudInfrastructure.Services.WellOperationImport;
|
using AsbCloudInfrastructure.Services.WellOperationImport;
|
||||||
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
|
|
||||||
using AsbCloudInfrastructure.Services.ProcessMap.ProcessMapWellboreDevelopment;
|
using AsbCloudInfrastructure.Services.ProcessMap.ProcessMapWellboreDevelopment;
|
||||||
using AsbCloudApp.Data.WellOperationImport.Options;
|
using AsbCloudApp.Data.WellOperationImport.Options;
|
||||||
|
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure
|
namespace AsbCloudInfrastructure
|
||||||
{
|
{
|
||||||
@ -122,9 +122,10 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddSingleton<IReduceSamplingService>(provider => ReduceSamplingService.GetInstance(configuration));
|
services.AddSingleton<IReduceSamplingService>(provider => ReduceSamplingService.GetInstance(configuration));
|
||||||
|
|
||||||
services.AddTransient<IAuthService, AuthService>();
|
services.AddTransient<IAuthService, AuthService>();
|
||||||
|
services.AddTransient<IProcessMapWellboreDevelopmentRepository, ProcessMapWellboreDevelopmentRepository>();
|
||||||
|
services.AddTransient<IProcessMapWellboreDevelopmentService, ProcessMapWellboreDevelopmentService>();
|
||||||
services.AddTransient<IDepositRepository, DepositRepository>();
|
services.AddTransient<IDepositRepository, DepositRepository>();
|
||||||
services.AddTransient<IProcessMapPlanRepository, ProcessMapRepository>();
|
services.AddTransient<IProcessMapPlanRepository, ProcessMapRepository>();
|
||||||
services.AddTransient<IProcessMapWellboreDevelopmentRepository, ProcessMapWellboreDevelopmentRepository>();
|
|
||||||
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
||||||
services.AddTransient<IEventService, EventService>();
|
services.AddTransient<IEventService, EventService>();
|
||||||
services.AddTransient<FileService>();
|
services.AddTransient<FileService>();
|
||||||
@ -137,6 +138,7 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<ITelemetryUserService, TelemetryUserService>();
|
services.AddTransient<ITelemetryUserService, TelemetryUserService>();
|
||||||
services.AddTransient<ITimezoneService, TimezoneService>();
|
services.AddTransient<ITimezoneService, TimezoneService>();
|
||||||
services.AddTransient<IWellService, WellService>();
|
services.AddTransient<IWellService, WellService>();
|
||||||
|
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
||||||
services.AddTransient<IProcessMapPlanImportService, ProcessMapPlanImportService>();
|
services.AddTransient<IProcessMapPlanImportService, ProcessMapPlanImportService>();
|
||||||
services.AddTransient<IPlannedTrajectoryImportService, PlannedTrajectoryImportService>();
|
services.AddTransient<IPlannedTrajectoryImportService, PlannedTrajectoryImportService>();
|
||||||
services.AddTransient<IWellOperationRepository, WellOperationRepository>();
|
services.AddTransient<IWellOperationRepository, WellOperationRepository>();
|
||||||
@ -152,7 +154,6 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<ILimitingParameterService, LimitingParameterService>();
|
services.AddTransient<ILimitingParameterService, LimitingParameterService>();
|
||||||
services.AddTransient<IProcessMapReportMakerService, ProcessMapReportMakerService>();
|
services.AddTransient<IProcessMapReportMakerService, ProcessMapReportMakerService>();
|
||||||
services.AddTransient<IProcessMapService, ProcessMapService>();
|
services.AddTransient<IProcessMapService, ProcessMapService>();
|
||||||
services.AddTransient<IProcessMapWellboreDevelopmentService, ProcessMapWellboreDevelopmentService>();
|
|
||||||
services.AddTransient<WellInfoService>();
|
services.AddTransient<WellInfoService>();
|
||||||
services.AddTransient<IHelpPageService, HelpPageService>();
|
services.AddTransient<IHelpPageService, HelpPageService>();
|
||||||
|
|
||||||
@ -205,6 +206,7 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<ITrajectoryPlanRepository, TrajectoryPlanRepository>();
|
services.AddTransient<ITrajectoryPlanRepository, TrajectoryPlanRepository>();
|
||||||
services.AddTransient<ITrajectoryFactRepository, TrajectoryFactRepository>();
|
services.AddTransient<ITrajectoryFactRepository, TrajectoryFactRepository>();
|
||||||
services.AddTransient<IFaqRepository, FaqRepository>();
|
services.AddTransient<IFaqRepository, FaqRepository>();
|
||||||
|
services.AddTransient<ISlipsStatService, SlipsStatService>();
|
||||||
services.AddTransient<IWellContactService, WellContactService>();
|
services.AddTransient<IWellContactService, WellContactService>();
|
||||||
services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto,
|
services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto,
|
||||||
WellSectionType>>();
|
WellSectionType>>();
|
||||||
@ -240,8 +242,8 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
||||||
services.AddTransient<IWellOperationImportTemplateService, WellOperationImportTemplateService>();
|
services.AddTransient<IWellOperationImportTemplateService, WellOperationImportTemplateService>();
|
||||||
|
|
||||||
services.AddTransient<IWellOperationExcelParser<WellOperationImportDefaultOptionsDto>, WellOperationDefaultExcelParser>();
|
services.AddTransient<IWellOperationExcelParser, WellOperationDefaultExcelParser>();
|
||||||
services.AddTransient<IWellOperationExcelParser<WellOperationImportGazpromKhantosOptionsDto>, WellOperationGazpromKhantosExcelParser>();
|
services.AddTransient<IWellOperationExcelParser, WellOperationGazpromKhantosExcelParser>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
@ -67,27 +67,58 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
|||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<(int idTelemetry, double depthIntervalRotor, double depthIntervalSlide)>> GetDepthIntervalAllOperationsAsync(IEnumerable<int?> telemetryIds, DateTimeOffset gtDate, DateTimeOffset ltDate, CancellationToken token)
|
public async Task<IEnumerable<OperationsSummaryDto>> GetOperationSummaryAsync(DetectedOperationSummaryRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = db.Set<DetectedOperation>()
|
var query = db.Set<DetectedOperation>()
|
||||||
.Include(o => o.OperationCategory)
|
.AsNoTracking();
|
||||||
.Where(o => o.DateStart >= gtDate)
|
|
||||||
.Where(o => o.DateEnd <= ltDate)
|
if (request.IdsTelemetries.Any())
|
||||||
.Where(o => telemetryIds.Contains(o.IdTelemetry))
|
query = query.Where(operation => request.IdsTelemetries.Contains(operation.IdTelemetry));
|
||||||
.GroupBy(g => g.IdTelemetry)
|
|
||||||
.Select(g => new
|
if (request.IdsOperationCategories.Any())
|
||||||
|
query = query.Where(operation => request.IdsOperationCategories.Contains(operation.IdCategory));
|
||||||
|
|
||||||
|
if (request.GeDateStart.HasValue)
|
||||||
{
|
{
|
||||||
IdTelemetry = g.Key,
|
var geDateStart = request.GeDateStart.Value.ToUniversalTime();
|
||||||
RotorDepthInterval = g.Where(o => o.IdCategory == WellOperationCategory.IdRotor).Sum(o => o.DepthEnd - o.DepthStart),
|
query = query.Where(operation => operation.DateStart >= geDateStart);
|
||||||
SlideDepthInterval = g.Where(o => o.IdCategory == WellOperationCategory.IdSlide).Sum(o => o.DepthEnd - o.DepthStart)
|
}
|
||||||
});
|
|
||||||
var data = await query.ToArrayAsync(token);
|
if (request.LeDateStart.HasValue)
|
||||||
var result = data.Select(g =>
|
{
|
||||||
(
|
var leDateStart = request.LeDateStart.Value.ToUniversalTime();
|
||||||
g.IdTelemetry,
|
query = query.Where(operation => operation.DateStart <= leDateStart);
|
||||||
g.RotorDepthInterval,
|
}
|
||||||
g.SlideDepthInterval
|
|
||||||
));
|
if (request.LeDateEnd.HasValue)
|
||||||
|
{
|
||||||
|
var leDateEnd = request.LeDateEnd.Value.ToUniversalTime();
|
||||||
|
query = query.Where(operation => operation.DateEnd <= leDateEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.GeDepthStart.HasValue)
|
||||||
|
query = query.Where(operation => operation.DepthStart >= request.GeDepthStart.Value);
|
||||||
|
|
||||||
|
if (request.LeDepthStart.HasValue)
|
||||||
|
query = query.Where(operation => operation.DepthStart <= request.LeDepthStart.Value);
|
||||||
|
|
||||||
|
if (request.LeDepthEnd.HasValue)
|
||||||
|
query = query.Where(operation => operation.DepthEnd <= request.LeDepthEnd.Value);
|
||||||
|
|
||||||
|
var queryGroup = query
|
||||||
|
.GroupBy(operation => new { operation.IdTelemetry, operation.IdCategory })
|
||||||
|
.Select(group => new OperationsSummaryDto
|
||||||
|
{
|
||||||
|
IdTelemetry = group.Key.IdTelemetry,
|
||||||
|
IdCategory = group.Key.IdCategory,
|
||||||
|
Count = group.Count(),
|
||||||
|
SumDepthIntervals = group.Sum(operation => operation.DepthEnd - operation.DepthStart),
|
||||||
|
SumDurationHours = group.Sum(operation => (operation.DateEnd - operation.DateStart).TotalHours)
|
||||||
|
})
|
||||||
|
.OrderBy(summ => summ.IdTelemetry)
|
||||||
|
.ThenBy(summ => summ.IdCategory);
|
||||||
|
|
||||||
|
var result = await queryGroup.ToArrayAsync(token);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
WellDepth = message.WellDepth
|
WellDepth = message.WellDepth
|
||||||
};
|
};
|
||||||
|
|
||||||
messageDto.Date = message.DateTime.ToRemoteDateTime(timezone.Hours);
|
messageDto.DateTime = message.DateTime.ToRemoteDateTime(timezone.Hours);
|
||||||
|
|
||||||
if (message.IdTelemetryUser is not null)
|
if (message.IdTelemetryUser is not null)
|
||||||
{
|
{
|
||||||
|
163
AsbCloudInfrastructure/Services/SlipsStatService.cs
Normal file
163
AsbCloudInfrastructure/Services/SlipsStatService.cs
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Services;
|
||||||
|
|
||||||
|
public class SlipsStatService : ISlipsStatService
|
||||||
|
{
|
||||||
|
private readonly IAsbCloudDbContext db;
|
||||||
|
|
||||||
|
public SlipsStatService(IAsbCloudDbContext db)
|
||||||
|
{
|
||||||
|
this.db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<SlipsStatDto>> GetAllAsync(OperationStatRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
if (request.DateStartUTC.HasValue)
|
||||||
|
request.DateStartUTC = DateTime.SpecifyKind(request.DateStartUTC.Value, DateTimeKind.Utc);
|
||||||
|
|
||||||
|
if (request.DateEndUTC.HasValue)
|
||||||
|
request.DateEndUTC = DateTime.SpecifyKind(request.DateEndUTC.Value, DateTimeKind.Utc);
|
||||||
|
|
||||||
|
var schedulesQuery = db.Schedule
|
||||||
|
.Include(s => s.Well)
|
||||||
|
.Include(s => s.Driller)
|
||||||
|
.AsNoTracking();
|
||||||
|
|
||||||
|
if (request.DateStartUTC.HasValue && request.DateEndUTC.HasValue)
|
||||||
|
schedulesQuery = schedulesQuery.
|
||||||
|
Where(s => s.DrillStart >= request.DateStartUTC && s.DrillEnd <= request.DateEndUTC);
|
||||||
|
|
||||||
|
var schedules = await schedulesQuery.ToArrayAsync(token);
|
||||||
|
|
||||||
|
var wells = schedules
|
||||||
|
.Select(d => d.Well)
|
||||||
|
.Where(well => well.IdTelemetry != null)
|
||||||
|
.GroupBy(w => w.Id)
|
||||||
|
.ToDictionary(g => g.Key, g => g.First().IdTelemetry!.Value);
|
||||||
|
|
||||||
|
var idsWells = wells.Keys;
|
||||||
|
var idsTelemetries = wells.Values;
|
||||||
|
var telemetries = wells.ToDictionary(wt => wt.Value, wt => wt.Key);
|
||||||
|
|
||||||
|
var factWellOperationsQuery = db.WellOperations
|
||||||
|
.Where(o => idsWells.Contains(o.IdWell))
|
||||||
|
.Where(o => o.IdType == 1)
|
||||||
|
.Where(o => WellOperationCategory.MechanicalDrillingSubIds.Contains(o.IdCategory))
|
||||||
|
.Include(o => o.WellSectionType)
|
||||||
|
.AsNoTracking();
|
||||||
|
|
||||||
|
if (request.DateStartUTC.HasValue && request.DateEndUTC.HasValue)
|
||||||
|
factWellOperationsQuery = factWellOperationsQuery
|
||||||
|
.Where(o => o.DateStart.AddHours(o.DurationHours) > request.DateStartUTC && o.DateStart < request.DateEndUTC);
|
||||||
|
|
||||||
|
var factWellOperations = await factWellOperationsQuery.ToArrayAsync(token);
|
||||||
|
|
||||||
|
var sections = factWellOperations
|
||||||
|
.GroupBy(o => new { o.IdWell, o.IdWellSectionType })
|
||||||
|
.Select(g => new
|
||||||
|
{
|
||||||
|
g.Key.IdWell,
|
||||||
|
g.Key.IdWellSectionType,
|
||||||
|
DepthStart = g.Min(o => o.DepthStart),
|
||||||
|
DepthEnd = g.Max(o => o.DepthEnd),
|
||||||
|
g.First().WellSectionType.Caption
|
||||||
|
});
|
||||||
|
|
||||||
|
var detectedOperationsQuery = db.DetectedOperations
|
||||||
|
.Where(o => idsTelemetries.Contains(o.IdTelemetry))
|
||||||
|
.Where(o => o.IdCategory == WellOperationCategory.IdSlipsTime)
|
||||||
|
.AsNoTracking();
|
||||||
|
|
||||||
|
if (request.DateStartUTC.HasValue && request.DateEndUTC.HasValue)
|
||||||
|
detectedOperationsQuery = detectedOperationsQuery
|
||||||
|
.Where(o => o.DateStart < request.DateEndUTC)
|
||||||
|
.Where(o => o.DateEnd > request.DateStartUTC);
|
||||||
|
|
||||||
|
if (request.DurationMinutesMin.HasValue)
|
||||||
|
{
|
||||||
|
var durationMinutesMin = TimeSpan.FromMinutes(request.DurationMinutesMin.Value);
|
||||||
|
detectedOperationsQuery = detectedOperationsQuery
|
||||||
|
.Where(o => o.DateEnd - o.DateStart >= durationMinutesMin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.DurationMinutesMax.HasValue)
|
||||||
|
{
|
||||||
|
var durationMinutesMax = TimeSpan.FromMinutes(request.DurationMinutesMax.Value);
|
||||||
|
detectedOperationsQuery = detectedOperationsQuery
|
||||||
|
.Where(o => o.DateEnd - o.DateStart <= durationMinutesMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
var detectedOperations = await detectedOperationsQuery
|
||||||
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
|
var detectedOperationsGroupedByDrillerAndSection = detectedOperations.Select(o => new
|
||||||
|
{
|
||||||
|
Operation = o,
|
||||||
|
IdWell = telemetries[o.IdTelemetry],
|
||||||
|
schedules.FirstOrDefault(s =>
|
||||||
|
s.IdWell == telemetries[o.IdTelemetry]
|
||||||
|
&& s.DrillStart <= o.DateStart
|
||||||
|
&& s.DrillEnd >= o.DateStart
|
||||||
|
&& new TimeDto(s.ShiftStart) <= new TimeDto(o.DateStart.DateTime)
|
||||||
|
&& new TimeDto(s.ShiftEnd) >= new TimeDto(o.DateStart.DateTime))
|
||||||
|
?.Driller,
|
||||||
|
Section = sections.FirstOrDefault(s =>
|
||||||
|
s.IdWell == telemetries[o.IdTelemetry]
|
||||||
|
&& s.DepthStart <= o.DepthStart
|
||||||
|
&& s.DepthEnd >= o.DepthStart)
|
||||||
|
})
|
||||||
|
.Where(o => o.Driller != null)
|
||||||
|
.Where(o => o.Section != null)
|
||||||
|
.Select(o => new
|
||||||
|
{
|
||||||
|
o.Operation,
|
||||||
|
o.IdWell,
|
||||||
|
Driller = o.Driller!,
|
||||||
|
Section = o.Section!
|
||||||
|
})
|
||||||
|
.GroupBy(o => new { o.Driller.Id, o.Section.IdWellSectionType });
|
||||||
|
|
||||||
|
|
||||||
|
var factWellOperationsGroupedByDrillerAndSection = factWellOperations
|
||||||
|
.Select(o => new
|
||||||
|
{
|
||||||
|
Operation = o,
|
||||||
|
schedules.FirstOrDefault(s =>
|
||||||
|
s.IdWell == o.IdWell
|
||||||
|
&& s.DrillStart <= o.DateStart
|
||||||
|
&& s.DrillEnd >= o.DateStart
|
||||||
|
&& new TimeDto(s.ShiftStart) <= new TimeDto(o.DateStart.DateTime)
|
||||||
|
&& new TimeDto(s.ShiftEnd) >= new TimeDto(o.DateStart.DateTime))
|
||||||
|
?.Driller,
|
||||||
|
})
|
||||||
|
.Where(o => o.Driller != null)
|
||||||
|
.GroupBy(o => new { o.Driller!.Id, o.Operation.IdWellSectionType });
|
||||||
|
|
||||||
|
|
||||||
|
var stats = detectedOperationsGroupedByDrillerAndSection.Select(group => new SlipsStatDto
|
||||||
|
{
|
||||||
|
DrillerName = $"{group.First().Driller!.Name} {group.First().Driller!.Patronymic} {group.First().Driller!.Surname}",
|
||||||
|
SlipsCount = group.Count(),
|
||||||
|
SlipsTimeInMinutes = group
|
||||||
|
.Sum(y => (y.Operation.DateEnd - y.Operation.DateStart).TotalMinutes),
|
||||||
|
SectionDepth = factWellOperationsGroupedByDrillerAndSection
|
||||||
|
.Where(o => o.Key.Id == group.Key.Id)
|
||||||
|
.Where(o => o.Key.IdWellSectionType == group.Key.IdWellSectionType)
|
||||||
|
.Sum(o => o.Max(op => op.Operation.DepthEnd) - o.Min(op => op.Operation.DepthStart)),
|
||||||
|
SectionCaption = group.First().Section.Caption,
|
||||||
|
WellCount = group.GroupBy(g => g.IdWell).Count(),
|
||||||
|
});
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
}
|
@ -16,10 +16,10 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.Subsystems
|
namespace AsbCloudInfrastructure.Services.Subsystems;
|
||||||
|
|
||||||
|
internal class SubsystemOperationTimeService : ISubsystemOperationTimeService
|
||||||
{
|
{
|
||||||
internal class SubsystemOperationTimeService : ISubsystemOperationTimeService
|
|
||||||
{
|
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
private readonly ICrudRepository<SubsystemDto> subsystemService;
|
private readonly ICrudRepository<SubsystemDto> subsystemService;
|
||||||
@ -30,6 +30,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
public const int IdSubsystemMSE = 2;
|
public const int IdSubsystemMSE = 2;
|
||||||
public const int IdSubsystemSpin = 65536;
|
public const int IdSubsystemSpin = 65536;
|
||||||
public const int IdSubsystemTorque = 65537;
|
public const int IdSubsystemTorque = 65537;
|
||||||
|
|
||||||
public SubsystemOperationTimeService(IAsbCloudDbContext db, IWellService wellService, ICrudRepository<SubsystemDto> subsystemService, IDetectedOperationService detectedOperationService)
|
public SubsystemOperationTimeService(IAsbCloudDbContext db, IWellService wellService, ICrudRepository<SubsystemDto> subsystemService, IDetectedOperationService detectedOperationService)
|
||||||
{
|
{
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@ -41,28 +42,27 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<int> DeleteAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
public async Task<int> DeleteAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var well = await wellService.GetOrDefaultAsync(request.IdWell, token);
|
var well = await wellService.GetOrDefaultAsync(request.IdWell, token)
|
||||||
if (well?.IdTelemetry is null || well.Timezone is null)
|
?? throw new ArgumentInvalidException(nameof(request.IdWell), $"Well Id: {request.IdWell} does not exist");
|
||||||
return 0;
|
|
||||||
var query = BuildQuery(request);
|
var query = BuildQuery(request, well);
|
||||||
if (query is null)
|
|
||||||
return 0;
|
|
||||||
db.SubsystemOperationTimes.RemoveRange(query);
|
db.SubsystemOperationTimes.RemoveRange(query);
|
||||||
return await db.SaveChangesAsync(token);
|
return await db.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<IEnumerable<SubsystemOperationTimeDto>?> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
public async Task<IEnumerable<SubsystemOperationTimeDto>> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var well = await wellService.GetOrDefaultAsync(request.IdWell, token);
|
var well = await wellService.GetOrDefaultAsync(request.IdWell, token)
|
||||||
if (well?.IdTelemetry is null || well.Timezone is null)
|
?? throw new ArgumentInvalidException(nameof(request.IdWell), $"Well Id: {request.IdWell} does not exist");
|
||||||
return null;
|
|
||||||
|
|
||||||
var query = BuildQuery(request);
|
var dtos = await GetOperationTimeAsync(request, well, token);
|
||||||
|
return dtos;
|
||||||
if (query is null)
|
}
|
||||||
return null;
|
|
||||||
|
|
||||||
|
private async Task<IEnumerable<SubsystemOperationTimeDto>> GetOperationTimeAsync(SubsystemOperationTimeRequest request, WellDto well, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request, well);
|
||||||
IEnumerable<SubsystemOperationTime> data = await query.ToListAsync(token);
|
IEnumerable<SubsystemOperationTime> data = await query.ToListAsync(token);
|
||||||
|
|
||||||
if (request.SelectMode == SubsystemOperationTimeRequest.SelectModeInner)
|
if (request.SelectMode == SubsystemOperationTimeRequest.SelectModeInner)
|
||||||
@ -85,28 +85,32 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<IEnumerable<SubsystemStatDto>?> GetStatAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
public async Task<IEnumerable<SubsystemStatDto>> GetStatAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
|
var well = await wellService.GetOrDefaultAsync(request.IdWell, token)
|
||||||
|
?? throw new ArgumentInvalidException(nameof(request.IdWell), $"Well Id: {request.IdWell} does not exist");
|
||||||
|
|
||||||
request.SelectMode = SubsystemOperationTimeRequest.SelectModeTrim;
|
request.SelectMode = SubsystemOperationTimeRequest.SelectModeTrim;
|
||||||
var data = await GetOperationTimeAsync(request, token);
|
var subsystemsTimes = await GetOperationTimeAsync(request, well, token);
|
||||||
if (data is null)
|
if (subsystemsTimes is null)
|
||||||
return null;
|
return Enumerable.Empty<SubsystemStatDto>();
|
||||||
|
|
||||||
var detectedOperationsRequest = new DetectedOperationRequest()
|
var detectedOperationSummaryRequest = new DetectedOperationSummaryRequest()
|
||||||
{
|
{
|
||||||
IdWell = request.IdWell,
|
IdsTelemetries = new[] {well.IdTelemetry!.Value},
|
||||||
IdsCategories = new int[] {
|
IdsOperationCategories = WellOperationCategory.MechanicalDrillingSubIds,
|
||||||
WellOperationCategory.IdRotor, WellOperationCategory.IdSlide,
|
|
||||||
},
|
|
||||||
LtDate = request.LtDate,
|
|
||||||
GtDate = request.GtDate,
|
|
||||||
};
|
|
||||||
var detectedOperations = await detectedOperationService.GetOperationsAsync(detectedOperationsRequest, token);
|
|
||||||
if(detectedOperations?.Any() != true)
|
|
||||||
return null;
|
|
||||||
var depthInterval = GetDepthInterval(detectedOperations);
|
|
||||||
|
|
||||||
var statList = CalcStat(data,depthInterval);
|
GeDateStart = request.GtDate,
|
||||||
|
LeDateStart = request.LtDate,
|
||||||
|
|
||||||
|
GeDepthStart = request.GtDepth,
|
||||||
|
LeDepthStart = request.LtDepth,
|
||||||
|
};
|
||||||
|
var operationsSummaries = await detectedOperationService.GetOperationSummaryAsync(detectedOperationSummaryRequest, token);
|
||||||
|
if(!operationsSummaries.Any())
|
||||||
|
return Enumerable.Empty<SubsystemStatDto>();
|
||||||
|
|
||||||
|
var statList = CalcStat(subsystemsTimes, operationsSummaries);
|
||||||
return statList;
|
return statList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,28 +149,29 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<SubsystemStatDto> CalcStat(
|
private IEnumerable<SubsystemStatDto> CalcStat(
|
||||||
IEnumerable<SubsystemOperationTimeDto> dtos,
|
IEnumerable<SubsystemOperationTimeDto> subsystemsTimes,
|
||||||
(double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
IEnumerable<OperationsSummaryDto> operationsSummaries)
|
||||||
{
|
{
|
||||||
var groupedDataSubsystems = dtos
|
var groupedSubsystemsTimes = subsystemsTimes
|
||||||
.OrderBy(o => o.Id)
|
.OrderBy(o => o.Id)
|
||||||
.GroupBy(o => o.IdSubsystem);
|
.GroupBy(o => o.IdSubsystem);
|
||||||
var periodGroupTotal = dtos.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
|
||||||
|
|
||||||
var result = groupedDataSubsystems.Select(g =>
|
var periodGroupTotal = subsystemsTimes.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
||||||
|
|
||||||
|
var result = groupedSubsystemsTimes.Select(g =>
|
||||||
{
|
{
|
||||||
var depthIntervalSubsystem = GetDepthIntervalSubsystem(g.Key, depthInterval);
|
|
||||||
var periodGroup = g.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
var periodGroup = g.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
||||||
var periodGroupDepth = g.Sum(o => o.DepthEnd - o.DepthStart);
|
var periodGroupDepth = g.Sum(o => o.DepthEnd - o.DepthStart);
|
||||||
|
var (sumOprationsDepth, sumOprationsDurationHours) = AggregateOperationsSummaries(g.Key, operationsSummaries);
|
||||||
var subsystemStat = new SubsystemStatDto()
|
var subsystemStat = new SubsystemStatDto()
|
||||||
{
|
{
|
||||||
IdSubsystem = g.Key,
|
IdSubsystem = g.Key,
|
||||||
SubsystemName = subsystemService.GetOrDefault(g.Key)?.Name ?? "unknown",
|
SubsystemName = subsystemService.GetOrDefault(g.Key)?.Name ?? "unknown",
|
||||||
UsedTimeHours = periodGroup,
|
UsedTimeHours = periodGroup,
|
||||||
//% использования = суммарная проходка АПД в слайде
|
SumOperationDepthInterval = sumOprationsDepth,
|
||||||
/// суммарную проходку автоопределенных операций в слайде.
|
SumOperationDurationHours = sumOprationsDurationHours,
|
||||||
KUsage = periodGroupDepth / depthIntervalSubsystem,
|
|
||||||
SumDepthInterval = periodGroupDepth,
|
SumDepthInterval = periodGroupDepth,
|
||||||
|
KUsage = periodGroupDepth / sumOprationsDepth,
|
||||||
OperationCount = g.Count(),
|
OperationCount = g.Count(),
|
||||||
};
|
};
|
||||||
if (subsystemStat.KUsage > 1)
|
if (subsystemStat.KUsage > 1)
|
||||||
@ -182,57 +187,37 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
IdSubsystem = IdSubsystemAKB,
|
IdSubsystem = IdSubsystemAKB,
|
||||||
SubsystemName = "АПД",
|
SubsystemName = "АПД",
|
||||||
UsedTimeHours = apdParts.Sum(part => part.UsedTimeHours),
|
UsedTimeHours = apdParts.Sum(part => part.UsedTimeHours),
|
||||||
KUsage = apdParts.Sum(part => part.SumDepthInterval) / GetDepthIntervalSubsystem(IdSubsystemAKB, depthInterval),
|
SumOperationDepthInterval = apdParts.Sum(part => part.SumOperationDepthInterval),
|
||||||
|
SumOperationDurationHours = apdParts.Sum(part => part.SumOperationDurationHours),
|
||||||
SumDepthInterval = apdParts.Sum(part => part.SumDepthInterval),
|
SumDepthInterval = apdParts.Sum(part => part.SumDepthInterval),
|
||||||
OperationCount = apdParts.Sum(part => part.OperationCount),
|
OperationCount = apdParts.Sum(part => part.OperationCount),
|
||||||
};
|
};
|
||||||
|
apdSum.KUsage = apdSum.SumDepthInterval / apdSum.SumOperationDepthInterval;
|
||||||
|
if (apdSum.KUsage > 1)
|
||||||
|
apdSum.KUsage = 1;
|
||||||
result = result.Append(apdSum).OrderBy(m => m.IdSubsystem);
|
result = result.Append(apdSum).OrderBy(m => m.IdSubsystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static (double depthIntervalRotor, double depthIntervalSlide) GetDepthInterval (IEnumerable<DetectedOperationDto> detectedOperations)
|
private static (double SumDepth, double SumDurationHours) AggregateOperationsSummaries(int idSubsystem, IEnumerable<OperationsSummaryDto> operationsSummaries)
|
||||||
|
=> idSubsystem switch
|
||||||
{
|
{
|
||||||
var depthIntervalRotor = detectedOperations.Where(o => o.IdCategory == WellOperationCategory.IdRotor)
|
IdSubsystemAKBRotor or IdSubsystemTorque => CalcOperationSummariesByCategories(operationsSummaries, WellOperationCategory.IdRotor),
|
||||||
.Sum(o => o.DepthEnd - o.DepthStart);
|
IdSubsystemAKBSlide or IdSubsystemSpin => CalcOperationSummariesByCategories(operationsSummaries, WellOperationCategory.IdSlide),
|
||||||
var depthIntervalSlide = detectedOperations.Where(o => o.IdCategory == WellOperationCategory.IdSlide)
|
IdSubsystemAKB or IdSubsystemMSE => CalcOperationSummariesByCategories(operationsSummaries, WellOperationCategory.IdRotor, WellOperationCategory.IdSlide),
|
||||||
.Sum(o => o.DepthEnd - o.DepthStart);
|
_ => throw new ArgumentException($"idSubsystem: {idSubsystem} does not supported in this method", nameof(idSubsystem)),
|
||||||
var depthInterval = (depthIntervalRotor, depthIntervalSlide);
|
};
|
||||||
|
|
||||||
return depthInterval;
|
private static (double SumDepth, double SumDurationHours) CalcOperationSummariesByCategories(
|
||||||
}
|
IEnumerable<OperationsSummaryDto> operationsSummaries,
|
||||||
|
params int[] idsOperationCategories)
|
||||||
private static double GetDepthIntervalSubsystem(int idSubsystem, (double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
|
||||||
{
|
{
|
||||||
var depthIntervalSubsystem = 0d;
|
var filtered = operationsSummaries.Where(sum => idsOperationCategories.Contains(sum.IdCategory));
|
||||||
//AKB - MSE
|
var sumDepth = filtered.Sum(summ => summ.SumDepthIntervals);
|
||||||
if (idSubsystem == IdSubsystemAKB | idSubsystem == IdSubsystemMSE)
|
var sumDurationHours = filtered.Sum(summ => summ.SumDurationHours);
|
||||||
{
|
return (sumDepth, sumDurationHours);
|
||||||
depthIntervalSubsystem = depthInterval.depthIntervalRotor + depthInterval.depthIntervalSlide;
|
|
||||||
}
|
|
||||||
//AKB - Rotor
|
|
||||||
if (idSubsystem == IdSubsystemAKBRotor)
|
|
||||||
{
|
|
||||||
depthIntervalSubsystem = depthInterval.depthIntervalRotor;
|
|
||||||
}
|
|
||||||
//AKB - Slide
|
|
||||||
if (idSubsystem == IdSubsystemAKBSlide)
|
|
||||||
{
|
|
||||||
depthIntervalSubsystem = depthInterval.depthIntervalSlide;
|
|
||||||
}
|
|
||||||
//Spin
|
|
||||||
if (idSubsystem == IdSubsystemSpin)
|
|
||||||
{
|
|
||||||
depthIntervalSubsystem = depthInterval.depthIntervalSlide;
|
|
||||||
}
|
|
||||||
//Torque
|
|
||||||
if (idSubsystem == IdSubsystemTorque)
|
|
||||||
{
|
|
||||||
depthIntervalSubsystem = depthInterval.depthIntervalRotor;
|
|
||||||
}
|
|
||||||
return depthIntervalSubsystem;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@ -273,21 +258,27 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
.DateTime
|
.DateTime
|
||||||
.ToUtcDateTimeOffset(hoursOffset);
|
.ToUtcDateTimeOffset(hoursOffset);
|
||||||
|
|
||||||
var telemetryIds = wells
|
IEnumerable<int> idsTelemetries = wells
|
||||||
.Where(w => w.IdTelemetry is not null)
|
.Where(w => w.IdTelemetry is not null)
|
||||||
.Select(w => w.IdTelemetry)
|
.Select(w => w.IdTelemetry!.Value)
|
||||||
.Distinct();
|
.Distinct();
|
||||||
|
|
||||||
var query = db.SubsystemOperationTimes
|
var query = db.SubsystemOperationTimes
|
||||||
.Where(o => telemetryIds.Contains(o.IdTelemetry) &&
|
.Where(o => idsTelemetries.Contains(o.IdTelemetry) &&
|
||||||
o.DateStart >= beginUTC &&
|
o.DateStart >= beginUTC &&
|
||||||
o.DateEnd <= endUTC)
|
o.DateEnd <= endUTC)
|
||||||
.AsNoTracking();
|
.AsNoTracking();
|
||||||
|
|
||||||
var subsystemsOperationTime = await query.ToListAsync(token);
|
var subsystemsOperationTime = await query.ToArrayAsync(token);
|
||||||
|
|
||||||
var depthIntervals = await detectedOperationService
|
var operationSummaries = await detectedOperationService
|
||||||
.GetDepthIntervalAllOperationsAsync(telemetryIds, beginUTC, endUTC, token);
|
.GetOperationSummaryAsync(new ()
|
||||||
|
{
|
||||||
|
IdsTelemetries = idsTelemetries,
|
||||||
|
IdsOperationCategories = WellOperationCategory.MechanicalDrillingSubIds,
|
||||||
|
GeDateStart = beginUTC,
|
||||||
|
LeDateEnd = endUTC,
|
||||||
|
}, token);
|
||||||
|
|
||||||
var result = wells
|
var result = wells
|
||||||
.Select(well => {
|
.Select(well => {
|
||||||
@ -295,21 +286,22 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
.Where(s => s.IdTelemetry == well.IdTelemetry)
|
.Where(s => s.IdTelemetry == well.IdTelemetry)
|
||||||
.Select(s => Convert(s, well.Timezone.Hours));
|
.Select(s => Convert(s, well.Timezone.Hours));
|
||||||
|
|
||||||
var (idTelemetry, depthIntervalRotor, depthIntervalSlide) = depthIntervals
|
var wellStat = new SubsystemActiveWellStatDto{ Well = well };
|
||||||
.FirstOrDefault(i => i.idTelemetry == well.IdTelemetry);
|
|
||||||
|
|
||||||
var subsystemStat = idTelemetry > 0 && dtos.Any()
|
var telemetryOperationSummaries = operationSummaries.Where(summ => summ.IdTelemetry == well.IdTelemetry);
|
||||||
? CalcStat(dtos, (depthIntervalRotor, depthIntervalSlide))
|
if (telemetryOperationSummaries.Any())
|
||||||
: Enumerable.Empty<SubsystemStatDto>();
|
|
||||||
|
|
||||||
return new SubsystemActiveWellStatDto
|
|
||||||
{
|
{
|
||||||
Well = well,
|
var subsystemStat = CalcStat(dtos, telemetryOperationSummaries);
|
||||||
SubsystemAKB = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemAKB),
|
if (subsystemStat.Any())
|
||||||
SubsystemMSE = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemMSE),
|
{
|
||||||
SubsystemSpinMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemSpin),
|
wellStat.SubsystemAKB = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemAKB);
|
||||||
SubsystemTorqueMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemTorque),
|
wellStat.SubsystemMSE = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemMSE);
|
||||||
};
|
wellStat.SubsystemSpinMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemSpin);
|
||||||
|
wellStat.SubsystemTorqueMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemTorque);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return wellStat;
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -318,7 +310,10 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<DatesRangeDto?> GetDateRangeOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
public async Task<DatesRangeDto?> GetDateRangeOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = BuildQuery(request);
|
var well = await wellService.GetOrDefaultAsync(request.IdWell, token)
|
||||||
|
?? throw new ArgumentInvalidException(nameof(request.IdWell), $"Well Id: {request.IdWell} does not exist");
|
||||||
|
|
||||||
|
var query = BuildQuery(request, well);
|
||||||
if (query is null)
|
if (query is null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@ -334,14 +329,14 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IQueryable<SubsystemOperationTime> BuildQuery(SubsystemOperationTimeRequest request)
|
private IQueryable<SubsystemOperationTime> BuildQuery(SubsystemOperationTimeRequest request, WellDto well)
|
||||||
{
|
{
|
||||||
var well = wellService.GetOrDefault(request.IdWell)
|
var idTelemetry = well.IdTelemetry
|
||||||
?? throw new ArgumentInvalidException(nameof(request.IdWell), $"Not valid IdWell = {request.IdWell}");
|
?? throw new ArgumentInvalidException(nameof(request.IdWell), $"Well Id: {request.IdWell} has no telemetry");
|
||||||
|
|
||||||
var query = db.SubsystemOperationTimes
|
var query = db.SubsystemOperationTimes
|
||||||
.Include(o => o.Subsystem)
|
.Include(o => o.Subsystem)
|
||||||
.Where(o => o.IdTelemetry == well.IdTelemetry)
|
.Where(o => o.IdTelemetry == idTelemetry)
|
||||||
.AsNoTracking();
|
.AsNoTracking();
|
||||||
|
|
||||||
if (request.IdsSubsystems.Any())
|
if (request.IdsSubsystems.Any())
|
||||||
@ -396,5 +391,4 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
dto.DateEnd = operationTime.DateEnd.ToRemoteDateTime(hours);
|
dto.DateEnd = operationTime.DateEnd.ToRemoteDateTime(hours);
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
53
AsbCloudWebApi/Controllers/SlipsStatController.cs
Normal file
53
AsbCloudWebApi/Controllers/SlipsStatController.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Exceptions;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Аналитика по удержанию в клиньях
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/slipsStat")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class SlipsStatController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ISlipsStatService slipsAnalyticsService;
|
||||||
|
|
||||||
|
public SlipsStatController(ISlipsStatService slipsAnalyticsService)
|
||||||
|
{
|
||||||
|
this.slipsAnalyticsService = slipsAnalyticsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить аналитику по удержанию в клиньях (по бурильщикам)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">Параметры запроса</param>
|
||||||
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
|
/// <returns>Список бурильщиков</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<SlipsStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetAllAsync(
|
||||||
|
[FromQuery] OperationStatRequest request,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
var idUser = User.GetUserId();
|
||||||
|
|
||||||
|
if (!idUser.HasValue)
|
||||||
|
throw new ForbidException("Не удается вас опознать");
|
||||||
|
|
||||||
|
var data = await slipsAnalyticsService.GetAllAsync(request, token).ConfigureAwait(false);
|
||||||
|
return Ok(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user