Метод получения минимальных и максимальных глубин для последующего расчета наработки подсистем

This commit is contained in:
Olga Nemt 2024-10-02 12:10:01 +05:00
parent a137136e21
commit 58d7c11940
5 changed files with 45 additions and 27 deletions

View File

@ -15,14 +15,24 @@ public interface ITelemetryDataSaubService : ITelemetryDataService<TelemetryData
/// <summary> /// <summary>
/// Получение телеметрии для РТК статистики /// Получение телеметрии для РТК статистики
/// </summary> /// </summary>
/// <param name="idsTelemetries"></param> /// <param name="idTelemetry"></param>
/// <param name="isBitOnBottom"></param> /// <param name="isBitOnBottom"></param>
/// <param name="geDate"></param> /// <param name="geDate"></param>
/// <param name="leDate"></param> /// <param name="leDate"></param>
/// <param name="take"></param> /// <param name="take"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<TelemetryDataSaubDto>> Get(IEnumerable<int> idsTelemetries, bool isBitOnBottom, DateTimeOffset geDate, DateTimeOffset leDate, int take, CancellationToken token); Task<IEnumerable<TelemetryDataSaubDto>> Get(int idTelemetry, bool isBitOnBottom, DateTimeOffset geDate, DateTimeOffset leDate, int take, CancellationToken token);
/// <summary>
/// Получение минимальных и максимальных глубин скважин на определенную дату для заданных телеметрий
/// </summary>
/// <param name="idsTelemetries"></param>
/// <param name="geDate"></param>
/// <param name="leDate"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<Dictionary<int, (float MinDepth, float MaxDepth)>> GetMinAndMaxWellDepths(IEnumerable<int> idsTelemetries, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token);
/// <summary> /// <summary>
/// усредненная статистика по 1м за весь период /// усредненная статистика по 1м за весь период

View File

