Fix ProcessMapReportDrillingService.CalcByIntervals() улучшена производительность локальной функции GetSection()

This commit is contained in:
ngfrolov 2024-03-28 12:12:15 +05:00
parent ab9a40e65e
commit 12f6fda7b2
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
2 changed files with 35 additions and 9 deletions

View File

@ -430,7 +430,14 @@ public class WellOperationRepository : IWellOperationRepository
.Where(subOp => subOp.IdType == 1)
.Where(subOp => WellOperationCategory.NonProductiveTimeSubIds.Contains(subOp.IdCategory));
// TODO: Вынести query.Select из метода BuildQuery
var firstOperations = db.Set<WellOperation>()
.Where(o => o.IdWell == request.IdWell)
.GroupBy(o => o.IdType)
.Select(group => new {
idType = group.Key,
Date = group.Min(o => o.DateStart),
}).ToDictionary(e => e.idType, e => e.Date);
var dtos = query.Select(o => new WellOperationDto
{
Id = o.Id,
@ -455,10 +462,7 @@ public class WellOperationRepository : IWellOperationRepository
.Select(subOp => subOp.DurationHours)
.Sum(),
Day = (o.DateStart - currentWellOperations
.Where(subOp => subOp.IdType == o.IdType)
.Where(subOp => subOp.DateStart <= o.DateStart)
.Min(subOp => subOp.DateStart))
Day = (o.DateStart - firstOperations[o.IdType])
.TotalDays,
IdUser = o.IdUser,
LastUpdateDate = o.LastUpdateDate,

View File

@ -64,6 +64,11 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
};
var wellOperations = await wellOperationRepository
.GetAsync(requestWellOperationFact, token);
var orderedWellOperations = wellOperations
.OrderBy(operation => operation.DateStart)
.ToArray();
if (!wellOperations.Any())
return Enumerable.Empty<ProcessMapReportDataSaubStatDto>();
@ -76,13 +81,14 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
return Enumerable.Empty<ProcessMapReportDataSaubStatDto>();
var wellOperationCategories = wellOperationCategoryRepository.Get(false);
var wellSectionTypes = wellOperationRepository.GetSectionTypes();
var result = CalcByIntervals(
request,
processMapPlanWellDrillings,
dataSaubStats,
wellOperations,
orderedWellOperations,
wellOperationCategories,
wellSectionTypes);
@ -101,8 +107,23 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
var list = new List<ProcessMapReportDataSaubStatDto>();
var firstElemInInterval = dataSaubStats[0];
var orderedWellOperations = wellOperations
.OrderBy(o => o.DateStart)
.ToArray();
var lastFoundIndex = 1;
int GetSection(DataSaubStatDto data)
=> wellOperations.MinBy(o => data.DateStart - o.DateStart)!.IdWellSectionType;
{
if(lastFoundIndex < orderedWellOperations.Length - 1)
{
lastFoundIndex = Array.FindIndex(orderedWellOperations, lastFoundIndex, o => o.DateStart > data.DateStart) - 1;
lastFoundIndex = lastFoundIndex < 0 ? orderedWellOperations.Length - 1 : lastFoundIndex;
}
var operation = orderedWellOperations[lastFoundIndex];
return operation.IdWellSectionType;
}
ProcessMapPlanDrillingDto? GetProcessMapPlan(int idWellSectionType, DataSaubStatDto data)
=> processMapPlanWellDrillings
@ -145,6 +166,7 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
.First();
var elem = CalcStat(processMapPlan, span, wellOperationCategoryName, wellSectionType);
if (elem is not null)
list.Add(elem);
}