Fix tvd predict

This commit is contained in:
Фролов 2021-10-06 16:30:46 +05:00
parent 3d1f96655a
commit 197142eca2
2 changed files with 68 additions and 18 deletions

View File

@ -367,10 +367,14 @@ namespace AsbCloudInfrastructure.Services
.OrderBy(o => o.StartDate)
.ThenBy(o => o.WellDepth);
var sectionsIds = wellOperations
.Select(o => o.IdWellSectionType)
.Distinct();
if (!wellOperationsPlan.Any())
return null;
var merged = MergeArrays(wellOperationsPlan, wellOperationsFact);
var merged = MergeArraysBySections(sectionsIds, wellOperationsPlan, wellOperationsFact);
var tvd = new List<PlanFactPredictBase<WellOperationDto>>(merged.Count);
int iLastMatch = 0;
int iLastFact = 0;
@ -411,6 +415,24 @@ namespace AsbCloudInfrastructure.Services
return tvd;
}
private List<Tuple<WellOperation, WellOperation>> MergeArraysBySections(
IEnumerable<int> sectionsIds,
IOrderedEnumerable<WellOperation> wellOperationsPlan,
IOrderedEnumerable<WellOperation> wellOperationsFact)
{
var merged = new List<Tuple<WellOperation, WellOperation>>(wellOperationsPlan.Count());
foreach (var sectionId in sectionsIds)
{
var sectionOperationsPlan = wellOperationsPlan
.Where(o => o.IdWellSectionType == sectionId);
var sectionOperationsFact = wellOperationsFact
.Where(o => o.IdWellSectionType == sectionId);
var sectionMerged = MergeArrays(sectionOperationsPlan, sectionOperationsFact);
merged.AddRange(sectionMerged);
}
return merged;
}
public static List<Tuple<WellOperation, WellOperation>> MergeArrays(IEnumerable<WellOperation> array1, IEnumerable<WellOperation> array2)
{
var a1 = array1.ToArray();
@ -420,8 +442,8 @@ namespace AsbCloudInfrastructure.Services
void Add(WellOperation item1, WellOperation item2) =>
m.Add(new Tuple<WellOperation, WellOperation>(item1, item2));
bool Compare(WellOperation item1, WellOperation item2) =>
item1.IdCategory == item2.IdCategory && Math.Abs(item1.WellDepth - item2.WellDepth) < 250;
static bool Compare(WellOperation item1, WellOperation item2) =>
item1.IdCategory == item2.IdCategory && Math.Abs(item1.WellDepth - item2.WellDepth) < (30d + 0.005d*(item1.WellDepth + item2.WellDepth));
int i1 = 0;
int i2 = 0;
@ -441,25 +463,34 @@ namespace AsbCloudInfrastructure.Services
int nextI1 = Array.FindIndex<WellOperation>(a1, i1, (item) => Compare(item, a2[i2]));
int nextI2 = Array.FindIndex<WellOperation>(a2, i2, (item) => Compare(item, a1[i1]));
if ((nextI1 > -1) && ((nextI2 == -1) || ((nextI1 - i1) < (nextI2 - i2))))
bool deltaI1_Lt_deltaI2 = (nextI1 - i1) < (nextI2 - i2);
if (nextI1 == -1 && nextI2 == -1)
{
for (; i1 < nextI1; i1++)
Add(a1[i1], null);
if (a1[i1].WellDepth < a2[i2].WellDepth)
{
Add(a1[i1++], null);
}
else
{
Add(null, a2[i2++]);
}
}
if ((nextI2 > -1) && ((nextI1 == -1) || ((nextI1 - i1) > (nextI2 - i2))))
else if (nextI1 > -1 && nextI2 == -1)
{
for (; i2 < nextI2; i2++)
Add(null, a2[i2]);
Add(a1[i1++], null);
}
if ((nextI1 == -1) && (nextI2 == -1))
else if (nextI1 == -1 && nextI2 > -1)
{
for (; i2 < a2.Length; i2++)
Add(null, a2[i2]);
for (; i1 < a1.Length; i1++)
Add(a1[i1], null);
Add(null, a2[i2++]);
}
else if (deltaI1_Lt_deltaI2)
{
Add(a1[i1++], null);
}
else if (!deltaI1_Lt_deltaI2)
{
Add(null, a2[i2++]);
}
}
}

View File

@ -34,8 +34,27 @@ namespace ConsoleApp1
var wellOptsStat = new WellOperationsStatService(db, cacheDb, wellService);
var tvd = wellOptsStat.GetTvdAsync(1, default).Result;
Print(tvd);
Console.WriteLine("_");
}
private static void Print(IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd)
{
Console.WriteLine("|\tplan\t|\tfact\t|\tprog\t|");
Console.WriteLine("|:-------------:|:-------------:|:-------------:|");
foreach (var item in tvd)
Print(item);
}
private static void Print(PlanFactPredictBase<WellOperationDto> item)
{
static string GetText(WellOperationDto item)
=> (item is null)
? " --------- "
: $"{item.IdCategory} d:{item.WellDepth} ";
Console.WriteLine($"|\t{GetText(item.Plan)}\t|\t{GetText(item.Fact)}\t|\t{GetText(item.Predict)}\t|");
}
}
}