forked from ddrilling/AsbCloudServer
CS2-54: Added Well section data calculation
This commit is contained in:
parent
d6bf5d3252
commit
977645e23a
@ -2,6 +2,12 @@
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public enum WellOpertaionType
|
||||
{
|
||||
Plan,
|
||||
Fact
|
||||
}
|
||||
|
||||
public class WellOperationDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
@ -12,11 +18,16 @@ namespace AsbCloudApp.Data
|
||||
|
||||
public string WellSectionTypeName { get; set; }
|
||||
|
||||
public int IdOperationCategory { get; set; }
|
||||
public int IdCategory { get; set; }
|
||||
|
||||
public string CategoryName { get; set; }
|
||||
|
||||
public int Type { get; set; }
|
||||
public string CategoryInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// План или факт
|
||||
/// </summary>
|
||||
public WellOpertaionType Type { get; set; }
|
||||
|
||||
public double WellDepth { get; set; }
|
||||
|
||||
@ -24,8 +35,6 @@ namespace AsbCloudApp.Data
|
||||
|
||||
public double DurationHours { get; set; }
|
||||
|
||||
public string Info { get; set; }
|
||||
|
||||
public string Comment { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -21,22 +21,22 @@
|
||||
/// <summary>
|
||||
/// Период план, д
|
||||
/// </summary>
|
||||
public double BuildDaysPlan { get; set; }
|
||||
public double DurationPlan { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Период факт, д
|
||||
/// </summary>
|
||||
public double BuildDaysFact { get; set; }
|
||||
public double DurationFact { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Механическая скорость проходки план, м/час
|
||||
/// </summary>
|
||||
public double RateOfPenetrationPlan { get; set; }
|
||||
public double MechSpeedPlan { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Механическая скорость проходки факт, м/час
|
||||
/// </summary>
|
||||
public double RateOfPenetrationFact { get; set; }
|
||||
public double MechSpeedFact { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Рейсовая скорость план, м/час
|
||||
|
@ -8,7 +8,7 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IWellOperationService
|
||||
{
|
||||
IEnumerable<WellOperationCategoryDto> GetTypes();
|
||||
IEnumerable<WellOperationCategoryDto> GetCategories();
|
||||
|
||||
Task<PaginationContainer<WellOperationDto>> GetAllByWellIdAsync(int idWell,
|
||||
int skip = 0, int take = 32, CancellationToken token = default);
|
||||
|
@ -7,12 +7,12 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IWellSectionService
|
||||
{
|
||||
Task<PaginationContainer<WellSectionDto>> GetAllByWellIdAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default);
|
||||
Task<WellSectionDto> GetAsync(int id, CancellationToken token = default);
|
||||
Task<WellSectionDto> InsertAsync(WellSectionDto newItem, int idWell, CancellationToken token = default);
|
||||
Task<IEnumerable<WellSectionDto>> InsertRangeAsync(int idWell, IEnumerable<WellSectionDto> newItems, CancellationToken token = default);
|
||||
Task<WellSectionDto> UpdateAsync(int idWell, int idSection, WellSectionDto item, CancellationToken token = default);
|
||||
Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token = default);
|
||||
Task<string[]> GetTypesAsync(CancellationToken token);
|
||||
Task<PaginationContainer<WellSectionDto>> GetSectionsByWellIdAsync(int idWell, int skip = 0, int take = 32, CancellationToken token = default);
|
||||
Task<WellSectionDto> GetSectionByWellIdAsync(int id, CancellationToken token = default);
|
||||
//Task<WellSectionDto> InsertAsync(WellSectionDto newItem, int idWell, CancellationToken token = default);
|
||||
//Task<IEnumerable<WellSectionDto>> InsertRangeAsync(int idWell, IEnumerable<WellSectionDto> newItems, CancellationToken token = default);
|
||||
//Task<WellSectionDto> UpdateAsync(int idWell, int idSection, WellSectionDto item, CancellationToken token = default);
|
||||
//Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token = default);
|
||||
}
|
||||
}
|
||||
|
@ -158,12 +158,12 @@ namespace AsbCloudInfrastructure.Services
|
||||
BhaDownSpeedPlan = s.BhaDownSpeedPlan,
|
||||
BhaUpSpeedFact = s.BhaUpSpeedFact,
|
||||
BhaUpSpeedPlan = s.BhaUpSpeedPlan,
|
||||
BuildDaysFact = s.BuildDaysFact,
|
||||
BuildDaysPlan = s.BuildDaysPlan,
|
||||
DurationFact = s.BuildDaysFact,
|
||||
DurationPlan = s.BuildDaysPlan,
|
||||
CasingDownSpeedFact = s.CasingDownSpeedFact,
|
||||
CasingDownSpeedPlan = s.CasingDownSpeedPlan,
|
||||
RateOfPenetrationFact = s.RateOfPenetrationFact,
|
||||
RateOfPenetrationPlan = s.RateOfPenetrationPlan,
|
||||
MechSpeedFact = s.RateOfPenetrationFact,
|
||||
MechSpeedPlan = s.RateOfPenetrationPlan,
|
||||
RouteSpeedFact = s.RouteSpeedFact,
|
||||
RouteSpeedPlan = s.RouteSpeedPlan,
|
||||
SectionType = s.WellSectionType.Caption,
|
||||
|
@ -14,57 +14,93 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class WellSectionService: IWellSectionService
|
||||
{
|
||||
private readonly IAsbCloudDbContext context;
|
||||
private readonly DbSet<WellSection> dbSet;
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly CacheTable<WellSectionType> cachedSectionsTypes;
|
||||
|
||||
public WellSectionService(IAsbCloudDbContext context, Cache.CacheDb cache)
|
||||
public WellSectionService(IAsbCloudDbContext db, Cache.CacheDb cache)
|
||||
{
|
||||
this.context = context;
|
||||
dbSet = context.Set<WellSection>();
|
||||
cachedSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)context);
|
||||
this.db = db;
|
||||
cachedSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)db);
|
||||
}
|
||||
|
||||
public Task<string[]> GetTypesAsync(CancellationToken token) =>
|
||||
context.WellSectionTypes.Select(e => e.Caption).Distinct().AsNoTracking().ToArrayAsync(token);
|
||||
|
||||
public async Task<PaginationContainer<WellSectionDto>> GetAllByWellIdAsync(int idWell, int skip, int take, CancellationToken token = default)
|
||||
db.WellSectionTypes.Select(e => e.Caption).Distinct().AsNoTracking().ToArrayAsync(token);
|
||||
|
||||
public async Task<PaginationContainer<WellSectionDto>> GetSectionsByWellIdAsync(int idWell,
|
||||
int skip, int take, CancellationToken token = default)
|
||||
{
|
||||
var query = dbSet
|
||||
.Include(s => s.WellSectionType)
|
||||
.Where(s => s.IdWell == idWell)
|
||||
.AsNoTracking();
|
||||
var groupedWellOperationsQuery = (from w in db.WellOperations
|
||||
where w.IdWell == idWell
|
||||
select w)
|
||||
.Include(w => w.WellSectionType)
|
||||
.GroupBy(op => op.IdWellSectionType);
|
||||
|
||||
if (skip > 0)
|
||||
groupedWellOperationsQuery = groupedWellOperationsQuery.Skip(skip);
|
||||
|
||||
var wellOperationsGroupedBySections = await groupedWellOperationsQuery
|
||||
.Take(take).ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var result = new PaginationContainer<WellSectionDto>
|
||||
{
|
||||
Skip = skip,
|
||||
Take = take,
|
||||
Count = await query.CountAsync(token).ConfigureAwait(false),
|
||||
Count = wellOperationsGroupedBySections.Count
|
||||
};
|
||||
|
||||
query = query
|
||||
.OrderBy(e => e.WellDepthPlan);
|
||||
if (!wellOperationsGroupedBySections.Any())
|
||||
return result;
|
||||
|
||||
if (skip > 0)
|
||||
query = query.Skip(skip);
|
||||
// TODO: Подставить нормальные ID операций спускоа, подъема и т.д.
|
||||
var depthsPlanFactList = GetWellDepthPlanFact(wellOperationsGroupedBySections).ToList();
|
||||
|
||||
query = query.Take(take);
|
||||
var durationsPlanFactList = GetWellDurationPlanFact(wellOperationsGroupedBySections).ToList();
|
||||
|
||||
var entities = await query.Take(take).ToListAsync(token).ConfigureAwait(false);
|
||||
var mechSpeedsList = GetWellMechSpeedPlanFact(wellOperationsGroupedBySections).ToList();
|
||||
|
||||
foreach (var item in entities)
|
||||
var bhaUpSpeedList = GetWellBhaUpSpeedPlanFact(wellOperationsGroupedBySections).ToList();
|
||||
|
||||
var bhaDownSpeedList = GetWellBhaDownSpeedPlanFact(wellOperationsGroupedBySections).ToList();
|
||||
|
||||
var casingDownList = GetWellCasingDownPlanFact(wellOperationsGroupedBySections).ToList();
|
||||
|
||||
var routeSpeeds = GetWellRouteSpeedsPlanFact(wellOperationsGroupedBySections).ToList();
|
||||
|
||||
var dtos = new List<WellSectionDto>();
|
||||
|
||||
for(int i = 0; i <= wellOperationsGroupedBySections.Count; i++)
|
||||
{
|
||||
var dto = item.Adapt<WellSectionDto>();
|
||||
dto.SectionType = item.WellSectionType.Caption;
|
||||
result.Items.Add(dto);
|
||||
var dto = new WellSectionDto
|
||||
{
|
||||
SectionType = wellOperationsGroupedBySections[i].FirstOrDefault().OperationCategory.Name,
|
||||
WellDepthPlan = depthsPlanFactList[i].DepthPlan,
|
||||
WellDepthFact = depthsPlanFactList[i].DepthFact,
|
||||
DurationPlan = durationsPlanFactList[i].DurationPlan,
|
||||
DurationFact = durationsPlanFactList[i].DurationFact,
|
||||
MechSpeedPlan = mechSpeedsList[i].MechSpeedPlan,
|
||||
MechSpeedFact = mechSpeedsList[i].MechSpeedFact,
|
||||
BhaUpSpeedPlan = bhaUpSpeedList[i].BhaUpSpeedPlan,
|
||||
BhaUpSpeedFact = bhaUpSpeedList[i].BhaUpSpeedFact,
|
||||
BhaDownSpeedPlan = bhaDownSpeedList[i].BhaDownSpeedPlan,
|
||||
BhaDownSpeedFact = bhaDownSpeedList[i].BhaDownSpeedFact,
|
||||
CasingDownSpeedPlan = casingDownList[i].CasingDownSpeedPlan,
|
||||
CasingDownSpeedFact = casingDownList[i].CasingDownSpeedFact,
|
||||
RouteSpeedPlan = routeSpeeds[i].RouteSpeedPlan,
|
||||
RouteSpeedFact = routeSpeeds[i].RouteSpeedFact
|
||||
};
|
||||
|
||||
dtos.Add(dto);
|
||||
}
|
||||
|
||||
result.Items = dtos;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<WellSectionDto> GetAsync(int id, CancellationToken token = default)
|
||||
public async Task<WellSectionDto> GetSectionByWellIdAsync(int id, CancellationToken token = default)
|
||||
{
|
||||
var entity = await dbSet
|
||||
var entity = await db.WellSections
|
||||
.Include(s => s.WellSectionType)
|
||||
.FirstOrDefaultAsync(e => e.Id == id, token)
|
||||
.ConfigureAwait(false);
|
||||
@ -77,69 +113,227 @@ namespace AsbCloudInfrastructure.Services
|
||||
return dto;
|
||||
}
|
||||
|
||||
public async Task<WellSectionDto> InsertAsync(WellSectionDto item, int idWell, CancellationToken token = default)
|
||||
//public async Task<WellSectionDto> InsertAsync(WellSectionDto item, int idWell, CancellationToken token = default)
|
||||
//{
|
||||
// var sectionType = await GetWellSectionTypeFromCacheAndAssertAsync(item.SectionType);
|
||||
|
||||
// var entity = item.Adapt<WellSection>();
|
||||
// entity.Id = default;
|
||||
// entity.IdWell = idWell;
|
||||
// entity.IdWellSectionType = sectionType.Id;
|
||||
// var dbEntity = dbSet.Add(entity);
|
||||
// await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
|
||||
// var dto = dbEntity.Entity.Adapt<WellSectionDto>();
|
||||
// dto.SectionType = sectionType.Caption;
|
||||
// return dto;
|
||||
//}
|
||||
|
||||
//public async Task<IEnumerable<WellSectionDto>> InsertRangeAsync(int idWell, IEnumerable<WellSectionDto> items, CancellationToken token = default)
|
||||
//{
|
||||
// var dbEntities = new Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<WellSection>[items.Count()];
|
||||
|
||||
// for (int i = 0; i < dbEntities.Length; i++)
|
||||
// {
|
||||
// var sectionType = await GetWellSectionTypeFromCacheAndAssertAsync(items.ElementAt(i).SectionType, token);
|
||||
// var item = items.ElementAt(i).Adapt<WellSection>();
|
||||
// item.IdWell = idWell;
|
||||
// item.IdWellSectionType = sectionType.Id;
|
||||
// dbEntities[i] = dbSet.Add(item);
|
||||
// }
|
||||
|
||||
// await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
|
||||
// var dtos = dbEntities.Select((e) => {
|
||||
// var dto = e.Entity.Adapt<WellSectionDto>();
|
||||
// var sectionType = cachedSectionsTypes.FirstOrDefault(s => s.Id == e.Entity.IdWellSectionType);
|
||||
// dto.SectionType = sectionType.Caption;
|
||||
// return dto;
|
||||
// });
|
||||
|
||||
// return dtos;
|
||||
//}
|
||||
|
||||
//public async Task<WellSectionDto> UpdateAsync(int idWell, int idSection, WellSectionDto item, CancellationToken token = default)
|
||||
//{
|
||||
// var sectionType = await GetWellSectionTypeFromCacheAndAssertAsync(item.SectionType, token)
|
||||
// .ConfigureAwait(false);
|
||||
|
||||
// var entity = item.Adapt<WellSection>();
|
||||
// entity.Id = idSection;
|
||||
// entity.IdWell = idWell;
|
||||
// entity.IdWellSectionType = sectionType.Id;
|
||||
// var dbEntity = dbSet.Update(entity);
|
||||
// await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
|
||||
// var dto = dbEntity.Entity.Adapt<WellSectionDto>();
|
||||
// dto.SectionType = sectionType.Caption;
|
||||
// return dto;
|
||||
//}
|
||||
|
||||
//public Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token = default)
|
||||
//{
|
||||
// var entities = dbSet.Where(e => ids.Contains(e.Id));
|
||||
// dbSet.RemoveRange(entities);
|
||||
// return context.SaveChangesAsync(token);
|
||||
//}
|
||||
|
||||
private static IEnumerable<(double DepthPlan, double DepthFact)> GetWellDepthPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var sectionType = await GetWellSectionTypeFromCacheAndAssertAsync(item.SectionType);
|
||||
|
||||
var entity = item.Adapt<WellSection>();
|
||||
entity.Id = default;
|
||||
entity.IdWell = idWell;
|
||||
entity.IdWellSectionType = sectionType.Id;
|
||||
var dbEntity = dbSet.Add(entity);
|
||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
|
||||
var dto = dbEntity.Entity.Adapt<WellSectionDto>();
|
||||
dto.SectionType = sectionType.Caption;
|
||||
return dto;
|
||||
return groupedOperations
|
||||
.Select(group =>
|
||||
(
|
||||
DepthPlan: group.Where(o => o.Type == 0).Max(w => w.WellDepth),
|
||||
DepthFact: group.Where(o => o.Type == 1).Max(w => w.WellDepth)
|
||||
));
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WellSectionDto>> InsertRangeAsync(int idWell, IEnumerable<WellSectionDto> items, CancellationToken token = default)
|
||||
|
||||
private static IEnumerable<(double DurationPlan, double DurationFact)> GetWellDurationPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var dbEntities = new Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<WellSection>[items.Count()];
|
||||
|
||||
for (int i = 0; i < dbEntities.Length; i++)
|
||||
var durationsPlanFactsBase = groupedOperations.Select(group => new
|
||||
{
|
||||
var sectionType = await GetWellSectionTypeFromCacheAndAssertAsync(items.ElementAt(i).SectionType, token);
|
||||
var item = items.ElementAt(i).Adapt<WellSection>();
|
||||
item.IdWell = idWell;
|
||||
item.IdWellSectionType = sectionType.Id;
|
||||
dbEntities[i] = dbSet.Add(item);
|
||||
}
|
||||
DurationMaxPlan = group.Where(o => o.Type == 0).Select(op => op.StartDate +
|
||||
TimeSpan.FromHours(op.DurationHours)).Max(),
|
||||
|
||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
|
||||
var dtos = dbEntities.Select((e) => {
|
||||
var dto = e.Entity.Adapt<WellSectionDto>();
|
||||
var sectionType = cachedSectionsTypes.FirstOrDefault(s => s.Id == e.Entity.IdWellSectionType);
|
||||
dto.SectionType = sectionType.Caption;
|
||||
return dto;
|
||||
DurationMinPlan = group.Where(o => o.Type == 0).Min(i => i.StartDate),
|
||||
|
||||
DurationMaxFact = group.Where(o => o.Type == 1).Select(op => op.StartDate +
|
||||
TimeSpan.FromHours(op.DurationHours)).Max(),
|
||||
|
||||
DurationMinFact = group.Where(o => o.Type == 1).Min(i => i.StartDate)
|
||||
});
|
||||
|
||||
return dtos;
|
||||
return durationsPlanFactsBase.Select(o =>
|
||||
(
|
||||
DurationPlan: (o.DurationMaxPlan - o.DurationMinPlan).TotalHours,
|
||||
DurationFact: (o.DurationMaxFact - o.DurationMinFact).TotalHours
|
||||
));
|
||||
}
|
||||
|
||||
public async Task<WellSectionDto> UpdateAsync(int idWell, int idSection, WellSectionDto item, CancellationToken token = default)
|
||||
private static IEnumerable<(double MechSpeedPlan, double MechSpeedFact)> GetWellMechSpeedPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var sectionType = await GetWellSectionTypeFromCacheAndAssertAsync(item.SectionType, token)
|
||||
.ConfigureAwait(false);
|
||||
var mechSpeedBase = groupedOperations.Select(g => new
|
||||
{
|
||||
DepthChangePlanSum = g.Where(o => o.Type == 0 && o.IdOperationCategory == 1)
|
||||
.Select((el, i) => i > 0 ? el.WellDepth - g.ElementAt(i - 1).WellDepth : 0).Sum(),
|
||||
DurationsPlanSum = g.Where(o => o.Type == 0 && o.IdOperationCategory == 1)
|
||||
.Select(el => el.DurationHours).Sum(),
|
||||
DepthChangeFactSum = g.Where(o => o.Type == 1 && o.IdOperationCategory == 1)
|
||||
.Select((el, i) => i > 0 ? el.WellDepth - g.ElementAt(i - 1).WellDepth : 0).Sum(),
|
||||
DurationsFactSum = g.Where(o => o.Type == 1 && o.IdOperationCategory == 1)
|
||||
.Select(el => el.DurationHours).Sum()
|
||||
});
|
||||
|
||||
var entity = item.Adapt<WellSection>();
|
||||
entity.Id = idSection;
|
||||
entity.IdWell = idWell;
|
||||
entity.IdWellSectionType = sectionType.Id;
|
||||
var dbEntity = dbSet.Update(entity);
|
||||
await context.SaveChangesAsync(token).ConfigureAwait(false);
|
||||
|
||||
var dto = dbEntity.Entity.Adapt<WellSectionDto>();
|
||||
dto.SectionType = sectionType.Caption;
|
||||
return dto;
|
||||
return mechSpeedBase.Select(el =>
|
||||
(
|
||||
MechSpeedPlan: el.DepthChangePlanSum / el.DurationsPlanSum,
|
||||
MechSpeedFact: el.DepthChangeFactSum / el.DurationsFactSum
|
||||
));
|
||||
}
|
||||
|
||||
public Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token = default)
|
||||
private static IEnumerable<(double BhaUpSpeedPlan, double BhaUpSpeedFact)> GetWellBhaUpSpeedPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var entities = dbSet.Where(e => ids.Contains(e.Id));
|
||||
dbSet.RemoveRange(entities);
|
||||
return context.SaveChangesAsync(token);
|
||||
var bhaUpSpeedBase = GetParams(groupedOperations, 2);
|
||||
|
||||
return bhaUpSpeedBase.Select(el =>
|
||||
(
|
||||
BhaUpSpeedPlan: el.DepthDifferencePlanSum / el.DurationDifferencePlanSum,
|
||||
BhaUpSpeedFact: el.DepthDifferenceFactSum / el.DurationDifferenceFactSum
|
||||
));
|
||||
}
|
||||
|
||||
private static IEnumerable<(double BhaDownSpeedPlan, double BhaDownSpeedFact)> GetWellBhaDownSpeedPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var bhaDownSpeedBase = GetParams(groupedOperations, 3);
|
||||
|
||||
return bhaDownSpeedBase.Select(el =>
|
||||
(
|
||||
BhaDownSpeedPlan: el.DepthDifferencePlanSum / el.DurationDifferencePlanSum,
|
||||
BhaDownSpeedFact: el.DepthDifferenceFactSum / el.DurationDifferenceFactSum
|
||||
));
|
||||
}
|
||||
|
||||
private static IEnumerable<(double CasingDownSpeedPlan, double CasingDownSpeedFact)> GetWellCasingDownPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var casingDownBase = GetParams(groupedOperations, 4);
|
||||
|
||||
return casingDownBase.Select(el =>
|
||||
(
|
||||
CasingDownSpeedPlan: el.DepthDifferencePlanSum / el.DurationDifferencePlanSum,
|
||||
CasingDownSpeedFact: el.DepthDifferenceFactSum / el.DurationDifferenceFactSum
|
||||
)).ToList();
|
||||
}
|
||||
|
||||
private static IEnumerable<(double DepthDifferencePlanSum,
|
||||
double DurationDifferencePlanSum, double DepthDifferenceFactSum,
|
||||
double DurationDifferenceFactSum)> GetParams(IEnumerable<IGrouping<int, WellOperation>> items,
|
||||
int idOperationCategory)
|
||||
{
|
||||
return items.Select(g =>
|
||||
(
|
||||
DepthDifferencePlanSum: g.Where(o => o.Type == 0 && o.IdOperationCategory == idOperationCategory)
|
||||
.Select((el, i) => i > 0 ? el.WellDepth - g.ElementAt(i - 1).WellDepth : 0).Sum(),
|
||||
DurationDifferencePlanSum: g.Where(o => o.Type == 0 && o.IdOperationCategory == idOperationCategory)
|
||||
.Select(el => el.DurationHours).Sum(),
|
||||
DepthDifferenceFactSum: g.Where(o => o.Type == 1 && o.IdOperationCategory == idOperationCategory)
|
||||
.Select((el, i) => i > 0 ? el.WellDepth - g.ElementAt(i - 1).WellDepth : 0).Sum(),
|
||||
DurationDifferenceFactSum: g.Where(o => o.Type == 1 && o.IdOperationCategory == idOperationCategory)
|
||||
.Select(el => el.DurationHours).Sum()
|
||||
));
|
||||
}
|
||||
|
||||
private static IEnumerable<(double RouteSpeedPlan, double RouteSpeedFact)> GetWellRouteSpeedsPlanFact(
|
||||
IEnumerable<IGrouping<int, WellOperation>> groupedOperations)
|
||||
{
|
||||
var bhaRaiseDecreaseCollection = new List<(WellOperation FirstDecreasePlan, WellOperation LastIncreasePlan,
|
||||
WellOperation FirstDecreaseFact, WellOperation LastIncreaseFact)>();
|
||||
|
||||
foreach (var group in groupedOperations)
|
||||
{
|
||||
var firstBhaPositionDecreasePlan = group.Any(o => o.IdOperationCategory == 5 && o.Type == 0)
|
||||
? group.First(o => o.IdOperationCategory == 5 && o.Type == 0)
|
||||
: null;
|
||||
|
||||
var lastBhaPositionIncreasePlan = group.Any(o => o.IdOperationCategory == 6 && o.Type == 0)
|
||||
? group.First(o => o.IdOperationCategory == 5 && o.Type == 0)
|
||||
: null;
|
||||
|
||||
var firstBhaPositionDecreaseFact = group.Any(o => o.IdOperationCategory == 5 && o.Type == 1)
|
||||
? group.First(o => o.IdOperationCategory == 5 && o.Type == 1)
|
||||
: null;
|
||||
|
||||
var lastBhaPositionIncreaseFact = group.Any(o => o.IdOperationCategory == 6 && o.Type == 1)
|
||||
? group.First(o => o.IdOperationCategory == 5 && o.Type == 1)
|
||||
: null;
|
||||
|
||||
bhaRaiseDecreaseCollection.Add((firstBhaPositionDecreasePlan,
|
||||
lastBhaPositionIncreasePlan, firstBhaPositionDecreaseFact,
|
||||
lastBhaPositionIncreaseFact));
|
||||
}
|
||||
|
||||
var routeSpeedsBase = bhaRaiseDecreaseCollection.Select(el => new // TODO: check value for null
|
||||
{
|
||||
RouteDepthPlan = el.FirstDecreasePlan.WellDepth - el.LastIncreasePlan.WellDepth,
|
||||
RouteDepthFact = el.FirstDecreaseFact.WellDepth - el.LastIncreaseFact.WellDepth,
|
||||
RouteDurationPlan = (el.LastIncreasePlan.StartDate +
|
||||
TimeSpan.FromHours(el.LastIncreasePlan.DurationHours) -
|
||||
el.FirstDecreasePlan.StartDate).TotalHours,
|
||||
RouteDurationFact = (el.LastIncreaseFact.StartDate +
|
||||
TimeSpan.FromHours(el.LastIncreaseFact.DurationHours) -
|
||||
el.FirstDecreaseFact.StartDate).TotalHours
|
||||
});
|
||||
|
||||
return routeSpeedsBase.Select(el =>
|
||||
(
|
||||
RouteSpeedPlan: el.RouteDepthPlan / el.RouteDurationPlan,
|
||||
RouteSpeedFact: el.RouteDepthFact / el.RouteDurationFact
|
||||
)).ToList();
|
||||
}
|
||||
|
||||
private async Task<WellSectionType> GetWellSectionTypeFromCacheAndAssertAsync(string wellSectionType, CancellationToken token = default)
|
||||
@ -153,7 +347,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
if (sectionType is null)
|
||||
{
|
||||
throw new ArgumentException($"Тип секции '{wellSectionType}' отсутствует в справочнике", nameof(WellSectionDto.SectionType)) ;
|
||||
throw new ArgumentException($"Тип секции '{wellSectionType}' отсутствует в справочнике", nameof(WellSectionDto.SectionType));
|
||||
//sectionType = await cachedSectionsTypes.InsertAsync(new WellSectionType { Caption = item.SectionType}, token);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -42,7 +41,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
if(!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = await sectionsService.GetAllByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false);
|
||||
var result = await sectionsService.GetSectionsByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -55,50 +54,50 @@ namespace AsbCloudWebApi.Controllers
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = await sectionsService.GetAsync(idSection, token).ConfigureAwait(false);
|
||||
var result = await sectionsService.GetSectionByWellIdAsync(idSection, token).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(IEnumerable<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> InsertAsync(int idWell, [FromBody] IEnumerable<WellSectionDto> values,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
//[HttpPost]
|
||||
//[ProducesResponseType(typeof(IEnumerable<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
//public async Task<IActionResult> InsertAsync(int idWell, [FromBody] IEnumerable<WellSectionDto> values,
|
||||
// CancellationToken token = default)
|
||||
//{
|
||||
// if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
// return Forbid();
|
||||
|
||||
var result = await sectionsService.InsertRangeAsync(idWell, values, token).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
// var result = await sectionsService.InsertRangeAsync(idWell, values, token).ConfigureAwait(false);
|
||||
// return Ok(result);
|
||||
//}
|
||||
|
||||
[HttpPut("{idSection}")]
|
||||
[ProducesResponseType(typeof(WellSectionDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> UpdateAsync(int idWell, int idSection, [FromBody] WellSectionDto value, CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
//[HttpPut("{idSection}")]
|
||||
//[ProducesResponseType(typeof(WellSectionDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
//public async Task<IActionResult> UpdateAsync(int idWell, int idSection, [FromBody] WellSectionDto value, CancellationToken token = default)
|
||||
//{
|
||||
// if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
// return Forbid();
|
||||
|
||||
var result = await sectionsService.UpdateAsync(idWell, idSection, value, token).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
// var result = await sectionsService.UpdateAsync(idWell, idSection, value, token).ConfigureAwait(false);
|
||||
// return Ok(result);
|
||||
//}
|
||||
|
||||
[HttpDelete("{idSection}")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> DeleteAsync(int idWell, int idItem, CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell,
|
||||
token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
//[HttpDelete("{idSection}")]
|
||||
//[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
//public async Task<IActionResult> DeleteAsync(int idWell, int idItem, CancellationToken token = default)
|
||||
//{
|
||||
// if (!await CanUserAccessToWellAsync(idWell,
|
||||
// token).ConfigureAwait(false))
|
||||
// return Forbid();
|
||||
|
||||
var result = await sectionsService.DeleteAsync(new int[] { idItem }, token).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
// var result = await sectionsService.DeleteAsync(new int[] { idItem }, token).ConfigureAwait(false);
|
||||
// return Ok(result);
|
||||
//}
|
||||
|
||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false);
|
||||
int? idCompany = User.GetCompanyId();
|
||||
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user