This commit is contained in:
KharchenkoVV 2021-10-08 11:12:57 +05:00
commit eac35cd3e9
12 changed files with 2507 additions and 24 deletions

View File

@ -23,7 +23,7 @@ namespace AsbCloudApp.Services
Task<int> MarkAsDeletedAsync(int idFile,
CancellationToken token = default);
Task<IEnumerable<FileInfoDto>> GetInfosByCategoryAsync(int idWell, int idCategory, CancellationToken token = default);
Task<int> DeletedAsync(int id, CancellationToken token);
Task<int> DeleteAsync(int id, CancellationToken token);
string GetUrl(FileInfoDto fileInfo);
string GetUrl(int idFile);
string GetUrl(int idWell, int idCategory, int idFile, string dotExtention);

View File

@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace AsbCloudDb.Migrations
{
public partial class Update_WellOperationsCategory_by_new_initial_values : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "t_well_operation_category",
columns: new[] { "id", "code", "name" },
values: new object[] { 1019, 0, "Наращивание, промывка" });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "t_well_operation_category",
keyColumn: "id",
keyValue: 1019);
}
}
}

View File

@ -1765,6 +1765,12 @@ namespace AsbCloudDb.Migrations
Name = "Перетяжка талевого каната"
},
new
{
Id = 1019,
Code = 0,
Name = "Наращивание, промывка"
},
new
{
Id = 1020,
Code = 0,

View File

@ -254,6 +254,7 @@ namespace AsbCloudDb.Model
new WellOperationCategory {Id = 1016, Name = "Перевод скв на другой тип промывочной жидкости", Code = 0 },
new WellOperationCategory {Id = 1017, Name = "Перезапись каротажа", Code = 0 },
new WellOperationCategory {Id = 1018, Name = "Перетяжка талевого каната", Code = 0 },
new WellOperationCategory {Id = 1019, Name = "Наращивание, промывка", Code = 0 },
new WellOperationCategory {Id = 1020, Name = "Подъем инструмента", Code = 0 },
new WellOperationCategory {Id = 1021, Name = "Подъем инструмента с промывкой", Code = 0 },
new WellOperationCategory {Id = 1022, Name = "Обратная проработка", Code = 0 },

View File

@ -0,0 +1 @@
select setval('t_well_operation_id_seq', 175);

View File

@ -0,0 +1,25 @@
SELECT
to_timestamp(unix_date),
twoc.name,
duration_sec,
operation_start_depth,
operation_end_depth,
is_bit_posision_lt_20,
is_bit_position_decreasing,
is_bit_position_increasing,
is_block_posision_decresing,
is_block_posision_incresing,
is_hook_weight_lt_3,
is_hook_weight_not_changes,
is_pressure_gt_20,
is_pressure_lt_20,
is_rotor_speed_gt_3,
is_rotor_speed_lt_3,
is_well_depth_increasing,
is_well_depth_decreasing
FROM t_telemetry_analysis
LEFT JOIN t_well_operation_category twoc on t_telemetry_analysis.id_operation = twoc.id
where id_telemetry = 34 and not id_operation in (0, 1, 15)
order by unix_date, operation_start_depth
Limit 1000;

View File

@ -43,13 +43,13 @@ namespace AsbCloudInfrastructure.Services
matchFilesIterator.MoveNext();
var matchFile = matchFilesIterator.Current;
while (matchFilesIterator.MoveNext())
await fileService.DeletedAsync(matchFilesIterator.Current.Id, token)
await fileService.DeleteAsync(matchFilesIterator.Current.Id, token)
.ConfigureAwait(false);
if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate))
return matchFile;
else
await fileService.DeletedAsync(matchFile.Id, token)
await fileService.DeleteAsync(matchFile.Id, token)
.ConfigureAwait(false);
}

View File

@ -41,13 +41,13 @@ namespace AsbCloudInfrastructure.Services
matchFilesIterator.MoveNext();
var matchFile = matchFilesIterator.Current;
while (matchFilesIterator.MoveNext())
await fileService.DeletedAsync(matchFilesIterator.Current.Id, token)
await fileService.DeleteAsync(matchFilesIterator.Current.Id, token)
.ConfigureAwait(false);
if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate))
return matchFile;
else
await fileService.DeletedAsync(matchFile.Id, token)
await fileService.DeleteAsync(matchFile.Id, token)
.ConfigureAwait(false);
}

View File

@ -191,7 +191,7 @@ namespace AsbCloudInfrastructure.Services
return await db.SaveChangesAsync(token).ConfigureAwait(false);
}
public async Task<int> DeletedAsync(int idFile, CancellationToken token)
public async Task<int> DeleteAsync(int idFile, CancellationToken token)
{
var fileInfo = await db.Files
.FirstOrDefaultAsync(f => f.Id == idFile, token)

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|");
}
}
}