forked from ddrilling/AsbCloudServer
Fix ProcessMapReportDrillingService.CalcByIntervals() улучшена производительность локальной функции GetSection()
This commit is contained in:
parent
ab9a40e65e
commit
12f6fda7b2
@ -430,7 +430,14 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
.Where(subOp => subOp.IdType == 1)
|
.Where(subOp => subOp.IdType == 1)
|
||||||
.Where(subOp => WellOperationCategory.NonProductiveTimeSubIds.Contains(subOp.IdCategory));
|
.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
|
var dtos = query.Select(o => new WellOperationDto
|
||||||
{
|
{
|
||||||
Id = o.Id,
|
Id = o.Id,
|
||||||
@ -455,10 +462,7 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
.Select(subOp => subOp.DurationHours)
|
.Select(subOp => subOp.DurationHours)
|
||||||
.Sum(),
|
.Sum(),
|
||||||
|
|
||||||
Day = (o.DateStart - currentWellOperations
|
Day = (o.DateStart - firstOperations[o.IdType])
|
||||||
.Where(subOp => subOp.IdType == o.IdType)
|
|
||||||
.Where(subOp => subOp.DateStart <= o.DateStart)
|
|
||||||
.Min(subOp => subOp.DateStart))
|
|
||||||
.TotalDays,
|
.TotalDays,
|
||||||
IdUser = o.IdUser,
|
IdUser = o.IdUser,
|
||||||
LastUpdateDate = o.LastUpdateDate,
|
LastUpdateDate = o.LastUpdateDate,
|
||||||
|
@ -64,6 +64,11 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
|
|||||||
};
|
};
|
||||||
var wellOperations = await wellOperationRepository
|
var wellOperations = await wellOperationRepository
|
||||||
.GetAsync(requestWellOperationFact, token);
|
.GetAsync(requestWellOperationFact, token);
|
||||||
|
|
||||||
|
var orderedWellOperations = wellOperations
|
||||||
|
.OrderBy(operation => operation.DateStart)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
if (!wellOperations.Any())
|
if (!wellOperations.Any())
|
||||||
return Enumerable.Empty<ProcessMapReportDataSaubStatDto>();
|
return Enumerable.Empty<ProcessMapReportDataSaubStatDto>();
|
||||||
|
|
||||||
@ -76,13 +81,14 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
|
|||||||
return Enumerable.Empty<ProcessMapReportDataSaubStatDto>();
|
return Enumerable.Empty<ProcessMapReportDataSaubStatDto>();
|
||||||
|
|
||||||
var wellOperationCategories = wellOperationCategoryRepository.Get(false);
|
var wellOperationCategories = wellOperationCategoryRepository.Get(false);
|
||||||
|
|
||||||
var wellSectionTypes = wellOperationRepository.GetSectionTypes();
|
var wellSectionTypes = wellOperationRepository.GetSectionTypes();
|
||||||
|
|
||||||
var result = CalcByIntervals(
|
var result = CalcByIntervals(
|
||||||
request,
|
request,
|
||||||
processMapPlanWellDrillings,
|
processMapPlanWellDrillings,
|
||||||
dataSaubStats,
|
dataSaubStats,
|
||||||
wellOperations,
|
orderedWellOperations,
|
||||||
wellOperationCategories,
|
wellOperationCategories,
|
||||||
wellSectionTypes);
|
wellSectionTypes);
|
||||||
|
|
||||||
@ -101,8 +107,23 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
|
|||||||
var list = new List<ProcessMapReportDataSaubStatDto>();
|
var list = new List<ProcessMapReportDataSaubStatDto>();
|
||||||
var firstElemInInterval = dataSaubStats[0];
|
var firstElemInInterval = dataSaubStats[0];
|
||||||
|
|
||||||
|
var orderedWellOperations = wellOperations
|
||||||
|
.OrderBy(o => o.DateStart)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
var lastFoundIndex = 1;
|
||||||
|
|
||||||
int GetSection(DataSaubStatDto data)
|
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)
|
ProcessMapPlanDrillingDto? GetProcessMapPlan(int idWellSectionType, DataSaubStatDto data)
|
||||||
=> processMapPlanWellDrillings
|
=> processMapPlanWellDrillings
|
||||||
@ -145,6 +166,7 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
|
|||||||
.First();
|
.First();
|
||||||
|
|
||||||
var elem = CalcStat(processMapPlan, span, wellOperationCategoryName, wellSectionType);
|
var elem = CalcStat(processMapPlan, span, wellOperationCategoryName, wellSectionType);
|
||||||
|
|
||||||
if (elem is not null)
|
if (elem is not null)
|
||||||
list.Add(elem);
|
list.Add(elem);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user