Fix Rop and RaceSpeed

This commit is contained in:
Фролов 2021-08-25 17:58:35 +05:00
parent 54d4a16d14
commit fb914cc2b9
2 changed files with 135 additions and 117 deletions

View File

@ -298,8 +298,16 @@ namespace AsbCloudDb.Model
new WellSectionType{ Id = 6, Caption = "Хвостовик"}, new WellSectionType{ Id = 6, Caption = "Хвостовик"},
}); });
}); });
modelBuilder.Entity<WellType>(entity => {
entity.HasData(new List<WellType> {
new WellType{ Id = 1, Caption = "Наклонно-направленная"},
new WellType{ Id = 2, Caption = "Горизонтальная"},
});
});
} }
// Эти данные не должны быть в релизе
private static void FillDemoData(ModelBuilder modelBuilder) private static void FillDemoData(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<CompanyType>(entity => modelBuilder.Entity<CompanyType>(entity =>
@ -355,15 +363,15 @@ namespace AsbCloudDb.Model
modelBuilder.Entity<Well>(entity => modelBuilder.Entity<Well>(entity =>
{ {
entity.HasData(new List<Well> { entity.HasData(new List<Well> {
new Well{Id = 1, IdCluster = 1, IdTelemetry = 1, Caption = "скв 16314", Latitude = 60.8705722222222, Longitude = 70.3811888888889}, new Well{Id = 1, IdCluster = 1, IdWellType = 1, Caption = "скв 16314", Latitude = 60.8705722222222, Longitude = 70.3811888888889, IdTelemetry = 1, },
new Well{Id = 2, IdCluster = 1, Caption = "скв 16311", Latitude = 60.8705722222222, Longitude = 70.3811888888889}, new Well{Id = 2, IdCluster = 1, IdWellType = 2, Caption = "скв 16311", Latitude = 60.8705722222222, Longitude = 70.3811888888889},
new Well{Id = 3, IdCluster = 2, Caption = "скв 16315", Latitude = 60.8205750000000, Longitude = 70.1343833333334}, new Well{Id = 3, IdCluster = 2, IdWellType = 1, Caption = "скв 16315", Latitude = 60.8205750000000, Longitude = 70.1343833333334},
new Well{Id = 4, IdCluster = 2, Caption = "скв 16318", Latitude = 60.8205750000000, Longitude = 70.1343833333334}, new Well{Id = 4, IdCluster = 2, IdWellType = 1, Caption = "скв 16318", Latitude = 60.8205750000000, Longitude = 70.1343833333334},
new Well{Id = 5, IdCluster = 3, Caption = "скв 16310", Latitude = 60.8100666666667, Longitude = 69.7778388888889}, new Well{Id = 5, IdCluster = 3, IdWellType = 1, Caption = "скв 16310", Latitude = 60.8100666666667, Longitude = 69.7778388888889},
new Well{Id = 6, IdCluster = 4, Caption = "скв 16316", Latitude = 60.8928805555556, Longitude = 70.3272055555556}, new Well{Id = 6, IdCluster = 4, IdWellType = 1, Caption = "скв 16316", Latitude = 60.8928805555556, Longitude = 70.3272055555556},
new Well{Id = 7, IdCluster = 5, Caption = "скв 16312", Latitude = 60.6672055555556, Longitude = 69.6603861111111}, new Well{Id = 7, IdCluster = 5, IdWellType = 1, Caption = "скв 16312", Latitude = 60.6672055555556, Longitude = 69.6603861111111},
new Well{Id = 8, IdCluster = 5, Caption = "скв 16313", Latitude = 60.6672055555556, Longitude = 69.6603861111111}, new Well{Id = 8, IdCluster = 5, IdWellType = 1, Caption = "скв 16313", Latitude = 60.6672055555556, Longitude = 69.6603861111111},
new Well{Id = 9, IdCluster = 5, Caption = "скв 42669", Latitude = 60.6672055555556, Longitude = 69.6603861111111}, new Well{Id = 9, IdCluster = 5, IdWellType = 1, Caption = "скв 42669", Latitude = 60.6672055555556, Longitude = 69.6603861111111},
}); });
}); });

View File

@ -53,8 +53,9 @@ namespace AsbCloudInfrastructure.Services
{ {
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly CacheTable<WellSectionType> cachedSectionsTypes; private readonly CacheTable<WellSectionType> cacheSectionsTypes;
private readonly CacheTable<Well> cachedWell; private readonly CacheTable<Well> cacheWell;
private readonly CacheTable<WellType> cacheWellType;
private readonly CacheTable<Cluster> cacheCluster; private readonly CacheTable<Cluster> cacheCluster;
private const int idOperationBhaAssembly = 1025; private const int idOperationBhaAssembly = 1025;
private const int idOperationBhaDisassembly = 1026; private const int idOperationBhaDisassembly = 1026;
@ -68,8 +69,9 @@ namespace AsbCloudInfrastructure.Services
{ {
this.db = db; this.db = db;
this.wellService = wellService; this.wellService = wellService;
cachedSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)db); cacheSectionsTypes = cache.GetCachedTable<WellSectionType>((DbContext)db);
cachedWell = cache.GetCachedTable<Well>((DbContext)db); cacheWell = cache.GetCachedTable<Well>((DbContext)db);
cacheWellType = cache.GetCachedTable<WellType>((DbContext)db);
cacheCluster = cache.GetCachedTable<Cluster>((DbContext)db); cacheCluster = cache.GetCachedTable<Cluster>((DbContext)db);
} }
@ -121,13 +123,14 @@ namespace AsbCloudInfrastructure.Services
var wellOperations = operations var wellOperations = operations
.Where(o => o.IdWell == idWell); .Where(o => o.IdWell == idWell);
var well = await cachedWell.FirstOrDefaultAsync(w => w.Id == idWell, token); var well = await cacheWell.FirstOrDefaultAsync(w => w.Id == idWell, token);
var wellType = await cacheWellType.FirstOrDefaultAsync(t => t.Id == well.IdWellType, token);
var statWellDto = new StatWellDto var statWellDto = new StatWellDto
{ {
Id = idWell, Id = idWell,
Caption = well.Caption, Caption = well.Caption,
WellType = well.WellType.Caption, WellType = wellType?.Caption,
Companies = await wellService.GetCompaniesAsync(idWell, token), Companies = await wellService.GetCompaniesAsync(idWell, token),
Sections = CalcSectionsStats(operations), Sections = CalcSectionsStats(operations),
Total = GetStat(operations), Total = GetStat(operations),
@ -141,7 +144,7 @@ namespace AsbCloudInfrastructure.Services
.Select(o => o.IdWellSectionType) .Select(o => o.IdWellSectionType)
.Distinct(); .Distinct();
var sectionTypes = cachedSectionsTypes var sectionTypes = cacheSectionsTypes
.Where(s => sectionTypeIds.Contains(s.Id)) .Where(s => sectionTypeIds.Contains(s.Id))
.ToDictionary(s => s.Id); .ToDictionary(s => s.Id);
@ -201,6 +204,7 @@ namespace AsbCloudInfrastructure.Services
return section; return section;
} }
// this will be deleted
private static double CalcSpeedByOperation(IEnumerable<OperationParams> operationsProps, int idOperation) private static double CalcSpeedByOperation(IEnumerable<OperationParams> operationsProps, int idOperation)
{ {
var ops = operationsProps.Where(o => o.IdCategory == idOperation); var ops = operationsProps.Where(o => o.IdCategory == idOperation);
@ -208,13 +212,18 @@ namespace AsbCloudInfrastructure.Services
var dHours = 0d; var dHours = 0d;
foreach (var operation in ops) foreach (var operation in ops)
{ {
if (maxDepth > operation.WellDepth) if (maxDepth < operation.WellDepth)
maxDepth = operation.WellDepth; maxDepth = operation.WellDepth;
dHours += operation.DurationHours; dHours += operation.DurationHours;
} }
return maxDepth / (dHours + double.Epsilon); return maxDepth / (dHours + double.Epsilon);
} }
//private static double CalcBhaDownSpeed(IEnumerable<OperationParams> operationsProps)
//{
//}
private static double CalcROP(IEnumerable<OperationParams> operationsProps) private static double CalcROP(IEnumerable<OperationParams> operationsProps)
{ {
var drillingOperations = operationsProps.Where(o => o.IdCategory == idOperationDrilling); var drillingOperations = operationsProps.Where(o => o.IdCategory == idOperationDrilling);
@ -253,11 +262,9 @@ namespace AsbCloudInfrastructure.Services
for (int i = 1; i < count; i++) for (int i = 1; i < count; i++)
{ {
item = operations.ElementAt(i); item = operations.ElementAt(i);
current = new OperationParams(item) current = new OperationParams(item){ WellDepth = Helper.Max(wellDepth, item.WellDepth) };
{
WellDepth = Helper.Max(wellDepth, item.WellDepth) // TODO: учесть операциии с уменьшение глубины ствола.
};
pre.DeltaDepth = current.WellDepth - wellDepth; pre.DeltaDepth = current.WellDepth - wellDepth;
wellDepth = current.WellDepth;
pre.DurationHours = (current.Start - pre.Start).TotalHours; pre.DurationHours = (current.Start - pre.Start).TotalHours;
ops.Add(pre); ops.Add(pre);
pre = current; pre = current;
@ -269,7 +276,9 @@ namespace AsbCloudInfrastructure.Services
private static IEnumerable<Race> GetCompleteRaces(IEnumerable<OperationParams> operations) private static IEnumerable<Race> GetCompleteRaces(IEnumerable<OperationParams> operations)
{ {
var races = new List<Race>(); var races = new List<Race>();
var iterator = operations.GetEnumerator(); var iterator = operations
.OrderBy(o => o.Start)
.GetEnumerator();
while (iterator.MoveNext()) while (iterator.MoveNext())
{ {
if (iterator.Current.IdCategory == idOperationBhaAssembly) if (iterator.Current.IdCategory == idOperationBhaAssembly)
@ -287,9 +296,10 @@ namespace AsbCloudInfrastructure.Services
} }
if (iterator.Current.IdCategory == idOperationBhaDisassembly) if (iterator.Current.IdCategory == idOperationBhaDisassembly)
{ {
race.EndDate = iterator.Current.Start.AddHours(iterator.Current.DurationHours); race.EndDate = iterator.Current.Start;
race.EndWellDepth = iterator.Current.WellDepth; race.EndWellDepth = iterator.Current.WellDepth;
races.Add(race); races.Add(race);
break;
} }
} }
} }