доработка SubsystemOperationTimeServie

This commit is contained in:
eugeniy_ivanov 2022-08-17 00:29:32 +05:00
parent 4f37564a7b
commit dcda244e3c

View File

@ -59,8 +59,8 @@ namespace AsbCloudInfrastructure.Services.Subsystems
}
if (request.SelectMode == SubsystemOperationTimeRequest.SelectModeTrim)
{
var begin = request.GtDate ?? throw new ArgumentNullException(nameof(request.GtDate));
var end = request.GtDate ?? throw new ArgumentNullException(nameof(request.LtDate));
var begin = request.GtDate ?? query.Min(d => d.DateStart).UtcDateTime;
var end = request.LtDate ?? query.Max(d => d.DateEnd).UtcDateTime;
var data = query.ToList();
data = Trim(data, begin, end);
return data.Select(o => Convert(o, well));
@ -79,7 +79,9 @@ namespace AsbCloudInfrastructure.Services.Subsystems
}
private List<SubsystemOperationTime> Trim(List<SubsystemOperationTime> data, DateTime gtDate, DateTime ltDate)
{
var itemsToTrim = data.Where(q => q.DateStart == gtDate & q.DateEnd == ltDate)
var itemsToTrim = data.Where(q =>
(q.DateStart >= gtDate && q.DateStart <= ltDate)||
(q.DateEnd >= gtDate && q.DateEnd <= ltDate))
.Select(o => new SubsystemOperationTime
{
Id = o.Id,
@ -87,29 +89,28 @@ namespace AsbCloudInfrastructure.Services.Subsystems
DateEnd = ltDate > o.DateEnd ? ltDate : o.DateEnd,
IdSubsystem = o.IdSubsystem,
IdTelemetry = o.IdTelemetry,
DepthEnd = o.DepthEnd,
DepthStart = o.DepthStart,
DepthEnd = ltDate>o.DateEnd ? null : o.DepthEnd,
DepthStart = gtDate < o.DateStart ? null : o.DepthStart,
Subsystem = o.Subsystem,
Telemetry = o.Telemetry
})
.ToList();
return itemsToTrim;
}
private IEnumerable<SubsystemStatDto> CalcStat(IEnumerable<SubsystemOperationTimeDto> groupedData, SubsystemOperationTimeRequest request)
private IEnumerable<SubsystemStatDto> CalcStat(IEnumerable<SubsystemOperationTimeDto> listOperationTimeSubsystems, SubsystemOperationTimeRequest request)
{
var result = new List<SubsystemStatDto>();
var groupedDataSubsystems = groupedData
var groupedDataSubsystems = listOperationTimeSubsystems
.GroupBy(x => x.IdSubsystem);
var periodGroupTotal = groupedData
.GroupBy(x => x.IdSubsystem)
var periodGroupTotal = groupedDataSubsystems
.Sum(g => g.Sum(o=> (o.DateEnd - o.DateStart).TotalHours));
var gtDate = request.GtDate ?? listOperationTimeSubsystems.Min(d => d.DateStart);
var ltDate = request.LtDate ?? listOperationTimeSubsystems.Max(d => d.DateEnd);
var periodRequest = listOperationTimeSubsystems
.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
foreach (var item in groupedDataSubsystems)
{
var periodGroup = item.Sum(g => (g.DateEnd - g.DateStart).TotalHours);
var gtDate = request.GtDate ?? item.Min(d => d.DateStart);
var ltDate = request.LtDate ?? item.Max(d => d.DateEnd);
var periodRequest = item.Where(o => o.DateStart>=gtDate && o.DateEnd <= ltDate)
.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
int idSubsystem = item.First().IdSubsystem;
var subsystemStat = new SubsystemStatDto()
{
@ -125,23 +126,23 @@ namespace AsbCloudInfrastructure.Services.Subsystems
}
private IQueryable<SubsystemOperationTime>? BuildQuery(SubsystemOperationTimeRequest request)
{
var idTelemetry = wellService.GetOrDefault(request.IdWell)?.IdTelemetry;
if (idTelemetry is null)
var well = wellService.GetOrDefault(request.IdWell);
if (well?.IdTelemetry is null || well.Timezone is null)
return null;
var query = db.SubsystemOperationTimes
.Include(o => o.Subsystem)
.Where(o => o.IdTelemetry == idTelemetry);
.Where(o => o.IdTelemetry == well.IdTelemetry);
if(request.IdsSubsystems?.Any() == true)
query = query.Where(o => request.IdsSubsystems.Contains(o.IdSubsystem));
if (request.GtDate is not null)
query = query.Where(o => o.DateStart >= request.GtDate.Value);
query = query.Where(o => o.DateStart >= request.GtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours));
if (request.LtDate is not null)
query = query.Where(o => o.DateEnd <= request.LtDate.Value);
query = query.Where(o => o.DateEnd <= request.LtDate.Value.ToUtcDateTimeOffset(well.Timezone.Hours));
if (request.GtDepth is not null)