diff --git a/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs b/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs index a6b28866..ed2571a9 100644 --- a/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs +++ b/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs @@ -57,7 +57,7 @@ internal class SubsystemService : ISubsystemService var result = new List(); var schedulePage = await scheduleRepository.GetPageAsync(request, token); var wells = await wellService.GetAsync(new WellRequest { Ids = request.IdsWells }, token); - + foreach (var schedule in schedulePage) { var idWell = schedule.IdWell; @@ -68,15 +68,21 @@ internal class SubsystemService : ISubsystemService var detectedOperations = await detectedOperationService .GetOperationsAsync(byWellRequest, token); - var detectedOperationsByCurrentDriller = detectedOperations.Where(d => d.Driller?.Id == schedule.IdDriller); - var drillerOperationsStat = await CalcStatAsync(detectedOperationsByCurrentDriller, token); - var dto = new DrillerDetectedOperationStatDto + var groupByDriller = detectedOperations + .Where(operation => operation.Driller is not null) + .GroupBy(operation => operation.Driller); + + foreach (var entry in groupByDriller) { - Statistic = drillerOperationsStat, - Schedule = schedule, - Well = well, - }; - result.Add(dto); + var drillerOperationsStat = await CalcStatAsync(entry, token); + var dto = new DrillerDetectedOperationStatDto + { + Statistic = drillerOperationsStat, + Schedule = schedule, + Well = well, + }; + result.Add(dto); + } } return result;