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