Add DetectorFlashing

This commit is contained in:
ngfrolov 2022-07-19 10:29:38 +05:00
parent 7b99e0fc88
commit 48cee90d91
11 changed files with 6249 additions and 8 deletions

View File

@ -65,7 +65,7 @@ namespace AsbCloudDb
{
var factory = GetQueryStringFactory(dbSet);
var query = factory.MakeInsertOrUpdateSql(items);
return database.ExecuteSqlRawAsync(query, token);
}
@ -130,7 +130,10 @@ namespace AsbCloudDb
pk = pkColsNames is null ? string.Empty : $"({string.Join(", ", pkColsNames)})";
TableName = dbset.EntityType.GetTableName()!;
getters = properties.Select(p => p.GetGetter());
getters = properties
.Where(p => !p.IsShadowProperty())
.Select(p => p.GetGetter()).ToList();
Columns = properties.Select(p => $"\"{p.GetColumnBaseName()}\"");
var colunmsString = $"({string.Join(", ", Columns)})";
@ -175,13 +178,21 @@ namespace AsbCloudDb
private static string FormatValue(object? v)
=> v switch
{
string vStr => $"'{vStr}'",
string vStr => $"'{EscapeCurlyBraces(vStr)}'",
DateTime vDate => $"'{FormatDateValue(vDate)}'",
DateTimeOffset vDate => $"'{FormatDateValue(vDate.UtcDateTime)}'",
IFormattable vFormattable => FormatFormattableValue(vFormattable),
_ => System.Text.Json.JsonSerializer.Serialize(v),
};
private static string EscapeCurlyBraces(string vStr)
{
var result = vStr
.Replace("{", "{{")
.Replace("}", "}}");
return result;
}
private static string FormatFormattableValue(IFormattable v)
=> v switch
{

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -4175,6 +4175,12 @@ namespace AsbCloudDb.Migrations
Name = "Шаблонировка перед наращиванием"
},
new
{
Id = 20,
Code = 0,
Name = "Шаблонировка перед наращиванием"
},
new
{
Id = 1001,
Code = 0,
@ -4732,7 +4738,7 @@ namespace AsbCloudDb.Migrations
b.HasKey("IdTelemetry", "DateTime");
b.ToTable("RecordBase");
b.ToTable("t_telemetry_wits_base");
});
modelBuilder.Entity("AsbCloudDb.Model.WITS.Record1", b =>

View File

@ -683,6 +683,7 @@ namespace AsbCloudDb.Model
new WellOperationCategory {Id = 17, Name = "На поверхности", Code = 0 },
new WellOperationCategory {Id = 18, Name = "Проработка перед наращиванием", Code = 0 },
new WellOperationCategory {Id = 19, Name = "Шаблонировка перед наращиванием", Code = 0 },
new WellOperationCategory {Id = 20, Name = "Промывка перед наращиванием", Code = 0 },
// Операции ручного ввода
new WellOperationCategory {Id = 1001, Name = "Бурение", Code = 0 },

View File

@ -195,10 +195,13 @@ namespace AsbCloudInfrastructure.Services
private bool CheckPassword(string passwordHash, string password)
{
if (passwordHash.Length == 0 && password.Length == 0)
if (passwordHash?.Length == 0 && password.Length == 0)
return true;
if (passwordHash.Length < PasswordSaltLength)
if (passwordHash?.Length < PasswordSaltLength)
return false;
if (passwordHash is null)
return false;
var salt = passwordHash[0..PasswordSaltLength];

View File

@ -258,6 +258,27 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
}
return false;
}
protected static bool DeviatesFromBegin(
DetectableTelemetry[] telemetry,
Func<DetectableTelemetry, double> getter,
int begin,
int count,
double deviation)
{
var beginPointValue = getter(telemetry[begin]);
var end = begin + count;
end = end < telemetry.Length ? end : telemetry.Length;
var step = count > 15 ? count / 5 : count > 3 ? 3 : 1;
for (var i = begin; i < end; i += step)
{
var item = telemetry[i];
var itemValue = getter(item);
if (Math.Abs(beginPointValue - itemValue) > deviation)
return true;
}
return false;
}
}
#nullable disable

View File

@ -0,0 +1,56 @@
using AsbCloudDb.Model;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
{
#nullable enable
/// <summary>
/// Промывка перед наращиванием
/// </summary>
internal class DetectorFlashing : DetectorAbstract
{
public DetectorFlashing()
: base(20) { }
protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end)
=> CalcDeltaMinutes(telemetry, begin, end);
protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
{
if (!((previousOperation?.IdCategory == 2) ||
(previousOperation?.IdCategory == 3)))
return false;
var point0 = telemetry[position];
var delta = point0.WellDepth - point0.BitDepth;
if (delta > 0.05d)
return false;
if (point0.Pressure < 15)
return false;
if (point0.BlockPosition > 3)
return false;
return true;
}
protected override bool DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
{
var point0 = telemetry[position];
var delta = point0.WellDepth - point0.BitDepth;
if ((delta > 0.03d )
&& (point0.Pressure > 15)
&& DeviatesFromBegin(telemetry, t=>t.BlockPosition, position, 300, 1))
return true;
return false;
}
protected override bool IsValid(DetectableTelemetry[] telemetry, int begin, int end)
=> IsValidByWellDepthDoesNotChange(telemetry, begin, end);
}
#nullable disable
}

View File

@ -25,6 +25,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
new DetectorDevelopment(),
new DetectorTemplating(),
new DetectorSlipsTime(),
new DetectorFlashing(),
};
public OperationDetectionBackgroundService(IConfiguration configuration)

View File

@ -0,0 +1,26 @@
# Алгоритм определения промывки перед проработкой/ шаблонировкой перед наращиванием
## Описание
Промывка перед проработкой/ шаблонировкой перед наращиванием операция, во время которой после добуривания очередной трубы происходит снижение осевой нагрузки и дифференциального давления, талевый блок остается условно неподвижным.
Проработка перед наращиванием определяется как время между:
- окончанием операции бурения (ротор/ слайд/ ручное бурение)
- началом операции проработки/ шаблонировки перед наращивании
## Метод определения
Признак начала операции =
( предыдущая операция == бурение в роторе или слайде)
( расстояние от долота до забоя < 0,05м ) И
( давление > 15 атм ) И
( положение блока < )
Признак окончания операции =
( расстояние от долота до забоя > 0.03м ) И
( давление > 15 атм ) И
( высота блока изменяется больше чем на 1м в течении 300 сек с начала операции);
## Ключевой параметр
Продолжительность операции.

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Services;
using AsbCloudDb;
using AsbCloudDb.Model;
using Mapster;
using Microsoft.EntityFrameworkCore;
@ -71,8 +72,9 @@ namespace AsbCloudInfrastructure.Services
return Task.CompletedTask;
var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours;
var entities = dtos.Select(dto => Convert(dto, idTelemetry, timezoneHours));
var entities = dtos
.DistinctBy(d => d.DateTime)
.Select(dto => Convert(dto, idTelemetry, timezoneHours));
dbset.AddRange(entities);
return db.SaveChangesAsync(token);
}