@ -220,7 +220,7 @@ public class DataSaubStatServiceTest
} }
dataSaubServiceMock dataSaubServiceMock
.Get(Arg.Any<IEnumerable<int>>(), Arg.Any<bool>(), Arg.Any<DateTimeOffset>(), Arg.Any<DateTimeOffset>(), Arg.Any<int>(), Arg.Any<CancellationToken>()) .Get(Arg.Any<int>(), Arg.Any<bool>(), Arg.Any<DateTimeOffset>(), Arg.Any<DateTimeOffset>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(telemetryDataSaubDtos); .Returns(telemetryDataSaubDtos);
dataSaubStatService = new DataSaubStatService( dataSaubStatService = new DataSaubStatService(

View File

@ -78,7 +78,7 @@ public class DataSaubStatService : IDataSaubStatService
var geDate = detectedOperations.First().DateStart; var geDate = detectedOperations.First().DateStart;
var leDate = detectedOperations.OrderByDescending(d => d.DateEnd).First().DateEnd; var leDate = detectedOperations.OrderByDescending(d => d.DateEnd).First().DateEnd;
var dataSaub = await dataSaubService.Get([idTelemetry], true, geDate, leDate, 100_000, token); var dataSaub = await dataSaubService.Get(idTelemetry, true, geDate, leDate, 100_000, token);
if (!dataSaub.Any()) if (!dataSaub.Any())
return 0; return 0;

View File

@ -13,8 +13,6 @@ using System.Linq;
using System.Text.Csv; using System.Text.Csv;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Requests;
namespace AsbCloudInfrastructure.Services.SAUB; namespace AsbCloudInfrastructure.Services.SAUB;
@ -37,19 +35,14 @@ public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSa
this.telemetryUserService = telemetryUserService; this.telemetryUserService = telemetryUserService;
} }
public async Task<IEnumerable<TelemetryDataSaubDto>> Get(IEnumerable<int> idsTelemetries, bool isBitOnBottom, DateTimeOffset geDate, DateTimeOffset leDate, int take, CancellationToken token) public async Task<IEnumerable<TelemetryDataSaubDto>> Get(int idTelemetry, bool isBitOnBottom, DateTimeOffset geDate, DateTimeOffset leDate, int take, CancellationToken token)
{ {
var offsetDict = new Dictionary<int, TimeSpan>(); var offset = telemetryService.GetTimezone(idTelemetry).Offset;
foreach (var idTelemetry in idsTelemetries)
{
offsetDict.Add(idTelemetry, telemetryService.GetTimezone(idTelemetry).Offset);
}
var geDateUtc = geDate.ToUniversalTime(); var geDateUtc = geDate.ToUniversalTime();
var leDateUtc = leDate.ToUniversalTime(); var leDateUtc = leDate.ToUniversalTime();
var query = db.Set<TelemetryDataSaub>() var query = db.Set<TelemetryDataSaub>()
.Where(t => idsTelemetries.Contains(t.IdTelemetry)) .Where(t => t.IdTelemetry == idTelemetry)
.Where(t => t.DateTime >= geDateUtc) .Where(t => t.DateTime >= geDateUtc)
.Where(t => t.DateTime <= leDateUtc); .Where(t => t.DateTime <= leDateUtc);
@ -61,10 +54,31 @@ public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSa
.Take(take); .Take(take);
var entities = await query.ToArrayAsync(token); var entities = await query.ToArrayAsync(token);
var dtos = entities.Select(e => Convert(e, offsetDict.GetValueOrDefault(e.IdTelemetry).TotalHours));
var dtos = entities.Select(e => Convert(e, offset.TotalHours));
return dtos; return dtos;
} }
public async Task<Dictionary<int, (float MinDepth, float MaxDepth)>> GetMinAndMaxWellDepths(IEnumerable<int> idsTelemetries, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token)
{
var geDateUtc = geDate.ToUniversalTime();
var leDateUtc = leDate.ToUniversalTime();
var query = db.Set<TelemetryDataSaub>()
.Where(t => idsTelemetries.Contains(t.IdTelemetry))
.Where(t => t.DateTime >= geDateUtc)
.Where(t => t.DateTime <= leDateUtc)
.GroupBy(t => t.IdTelemetry);
var result = await query
.ToDictionaryAsync(t => t.Key, t => (
t.MinBy(x => x.WellDepth)!.WellDepth,
t.MaxBy(x => x.WellDepth)!.WellDepth
));
return result;
}
public async Task<IEnumerable<TelemetryDataSaubStatDto>> GetTelemetryDataStatAsync(int idTelemetry, CancellationToken token) public async Task<IEnumerable<TelemetryDataSaubStatDto>> GetTelemetryDataStatAsync(int idTelemetry, CancellationToken token)
{ {
var timezone = telemetryService.GetTimezone(idTelemetry); var timezone = telemetryService.GetTimezone(idTelemetry);

View File

@ -141,26 +141,20 @@ public class SubsystemService : ISubsystemService
.GetOrDefaultTelemetriesByIdsWells(request.IdsWell) .GetOrDefaultTelemetriesByIdsWells(request.IdsWell)
.ToDictionary(t => t.Id, t => t.IdWell); .ToDictionary(t => t.Id, t => t.IdWell);
var dtNow = DateTimeOffset.UtcNow;
var geDate = request.GeDate ?? SubsystemPlanFactRequest.ValidationMinDate; var geDate = request.GeDate ?? SubsystemPlanFactRequest.ValidationMinDate;
var leDate = request.LeDate ?? DateTimeOffset.UtcNow; var leDate = request.LeDate ?? DateTimeOffset.UtcNow;
var telemetryDataSaub = await telemetryDataSaubService.Get(telemetriesDict.Keys, false, geDate, leDate, 100_000, token); var groupedTelemetryDataSaub = await telemetryDataSaubService.GetMinAndMaxWellDepths(telemetriesDict.Keys, geDate, leDate, token);
var groupedTelemetryDataSaub = telemetryDataSaub
.GroupBy(t => t.IdTelemetry)
.ToDictionary(t => t.Key, t => new
{
IdWell = telemetriesDict.GetValueOrDefault(t.Key)!,
MinDepth = t.MinBy(x => x.WellDepth)!.WellDepth,
MaxDepth = t.MaxBy(x => x.WellDepth)!.WellDepth
});
var result = new List<SubsystemPlanFactStatDto>(); var result = new List<SubsystemPlanFactStatDto>();
foreach (var telemetryDataSaubItem in groupedTelemetryDataSaub) foreach (var telemetryDataSaubItem in groupedTelemetryDataSaub)
{ {
var idWell = telemetriesDict.GetValueOrDefault(telemetryDataSaubItem.Key);
if (!idWell.HasValue)
continue;
var telemetryDataSaubInfo = telemetryDataSaubItem.Value; var telemetryDataSaubInfo = telemetryDataSaubItem.Value;
var requestProcessMapPlan = new ProcessMapPlanBaseRequestWithWell(telemetryDataSaubInfo.IdWell!.Value, telemetryDataSaubInfo.MinDepth, telemetryDataSaubInfo.MaxDepth); var requestProcessMapPlan = new ProcessMapPlanBaseRequestWithWell(idWell.Value, telemetryDataSaubInfo.MinDepth, telemetryDataSaubInfo.MaxDepth);
var processMapPlanSubsystems = await processMapPlanRepository.GetCurrent(requestProcessMapPlan, token); var processMapPlanSubsystems = await processMapPlanRepository.GetCurrent(requestProcessMapPlan, token);
foreach (var processMapPlanSubsystem in processMapPlanSubsystems) foreach (var processMapPlanSubsystem in processMapPlanSubsystems)