forked from ddrilling/AsbCloudServer
#7554801 Printify
This commit is contained in:
parent
5f9b4594fe
commit
06428838c5
@ -10,7 +10,7 @@ namespace AsbCloudApp.Data.Subsystems
|
||||
/// <summary>
|
||||
/// Активная скважина
|
||||
/// </summary>
|
||||
public WellDto ActiveWell { get; set; }
|
||||
public WellDto Well { get; set; }
|
||||
/// <summary>
|
||||
/// Наработки подсистемы АКБ
|
||||
/// </summary>
|
||||
|
@ -48,7 +48,7 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="ltDate"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns>кортеж - ид телеметрии, интервалы глубины забоя (ротор,слайд) </returns>
|
||||
Task<IEnumerable<(int idTelemetry,double depthIntervalRotor, double depthIntervalSlide)>?> GetDepthIntervalAllOperationsAsync(IEnumerable<int?> telemetryIds,DateTimeOffset gtDate, DateTimeOffset ltDate, CancellationToken token);
|
||||
Task<IEnumerable<(int idTelemetry,double depthIntervalRotor, double depthIntervalSlide)>> GetDepthIntervalAllOperationsAsync(IEnumerable<int?> telemetryIds,DateTimeOffset gtDate, DateTimeOffset ltDate, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить операции
|
||||
|
@ -55,7 +55,7 @@ namespace AsbCloudApp.Services.Subsystems
|
||||
/// <param name="ltDate"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<SubsystemActiveWellStatDto>?> GetStatByActiveWells(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token);
|
||||
Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatByActiveWells(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token);
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
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<(int idTelemetry, double depthIntervalRotor, double depthIntervalSlide)>> GetDepthIntervalAllOperationsAsync(IEnumerable<int?> telemetryIds, DateTimeOffset gtDate, DateTimeOffset ltDate, CancellationToken token)
|
||||
{
|
||||
var query = db.Set<DetectedOperation>()
|
||||
.Include(o => o.OperationCategory)
|
||||
@ -98,18 +98,14 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
RotorDepthInterval = g.Where(o => o.IdCategory == IdOperationRotor).Sum(o => o.DepthEnd - o.DepthStart),
|
||||
SlideDepthInterval = g.Where(o => o.IdCategory == IdOperationSlide).Sum(o => o.DepthEnd - o.DepthStart)
|
||||
});
|
||||
var data = await query.ToListAsync(token);
|
||||
if (data.Any())
|
||||
{
|
||||
var result = data.Select(g =>
|
||||
(
|
||||
g.IdTelemetry,
|
||||
g.RotorDepthInterval,
|
||||
g.SlideDepthInterval
|
||||
));
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
var data = await query.ToArrayAsync(token);
|
||||
var result = data.Select(g =>
|
||||
(
|
||||
g.IdTelemetry,
|
||||
g.RotorDepthInterval,
|
||||
g.SlideDepthInterval
|
||||
));
|
||||
return result;
|
||||
}
|
||||
|
||||
private static IEnumerable<DetectedOperationDrillersStatDto> GetOperationsDrillersStat(IEnumerable<DetectedOperationDto> operations)
|
||||
|
@ -79,7 +79,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
data = Trim(data, begin, end);
|
||||
}
|
||||
|
||||
var dtos = data.Select(o => Convert(o, well));
|
||||
var dtos = data.Select(o => Convert(o, well.Timezone.Hours));
|
||||
return dtos;
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
|
||||
return result;
|
||||
}
|
||||
private (double depthIntervalRotor, double depthIntervalSlide) GetDepthInterval (IEnumerable<DetectedOperationDto> detectedOperations)
|
||||
private static (double depthIntervalRotor, double depthIntervalSlide) GetDepthInterval (IEnumerable<DetectedOperationDto> detectedOperations)
|
||||
{
|
||||
var depthIntervalRotor = detectedOperations.Where(o => o.IdCategory == 1)
|
||||
.Sum(o => o.DepthEnd - o.DepthStart);
|
||||
@ -166,7 +166,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
|
||||
return depthInterval;
|
||||
}
|
||||
private double GetDepthIntervalSubsystem(int idSubsystem, (double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
||||
private static double GetDepthIntervalSubsystem(int idSubsystem, (double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
||||
{
|
||||
var depthIntervalSubsystem = 0d;
|
||||
//AKB - MSE
|
||||
@ -193,59 +193,67 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
var listWell = await wellService.GetWellsByCompanyAsync(idCompany, token);
|
||||
var active = listWell.Where(w => w.IdState == 1);
|
||||
return active;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<SubsystemActiveWellStatDto>?> GetStatByActiveWells(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token)
|
||||
/// <inheritdoc/>
|
||||
public async Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatByActiveWells(int idCompany, DateTime? gtDate, DateTime? ltDate, CancellationToken token)
|
||||
{
|
||||
var activeWell = await GetActiveWellsByCompany(idCompany, token);
|
||||
var telemetryIds = activeWell.Select(w => w.IdTelemetry).Distinct();
|
||||
var firstWell = activeWell.FirstOrDefault();
|
||||
if (firstWell == null)
|
||||
var wells = await GetActiveWellsByCompany(idCompany, token);
|
||||
if (!wells.Any())
|
||||
return Enumerable.Empty<SubsystemActiveWellStatDto>();
|
||||
var result =activeWell.Select( t => new SubsystemActiveWellStatDto
|
||||
{
|
||||
ActiveWell = t
|
||||
}).ToList();
|
||||
|
||||
var hoursOffset = wells
|
||||
.FirstOrDefault(well => well.Timezone is not null)
|
||||
?.Timezone.Hours
|
||||
?? 5d;
|
||||
|
||||
var beginUTC = gtDate.HasValue
|
||||
? gtDate.Value.ToUtcDateTimeOffset(hoursOffset)
|
||||
:DateTime.Today.AddDays(-1).ToUtcDateTimeOffset(hoursOffset);
|
||||
|
||||
var endUTC = ltDate.HasValue
|
||||
? ltDate.Value.ToUtcDateTimeOffset(hoursOffset)
|
||||
: DateTime.Today.ToUtcDateTimeOffset(hoursOffset);
|
||||
|
||||
var telemetryIds = wells
|
||||
.Where(w => w.IdTelemetry is not null)
|
||||
.Select(w => w.IdTelemetry)
|
||||
.Distinct();
|
||||
|
||||
var query = db.SubsystemOperationTimes
|
||||
.Where(o => telemetryIds.Contains(o.IdTelemetry))
|
||||
.Where(o => telemetryIds.Contains(o.IdTelemetry) &&
|
||||
o.DateStart >= beginUTC &&
|
||||
o.DateEnd <= endUTC)
|
||||
.AsNoTracking();
|
||||
|
||||
var beginUTC = DateTime.Today.AddDays(-1).ToUtcDateTimeOffset(firstWell.Timezone.Hours);
|
||||
var endUTC = DateTime.Today.ToUtcDateTimeOffset(firstWell.Timezone.Hours);
|
||||
if (gtDate is not null)
|
||||
{
|
||||
beginUTC = gtDate.Value.ToUtcDateTimeOffset(firstWell.Timezone.Hours);
|
||||
}
|
||||
if (ltDate is not null)
|
||||
{
|
||||
endUTC = ltDate.Value.ToUtcDateTimeOffset(firstWell.Timezone.Hours);
|
||||
}
|
||||
query = query.Where(d => d.DateStart >= beginUTC);
|
||||
query = query.Where(o => o.DateEnd <= endUTC);
|
||||
|
||||
var depthIntervals = await detectedOperationService.GetDepthIntervalAllOperationsAsync(telemetryIds, beginUTC, endUTC, token);
|
||||
if (depthIntervals is null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
var subsystemsOperationTime = await query.ToListAsync(token);
|
||||
var groupingSubsystemsOperationTime = subsystemsOperationTime.GroupBy(g => g.IdTelemetry);
|
||||
foreach (var group in groupingSubsystemsOperationTime)
|
||||
{
|
||||
var well = result.Where(w => w.ActiveWell.IdTelemetry == group.Key).FirstOrDefault();
|
||||
if (well is not null)
|
||||
{
|
||||
var depthInterval = depthIntervals.Where(o => o.idTelemetry == well.ActiveWell.IdTelemetry).Select(o => (o.depthIntervalRotor, o.depthIntervalSlide)).FirstOrDefault();
|
||||
var dto = group.Select(s => s.Adapt<SubsystemOperationTimeDto>());
|
||||
var subsystemStat = CalcStat(dto, depthInterval);
|
||||
well.SubsystemAKB = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemAKB);
|
||||
well.SubsystemMSE = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemMSE);
|
||||
well.SubsystemSpinMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemSpin);
|
||||
well.SubsystemTorqueMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemTorque);
|
||||
}
|
||||
}
|
||||
|
||||
var depthIntervals = await detectedOperationService
|
||||
.GetDepthIntervalAllOperationsAsync(telemetryIds, beginUTC, endUTC, token);
|
||||
|
||||
var result = wells
|
||||
.Select(well => {
|
||||
var dtos = subsystemsOperationTime
|
||||
.Where(s => s.IdTelemetry == well.IdTelemetry)
|
||||
.Select(s => Convert(s, well.Timezone.Hours));
|
||||
|
||||
var (idTelemetry, depthIntervalRotor, depthIntervalSlide) = depthIntervals
|
||||
.FirstOrDefault(i => i.idTelemetry == well.IdTelemetry);
|
||||
|
||||
var subsystemStat = idTelemetry > 0 && dtos.Any()
|
||||
? CalcStat(dtos, (depthIntervalRotor, depthIntervalSlide))
|
||||
: Enumerable.Empty<SubsystemStatDto>();
|
||||
|
||||
return new SubsystemActiveWellStatDto
|
||||
{
|
||||
Well = well,
|
||||
SubsystemAKB = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemAKB),
|
||||
SubsystemMSE = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemMSE),
|
||||
SubsystemSpinMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemSpin),
|
||||
SubsystemTorqueMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemTorque),
|
||||
};
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -325,11 +333,12 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
return query;
|
||||
}
|
||||
|
||||
private static SubsystemOperationTimeDto Convert(SubsystemOperationTime operationTime, WellDto well)
|
||||
private static SubsystemOperationTimeDto Convert(SubsystemOperationTime operationTime, double? timezoneHours = null)
|
||||
{
|
||||
var dto = operationTime.Adapt<SubsystemOperationTimeDto>();
|
||||
dto.DateStart = operationTime.DateStart.ToRemoteDateTime(well.Timezone.Hours);
|
||||
dto.DateEnd = operationTime.DateEnd.ToRemoteDateTime(well.Timezone.Hours);
|
||||
var hours = timezoneHours ?? operationTime.Telemetry.TimeZone.Hours;
|
||||
dto.DateStart = operationTime.DateStart.ToRemoteDateTime(hours);
|
||||
dto.DateEnd = operationTime.DateEnd.ToRemoteDateTime(hours);
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
/// <param name="token"> Токен </param>
|
||||
/// <returns> </returns>
|
||||
[HttpGet("statByActiveWell")]
|
||||
[ProducesResponseType(typeof(IEnumerable<SubsystemStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(IEnumerable<SubsystemActiveWellStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetStatByWellAsync(DateTime? GtDate, DateTime? LtDate, CancellationToken token = default)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
|
Loading…
Reference in New Issue
Block a user