forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/sections
This commit is contained in:
commit
521e36834e
@ -6,7 +6,7 @@ namespace System.Collections.Generic
|
||||
/// Цикличный массив
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class CyclycArray<T> : IEnumerable<T>
|
||||
public class CyclicArray<T> : IEnumerable<T>
|
||||
{
|
||||
readonly T[] array;
|
||||
int used, current = -1;
|
||||
@ -15,7 +15,7 @@ namespace System.Collections.Generic
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="capacity"></param>
|
||||
public CyclycArray(int capacity)
|
||||
public CyclicArray(int capacity)
|
||||
{
|
||||
array = new T[capacity];
|
||||
}
|
@ -94,5 +94,5 @@ public class ProcessMapReportWellDrillingDto
|
||||
/// <summary>
|
||||
/// Механическая скорость, м/ч
|
||||
/// </summary>
|
||||
public PlanFactDto<double?> Rop { get; set; }
|
||||
public PlanFactDto<double?> Rop { get; set; } = new();
|
||||
}
|
@ -35,14 +35,18 @@ public class SectionByOperationsDto
|
||||
public DateTimeOffset DateStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Глубина после завершения последней операции операции в секции, м
|
||||
/// Глубина после завершения последней операции в секции, м
|
||||
/// </summary>
|
||||
[Range(0, 50_000)]
|
||||
public double DepthEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата после завершения последней операции операции в секции
|
||||
/// Дата после завершения последней операции в секции
|
||||
/// </summary>
|
||||
public DateTimeOffset DateEnd { get; set; }
|
||||
public string Caption { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название
|
||||
/// </summary>
|
||||
public string Caption { get; set; } = string.Empty;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace AsbCloudApp.Repositories
|
||||
void AddRange(int idTelemetry, IEnumerable<TDto> range);
|
||||
|
||||
/// <summary>
|
||||
/// вернуть последнюю записть
|
||||
/// вернуть последнюю запись
|
||||
/// </summary>
|
||||
/// <param name="idTelemetry"></param>
|
||||
/// <returns></returns>
|
||||
@ -49,7 +49,7 @@ namespace AsbCloudApp.Repositories
|
||||
/// </summary>
|
||||
/// <param name="idTelemetry"></param>
|
||||
/// <returns></returns>
|
||||
DatesRangeDto? GetOrDefaultCachedaDateRange(int idTelemetry);
|
||||
DatesRangeDto? GetOrDefaultCachedDateRange(int idTelemetry);
|
||||
|
||||
/// <summary>
|
||||
/// Получить диапазон дат телеметрии.
|
||||
|
@ -18,7 +18,7 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto>? dtos, CancellationToken token);
|
||||
Task<int> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение истории файлов
|
||||
|
@ -12,14 +12,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudDb
|
||||
{
|
||||
public static class EFExtentions
|
||||
public static class EFExtensions
|
||||
{
|
||||
private static readonly System.Text.Json.JsonSerializerOptions jsonSerializerOptions = new()
|
||||
private static readonly JsonSerializerOptions jsonSerializerOptions = new()
|
||||
{
|
||||
AllowTrailingCommas = true,
|
||||
WriteIndented = true,
|
||||
NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString |
|
||||
System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
||||
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
||||
};
|
||||
|
||||
public static Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasJsonConversion<TProperty>(
|
||||
@ -28,11 +27,11 @@ namespace AsbCloudDb
|
||||
|
||||
public static Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasJsonConversion<TProperty>(
|
||||
this Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> builder,
|
||||
System.Text.Json.JsonSerializerOptions jsonSerializerOptions)
|
||||
JsonSerializerOptions jsonSerializerOptions)
|
||||
{
|
||||
builder.HasConversion(
|
||||
s => System.Text.Json.JsonSerializer.Serialize(s, jsonSerializerOptions),
|
||||
s => System.Text.Json.JsonSerializer.Deserialize<TProperty>(s, jsonSerializerOptions)!);
|
||||
s => JsonSerializer.Serialize(s, jsonSerializerOptions),
|
||||
s => JsonSerializer.Deserialize<TProperty>(s, jsonSerializerOptions)!);
|
||||
|
||||
ValueComparer<TProperty> valueComparer = new (
|
||||
(a,b) =>
|
||||
@ -102,7 +101,7 @@ namespace AsbCloudDb
|
||||
return factory.Columns;
|
||||
}
|
||||
|
||||
public static Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<T> Upsert<T>(this DbSet<T> dbSet, T value)
|
||||
public static EntityEntry<T> Upsert<T>(this DbSet<T> dbSet, T value)
|
||||
where T : class
|
||||
{
|
||||
return dbSet.Contains(value)
|
@ -5,9 +5,9 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
|
||||
namespace AsbCloudDb
|
||||
{
|
||||
public static class EFExtentionsInnitialization
|
||||
public static class EFExtensionsInitialization
|
||||
{
|
||||
public static void EnshureCreatedAndMigrated(this DatabaseFacade db)
|
||||
public static void EnsureCreatedAndMigrated(this DatabaseFacade db)
|
||||
{
|
||||
db.SetCommandTimeout(TimeSpan.FromMinutes(5));
|
||||
if (db.EnsureCreated())
|
9083
AsbCloudDb/Migrations/20231205062914_Daily_report_lost_migration.Designer.cs
generated
Normal file
9083
AsbCloudDb/Migrations/20231205062914_Daily_report_lost_migration.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class Daily_report_lost_migration : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_relation_user_role_permission",
|
||||
keyColumns: new[] { "id_permission", "id_user_role" },
|
||||
keyValues: new object[] { 529, 1 });
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_permission",
|
||||
keyColumn: "id",
|
||||
keyValue: 529);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.InsertData(
|
||||
table: "t_permission",
|
||||
columns: new[] { "id", "description", "name" },
|
||||
values: new object[] { 529, "Разрешение редактировать фактические траектории", "FactTrajectory.edit" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "t_relation_user_role_permission",
|
||||
columns: new[] { "id_permission", "id_user_role" },
|
||||
values: new object[] { 529, 1 });
|
||||
}
|
||||
}
|
||||
}
|
9090
AsbCloudDb/Migrations/20231205063450_DetectedOperation_add_subsystems_and_extraData.Designer.cs
generated
Normal file
9090
AsbCloudDb/Migrations/20231205063450_DetectedOperation_add_subsystems_and_extraData.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class DetectedOperation_add_subsystems_and_extraData : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_relation_user_role_permission",
|
||||
keyColumns: new[] { "id_permission", "id_user_role" },
|
||||
keyValues: new object[] { 529, 1 });
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_permission",
|
||||
keyColumn: "id",
|
||||
keyValue: 529);
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "id_reason_of_end",
|
||||
table: "t_detected_operation");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "enabled_subsystems",
|
||||
table: "t_detected_operation",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
comment: "флаги аключенных подсистем");
|
||||
|
||||
migrationBuilder.AddColumn<IDictionary<string, object>>(
|
||||
name: "extra_data",
|
||||
table: "t_detected_operation",
|
||||
type: "jsonb",
|
||||
nullable: false,
|
||||
defaultValue: new { },
|
||||
comment: "доп. инфо по операции");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "enabled_subsystems",
|
||||
table: "t_detected_operation");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "extra_data",
|
||||
table: "t_detected_operation");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "id_reason_of_end",
|
||||
table: "t_detected_operation",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
comment: "Код признака окончания операции");
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "t_permission",
|
||||
columns: new[] { "id", "description", "name" },
|
||||
values: new object[] { 529, "Разрешение редактировать фактические траектории", "FactTrajectory.edit" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "t_relation_user_role_permission",
|
||||
columns: new[] { "id_permission", "id_user_role" },
|
||||
values: new object[] { 529, 1 });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -19,7 +20,7 @@ namespace AsbCloudDb.Migrations
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.UseCollation("Russian_Russia.1251")
|
||||
.HasAnnotation("ProductVersion", "6.0.22")
|
||||
.HasAnnotation("ProductVersion", "6.0.7")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack");
|
||||
@ -136,21 +137,21 @@ namespace AsbCloudDb.Migrations
|
||||
{
|
||||
Id = 1,
|
||||
Caption = "Недропользователь",
|
||||
IsContact = false,
|
||||
IsContact = true,
|
||||
Order = 3
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 2,
|
||||
Caption = "Буровой подрядчик",
|
||||
IsContact = false,
|
||||
IsContact = true,
|
||||
Order = 2
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 3,
|
||||
Caption = "Сервис автоматизации бурения",
|
||||
IsContact = false,
|
||||
IsContact = true,
|
||||
Order = 0
|
||||
},
|
||||
new
|
||||
@ -178,7 +179,7 @@ namespace AsbCloudDb.Migrations
|
||||
{
|
||||
Id = 7,
|
||||
Caption = "Служба супервайзинга",
|
||||
IsContact = true,
|
||||
IsContact = false,
|
||||
Order = 1
|
||||
},
|
||||
new
|
||||
@ -189,11 +190,18 @@ namespace AsbCloudDb.Migrations
|
||||
Order = 7
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 11,
|
||||
Caption = "Дизельный сервис",
|
||||
IsContact = false,
|
||||
Order = 9
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 12,
|
||||
Caption = "Сервис по обслуживанию верхних силовых приводов",
|
||||
IsContact = true,
|
||||
Order = 7
|
||||
Order = 8
|
||||
});
|
||||
});
|
||||
|
||||
@ -264,24 +272,46 @@ namespace AsbCloudDb.Migrations
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.DailyReports.DailyReport", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("Date")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("date")
|
||||
.HasComment("Дата формирования отчёта");
|
||||
|
||||
b.Property<DateTime?>("DateLastUpdate")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("date_last_update")
|
||||
.HasComment("Дата последнего обновления");
|
||||
|
||||
b.Property<int>("IdWell")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_well")
|
||||
.HasComment("ID скважины");
|
||||
|
||||
b.Property<DateOnly>("StartDate")
|
||||
.HasColumnType("date")
|
||||
.HasColumnName("start_date")
|
||||
.HasComment("Дата отчёта");
|
||||
|
||||
b.Property<string>("Info")
|
||||
.IsRequired()
|
||||
b.Property<string>("SignBlock")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("info")
|
||||
.HasComment("Список параметров для отчёта");
|
||||
.HasColumnName("sign_block")
|
||||
.HasComment("Подпись");
|
||||
|
||||
b.HasKey("IdWell", "StartDate")
|
||||
.HasName("t_id_well_date_start_pk");
|
||||
b.Property<string>("SubsystemBlock")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("subsystem_block")
|
||||
.HasComment("Наработкой подсистем");
|
||||
|
||||
b.Property<string>("TimeBalanceBlock")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("time_balance_block")
|
||||
.HasComment("Баланс времени");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IdWell", "Date")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("t_daily_report");
|
||||
|
||||
@ -353,16 +383,22 @@ namespace AsbCloudDb.Migrations
|
||||
.HasColumnName("depth_start")
|
||||
.HasComment("Глубина на начало операции, м");
|
||||
|
||||
b.Property<int>("EnabledSubsystems")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("enabled_subsystems")
|
||||
.HasComment("флаги аключенных подсистем");
|
||||
|
||||
b.Property<IDictionary<string, object>>("ExtraData")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("extra_data")
|
||||
.HasComment("доп. инфо по операции");
|
||||
|
||||
b.Property<int>("IdCategory")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_category")
|
||||
.HasComment("Id категории операции");
|
||||
|
||||
b.Property<int>("IdReasonOfEnd")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_reason_of_end")
|
||||
.HasComment("Код признака окончания операции");
|
||||
|
||||
b.Property<int>("IdTelemetry")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_telemetry");
|
||||
@ -8147,7 +8183,7 @@ namespace AsbCloudDb.Migrations
|
||||
b.Navigation("Well");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.DailyReport.DailyReport", b =>
|
||||
modelBuilder.Entity("AsbCloudDb.Model.DailyReports.DailyReport", b =>
|
||||
{
|
||||
b.HasOne("AsbCloudDb.Model.Well", "Well")
|
||||
.WithMany()
|
||||
|
@ -351,6 +351,10 @@ namespace AsbCloudDb.Model
|
||||
.HasJsonConversion();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<DetectedOperation>(entity => entity
|
||||
.Property(p=>p.ExtraData)
|
||||
.HasJsonConversion());
|
||||
|
||||
modelBuilder.Entity<TelemetryDataSaubStat>(entity =>
|
||||
{
|
||||
entity.HasNoKey()
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
@ -40,8 +41,11 @@ namespace AsbCloudDb.Model
|
||||
[Column("value"), Comment("Ключевой показатель операции")]
|
||||
public double Value { get; set; }
|
||||
|
||||
[Column("id_reason_of_end"), Comment("Код признака окончания операции")]
|
||||
public int IdReasonOfEnd { get; set; }
|
||||
[Column("enabled_subsystems"), Comment("флаги аключенных подсистем")]
|
||||
public int EnabledSubsystems { get; set; }
|
||||
|
||||
[Column("extra_data", TypeName = "jsonb"), Comment("доп. инфо по операции")]
|
||||
public IDictionary<string, object> ExtraData { get; set; } = null!;
|
||||
|
||||
[JsonIgnore]
|
||||
[ForeignKey(nameof(IdTelemetry))]
|
||||
@ -53,5 +57,57 @@ namespace AsbCloudDb.Model
|
||||
|
||||
public override string ToString()
|
||||
=> $"{IdCategory}\t{DateStart:G}\t{DateEnd:G}\t{DurationMinutes:#0.#}\t{DepthStart:#0.#}\t{DepthEnd:#0.#}";
|
||||
|
||||
/// <summary>
|
||||
/// Флаги аключенных подсистем
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum EnabledSubsystemsFlags
|
||||
{
|
||||
/// <summary>
|
||||
/// Автоподача долота
|
||||
/// </summary>
|
||||
AutoRotor = 1 << 0,
|
||||
/// <summary>
|
||||
/// БУРЕНИЕ В СЛАЙДЕ
|
||||
/// </summary>
|
||||
AutoSlide = 1 << 1,
|
||||
/// <summary>
|
||||
/// ПРОРАБОТКА
|
||||
/// </summary>
|
||||
AutoConditionig = 1 << 2,
|
||||
/// <summary>
|
||||
/// СПУСК СПО
|
||||
/// </summary>
|
||||
AutoSinking = 1 << 3,
|
||||
/// <summary>
|
||||
/// ПОДЪЕМ СПО
|
||||
/// </summary>
|
||||
AutoLifting = 1 << 4,
|
||||
/// <summary>
|
||||
/// ПОДЪЕМ С ПРОРАБОТКОЙ
|
||||
/// </summary>
|
||||
AutoLiftingWithConditionig = 1 << 5,
|
||||
/// <summary>
|
||||
/// блокировка
|
||||
/// </summary>
|
||||
AutoBlocknig = 1 << 6,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Есть ли флаг подсистемы у операции
|
||||
/// </summary>
|
||||
/// <param name="flag"></param>
|
||||
/// <returns></returns>
|
||||
public bool HasSubsystemFlag(EnabledSubsystemsFlags flag)
|
||||
=> HasSubsystemFlag((int)flag);
|
||||
|
||||
/// <summary>
|
||||
/// Есть ли флаг/флаги подсистемы у операции
|
||||
/// </summary>
|
||||
/// <param name="flags"></param>
|
||||
/// <returns></returns>
|
||||
public bool HasSubsystemFlag(int flags)
|
||||
=> (EnabledSubsystems & flags) > 0;
|
||||
}
|
||||
}
|
@ -42,7 +42,7 @@ namespace AsbCloudDb.Model
|
||||
/// <summary>
|
||||
/// КНБК
|
||||
/// </summary>
|
||||
public const int IdKnbk = 4000;
|
||||
public const int IdBha = 4000;
|
||||
|
||||
/// <summary>
|
||||
/// Механическое. бурение
|
||||
@ -246,7 +246,7 @@ namespace AsbCloudDb.Model
|
||||
/// Виды работ
|
||||
/// </summary>
|
||||
public static WellOperationCategory[] WorkTypes { get; } = new WellOperationCategory[]{
|
||||
new () {Id = IdKnbk, IdParent = 3000, Name = "КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||
new () {Id = IdBha, IdParent = 3000, Name = "КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||
new () {Id = IdMechanicalDrilling, IdParent = 3000, Name = "Механическое. бурение", KeyValueName = "dT", KeyValueUnits = "м/ч" },
|
||||
new () {Id = IdMeasurementStat, IdParent = 3000, Name = "Статический замер", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||
new () {Id = IdNormalizedWellDiameter, IdParent = 3000, Name = "Нормализация диаметра скважины", KeyValueName = "dT", KeyValueUnits = "мин" },
|
||||
|
@ -36,12 +36,12 @@ public class BackgroundWorker : BackgroundService
|
||||
/// <summary>
|
||||
/// последние 16 завершившиеся с ошибкой
|
||||
/// </summary>
|
||||
public CyclycArray<Work> Felled { get; } = new(16);
|
||||
public CyclicArray<Work> Felled { get; } = new(16);
|
||||
|
||||
/// <summary>
|
||||
/// последние 16 успешно завершенных
|
||||
/// </summary>
|
||||
public CyclycArray<Work> Done { get; } = new(16);
|
||||
public CyclicArray<Work> Done { get; } = new(16);
|
||||
|
||||
/// <summary>
|
||||
/// Ошибка в главном цикле, никогда не должна появляться
|
||||
|
@ -167,7 +167,6 @@ public class WorkSubsystemOscillationOperationTimeCalc : WorkSubsystemOperationT
|
||||
.Where(d => d.IdTelemetry == idTelemetry)
|
||||
.Where(d => d.DateTime >= dateBegin)
|
||||
.Where(d => d.DateTime <= dateEnd)
|
||||
.Where(d => d.WellDepth != null)
|
||||
.Where(d => d.WellDepth > 0)
|
||||
.GroupBy(d => Math.Ceiling(d.WellDepth * 10))
|
||||
.Select(g => new
|
||||
|
@ -111,7 +111,8 @@ public class WellOperationRepository : IWellOperationRepository
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (lastFactOperation is not null)
|
||||
return DateTime.SpecifyKind(lastFactOperation.OperationPlan.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified);
|
||||
return DateTime.SpecifyKind(lastFactOperation.OperationPlan!.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -95,12 +95,10 @@ public class DailyReportService : IDailyReportService
|
||||
|
||||
public async Task<DailyReportDto> GetAsync(int idWell, DateTime dateDailyReport, CancellationToken cancellationToken)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken);
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken)
|
||||
?? throw new ArgumentNullException(nameof(idWell), $"Скважина с Id: {idWell} не найдена");
|
||||
|
||||
if (well is null)
|
||||
throw new ArgumentNullException(nameof(idWell), $"Скважина с Id: {idWell} не найдена");
|
||||
|
||||
if (!await IsDateDailyReportInRangeAsync(idWell, dateDailyReport, cancellationToken))
|
||||
if (!await IsDateDailyReportInRangeAsync(idWell, dateDailyReport, cancellationToken))
|
||||
throw new ArgumentInvalidException(nameof(dateDailyReport), "Невозможно получить суточный отчёт");
|
||||
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,18 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations;
|
||||
|
||||
public class DetectableTelemetry
|
||||
{
|
||||
|
||||
public class DetectableTelemetry
|
||||
{
|
||||
public DateTimeOffset DateTime { get; set; }
|
||||
public int? IdUser { get; set; }
|
||||
public float WellDepth { get; set; }
|
||||
public float Pressure { get; set; }
|
||||
public float HookWeight { get; set; }
|
||||
public float BlockPosition { get; set; }
|
||||
public float BitDepth { get; set; }
|
||||
public float RotorSpeed { get; set; }
|
||||
}
|
||||
|
||||
public DateTimeOffset DateTime { get; set; }
|
||||
public int? IdUser { get; set; }
|
||||
public int Mode { get; set; }
|
||||
public float WellDepth { get; set; }
|
||||
public float Pressure { get; set; }
|
||||
public float HookWeight { get; set; }
|
||||
public float BlockPosition { get; set; }
|
||||
public float BitDepth { get; set; }
|
||||
public float RotorSpeed { get; set; }
|
||||
}
|
||||
|
@ -9,12 +9,17 @@ using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
|
||||
using AsbCloudApp.Repositories;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations;
|
||||
|
||||
public class DetectedOperationExportService
|
||||
{
|
||||
private readonly DetectorAbstract[] detectors = { new DetectorDrilling(), new DetectorSlipsTime() };
|
||||
private readonly DetectorAbstract[] detectors =
|
||||
{
|
||||
new DetectorDrilling(),
|
||||
new DetectorSlipsTime()
|
||||
};
|
||||
|
||||
private readonly IDictionary<int, string> domains = new Dictionary<int, string>
|
||||
{
|
||||
@ -38,13 +43,16 @@ public class DetectedOperationExportService
|
||||
private const int columnDeltaDepth = 7;
|
||||
private const int columnDepth = 8;
|
||||
private const int columnIdReasonOfEnd = 9;
|
||||
private const int columnComment = 10;
|
||||
|
||||
private readonly IAsbCloudDbContext dbContext;
|
||||
private readonly IWellOperationRepository wellOperationRepository;
|
||||
|
||||
public DetectedOperationExportService(IAsbCloudDbContext dbContext)
|
||||
public DetectedOperationExportService(IAsbCloudDbContext dbContext, IWellOperationRepository wellOperationRepository)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
}
|
||||
this.wellOperationRepository = wellOperationRepository;
|
||||
}
|
||||
|
||||
public async Task<Stream> ExportAsync(int idWell, int idDomain, CancellationToken cancellationToken)
|
||||
{
|
||||
@ -59,20 +67,19 @@ public class DetectedOperationExportService
|
||||
if (!well.IdTelemetry.HasValue)
|
||||
throw new ArgumentNullException(nameof(well));
|
||||
|
||||
var operations = await DetectOperationsAsync(well.IdTelemetry.Value, new DateTime(2023, 10, 14)
|
||||
.ToUtcDateTimeOffset(well.Timezone.Hours), cancellationToken);
|
||||
var operations = await DetectOperationsAsync(well.IdTelemetry.Value, DateTime.UnixEpoch, cancellationToken);
|
||||
|
||||
return await GenerateExcelFileStreamAsync(well, idDomain, operations, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task<Stream> GenerateExcelFileStreamAsync(Well well, int idDomain, IEnumerable<DetectedOperation> detectedOperations,
|
||||
private async Task<Stream> GenerateExcelFileStreamAsync(Well well, int idDomain, IEnumerable<OperationDetectorResult> operationDetectorResults,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken);
|
||||
|
||||
using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled);
|
||||
|
||||
await AddToWorkbookAsync(workbook, well, idDomain, detectedOperations, cancellationToken);
|
||||
await AddToWorkbookAsync(workbook, well, idDomain, operationDetectorResults, cancellationToken);
|
||||
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
workbook.SaveAs(memoryStream, new SaveOptions { });
|
||||
@ -80,22 +87,23 @@ public class DetectedOperationExportService
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
private async Task AddToWorkbookAsync(XLWorkbook workbook, Well well, int idDomain, IEnumerable<DetectedOperation> detectedOperations,
|
||||
private async Task AddToWorkbookAsync(XLWorkbook workbook, Well well, int idDomain, IEnumerable<OperationDetectorResult> operationDetectorResults,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
const string sheetName = "Операции";
|
||||
|
||||
if (!detectedOperations.Any())
|
||||
if (!operationDetectorResults.Any())
|
||||
return;
|
||||
|
||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName)
|
||||
?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}.");
|
||||
|
||||
await AddToSheetAsync(sheet, well, idDomain, detectedOperations.OrderBy(x => x.DateStart).ThenBy(x => x.DepthStart).ToArray(),
|
||||
await AddToSheetAsync(sheet, well, idDomain, operationDetectorResults
|
||||
.OrderBy(x => x.Operation.DateStart).ThenBy(x => x.Operation.DepthStart).ToArray(),
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private async Task AddToSheetAsync(IXLWorksheet sheet, Well well, int idDomain, IList<DetectedOperation> detectedOperations,
|
||||
private async Task AddToSheetAsync(IXLWorksheet sheet, Well well, int idDomain, IList<OperationDetectorResult> operationDetectorResults,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var wellOperationCategories = await dbContext.WellOperationCategories.ToListAsync(cancellationToken);
|
||||
@ -103,40 +111,70 @@ public class DetectedOperationExportService
|
||||
sheet.Cell(cellDepositName).Value = well.Cluster.Deposit.Caption;
|
||||
sheet.Cell(cellClusterName).Value = well.Cluster.Caption;
|
||||
sheet.Cell(cellWellName).Value = well.Caption;
|
||||
sheet.Cell(cellDeltaDate).Value = detectedOperations.Max(o => o.DateEnd) - detectedOperations.Min(o => o.DateStart);
|
||||
sheet.Cell(cellDeltaDate).Value = operationDetectorResults.Max(o => o.Operation.DateEnd) - operationDetectorResults.Min(o => o.Operation.DateStart);
|
||||
|
||||
var timeZoneWell = TimeSpan.FromHours(well.Timezone.Hours);
|
||||
var detectedOperations = operationDetectorResults.Select(o => o.Operation).ToArray();
|
||||
|
||||
for (int i = 0; i < detectedOperations.Count; i++)
|
||||
for (int i = 0; i < operationDetectorResults.Count; i++)
|
||||
{
|
||||
var dateStart = detectedOperations[i].DateStart.ToOffset(timeZoneWell);
|
||||
var dateEnd = detectedOperations[i].DateEnd.ToOffset(timeZoneWell);
|
||||
var current = detectedOperations[i];
|
||||
var dateStart = current.DateStart.ToRemoteDateTime(well.Timezone.Hours);
|
||||
var dateEnd = current.DateEnd.ToRemoteDateTime(well.Timezone.Hours);
|
||||
|
||||
var row = sheet.Row(5 + i + headerRowsCount);
|
||||
|
||||
row.Cell(columnOperationName).Value = detectedOperations[i].IdCategory == 12000
|
||||
? "Бурение в слайде с осцилляцией"
|
||||
: wellOperationCategories.Single(o => o.Id == detectedOperations[i].IdCategory).Name;
|
||||
row.Cell(columnOperationName).Value = GetCategoryName(wellOperationCategories, current);
|
||||
row.Cell(columnDateEnd).Value = dateEnd;
|
||||
row.Cell(columnDuration).Value = (dateEnd - dateStart).TotalMinutes;
|
||||
row.Cell(columnDepthStart).Value = detectedOperations[i].DepthStart;
|
||||
row.Cell(columnDepthEnd).Value = detectedOperations[i].DepthEnd;
|
||||
row.Cell(columnDepth).Value = detectedOperations[i].DepthEnd - detectedOperations[i].DepthStart;
|
||||
row.Cell(columnIdReasonOfEnd).Value = detectedOperations[i].IdReasonOfEnd;
|
||||
row.Cell(columnDepthStart).Value = current.DepthStart;
|
||||
row.Cell(columnDepthEnd).Value = current.DepthEnd;
|
||||
row.Cell(columnDepth).Value = current.DepthEnd - current.DepthStart;
|
||||
|
||||
if (current.ExtraData.TryGetValue("IdReasonOfEnd", out object? idReasonOfEndObject)
|
||||
&& idReasonOfEndObject is int idReasonOfEnd)
|
||||
row.Cell(columnIdReasonOfEnd).Value = GetIdReasonOfEnd(idReasonOfEnd);
|
||||
|
||||
var link =
|
||||
$"{domains[idDomain]}/well/{well.Id}/telemetry/monitoring?end={Uri.EscapeDataString(dateStart.AddSeconds(3544).ToString("yyyy-MM-ddTHH:mm:ss.fff"))}&range=3600";
|
||||
$"{domains[idDomain]}/well/{well.Id}/telemetry/monitoring?end={Uri.EscapeDataString(dateStart.AddSeconds(1800 * 0.9).ToString("yyyy-MM-ddTHH:mm:ss.fff"))}&range=1800";
|
||||
|
||||
row.Cell(columnDateStart).Value = dateStart;
|
||||
row.Cell(columnDateStart).SetHyperlink(new XLHyperlink(link));
|
||||
|
||||
row.Cell(columnDeltaDepth).Value = i > 0 && i + 1 < detectedOperations.Count
|
||||
? detectedOperations[i].DepthStart - detectedOperations[i - 1].DepthEnd
|
||||
row.Cell(columnDeltaDepth).Value = i > 0 && i + 1 < detectedOperations.Length
|
||||
? current.DepthStart - detectedOperations[i - 1].DepthEnd
|
||||
: 0;
|
||||
|
||||
row.Cell(columnComment).Value = CreateComment(operationDetectorResults[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Stream> GetExcelTemplateStreamAsync(CancellationToken cancellationToken)
|
||||
|
||||
private static string GetCategoryName(IEnumerable<WellOperationCategory> wellOperationCategories, DetectedOperation current)
|
||||
{
|
||||
var idCategory = current.IdCategory;
|
||||
if (idCategory == WellOperationCategory.IdSlide
|
||||
&& current.ExtraData[DetectorDrilling.ExtraDataKeyHasOscillation] is bool hasOscillation
|
||||
&& hasOscillation)
|
||||
return "Бурение в слайде с осцилляцией";
|
||||
|
||||
var category = wellOperationCategories.FirstOrDefault(o => o.Id == current.IdCategory);
|
||||
|
||||
if(category is not null)
|
||||
return category.Name;
|
||||
|
||||
return $"Операция №{idCategory}";
|
||||
}
|
||||
|
||||
private static string GetIdReasonOfEnd(int idReasonOfEnd)
|
||||
=> idReasonOfEnd switch {
|
||||
0 => "Не определена",
|
||||
1 => "Не определено начало операции",
|
||||
101 => "Разница глубин забоя и положением долота",
|
||||
300 => "Низкое давление",
|
||||
_ => idReasonOfEnd.ToString($"Причина № {idReasonOfEnd}"),
|
||||
|
||||
};
|
||||
|
||||
private async Task<Stream> GetExcelTemplateStreamAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
string resourceName = Assembly.GetExecutingAssembly()
|
||||
.GetManifestResourceNames()
|
||||
@ -151,8 +189,29 @@ public class DetectedOperationExportService
|
||||
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
private static string CreateComment(OperationDetectorResult operationDetectorResult)
|
||||
{
|
||||
var operation = operationDetectorResult.Operation;
|
||||
switch (operation.IdCategory)
|
||||
{
|
||||
case WellOperationCategory.IdRotor:
|
||||
case WellOperationCategory.IdSlide:
|
||||
var comment = "";
|
||||
if (operation.ExtraData.TryGetValue(DetectorDrilling.ExtraDataKeyAvgRotorSpeed, out object? oAvgRotorSpeed))
|
||||
comment += $"Средняя скорость оборотов ротора: {oAvgRotorSpeed}\r\n";
|
||||
|
||||
private async Task<IEnumerable<DetectedOperation>> DetectOperationsAsync(int idTelemetry, DateTimeOffset begin,
|
||||
if (operation.ExtraData.TryGetValue(DetectorDrilling.ExtraDataKeyDispersionOfNormalizedRotorSpeed, out object? oDispersionOfNormalizedRotorSpeed))
|
||||
comment += $"Дисперсия нормированных оборотов ротора: {oDispersionOfNormalizedRotorSpeed}";
|
||||
|
||||
return comment;
|
||||
|
||||
default:
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<OperationDetectorResult>> DetectOperationsAsync(int idTelemetry, DateTimeOffset begin,
|
||||
CancellationToken token)
|
||||
{
|
||||
var query = dbContext.TelemetryDataSaub
|
||||
@ -173,7 +232,7 @@ public class DetectedOperationExportService
|
||||
.OrderBy(d => d.DateTime);
|
||||
|
||||
var startDate = begin;
|
||||
var detectedOperations = new List<DetectedOperation>(8);
|
||||
var detectedOperationResults = new List<OperationDetectorResult>(8);
|
||||
DetectedOperation? lastDetectedOperation = null;
|
||||
const int minOperationLength = 5;
|
||||
const int maxDetectorsInterpolationFrameLength = 30;
|
||||
@ -191,26 +250,21 @@ public class DetectedOperationExportService
|
||||
var isDetected = false;
|
||||
var positionBegin = 0;
|
||||
var positionEnd = data.Length - gap;
|
||||
var step = 10;
|
||||
while (positionEnd > positionBegin)
|
||||
{
|
||||
step++;
|
||||
foreach (var detector in detectors)
|
||||
{
|
||||
if (!detector.TryDetect(idTelemetry, data, positionBegin, positionEnd, lastDetectedOperation, out var result))
|
||||
continue;
|
||||
|
||||
detectedOperations.Add(result!.Operation);
|
||||
lastDetectedOperation = result.Operation;
|
||||
detectedOperationResults.Add(result!);
|
||||
lastDetectedOperation = result!.Operation;
|
||||
isDetected = true;
|
||||
step = 1;
|
||||
positionBegin = result.TelemetryEnd;
|
||||
break;
|
||||
}
|
||||
|
||||
if (step > 20)
|
||||
step = 10;
|
||||
positionBegin += step;
|
||||
|
||||
positionBegin += 1;
|
||||
}
|
||||
|
||||
if (isDetected)
|
||||
@ -219,6 +273,6 @@ public class DetectedOperationExportService
|
||||
startDate = data[positionEnd].DateTime;
|
||||
}
|
||||
|
||||
return detectedOperations;
|
||||
return detectedOperationResults;
|
||||
}
|
||||
}
|
@ -201,7 +201,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
if (well?.IdTelemetry is null || well.Timezone is null)
|
||||
return 0;
|
||||
|
||||
var query = BuildQuery(well, request);
|
||||
var query = BuildQueryBase(well, request);
|
||||
|
||||
if (query is null)
|
||||
return 0;
|
||||
@ -232,13 +232,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
};
|
||||
}
|
||||
|
||||
private IQueryable<DetectedOperation>? BuildQuery(WellDto well, DetectedOperationRequest request)
|
||||
{
|
||||
if (well?.IdTelemetry is null || well.Timezone is null)
|
||||
return null;
|
||||
|
||||
private IQueryable<DetectedOperation> BuildQueryBase(WellDto well, DetectedOperationRequest request)
|
||||
{
|
||||
var query = db.Set<DetectedOperation>()
|
||||
.Include(o => o.OperationCategory)
|
||||
.Where(o => o.IdTelemetry == well.IdTelemetry);
|
||||
|
||||
if (request is not null)
|
||||
@ -262,6 +259,14 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
query = query.Where(o => o.IdUsersAtStart == request.EqIdTelemetryUser);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
private IQueryable<DetectedOperation> BuildQuery(WellDto well, DetectedOperationRequest request)
|
||||
{
|
||||
IQueryable<DetectedOperation> query = BuildQueryBase(well, request)
|
||||
.Include(o => o.OperationCategory);
|
||||
|
||||
if (request?.SortFields?.Any() == true)
|
||||
{
|
||||
query = query.SortBy(request.SortFields);
|
||||
|
@ -1,11 +1,11 @@
|
||||
using AsbCloudDb.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
{
|
||||
|
||||
internal abstract class DetectorAbstract
|
||||
public abstract class DetectorAbstract
|
||||
{
|
||||
private readonly int stepLength = 3;
|
||||
|
||||
@ -34,14 +34,13 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
protected const int IdReasonOfEnd_Drilling = 600;
|
||||
|
||||
protected const int IdReasonOfEnd_Custom1 = 10_000;
|
||||
|
||||
public abstract Func<DetectableTelemetry[], int, int, int> GetIdOperation { get; }
|
||||
|
||||
public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end, DetectedOperation? previousOperation, out OperationDetectorResult? result)
|
||||
public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end, DetectedOperation? previousOperation,
|
||||
out OperationDetectorResult? result)
|
||||
{
|
||||
// Проверка соответствия критерию начала операции
|
||||
if (DetectBegin(telemetry, begin, previousOperation))
|
||||
{
|
||||
{
|
||||
// Поиск окончания соответствия критерию
|
||||
int idReasonOfEnd = 0;
|
||||
var positionEnd = begin;
|
||||
@ -52,84 +51,142 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
break;
|
||||
|
||||
idReasonOfEnd = DetectEnd(telemetry, positionEnd, previousOperation);
|
||||
|
||||
if(idReasonOfEnd is IdReasonOfEnd_DeltaDepthIsHi or IdReasonOfEnd_PressureIsLo &&
|
||||
!IsValidByWellDepthDoesNotChange(telemetry, begin, positionEnd))
|
||||
break;
|
||||
|
||||
if (idReasonOfEnd != IdReasonOfEnd_NotDetected)
|
||||
|
||||
if (idReasonOfEnd != IdReasonOfEnd_NotDetected)
|
||||
break;
|
||||
}
|
||||
|
||||
result = null;
|
||||
result = MakeOperation(idTelemetry, telemetry, begin, positionEnd, idReasonOfEnd);
|
||||
return true;
|
||||
var (Begin, End) = RefineEdges(telemetry, begin, positionEnd);
|
||||
|
||||
if (!IsValidTelemetryRange(telemetry, Begin, End))
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
result = MakeOperationDetectorResult(idTelemetry, telemetry, Begin, End, idReasonOfEnd);
|
||||
|
||||
return IsValidOperationDetectorResult(result);
|
||||
}
|
||||
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation);
|
||||
protected virtual int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
||||
=> DetectBegin(telemetry, position, previousOperation)
|
||||
? IdReasonOfEnd_NotDetected
|
||||
: IdReasonOfEnd_NotDetectBegin;
|
||||
protected virtual bool IsValidTelemetryRange(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
=> end - begin > 1;
|
||||
|
||||
private OperationDetectorResult MakeOperation(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end, int idReasonOfEnd)
|
||||
protected virtual (int Begin, int End) RefineEdges(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
=> (begin, end);
|
||||
|
||||
protected virtual bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult)
|
||||
=> operationDetectorResult.Operation.DateEnd - operationDetectorResult.Operation.DateStart > TimeSpan.FromSeconds(3);
|
||||
|
||||
protected abstract bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation);
|
||||
|
||||
protected virtual int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
||||
=> DetectBegin(telemetry, position, previousOperation)
|
||||
? IdReasonOfEnd_NotDetected
|
||||
: IdReasonOfEnd_NotDetectBegin;
|
||||
|
||||
private OperationDetectorResult MakeOperationDetectorResult(
|
||||
int idTelemetry,
|
||||
DetectableTelemetry[] telemetry,
|
||||
int begin,
|
||||
int end,
|
||||
int idReasonOfEnd)
|
||||
{
|
||||
var pBegin = telemetry[begin];
|
||||
var pEnd = telemetry[end];
|
||||
var operation = MakeDetectedOperation(idTelemetry, telemetry, begin, end);
|
||||
|
||||
operation.ExtraData["IdReasonOfEnd"] = idReasonOfEnd;
|
||||
|
||||
var result = new OperationDetectorResult
|
||||
{
|
||||
TelemetryBegin = begin,
|
||||
TelemetryEnd = end,
|
||||
Operation = new DetectedOperation
|
||||
{
|
||||
IdTelemetry = idTelemetry,
|
||||
IdCategory = GetIdOperation.Invoke(telemetry, begin, end),
|
||||
IdUsersAtStart = pBegin.IdUser ?? -1,
|
||||
DateStart = pBegin.DateTime,
|
||||
DateEnd = pEnd.DateTime,
|
||||
DepthStart = (double)pBegin.WellDepth,
|
||||
DepthEnd = (double)pEnd.WellDepth,
|
||||
Value = CalcValue(telemetry, begin, end),
|
||||
IdReasonOfEnd = idReasonOfEnd,
|
||||
},
|
||||
Operation = operation,
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract bool IsValid(DetectableTelemetry[] telemetry, int begin, int end);
|
||||
private DetectedOperation MakeDetectedOperation(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end)
|
||||
{
|
||||
var pBegin = telemetry[begin];
|
||||
var pEnd = telemetry[end];
|
||||
var (IdCategory, ExtraData) = GetSpecificInformation(telemetry, begin, end);
|
||||
var operation = new DetectedOperation
|
||||
{
|
||||
IdCategory = IdCategory,
|
||||
IdTelemetry = idTelemetry,
|
||||
IdUsersAtStart = pBegin.IdUser ?? -1,
|
||||
DateStart = pBegin.DateTime,
|
||||
DateEnd = pEnd.DateTime,
|
||||
DepthStart = (double)pBegin.WellDepth,
|
||||
DepthEnd = (double)pEnd.WellDepth,
|
||||
ExtraData = ExtraData,
|
||||
Value = CalcValue(telemetry, begin, end),
|
||||
EnabledSubsystems = DetectEnabledSubsystems(telemetry, begin, end)
|
||||
};
|
||||
|
||||
protected abstract double CalcValue(DetectableTelemetry[] telemetry, int begin, int end);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Среднее арифметическое
|
||||
/// Получение информации специфичной для конкретного детектора
|
||||
/// IdCategory - одна из констант WellOperationCategory
|
||||
/// ExtraData - дополнительная информация для отладки алгоритмов авто определения
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract (int IdCategory, IDictionary<string, object> ExtraData) GetSpecificInformation(DetectableTelemetry[] telemetry, int begin, int end);
|
||||
|
||||
/// <summary>
|
||||
/// Расчет ключевого параметра операции
|
||||
/// </summary>
|
||||
/// <param name="yGetter"></param>
|
||||
/// <param name="telemetry"></param>
|
||||
/// <param name="begin"></param>
|
||||
/// <param name="fragmentLength"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <returns></returns>
|
||||
public static double CalcAvgAppr(
|
||||
Func<DetectableTelemetry, double> yGetter,
|
||||
DetectableTelemetry[] telemetry,
|
||||
int begin,
|
||||
int fragmentLength)
|
||||
protected abstract double CalcValue(DetectableTelemetry[] telemetry, int begin, int end);
|
||||
|
||||
/// <summary>
|
||||
/// Определение включенных подсистем во время выполнения операции
|
||||
/// </summary>
|
||||
/// <param name="telemetry"></param>
|
||||
/// <param name="begin"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <returns></returns>
|
||||
private static int DetectEnabledSubsystems(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
{
|
||||
var end = begin + fragmentLength;
|
||||
end = end < telemetry.Length
|
||||
? end
|
||||
: telemetry.Length;
|
||||
var subData = telemetry[begin..end].Select(yGetter);
|
||||
if (end - begin > 10)
|
||||
var enabledSubsystems = 0;
|
||||
|
||||
for (var i = begin; i < end; i += 2)
|
||||
{
|
||||
var ratio = (end - begin) / 5;
|
||||
subData = subData.Where((_,i) => i % ratio > 0);
|
||||
}
|
||||
|
||||
var avg = subData.Average();
|
||||
return avg;
|
||||
var mode = telemetry[i].Mode;
|
||||
|
||||
if(mode == 1)
|
||||
enabledSubsystems |= (int)DetectedOperation.EnabledSubsystemsFlags.AutoRotor;
|
||||
|
||||
if (mode == 3)
|
||||
enabledSubsystems |= (int)DetectedOperation.EnabledSubsystemsFlags.AutoSlide;
|
||||
|
||||
if (mode == 2)
|
||||
enabledSubsystems |= (int)DetectedOperation.EnabledSubsystemsFlags.AutoConditionig;
|
||||
|
||||
if (mode == 4)
|
||||
enabledSubsystems |= (int)DetectedOperation.EnabledSubsystemsFlags.AutoSinking;
|
||||
|
||||
if (mode == 5)
|
||||
enabledSubsystems |= (int)DetectedOperation.EnabledSubsystemsFlags.AutoLifting;
|
||||
|
||||
if (mode == 6)
|
||||
enabledSubsystems |= (int)DetectedOperation.EnabledSubsystemsFlags.AutoLiftingWithConditionig;
|
||||
|
||||
if (mode == 10)
|
||||
enabledSubsystems |= (int)DetectedOperation.EnabledSubsystemsFlags.AutoBlocknig;
|
||||
}
|
||||
|
||||
return enabledSubsystems;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -189,9 +246,9 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
/// <param name="count"></param>
|
||||
/// <returns></returns>
|
||||
protected static (double min, double max, double sum, int count) CalcStat(
|
||||
DetectableTelemetry[] telemetry,
|
||||
Func<DetectableTelemetry, double> getter,
|
||||
int begin,
|
||||
DetectableTelemetry[] telemetry,
|
||||
Func<DetectableTelemetry, double> getter,
|
||||
int begin,
|
||||
int count)
|
||||
{
|
||||
var sum = 0d;
|
||||
@ -210,6 +267,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
max = itemValue;
|
||||
sum += itemValue;
|
||||
}
|
||||
|
||||
return (min, max, sum, end - begin);
|
||||
}
|
||||
|
||||
@ -256,7 +314,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
var end = begin + count;
|
||||
end = end < telemetry.Length ? end : telemetry.Length;
|
||||
|
||||
for (var i = begin; i < end; i ++)
|
||||
for (var i = begin; i < end; i++)
|
||||
{
|
||||
var item = telemetry[i];
|
||||
var itemValue = getter(item);
|
||||
@ -264,9 +322,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
min = itemValue;
|
||||
if (max < itemValue)
|
||||
max = itemValue;
|
||||
if(max - min > deviation)
|
||||
if (max - min > deviation)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -290,8 +349,8 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
var max = double.MinValue;
|
||||
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 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);
|
||||
@ -302,6 +361,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
if (max - min > deviation)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -323,6 +383,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
if (Math.Abs(beginPointValue - itemValue) > deviation)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -341,13 +402,12 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
{
|
||||
var item = telemetry[i];
|
||||
var itemValue = getter(item);
|
||||
if ( itemValue - beginPointValue > deviation)
|
||||
if (itemValue - beginPointValue > deviation)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,68 +1,66 @@
|
||||
using System;
|
||||
using AsbCloudDb.Model;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Проработка перед наращиванием
|
||||
/// </summary>
|
||||
internal class DetectorDevelopment : DetectorAbstract
|
||||
{
|
||||
protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
=> CalcDeltaMinutes(telemetry, begin, end);
|
||||
|
||||
public override Func<DetectableTelemetry[], int, int, int> GetIdOperation => (_, _, _)
|
||||
=> WellOperationCategory.IdDevelopment;
|
||||
|
||||
protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
||||
{
|
||||
if (previousOperation?.IdCategory == WellOperationCategory.IdSlipsTime)
|
||||
return false;
|
||||
|
||||
var point0 = telemetry[position];
|
||||
var delta = point0.WellDepth - point0.BitDepth;
|
||||
if (delta < 0.03d || delta > 30)
|
||||
return false;
|
||||
|
||||
if (point0.Pressure < 15)
|
||||
return false;
|
||||
|
||||
if (point0.BlockPosition > 2.5)
|
||||
return false;
|
||||
|
||||
if (point0.RotorSpeed < 10)
|
||||
return false;
|
||||
|
||||
if (!ContainsDeviationApprox(telemetry, d => d.BlockPosition, position, 60, 0.03))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
||||
{
|
||||
var point0 = telemetry[position];
|
||||
var delta = point0.WellDepth - point0.BitDepth;
|
||||
if (delta < 0.03d || delta > 30)
|
||||
return IdReasonOfEnd_DeltaDepthOutOfRange;
|
||||
|
||||
if (point0.Pressure < 15)
|
||||
return IdReasonOfEnd_PressureIsLo;
|
||||
|
||||
if (point0.BlockPosition > 31)
|
||||
return IdReasonOfEnd_BlockPositionIsHi;
|
||||
|
||||
if (point0.RotorSpeed < 10)
|
||||
return IdReasonOfEnd_RotorSpeedIsLo;
|
||||
|
||||
return IdReasonOfEnd_NotDetected;
|
||||
}
|
||||
|
||||
protected override bool IsValid(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
=> IsValidByWellDepthDoesNotChange(telemetry, begin, end);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// using System;
|
||||
// using AsbCloudDb.Model;
|
||||
//
|
||||
// namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
// {
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Проработка перед наращиванием
|
||||
// /// </summary>
|
||||
// internal class DetectorDevelopment : DetectorAbstract
|
||||
// {
|
||||
// protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
// => CalcDeltaMinutes(telemetry, begin, end);
|
||||
//
|
||||
// public override Func<DetectableTelemetry[], int, int, int> GetIdOperation => (_, _, _)
|
||||
// => WellOperationCategory.IdDevelopment;
|
||||
//
|
||||
// protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
||||
// {
|
||||
// if (previousOperation?.IdCategory == WellOperationCategory.IdSlipsTime)
|
||||
// return false;
|
||||
//
|
||||
// var point0 = telemetry[position];
|
||||
// var delta = point0.WellDepth - point0.BitDepth;
|
||||
// if (delta < 0.03d || delta > 30)
|
||||
// return false;
|
||||
//
|
||||
// if (point0.Pressure < 15)
|
||||
// return false;
|
||||
//
|
||||
// if (point0.BlockPosition > 2.5)
|
||||
// return false;
|
||||
//
|
||||
// if (point0.RotorSpeed < 10)
|
||||
// return false;
|
||||
//
|
||||
// if (!ContainsDeviationApprox(telemetry, d => d.BlockPosition, position, 60, 0.03))
|
||||
// return false;
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// protected override int DetectEnd(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
||||
// {
|
||||
// var point0 = telemetry[position];
|
||||
// var delta = point0.WellDepth - point0.BitDepth;
|
||||
// if (delta < 0.03d || delta > 30)
|
||||
// return IdReasonOfEnd_DeltaDepthOutOfRange;
|
||||
//
|
||||
// if (point0.Pressure < 15)
|
||||
// return IdReasonOfEnd_PressureIsLo;
|
||||
//
|
||||
// if (point0.BlockPosition > 31)
|
||||
// return IdReasonOfEnd_BlockPositionIsHi;
|
||||
//
|
||||
// if (point0.RotorSpeed < 10)
|
||||
// return IdReasonOfEnd_RotorSpeedIsLo;
|
||||
//
|
||||
// return IdReasonOfEnd_NotDetected;
|
||||
// }
|
||||
//
|
||||
// protected override bool IsValid(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
// => IsValidByWellDepthDoesNotChange(telemetry, begin, end);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
@ -1,26 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using AsbCloudDb.Model;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors;
|
||||
|
||||
internal class DetectorDrilling : DetectorAbstract
|
||||
public class DetectorDrilling : DetectorAbstract
|
||||
{
|
||||
public override Func<DetectableTelemetry[], int, int, int> GetIdOperation => DefineDrillingOperation;
|
||||
private const double dispersionOfNormalizedRotorSpeedThreshold = 0.2d;
|
||||
public const string ExtraDataKeyHasOscillation = "hasOscillation";
|
||||
public const string ExtraDataKeyDispersionOfNormalizedRotorSpeed = "dispersionOfNormalizedRotorSpeed";
|
||||
public const string ExtraDataKeyAvgRotorSpeed = "avgRotorSpeed";
|
||||
|
||||
protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
||||
protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
||||
{
|
||||
var point0 = telemetry[position];
|
||||
var delta = point0.WellDepth - point0.BitDepth;
|
||||
if (delta > 0.03d)
|
||||
return false;
|
||||
|
||||
if (point0.Pressure < 25)
|
||||
if (point0.Pressure < 18)
|
||||
return false;
|
||||
|
||||
if (point0.RotorSpeed < 5)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -32,32 +34,61 @@ internal class DetectorDrilling : DetectorAbstract
|
||||
if (delta > 0.03d)
|
||||
return IdReasonOfEnd_DeltaDepthIsHi;
|
||||
|
||||
if (point0.Pressure < 25)
|
||||
if (point0.Pressure < 18)
|
||||
return IdReasonOfEnd_PressureIsLo;
|
||||
|
||||
return IdReasonOfEnd_NotDetected;
|
||||
}
|
||||
|
||||
protected override bool IsValid(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
=> IsValidByWellDepthIncreasing(telemetry, begin, end);
|
||||
|
||||
|
||||
protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
=> CalcRop(telemetry, begin, end);
|
||||
|
||||
private static int DefineDrillingOperation(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) =>
|
||||
base.IsValidOperationDetectorResult(operationDetectorResult)
|
||||
&& (operationDetectorResult.Operation.DepthEnd - operationDetectorResult.Operation.DepthStart) > 0.01;
|
||||
|
||||
protected override (int Begin, int End) RefineEdges(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
{
|
||||
var i = end;
|
||||
for (; i > begin + 1; i--)
|
||||
if (telemetry[i].WellDepth - telemetry[i - 1].WellDepth > 0.001d)
|
||||
break;
|
||||
|
||||
return (begin, i);
|
||||
}
|
||||
|
||||
protected override (int IdCategory, IDictionary<string, object> ExtraData) GetSpecificInformation(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
{
|
||||
var (avgRotorSpeed, dispersionOfNormalizedRotorSpeed) = CalcCriteries(telemetry, begin, end);
|
||||
var idCategory = GetIdOperation(avgRotorSpeed, dispersionOfNormalizedRotorSpeed);
|
||||
var extraData = new Dictionary<string, object>
|
||||
{
|
||||
[ExtraDataKeyAvgRotorSpeed] = avgRotorSpeed,
|
||||
[ExtraDataKeyDispersionOfNormalizedRotorSpeed] = dispersionOfNormalizedRotorSpeed,
|
||||
[ExtraDataKeyHasOscillation] = dispersionOfNormalizedRotorSpeed > dispersionOfNormalizedRotorSpeedThreshold
|
||||
};
|
||||
return (idCategory, extraData);
|
||||
}
|
||||
|
||||
private static (double avgRotorSpeed, double dispersionOfNormalizedRotorSpeed) CalcCriteries(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
{
|
||||
var telemetryRange = telemetry[begin..end];
|
||||
var avgRotorSpeed = telemetryRange.Average(t => t.RotorSpeed);
|
||||
var dispersion = telemetryRange.Average(t => Math.Pow(t.RotorSpeed / avgRotorSpeed - 1, 2));
|
||||
return (avgRotorSpeed, dispersion);
|
||||
}
|
||||
|
||||
private static int GetIdOperation(double avgRotorSpeed, double dispersionOfNormalizedRotorSpeed)
|
||||
{
|
||||
const int idSlideWithOscillation = 12000;
|
||||
|
||||
var telemetryRange = telemetry[begin.. end];
|
||||
|
||||
var avgRotorSpeed = telemetryRange.Average(t => t.RotorSpeed);
|
||||
|
||||
if (avgRotorSpeed < 10)
|
||||
return WellOperationCategory.IdSlide;
|
||||
const int idSlideWithOscillation = WellOperationCategory.IdSlide;
|
||||
|
||||
var despersion = telemetryRange
|
||||
.Average(t => Math.Pow((t.RotorSpeed - avgRotorSpeed) / avgRotorSpeed, 2));
|
||||
if (avgRotorSpeed < 5)
|
||||
return WellOperationCategory.IdSlide;
|
||||
|
||||
if (dispersionOfNormalizedRotorSpeed < dispersionOfNormalizedRotorSpeedThreshold)
|
||||
return WellOperationCategory.IdRotor;
|
||||
else
|
||||
return idSlideWithOscillation;
|
||||
}
|
||||
|
||||
return despersion < 0.2d ? WellOperationCategory.IdRotor : idSlideWithOscillation;
|
||||
}
|
||||
}
|
@ -1,39 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AsbCloudDb.Model;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors;
|
||||
|
||||
public class DetectorSlipsTime : DetectorAbstract
|
||||
{
|
||||
protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
=> CalcDeltaMinutes(telemetry, begin, end);
|
||||
|
||||
internal class DetectorSlipsTime : DetectorAbstract
|
||||
protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
||||
{
|
||||
var point0 = telemetry[position];
|
||||
var delta = point0.WellDepth - point0.BitDepth;
|
||||
if (delta > 2.5d)
|
||||
return false;
|
||||
|
||||
if (point0.Pressure > 15)
|
||||
return false;
|
||||
|
||||
if (point0.BlockPosition > 8)
|
||||
return false;
|
||||
|
||||
if (point0.HookWeight > 20)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override (int IdCategory, IDictionary<string, object> ExtraData) GetSpecificInformation(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
{
|
||||
protected override double CalcValue(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
=> CalcDeltaMinutes(telemetry, begin, end);
|
||||
|
||||
public override Func<DetectableTelemetry[], int, int, int> GetIdOperation => (_, _, _) => WellOperationCategory.IdSlipsTime;
|
||||
|
||||
protected override bool DetectBegin(DetectableTelemetry[] telemetry, int position, DetectedOperation? previousOperation)
|
||||
{
|
||||
var point0 = telemetry[position];
|
||||
var delta = point0.WellDepth - point0.BitDepth;
|
||||
if (delta > 2.5d)
|
||||
return false;
|
||||
|
||||
if (point0.Pressure > 15)
|
||||
return false;
|
||||
|
||||
if (point0.BlockPosition > 8)
|
||||
return false;
|
||||
|
||||
if (point0.HookWeight > 20)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool IsValid(DetectableTelemetry[] telemetry, int begin, int end)
|
||||
=> IsValidByWellDepthDoesNotChange(telemetry, begin, end);
|
||||
return (WellOperationCategory.IdSlipsTime, new Dictionary<string, object>());
|
||||
}
|
||||
|
||||
|
||||
protected override bool IsValidOperationDetectorResult(OperationDetectorResult operationDetectorResult) =>
|
||||
Math.Abs(operationDetectorResult.Operation.DepthStart - operationDetectorResult.Operation.DepthEnd) > 0.01;
|
||||
}
|
||||
|
||||
|
@ -1,29 +1,27 @@
|
||||
Метод определения бурения
|
||||
# Алгоритм определения бурения в роторе, слайде, слайде с осцилляцией
|
||||
|
||||
Признак начала операции =
|
||||
## Метод определения операции бурения
|
||||
|
||||
расстояние от долота до забоя < 0.03м И
|
||||
Признак начала операции =
|
||||
(расстояние от долота до забоя < 0.03м) И
|
||||
(давление > 18атм)
|
||||
|
||||
Признак окончания операции =
|
||||
(расстояние от долота до забоя > 0.03м) ИЛИ
|
||||
(давление < 18атм)
|
||||
|
||||
давление > 25атм
|
||||
## Валидация
|
||||
Для точного определения операции бурения, необходимо убрать диапазон в которых сработал признак окончания операции и не менялась глубина:
|
||||
Определили точку окончания операции исходя из Признак окончания операции.
|
||||
Определяем временной интервал, когда не менялась глубина (т.е. время шло, а глубина была неизменна)
|
||||
Определив начальную точку и точку окончания операции
|
||||
Исключаем этот интервал из операции.
|
||||
|
||||
Признак окончания операции =
|
||||
## Метод определения бурения в слайде
|
||||
Необходимо рассчитать средние обороты ротора за всю операцию бурения.
|
||||
Если среднее арифметическое больше константы (5 об/мин), то это бурение в роторе, если меньше, то это бурение в слайде.
|
||||
|
||||
расстояние от долота до забоя > 0.03м ИЛИ
|
||||
|
||||
давление < 25атм
|
||||
|
||||
Находим границы
|
||||
|
||||
После того когда мы нашли границы, мы должны определить операцию, тогда мы смотрим на забой точки окончания операций сравниваем с забоем точками начала операций:
|
||||
|
||||
Если они равны друг другу, то мы эту операцию дальше не обрабатываем, а выбрасываем.
|
||||
|
||||
Если они не равны, то у нас произошло увеличение забоя, значит эта операция бурения.
|
||||
|
||||
Дальше мы определяем как мы бурили в роторе или слайде, для этого нам необходимо рассчитать среднюю скорость(среднее арифметическое) за всю операцию бурения . Если среднее арифметическое больше константы (10 об/мин), то это бурение в роторе, если меньше, то это бурение в слайде.
|
||||
|
||||
Если бурение в роторе, то мы считаем только дисперсию нормированных оборотов ротора(по среднему значению). (Так как это может быть бурение в слайде с осцилляцией и выглядеть как бурение в роторе):
|
||||
|
||||
Если полученное значение меньше константы(0,2), то мы подтвердили что бурение в роторе.
|
||||
|
||||
Если полученное значение больше константы, то это бурение в слайде с осцилляцией.
|
||||
## Метод определения бурения в роторе, слайде с осцилляцией
|
||||
Необходимо рассчитать десперсию нормированных оборотов ротора по(по среднему значению)
|
||||
1. Если полученное значение больше константы(0,2), то мы подтвердили что бурение в роторе.
|
||||
2. Если полученное значение меньше константы, то это бурение в слайде с осцилляцией.
|
@ -16,11 +16,12 @@ public class WorkOperationDetection: Work
|
||||
{
|
||||
private static readonly DetectorAbstract[] detectors = new DetectorAbstract[]
|
||||
{
|
||||
new DetectorDrilling(),
|
||||
new DetectorSlipsTime()
|
||||
// new DetectorRotor(),
|
||||
// new DetectorSlide(),
|
||||
//new DetectorDevelopment(),
|
||||
//new DetectorTemplating(),
|
||||
new DetectorSlipsTime(),
|
||||
//new DetectorStaticSurveying(),
|
||||
//new DetectorFlashingBeforeConnection(),
|
||||
//new DetectorFlashing(),
|
||||
@ -95,6 +96,7 @@ public class WorkOperationDetection: Work
|
||||
{
|
||||
DateTime = d.DateTime,
|
||||
IdUser = d.IdUser,
|
||||
Mode = d.Mode,
|
||||
WellDepth = d.WellDepth,
|
||||
Pressure = d.Pressure,
|
||||
HookWeight = d.HookWeight,
|
||||
@ -125,25 +127,21 @@ public class WorkOperationDetection: Work
|
||||
var isDetected = false;
|
||||
var positionBegin = 0;
|
||||
var positionEnd = data.Length - gap;
|
||||
var step = 10;
|
||||
while (positionEnd > positionBegin)
|
||||
{
|
||||
step ++;
|
||||
for (int i = 0; i < detectors.Length; i++)
|
||||
foreach (var detector in detectors)
|
||||
{
|
||||
if (detectors[i].TryDetect(idTelemetry, data, positionBegin, positionEnd, lastDetectedOperation, out OperationDetectorResult? result))
|
||||
{
|
||||
detectedOperations.Add(result!.Operation);
|
||||
lastDetectedOperation = result.Operation;
|
||||
isDetected = true;
|
||||
step = 1;
|
||||
positionBegin = result.TelemetryEnd;
|
||||
break;
|
||||
}
|
||||
if (!detector.TryDetect(idTelemetry, data, positionBegin, positionEnd, lastDetectedOperation, out var result))
|
||||
continue;
|
||||
|
||||
detectedOperations.Add(result!.Operation);
|
||||
lastDetectedOperation = result.Operation;
|
||||
isDetected = true;
|
||||
positionBegin = result.TelemetryEnd;
|
||||
break;
|
||||
}
|
||||
if (step > 20)
|
||||
step = 10;
|
||||
positionBegin += step;
|
||||
|
||||
positionBegin += 1;
|
||||
}
|
||||
|
||||
if (isDetected)
|
||||
|
@ -13,192 +13,201 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
namespace AsbCloudInfrastructure.Services;
|
||||
|
||||
public class ReportService : IReportService
|
||||
{
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly FileService fileService;
|
||||
private readonly IWellService wellService;
|
||||
private readonly BackgroundWorker backgroundWorkerService;
|
||||
|
||||
public class ReportService : IReportService
|
||||
public int ReportCategoryId { get; private set; }
|
||||
|
||||
public ReportService(IAsbCloudDbContext db,
|
||||
ITelemetryService telemetryService,
|
||||
IWellService wellService,
|
||||
FileService fileService,
|
||||
BackgroundWorker backgroundWorkerService)
|
||||
{
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly FileService fileService;
|
||||
private readonly IWellService wellService;
|
||||
private readonly BackgroundWorker backgroundWorkerService;
|
||||
|
||||
public int ReportCategoryId { get; private set; }
|
||||
|
||||
public ReportService(IAsbCloudDbContext db,
|
||||
ITelemetryService telemetryService,
|
||||
IWellService wellService,
|
||||
FileService fileService,
|
||||
BackgroundWorker backgroundWorkerService)
|
||||
{
|
||||
this.db = db;
|
||||
this.wellService = wellService;
|
||||
this.backgroundWorkerService = backgroundWorkerService;
|
||||
this.telemetryService = telemetryService;
|
||||
this.fileService = fileService;
|
||||
ReportCategoryId = db.FileCategories
|
||||
.AsNoTracking()
|
||||
.First(c => c.Name.Equals("Рапорт"))
|
||||
.Id;
|
||||
}
|
||||
|
||||
public string EnqueueCreateReportWork(int idWell, int idUser, int stepSeconds, int format, DateTime begin,
|
||||
DateTime end, Action<object, string> progressHandler)
|
||||
{
|
||||
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
|
||||
var beginUtc = begin.ToUtcDateTimeOffset(timezoneOffset);
|
||||
var endUtc = end.ToUtcDateTimeOffset(timezoneOffset);
|
||||
var beginRemote = begin.ToTimeZoneOffsetHours(timezoneOffset);
|
||||
var endRemote = end.ToTimeZoneOffsetHours(timezoneOffset);
|
||||
|
||||
var workId = $"create report by wellid:{idWell} for userid:{idUser} requested at {DateTime.Now}";
|
||||
|
||||
var workAction = async (string id, IServiceProvider serviceProvider, Action<string, double?> onProgress, CancellationToken token) =>
|
||||
{
|
||||
using var context = serviceProvider.GetRequiredService<IAsbCloudDbContext>();
|
||||
var fileService = serviceProvider.GetRequiredService<FileService>();
|
||||
|
||||
var tempDir = Path.Combine(Path.GetTempPath(), "report");
|
||||
|
||||
var generator = GetReportGenerator(idWell, beginRemote, endRemote, stepSeconds, format, context);
|
||||
var reportFileName = Path.Combine(tempDir, generator.GetReportDefaultFileName());
|
||||
var totalPages = generator.GetPagesCount();
|
||||
|
||||
generator.OnProgress += (s, e) =>
|
||||
{
|
||||
var arg = e.Adapt<ReportProgressDto>();
|
||||
onProgress(arg.Operation?? string.Empty, arg.Progress);
|
||||
progressHandler.Invoke(arg, id);
|
||||
};
|
||||
generator.Make(reportFileName);
|
||||
|
||||
var fileInfo = (await fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName, token))!;
|
||||
|
||||
progressHandler.Invoke(new
|
||||
{
|
||||
Operation = "done",
|
||||
Progress = 100f,
|
||||
TotalPages = totalPages,
|
||||
CurrentPage = totalPages,
|
||||
file = fileInfo,
|
||||
}, id);
|
||||
|
||||
var newReportProperties = new ReportProperty
|
||||
{
|
||||
IdWell = idWell,
|
||||
IdFile = fileInfo.Id,
|
||||
Begin = beginUtc,
|
||||
End = endUtc,
|
||||
Step = stepSeconds,
|
||||
Format = format
|
||||
};
|
||||
context.ReportProperties.Add(newReportProperties);
|
||||
context.SaveChanges();
|
||||
};
|
||||
|
||||
var work = Work.CreateByDelegate(workId, workAction);
|
||||
backgroundWorkerService.Enqueue(work);
|
||||
|
||||
progressHandler.Invoke(new ReportProgressDto
|
||||
{
|
||||
Operation = "Ожидает начала в очереди.",
|
||||
Progress = 0f,
|
||||
}, workId);
|
||||
return workId;
|
||||
}
|
||||
|
||||
public int GetReportPagesCount(int idWell, DateTime begin, DateTime end, int stepSeconds, int format)
|
||||
{
|
||||
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
|
||||
var beginRemote = begin.ToTimeZoneOffsetHours(timezoneOffset);
|
||||
var endRemote = end.ToTimeZoneOffsetHours(timezoneOffset);
|
||||
|
||||
var generator = GetReportGenerator(idWell, beginRemote, endRemote, stepSeconds, format, db);
|
||||
var pagesCount = generator.GetPagesCount();
|
||||
return pagesCount;
|
||||
}
|
||||
|
||||
public DatesRangeDto? GetDatesRangeOrDefault(int idWell)
|
||||
{
|
||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||
if (telemetry is null)
|
||||
return null;
|
||||
var range = telemetryService.GetDatesRange(telemetry.Id);
|
||||
return range;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ReportPropertiesDto>> GetAllReportsByWellAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
|
||||
var propertiesQuery = db.ReportProperties.Include(r => r.File)
|
||||
.Where(p => p.IdWell == idWell)
|
||||
.OrderBy(o => o.File.UploadDate)
|
||||
this.db = db;
|
||||
this.wellService = wellService;
|
||||
this.backgroundWorkerService = backgroundWorkerService;
|
||||
this.telemetryService = telemetryService;
|
||||
this.fileService = fileService;
|
||||
ReportCategoryId = db.FileCategories
|
||||
.AsNoTracking()
|
||||
.Take(1024);
|
||||
var entities = await propertiesQuery.ToListAsync(token);
|
||||
var dtos = entities.Select(p => new ReportPropertiesDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.File.Name,
|
||||
File = new FileInfoDto
|
||||
{
|
||||
Id = p.File.Id,
|
||||
Author = null,
|
||||
IdAuthor = p.File.IdAuthor ?? 0,
|
||||
IdCategory = p.File.IdCategory,
|
||||
IdWell = p.File.IdWell,
|
||||
Name = p.File.Name,
|
||||
Size = p.File.Size,
|
||||
UploadDate = p.File.UploadDate.ToRemoteDateTime(timezoneOffset),
|
||||
},
|
||||
IdWell = p.IdWell,
|
||||
Date = p.File.UploadDate.ToRemoteDateTime(timezoneOffset),
|
||||
Begin = p.Begin.ToRemoteDateTime(timezoneOffset),
|
||||
End = p.End.ToRemoteDateTime(timezoneOffset),
|
||||
Step = p.Step,
|
||||
Format = p.Format == 0 ? ".pdf" : ".las"
|
||||
});
|
||||
return dtos;
|
||||
}
|
||||
.First(c => c.Name.Equals("Рапорт"))
|
||||
.Id;
|
||||
}
|
||||
|
||||
private static IReportGenerator GetReportGenerator(int idWell, DateTime begin,
|
||||
DateTime end, int stepSeconds, int format, IAsbCloudDbContext context)
|
||||
public string EnqueueCreateReportWork(int idWell, int idUser, int stepSeconds, int format, DateTime begin,
|
||||
DateTime end, Action<object, string> progressHandler)
|
||||
{
|
||||
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
|
||||
var beginUtc = begin.ToUtcDateTimeOffset(timezoneOffset);
|
||||
var endUtc = end.ToUtcDateTimeOffset(timezoneOffset);
|
||||
var beginRemote = begin.ToTimeZoneOffsetHours(timezoneOffset);
|
||||
var endRemote = end.ToTimeZoneOffsetHours(timezoneOffset);
|
||||
|
||||
var workId = $"create report by wellid:{idWell} for userid:{idUser} requested at {DateTime.Now}";
|
||||
|
||||
var workAction = async (string id, IServiceProvider serviceProvider, Action<string, double?> onProgress, CancellationToken token) =>
|
||||
{
|
||||
var dataSource = new ReportDataSourcePgCloud(context, idWell);
|
||||
IReportGenerator generator = format switch
|
||||
using var context = serviceProvider.GetRequiredService<IAsbCloudDbContext>();
|
||||
var fileService = serviceProvider.GetRequiredService<FileService>();
|
||||
|
||||
var tempDir = Path.Combine(Path.GetTempPath(), "report");
|
||||
|
||||
var generator = GetReportGenerator(idWell, beginRemote, endRemote, stepSeconds, format, context);
|
||||
var reportFileName = Path.Combine(tempDir, generator.GetReportDefaultFileName());
|
||||
var totalPages = generator.GetPagesCount();
|
||||
|
||||
generator.OnProgress += (s, e) =>
|
||||
{
|
||||
//LAS
|
||||
1 => new AsbSaubReportLas.ReprotGeneratorLas(dataSource),
|
||||
//PDF
|
||||
_ => new AsbSaubReportPdf.ReprotGeneratorPdf(dataSource),
|
||||
var arg = e.Adapt<ReportProgressDto>();
|
||||
onProgress(arg.Operation?? string.Empty, arg.Progress);
|
||||
progressHandler.Invoke(arg, id);
|
||||
};
|
||||
generator.Make(reportFileName);
|
||||
|
||||
if(begin == default || end == default)
|
||||
var fileInfo = (await fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName, token))!;
|
||||
|
||||
progressHandler.Invoke(new
|
||||
{
|
||||
var analyzeResult = dataSource.Analyze();
|
||||
begin = begin == default ? analyzeResult.MinDate : begin;
|
||||
end = end == default ? begin.AddDays(1) : end;
|
||||
}
|
||||
Operation = "done",
|
||||
Progress = 100f,
|
||||
TotalPages = totalPages,
|
||||
CurrentPage = totalPages,
|
||||
file = fileInfo,
|
||||
}, id);
|
||||
|
||||
generator.Begin = begin;
|
||||
generator.End = end;
|
||||
generator.Step = TimeSpan.FromSeconds(stepSeconds);
|
||||
generator.WithCharts = true;
|
||||
generator.WithEvents = true;
|
||||
var newReportProperties = new ReportProperty
|
||||
{
|
||||
IdWell = idWell,
|
||||
IdFile = fileInfo.Id,
|
||||
Begin = beginUtc,
|
||||
End = endUtc,
|
||||
Step = stepSeconds,
|
||||
Format = format
|
||||
};
|
||||
context.ReportProperties.Add(newReportProperties);
|
||||
context.SaveChanges();
|
||||
};
|
||||
|
||||
return generator;
|
||||
}
|
||||
var work = Work.CreateByDelegate(workId, workAction);
|
||||
work.OnErrorAsync = (message, exception, token) => Task.Run(() => progressHandler.Invoke(new
|
||||
{
|
||||
Operation = "error",
|
||||
Progress = 100f,
|
||||
Message = string.IsNullOrEmpty(message)
|
||||
? exception.Message
|
||||
: message,
|
||||
Exception = exception,
|
||||
}, workId)
|
||||
, token);
|
||||
|
||||
public async Task<int> DeleteAllOldReportsAsync(TimeSpan lifetime, CancellationToken token)
|
||||
backgroundWorkerService.Enqueue(work);
|
||||
|
||||
progressHandler.Invoke(new ReportProgressDto
|
||||
{
|
||||
var lifeTimeStartDate = DateTime.UtcNow.Date - lifetime;
|
||||
var fileIds = await db.ReportProperties
|
||||
.Where(r => r.File.UploadDate.Date < lifeTimeStartDate)
|
||||
.Select(r => r.IdFile)
|
||||
.ToArrayAsync(token);
|
||||
Operation = "Ожидает начала в очереди.",
|
||||
Progress = 0f,
|
||||
}, workId);
|
||||
return workId;
|
||||
}
|
||||
|
||||
return await fileService.DeleteAsync(fileIds, token);
|
||||
public int GetReportPagesCount(int idWell, DateTime begin, DateTime end, int stepSeconds, int format)
|
||||
{
|
||||
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
|
||||
var beginRemote = begin.ToTimeZoneOffsetHours(timezoneOffset);
|
||||
var endRemote = end.ToTimeZoneOffsetHours(timezoneOffset);
|
||||
|
||||
var generator = GetReportGenerator(idWell, beginRemote, endRemote, stepSeconds, format, db);
|
||||
var pagesCount = generator.GetPagesCount();
|
||||
return pagesCount;
|
||||
}
|
||||
|
||||
public DatesRangeDto? GetDatesRangeOrDefault(int idWell)
|
||||
{
|
||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||
if (telemetry is null)
|
||||
return null;
|
||||
var range = telemetryService.GetDatesRange(telemetry.Id);
|
||||
return range;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ReportPropertiesDto>> GetAllReportsByWellAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
|
||||
var propertiesQuery = db.ReportProperties.Include(r => r.File)
|
||||
.Where(p => p.IdWell == idWell)
|
||||
.OrderBy(o => o.File.UploadDate)
|
||||
.AsNoTracking()
|
||||
.Take(1024);
|
||||
var entities = await propertiesQuery.ToListAsync(token);
|
||||
var dtos = entities.Select(p => new ReportPropertiesDto
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.File.Name,
|
||||
File = new FileInfoDto
|
||||
{
|
||||
Id = p.File.Id,
|
||||
Author = null,
|
||||
IdAuthor = p.File.IdAuthor ?? 0,
|
||||
IdCategory = p.File.IdCategory,
|
||||
IdWell = p.File.IdWell,
|
||||
Name = p.File.Name,
|
||||
Size = p.File.Size,
|
||||
UploadDate = p.File.UploadDate.ToRemoteDateTime(timezoneOffset),
|
||||
},
|
||||
IdWell = p.IdWell,
|
||||
Date = p.File.UploadDate.ToRemoteDateTime(timezoneOffset),
|
||||
Begin = p.Begin.ToRemoteDateTime(timezoneOffset),
|
||||
End = p.End.ToRemoteDateTime(timezoneOffset),
|
||||
Step = p.Step,
|
||||
Format = p.Format == 0 ? ".pdf" : ".las"
|
||||
});
|
||||
return dtos;
|
||||
}
|
||||
|
||||
private static IReportGenerator GetReportGenerator(int idWell, DateTime begin,
|
||||
DateTime end, int stepSeconds, int format, IAsbCloudDbContext context)
|
||||
{
|
||||
var dataSource = new ReportDataSourcePgCloud(context, idWell);
|
||||
IReportGenerator generator = format switch
|
||||
{
|
||||
//LAS
|
||||
1 => new AsbSaubReportLas.ReprotGeneratorLas(dataSource),
|
||||
//PDF
|
||||
_ => new AsbSaubReportPdf.ReprotGeneratorPdf(dataSource),
|
||||
};
|
||||
|
||||
if(begin == default || end == default)
|
||||
{
|
||||
var analyzeResult = dataSource.Analyze();
|
||||
begin = begin == default ? analyzeResult.MinDate : begin;
|
||||
end = end == default ? begin.AddDays(1) : end;
|
||||
}
|
||||
|
||||
generator.Begin = begin;
|
||||
generator.End = end;
|
||||
generator.Step = TimeSpan.FromSeconds(stepSeconds);
|
||||
generator.WithCharts = true;
|
||||
generator.WithEvents = true;
|
||||
|
||||
return generator;
|
||||
}
|
||||
|
||||
public async Task<int> DeleteAllOldReportsAsync(TimeSpan lifetime, CancellationToken token)
|
||||
{
|
||||
var lifeTimeStartDate = DateTime.UtcNow.Date - lifetime;
|
||||
var fileIds = await db.ReportProperties
|
||||
.Where(r => r.File.UploadDate.Date < lifeTimeStartDate)
|
||||
.Select(r => r.IdFile)
|
||||
.ToArrayAsync(token);
|
||||
|
||||
return await fileService.DeleteAsync(fileIds, token);
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
if ((DateTimeOffset.UtcNow - geDate) < TimeSpan.FromHours(12))
|
||||
{
|
||||
// пробуем обойтись кешем
|
||||
var cechedRange = telemetryDataCache.GetOrDefaultCachedaDateRange(telemetry.Id);
|
||||
var cechedRange = telemetryDataCache.GetOrDefaultCachedDateRange(telemetry.Id);
|
||||
if (cechedRange?.From <= geDate)
|
||||
{
|
||||
var datesRange = new DatesRangeDto
|
||||
|
@ -20,7 +20,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
class TelemetryDataCacheItem
|
||||
{
|
||||
public TDto FirstByDate { get; init; } = default!;
|
||||
public CyclycArray<TDto> LastData { get; init; } = null!;
|
||||
public CyclicArray<TDto> LastData { get; init; } = null!;
|
||||
public double TimezoneHours { get; init; } = 5;
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
cacheItem = caches.GetOrAdd(idTelemetry, _ => new TelemetryDataCacheItem()
|
||||
{
|
||||
FirstByDate = range.ElementAt(0),
|
||||
LastData = new CyclycArray<TDto>(activeWellCapacity)
|
||||
LastData = new CyclicArray<TDto>(activeWellCapacity)
|
||||
});
|
||||
}
|
||||
|
||||
@ -159,7 +159,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
return new DatesRangeDto { From = from.Value, To = to };
|
||||
}
|
||||
|
||||
public DatesRangeDto? GetOrDefaultCachedaDateRange(int idTelemetry)
|
||||
public DatesRangeDto? GetOrDefaultCachedDateRange(int idTelemetry)
|
||||
{
|
||||
if (!caches.TryGetValue(idTelemetry, out TelemetryDataCacheItem? cacheItem))
|
||||
return null;
|
||||
@ -260,7 +260,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
return dto;
|
||||
});
|
||||
|
||||
var cacheItem = new CyclycArray<TDto>(capacity);
|
||||
var cacheItem = new CyclicArray<TDto>(capacity);
|
||||
cacheItem.AddRange(dtos);
|
||||
|
||||
var item = new TelemetryDataCacheItem
|
||||
|
@ -43,7 +43,6 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
.Where(t => t.IdTelemetry == idTelemetry)
|
||||
.Where(t => t.BlockPosition > 0.0001)
|
||||
.Where(t => t.WellDepth > 0.0001)
|
||||
.Where(t => t.Mode != null)
|
||||
.Where(t => modes.Contains(t.Mode))
|
||||
.Where(t => t.WellDepth - t.BitDepth < 0.01)
|
||||
.GroupBy(t => new {
|
||||
|
@ -13,7 +13,7 @@ abstract class TrajectoryBaseService<TGeo, TCartesian>
|
||||
where TGeo : TrajectoryGeoDto
|
||||
where TCartesian : TrajectoryCartesianDto, new()
|
||||
{
|
||||
ITrajectoryRepository<TGeo> repository;
|
||||
private readonly ITrajectoryRepository<TGeo> repository;
|
||||
|
||||
public TrajectoryBaseService(ITrajectoryRepository<TGeo> repository)
|
||||
{
|
||||
@ -31,16 +31,16 @@ abstract class TrajectoryBaseService<TGeo, TCartesian>
|
||||
public async Task<IEnumerable<TCartesian>?> GetAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var geoCoords = await repository.GetAsync(idWell, token);
|
||||
var locs = GetTrajectoryVisualisation(geoCoords);
|
||||
var locs = TrajectoryBaseService<TGeo, TCartesian>.GetTrajectoryVisualisation(geoCoords);
|
||||
var dtos = locs.Select(l => Convert(l));
|
||||
return dtos;
|
||||
}
|
||||
|
||||
private IEnumerable<Location> GetTrajectoryVisualisation(IEnumerable<TrajectoryGeoDto> geoCoordinates)
|
||||
private static IEnumerable<Location> GetTrajectoryVisualisation(IEnumerable<TrajectoryGeoDto> geoCoordinates)
|
||||
{
|
||||
var geoCoordinatesLength = geoCoordinates.Count();
|
||||
if (geoCoordinatesLength < 2)
|
||||
return new Location[0];
|
||||
return Enumerable.Empty<Location>();
|
||||
|
||||
var cartesianCoordinates = new Location[geoCoordinatesLength];
|
||||
cartesianCoordinates[0] = new();
|
||||
@ -48,7 +48,7 @@ abstract class TrajectoryBaseService<TGeo, TCartesian>
|
||||
var geoCoordinatesArray = geoCoordinates.OrderBy(c => c.WellboreDepth).ToArray();
|
||||
for (var i = 1; i < geoCoordinatesLength; i++)
|
||||
{
|
||||
var coordinates = Calculate(cartesianCoordinates[i - 1],
|
||||
var coordinates = TrajectoryBaseService<TGeo, TCartesian>.Calculate(cartesianCoordinates[i - 1],
|
||||
geoCoordinatesArray[i - 1],
|
||||
geoCoordinatesArray[i]);
|
||||
|
||||
@ -58,7 +58,7 @@ abstract class TrajectoryBaseService<TGeo, TCartesian>
|
||||
return cartesianCoordinates;
|
||||
}
|
||||
|
||||
protected Location Calculate(Location prevlocation, TrajectoryGeoDto prev, TrajectoryGeoDto current)
|
||||
protected static Location Calculate(Location prevLocation, TrajectoryGeoDto prev, TrajectoryGeoDto current)
|
||||
{
|
||||
var intervalGeoParams = prev;
|
||||
var deltaWellLength = current.WellboreDepth - intervalGeoParams.WellboreDepth;
|
||||
@ -70,9 +70,9 @@ abstract class TrajectoryBaseService<TGeo, TCartesian>
|
||||
|
||||
return new()
|
||||
{
|
||||
North = prevlocation.North + dNorth,
|
||||
East = prevlocation.East + dEast,
|
||||
Depth = prevlocation.Depth + dDepth,
|
||||
North = prevLocation.North + dNorth,
|
||||
East = prevLocation.East + dEast,
|
||||
Depth = prevLocation.Depth + dDepth,
|
||||
Trajectory = current,
|
||||
};
|
||||
}
|
||||
@ -125,9 +125,9 @@ class TrajectoryNnbService : TrajectoryBaseService<TrajectoryGeoFactDto, Traject
|
||||
|
||||
public class TrajectoryService
|
||||
{
|
||||
private TrajectoryPlanService trajectoryPlanService;
|
||||
private TrajectoryFactService trajectoryFactService;
|
||||
private TrajectoryNnbService trajectoryNnbService;
|
||||
private readonly TrajectoryPlanService trajectoryPlanService;
|
||||
private readonly TrajectoryFactService trajectoryFactService;
|
||||
private readonly TrajectoryNnbService trajectoryNnbService;
|
||||
|
||||
public TrajectoryService(
|
||||
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> planRepository,
|
||||
@ -147,11 +147,12 @@ public class TrajectoryService
|
||||
/// <returns></returns>
|
||||
public async Task<TrajectoryPlanFactDto<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>> GetTrajectoryCartesianAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var result = new TrajectoryPlanFactDto<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>();
|
||||
|
||||
result.Plan = await trajectoryPlanService.GetAsync(idWell, token);
|
||||
result.FactManual = await trajectoryFactService.GetAsync(idWell, token);
|
||||
result.FactNnb = await trajectoryNnbService.GetAsync(idWell, token);
|
||||
var result = new TrajectoryPlanFactDto<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>
|
||||
{
|
||||
Plan = await trajectoryPlanService.GetAsync(idWell, token),
|
||||
FactManual = await trajectoryFactService.GetAsync(idWell, token),
|
||||
FactNnb = await trajectoryNnbService.GetAsync(idWell, token)
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -28,8 +28,6 @@ namespace AsbCloudInfrastructure.Services
|
||||
private readonly IWellFinalDocumentsRepository wellFinalDocumentsRepository;
|
||||
private readonly NotificationService notificationService;
|
||||
|
||||
private const int FileServiceThrewException = -1;
|
||||
|
||||
public WellFinalDocumentsService(FileService fileService,
|
||||
IUserRepository userRepository,
|
||||
IWellService wellService,
|
||||
@ -48,7 +46,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
}
|
||||
|
||||
///<inheritdoc/>
|
||||
public async Task<int> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto>? dtos, CancellationToken token)
|
||||
public async Task<int> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto> dtos, CancellationToken token)
|
||||
{
|
||||
var data = await wellFinalDocumentsRepository.UpdateRangeAsync(idWell, dtos, token);
|
||||
|
||||
|
@ -38,16 +38,15 @@ public class WellOperationExportService : IWellOperationExportService
|
||||
|
||||
var timezone = wellService.GetTimezone(idWell);
|
||||
|
||||
return await MakeExcelFileStreamAsync(operations, timezone.Hours, cancellationToken);
|
||||
return MakeExcelFileStream(operations, timezone.Hours);
|
||||
}
|
||||
|
||||
private async Task<Stream> MakeExcelFileStreamAsync(IEnumerable<WellOperationDto> operations, double timezoneOffset,
|
||||
CancellationToken cancellationToken)
|
||||
private Stream MakeExcelFileStream(IEnumerable<WellOperationDto> operations, double timezoneOffset)
|
||||
{
|
||||
using Stream ecxelTemplateStream = wellOperationImportTemplateService.GetExcelTemplateStream();
|
||||
|
||||
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
|
||||
await AddOperationsToWorkbook(workbook, operations, timezoneOffset, cancellationToken);
|
||||
AddOperationsToWorkbook(workbook, operations, timezoneOffset);
|
||||
|
||||
var memoryStream = new MemoryStream();
|
||||
workbook.SaveAs(memoryStream, new SaveOptions { });
|
||||
@ -55,15 +54,14 @@ public class WellOperationExportService : IWellOperationExportService
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
private async Task AddOperationsToWorkbook(XLWorkbook workbook, IEnumerable<WellOperationDto> operations, double timezoneOffset,
|
||||
CancellationToken cancellationToken)
|
||||
private void AddOperationsToWorkbook(XLWorkbook workbook, IEnumerable<WellOperationDto> operations, double timezoneOffset)
|
||||
{
|
||||
var planOperations = operations.Where(o => o.IdType == 0);
|
||||
if (planOperations.Any())
|
||||
{
|
||||
var sheetPlan = workbook.Worksheets.FirstOrDefault(ws => ws.Name == DefaultTemplateInfo.SheetNamePlan);
|
||||
if (sheetPlan is not null)
|
||||
await AddOperationsToSheetAsync(sheetPlan, planOperations, timezoneOffset, cancellationToken);
|
||||
AddOperationsToSheet(sheetPlan, planOperations, timezoneOffset);
|
||||
}
|
||||
|
||||
var factOperations = operations.Where(o => o.IdType == 1);
|
||||
@ -71,12 +69,11 @@ public class WellOperationExportService : IWellOperationExportService
|
||||
{
|
||||
var sheetFact = workbook.Worksheets.FirstOrDefault(ws => ws.Name == DefaultTemplateInfo.SheetNameFact);
|
||||
if (sheetFact is not null)
|
||||
await AddOperationsToSheetAsync(sheetFact, factOperations, timezoneOffset, cancellationToken);
|
||||
AddOperationsToSheet(sheetFact, factOperations, timezoneOffset);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddOperationsToSheetAsync(IXLWorksheet sheet, IEnumerable<WellOperationDto> operations, double timezoneOffset,
|
||||
CancellationToken cancellationToken)
|
||||
private void AddOperationsToSheet(IXLWorksheet sheet, IEnumerable<WellOperationDto> operations, double timezoneOffset)
|
||||
{
|
||||
var operationsToArray = operations.ToArray();
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace AsbCloudInfrastructure
|
||||
var provider = scope.ServiceProvider;
|
||||
|
||||
var context = provider.GetRequiredService<IAsbCloudDbContext>();
|
||||
context.Database.EnshureCreatedAndMigrated();
|
||||
context.Database.EnsureCreatedAndMigrated();
|
||||
|
||||
// TODO: Сделать инициализацию кеша телеметрии более явной.
|
||||
_ = provider.GetRequiredService<ITelemetryDataCache<TelemetryDataSaubDto>>();
|
||||
|
@ -3,7 +3,7 @@ using System.Linq;
|
||||
|
||||
namespace AsbCloudWebApi.Tests
|
||||
{
|
||||
public static class AspExtentions
|
||||
public static class AspExtensions
|
||||
{
|
||||
public static IServiceCollection ReplaceService<T>(this IServiceCollection services, T instance)
|
||||
where T : notnull
|
@ -0,0 +1,295 @@
|
||||
using System.Collections.Generic;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.DetectOperations;
|
||||
using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.Services.DetectedOperations.Detectors;
|
||||
|
||||
public class DetectorDrillingTests : DetectorDrilling
|
||||
{
|
||||
private const int idSlide = 5002;
|
||||
private const int idRotor = 5003;
|
||||
private const int idSlideWithOscillation = 12000;
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(TelemetryRangeDrillingRotor))]
|
||||
public void DefineDrillingOperation_ShouldReturn_DrillingRotor(DetectableTelemetry[] telemetryRange)
|
||||
{
|
||||
//act
|
||||
var result = GetSpecificInformation(telemetryRange, 0, telemetryRange.Length);
|
||||
|
||||
//assert
|
||||
Assert.Equal(idRotor, result.IdCategory);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(TelemetryRangeDrillingSlide))]
|
||||
public void DefineDrillingOperation_ShouldReturn_DrillingSlide(DetectableTelemetry[] telemetryRange)
|
||||
{
|
||||
//act
|
||||
var result = GetSpecificInformation(telemetryRange, 0, telemetryRange.Length);
|
||||
|
||||
//assert
|
||||
Assert.Equal(idSlide, result.IdCategory);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(TelemetryRangeDrillingSlideWithOscillation))]
|
||||
public void DefineDrillingOperation_ShouldReturn_DrillingSlideWithOscillation(DetectableTelemetry[] telemetryRange)
|
||||
{
|
||||
//act
|
||||
var result = GetSpecificInformation(telemetryRange, 0, telemetryRange.Length);
|
||||
|
||||
//assert
|
||||
var oHasOscillation = result.ExtraData[ExtraDataKeyHasOscillation];
|
||||
|
||||
Assert.Equal(idSlide, result.IdCategory);
|
||||
Assert.True(oHasOscillation is bool hasOscillation && hasOscillation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValidOperationDetectorResult_ShouldReturn_True()
|
||||
{
|
||||
//arrange
|
||||
var operationDetectorResult = new OperationDetectorResult
|
||||
{
|
||||
Operation = new DetectedOperation
|
||||
{
|
||||
DepthStart = 5000,
|
||||
DepthEnd = 6000,
|
||||
DateStart = System.DateTimeOffset.Now.AddMinutes(-1),
|
||||
DateEnd = System.DateTimeOffset.Now,
|
||||
}
|
||||
};
|
||||
|
||||
//act
|
||||
var result = IsValidOperationDetectorResult(operationDetectorResult);
|
||||
|
||||
//assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValidOperationDetectorResult_ShouldReturn_False()
|
||||
{
|
||||
//arrange
|
||||
var operationDetectorResult = new OperationDetectorResult
|
||||
{
|
||||
Operation = new DetectedOperation
|
||||
{
|
||||
DepthStart = 5000,
|
||||
DepthEnd = 5000,
|
||||
DateStart = System.DateTimeOffset.Now.AddMinutes(-1),
|
||||
DateEnd = System.DateTimeOffset.Now,
|
||||
}
|
||||
};
|
||||
|
||||
//act
|
||||
var result = IsValidOperationDetectorResult(operationDetectorResult);
|
||||
|
||||
//assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> TelemetryRangeDrillingRotor()
|
||||
{
|
||||
yield return new object[]
|
||||
{
|
||||
new[]
|
||||
{
|
||||
new DetectableTelemetry
|
||||
{
|
||||
WellDepth = 4.187f,
|
||||
Pressure = 27.815952f,
|
||||
HookWeight = 34.221367f,
|
||||
BlockPosition = 24.388f,
|
||||
BitDepth = 4.187f,
|
||||
RotorSpeed = 40.3f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
WellDepth = 4.232f,
|
||||
Pressure = 28.080372f,
|
||||
HookWeight = 34.162174f,
|
||||
BlockPosition = 24.343f,
|
||||
BitDepth = 4.232f,
|
||||
RotorSpeed = 40.3f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
WellDepth = 4.277f,
|
||||
Pressure = 29.047901f,
|
||||
HookWeight = 33.688717f,
|
||||
BlockPosition = 24.298f,
|
||||
BitDepth = 24.298f,
|
||||
RotorSpeed = 40.3f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
WellDepth = 4.309f,
|
||||
Pressure = 29.574032f,
|
||||
HookWeight = 33.692104f,
|
||||
BlockPosition = 24.266f,
|
||||
BitDepth = 4.309f,
|
||||
RotorSpeed = 40.4f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
WellDepth = 4.324f,
|
||||
Pressure = 24.007977f,
|
||||
HookWeight = 34.838448f,
|
||||
BlockPosition = 24.251f,
|
||||
BitDepth = 4.324f,
|
||||
RotorSpeed = 40.5f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
WellDepth = 4.324f,
|
||||
Pressure = 24.04114f,
|
||||
HookWeight = 34.423424f,
|
||||
BlockPosition = 24.252f,
|
||||
BitDepth = 4.323f,
|
||||
RotorSpeed = 40.3f
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> TelemetryRangeDrillingSlide()
|
||||
{
|
||||
yield return new object[]
|
||||
{
|
||||
new[]
|
||||
{
|
||||
new DetectableTelemetry
|
||||
{
|
||||
WellDepth = 447.276001f,
|
||||
Pressure = 26.619421f,
|
||||
HookWeight = 40.9143829f,
|
||||
BlockPosition = 4.559f,
|
||||
BitDepth = 477.265991f,
|
||||
RotorSpeed = 0
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
WellDepth = 477.289f,
|
||||
Pressure = 28.716f,
|
||||
HookWeight = 38.27f,
|
||||
BlockPosition = 4.5f,
|
||||
BitDepth = 477.289f,
|
||||
RotorSpeed = 0.1f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
WellDepth = 477.30899f,
|
||||
Pressure = 33.953495f,
|
||||
HookWeight = 38.27f,
|
||||
BlockPosition = 4.5359997f,
|
||||
BitDepth = 477.289001f,
|
||||
RotorSpeed = 0.1f
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> TelemetryRangeDrillingSlideWithOscillation()
|
||||
{
|
||||
yield return new object[]
|
||||
{
|
||||
new[]
|
||||
{
|
||||
new DetectableTelemetry
|
||||
{
|
||||
IdUser = 1,
|
||||
WellDepth = 415.306f,
|
||||
Pressure = 53.731934f,
|
||||
HookWeight = 41.049942f,
|
||||
BlockPosition = 28.666f,
|
||||
BitDepth = 415.293f,
|
||||
RotorSpeed = 0.3f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
IdUser = 1,
|
||||
WellDepth = 415.311f,
|
||||
Pressure = 57.660595f,
|
||||
HookWeight = 40.898712f,
|
||||
BlockPosition = 28.648f,
|
||||
BitDepth = 415.311f,
|
||||
RotorSpeed = 0.2f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
IdUser = 1,
|
||||
WellDepth = 415.326f,
|
||||
Pressure = 59.211086f,
|
||||
HookWeight = 40.882797f,
|
||||
BlockPosition = 28.633f,
|
||||
BitDepth = 415.326f,
|
||||
RotorSpeed = 0.1f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
IdUser = 1,
|
||||
WellDepth = 415.344f,
|
||||
Pressure = 59.484406f,
|
||||
HookWeight = 40.91972f,
|
||||
BlockPosition = 28.615f,
|
||||
BitDepth = 415.344f,
|
||||
RotorSpeed = 0.2f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
IdUser = 1,
|
||||
WellDepth = 415.364f,
|
||||
Pressure = 60.739918f,
|
||||
HookWeight = 40.795666f,
|
||||
BlockPosition = 28.595f,
|
||||
BitDepth = 415.364f,
|
||||
RotorSpeed = 4.5f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
IdUser = 1,
|
||||
WellDepth = 415.378f,
|
||||
Pressure = 62.528984f,
|
||||
HookWeight = 40.52114f,
|
||||
BlockPosition = 28.581f,
|
||||
BitDepth = 415.378f,
|
||||
RotorSpeed = 22.6f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
IdUser = 1,
|
||||
WellDepth = 415.392f,
|
||||
Pressure = 67.0039f,
|
||||
HookWeight = 38.878895f,
|
||||
BlockPosition = 28.569f,
|
||||
BitDepth = 415.39f,
|
||||
RotorSpeed = 50f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
IdUser = 1,
|
||||
WellDepth = 415.392f,
|
||||
Pressure = 65.72418f,
|
||||
HookWeight = 42.53173f,
|
||||
BlockPosition = 28.622f,
|
||||
BitDepth = 415.337f,
|
||||
RotorSpeed = 93f
|
||||
},
|
||||
new DetectableTelemetry
|
||||
{
|
||||
IdUser = 1,
|
||||
WellDepth = 415.392f,
|
||||
Pressure = 56.82195f,
|
||||
HookWeight = 43.15844f,
|
||||
BlockPosition = 28.704f,
|
||||
BitDepth = 415.255f,
|
||||
RotorSpeed = 71.5f
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -86,7 +86,7 @@ public class PeriodicBackgroundWorkerTest
|
||||
service.Add(badWork, TimeSpan.FromSeconds(2));
|
||||
service.Add(goodWork, TimeSpan.FromSeconds(2));
|
||||
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(20));
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(128));
|
||||
|
||||
//assert
|
||||
Assert.Equal(expectadResult, result);
|
||||
|
@ -20,15 +20,16 @@ namespace AsbCloudWebApi.Controllers
|
||||
public class ReportController : ControllerBase
|
||||
{
|
||||
private readonly IReportService reportService;
|
||||
private readonly FileService fileService;
|
||||
private readonly IWellService wellService;
|
||||
private readonly IHubContext<ReportsHub, IReportHubClient> reportsHubContext;
|
||||
|
||||
public ReportController(IReportService reportService, IWellService wellService,
|
||||
FileService fileService, IHubContext<ReportsHub, IReportHubClient> reportsHubContext)
|
||||
public ReportController(
|
||||
IReportService reportService,
|
||||
IWellService wellService,
|
||||
IHubContext<ReportsHub,
|
||||
IReportHubClient> reportsHubContext)
|
||||
{
|
||||
this.reportService = reportService;
|
||||
this.fileService = fileService;
|
||||
this.wellService = wellService;
|
||||
this.reportsHubContext = reportsHubContext;
|
||||
}
|
||||
@ -149,7 +150,10 @@ namespace AsbCloudWebApi.Controllers
|
||||
|
||||
if (wellReportsDatesRange is null)
|
||||
return NoContent();
|
||||
|
||||
|
||||
if (wellReportsDatesRange.From == wellReportsDatesRange.To)
|
||||
return NoContent();
|
||||
|
||||
return Ok(wellReportsDatesRange);
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
[FromQuery] DetectedOperationRequest request,
|
||||
CancellationToken token)
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
if (!await UserHasAccessToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
|
||||
var result = await detectedOperationService.GetAsync(request, token);
|
||||
@ -79,7 +79,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
[FromQuery] DetectedOperationRequest request,
|
||||
CancellationToken token)
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
if (!await UserHasAccessToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
|
||||
var result = await detectedOperationService.GetOperationsStatAsync(request, token);
|
||||
@ -101,14 +101,14 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
[FromQuery] DetectedOperationRequest request,
|
||||
CancellationToken token)
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
if (!await UserHasAccessToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
|
||||
var result = await detectedOperationService.DeleteAsync(request, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
protected async Task<bool> UserHasAccesToWellAsync(int idWell, CancellationToken token)
|
||||
protected async Task<bool> UserHasAccessToWellAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
if (idCompany is not null &&
|
||||
|
@ -21,7 +21,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
||||
public abstract class TrajectoryController<TDto> : ControllerBase
|
||||
where TDto : TrajectoryGeoDto
|
||||
{
|
||||
protected abstract string fileName { get; set; }
|
||||
protected abstract string fileName { get; }
|
||||
|
||||
private readonly IWellService wellService;
|
||||
private readonly TrajectoryExportService<TDto> trajectoryExportService;
|
||||
|
@ -19,19 +19,17 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public abstract class TrajectoryEditableController<Tdto> : TrajectoryController<Tdto>
|
||||
where Tdto : TrajectoryGeoDto
|
||||
public abstract class TrajectoryEditableController<TDto> : TrajectoryController<TDto>
|
||||
where TDto : TrajectoryGeoDto
|
||||
{
|
||||
protected override string fileName { get; set; }
|
||||
|
||||
private readonly TrajectoryParserService<Tdto> trajectoryImportService;
|
||||
private readonly TrajectoryExportService<Tdto> trajectoryExportService;
|
||||
private readonly ITrajectoryEditableRepository<Tdto> trajectoryRepository;
|
||||
private readonly TrajectoryParserService<TDto> trajectoryImportService;
|
||||
private readonly TrajectoryExportService<TDto> trajectoryExportService;
|
||||
private readonly ITrajectoryEditableRepository<TDto> trajectoryRepository;
|
||||
|
||||
public TrajectoryEditableController(IWellService wellService,
|
||||
TrajectoryParserService<Tdto> trajectoryImportService,
|
||||
TrajectoryExportService<Tdto> trajectoryExportService,
|
||||
ITrajectoryEditableRepository<Tdto> trajectoryRepository)
|
||||
TrajectoryParserService<TDto> trajectoryImportService,
|
||||
TrajectoryExportService<TDto> trajectoryExportService,
|
||||
ITrajectoryEditableRepository<TDto> trajectoryRepository)
|
||||
: base(
|
||||
wellService,
|
||||
trajectoryExportService,
|
||||
@ -118,7 +116,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
||||
/// <returns>количество успешно записанных строк в БД</returns>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> AddAsync(int idWell, [FromBody] Tdto row,
|
||||
public async Task<IActionResult> AddAsync(int idWell, [FromBody] TDto row,
|
||||
CancellationToken token)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
@ -141,7 +139,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
||||
/// <returns>количество успешно записанных строк в БД</returns>
|
||||
[HttpPost("range")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> AddRangeAsync(int idWell, [FromBody] IEnumerable<Tdto> rows,
|
||||
public async Task<IActionResult> AddRangeAsync(int idWell, [FromBody] IEnumerable<TDto> rows,
|
||||
CancellationToken token)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
@ -169,7 +167,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
||||
[HttpPut("{idRow}")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> UpdateAsync(int idWell, int idRow,
|
||||
[FromBody] Tdto row, CancellationToken token)
|
||||
[FromBody] TDto row, CancellationToken token)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
@ -14,7 +14,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory;
|
||||
[Route("api/well/{idWell}/[controller]")]
|
||||
public class TrajectoryFactManualController : TrajectoryEditableController<TrajectoryGeoFactDto>
|
||||
{
|
||||
protected override string fileName { get; set; }
|
||||
protected override string fileName => "ЕЦП_шаблон_файла_фактическая_траектория.xlsx";
|
||||
public TrajectoryFactManualController(IWellService wellService,
|
||||
TrajectoryFactManualParserService factTrajectoryImportService,
|
||||
TrajectoryFactManualExportService factTrajectoryExportService,
|
||||
@ -24,7 +24,5 @@ public class TrajectoryFactManualController : TrajectoryEditableController<Traje
|
||||
factTrajectoryImportService,
|
||||
factTrajectoryExportService,
|
||||
trajectoryFactRepository)
|
||||
{
|
||||
fileName = "ЕЦП_шаблон_файла_фактическая_траектория.xlsx";
|
||||
}
|
||||
{ }
|
||||
}
|
@ -15,7 +15,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory;
|
||||
[Route("api/well/{idWell}/[controller]")]
|
||||
public class TrajectoryFactNnbController : TrajectoryController<TrajectoryGeoFactDto>
|
||||
{
|
||||
protected override string fileName { get; set; }
|
||||
protected override string fileName => "ЕЦП_шаблон_файла_фактическая_ннб_траектория.xlsx";
|
||||
public TrajectoryFactNnbController(
|
||||
ITrajectoryNnbRepository trajectoryNnbRepository,
|
||||
TrajectoryFactNnbExportService trajectoryExportService,
|
||||
@ -24,7 +24,5 @@ public class TrajectoryFactNnbController : TrajectoryController<TrajectoryGeoFac
|
||||
wellService,
|
||||
trajectoryExportService,
|
||||
trajectoryNnbRepository)
|
||||
{
|
||||
fileName = "ЕЦП_шаблон_файла_фактическая_ннб_траектория.xlsx";
|
||||
}
|
||||
{ }
|
||||
}
|
@ -21,6 +21,8 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
||||
{
|
||||
private readonly TrajectoryService trajectoryVisualizationService;
|
||||
|
||||
protected override string fileName => "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
|
||||
|
||||
public TrajectoryPlanController(IWellService wellService,
|
||||
TrajectoryPlanParserService trajectoryPlanImportService,
|
||||
TrajectoryPlanExportService trajectoryPlanExportService,
|
||||
@ -32,7 +34,6 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
||||
trajectoryPlanExportService,
|
||||
trajectoryPlanRepository)
|
||||
{
|
||||
fileName = "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
|
||||
this.trajectoryVisualizationService = trajectoryVisualizationService;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ namespace AsbCloudWebApi
|
||||
{
|
||||
// Uncomment next line to find wired exceptions by tracing.
|
||||
//static TraceListenerView trace4debug = new TraceListenerView();
|
||||
enum A { a = 1 << 2 }
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
@ -1,8 +1,9 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudInfrastructure.Background;
|
||||
using AsbCloudWebApi.SignalR.Clients;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -17,39 +18,44 @@ namespace AsbCloudWebApi.SignalR
|
||||
[Authorize]
|
||||
public class ReportsHub : BaseHub<IReportHubClient>
|
||||
{
|
||||
private readonly BackgroundWorker backgroundWorker;
|
||||
private readonly IWellService wellService;
|
||||
private readonly IReportService reportService;
|
||||
|
||||
public ReportsHub(BackgroundWorker backgroundWorker)
|
||||
public ReportsHub(IWellService wellService, IReportService reportService)
|
||||
{
|
||||
this.backgroundWorker = backgroundWorker;
|
||||
this.wellService = wellService;
|
||||
this.reportService = reportService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление в группу, отправка данных о формировании отчета
|
||||
/// </summary>
|
||||
/// <param name="groupName"></param>
|
||||
/// <param name="groupName">группа</param>
|
||||
/// <param name="idWell">ключ скважины</param>
|
||||
/// <param name="request">параметры запроса</param>
|
||||
/// <returns></returns>
|
||||
public override async Task AddToGroup(string groupName)
|
||||
public async Task CreateReport(string groupName, int idWell, ReportParametersRequest request)
|
||||
{
|
||||
var idUser = Context.User?.GetUserId();
|
||||
var idCompany = Context.User?.GetCompanyId();
|
||||
|
||||
if ((idCompany is null) || (idUser is null))
|
||||
return;
|
||||
|
||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, CancellationToken.None))
|
||||
return;
|
||||
|
||||
await base.AddToGroup(groupName);
|
||||
|
||||
var workId = groupName.Replace("Report_", "");
|
||||
var work = backgroundWorker.Works.FirstOrDefault(work => work.Id == workId);
|
||||
void HandleReportProgressAsync(object progress, string id) =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Clients.Group(groupName)
|
||||
.GetReportProgress(progress, CancellationToken.None);
|
||||
}, CancellationToken.None);
|
||||
|
||||
var progress = new ReportProgressDto()
|
||||
{
|
||||
Operation = "Ожидает начала в очереди.",
|
||||
Progress = 0f,
|
||||
};
|
||||
|
||||
var state = work?.CurrentState;
|
||||
if (state is not null)
|
||||
{
|
||||
progress.Operation = state.State;
|
||||
progress.Progress = (float)state.Progress;
|
||||
}
|
||||
|
||||
await Clients.Group(groupName).GetReportProgress(progress, CancellationToken.None);
|
||||
var id = reportService.EnqueueCreateReportWork(idWell, (int)idUser,
|
||||
request.StepSeconds, request.Format, request.Begin, request.End, HandleReportProgressAsync);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace SignalRTestClient;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
static void Main()
|
||||
{
|
||||
var connectionBuilder = new HubConnectionBuilder();
|
||||
var connection = connectionBuilder
|
||||
@ -47,7 +47,7 @@ internal class Program
|
||||
builder.AddProvider(provider);
|
||||
}
|
||||
|
||||
private static Task<string?> AccessTokenProvider()
|
||||
private static Task<string> AccessTokenProvider()
|
||||
{
|
||||
return Task.FromResult("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJpZCI6IjEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZGV2IiwiaWRDb21wYW55IjoiMSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6InJvb3QiLCJuYmYiOjE2NjI1NDgxNjIsImV4cCI6MTY5NDEwNTc2MiwiaXNzIjoiYSIsImF1ZCI6ImEifQ.OEAlNzxi7Jat6pzDBTAjTbChskc-tdJthJexyWwwUKE");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user