From f577adb1bcebf743f108ee14f9ae024f3ba8af7a Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 31 Jan 2024 10:47:00 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=B0=D0=BC=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudDb/Model/AsbCloudDbContext.cs | 2 +- AsbCloudDb/Model/DataSaubStat.cs | 82 ++++++++++ AsbCloudDb/Model/IAsbCloudDbContext.cs | 2 +- AsbCloudDb/Model/ProcessMapDrillingCache.cs | 142 ------------------ .../WorkProcessMapDrillingCache.cs | 52 +++---- 5 files changed, 108 insertions(+), 172 deletions(-) create mode 100644 AsbCloudDb/Model/DataSaubStat.cs delete mode 100644 AsbCloudDb/Model/ProcessMapDrillingCache.cs diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 3fcc2ad2..3fb2a292 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -91,7 +91,7 @@ namespace AsbCloudDb.Model public DbSet DrillTests => Set(); - public DbSet ProcessMapDrillingCache => Set(); + public DbSet DataSaubStat => Set(); public AsbCloudDbContext() : base() { Interlocked.Increment(ref referenceCount); diff --git a/AsbCloudDb/Model/DataSaubStat.cs b/AsbCloudDb/Model/DataSaubStat.cs new file mode 100644 index 00000000..32b5d392 --- /dev/null +++ b/AsbCloudDb/Model/DataSaubStat.cs @@ -0,0 +1,82 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text.Json.Serialization; + +namespace AsbCloudDb.Model +{ + [Table("t_data_saub_stat"), Comment("Кеш-таблица для хранения данных для РТК-отчета")] + public class DataSaubStat : IId + { + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("date_start", TypeName = "timestamp with time zone"), Comment("Дата и время начала")] + public DateTimeOffset DateStart { get; set; } + + [Column("date_end", TypeName = "timestamp with time zone"), Comment("Дата и время окончания")] + public DateTimeOffset DateEnd { get; set; } + + [Column("depth_start"), Comment("Глубина забоя по стволу начальная")] + public double DepthStart { get; set; } + + [Column("depth_end"), Comment("Глубина забоя по стволу конечная")] + public double DepthEnd { get; set; } + + [Column("speed"), Comment("Скорость бурения")] + public double Speed { get; set; } + + [Column("block_speed_sp"), Comment("Ограничение скорости блока")] + public double? BlockSpeedSp { get; set; } + + [Column("pressure"), Comment("Давление")] + public double Pressure { get; set; } + + [Column("pressure_idle"), Comment("Давление холостого хода")] + public double? PressureIdle { get; set; } + + [Column("pressure_sp"), Comment("Ограничение фактического давления")] + public double? PressureSp { get; set; } + + [Column("axial_load"), Comment("Фактическая нагрузка")] + public double AxialLoad { get; set; } + + [Column("axial_load_sp"), Comment("Ограничение факт. нагрузки")] + public double? AxialLoadSp { get; set; } + + [Column("axial_load_limit_max"), Comment("Максимально допустимая нагрузка")] + public double? AxialLoadLimitMax { get; set; } + + [Column("rotor_torque"), Comment("Фактический момент")] + public double RotorTorque { get; set; } + + [Column("rotor_torque_sp"), Comment("Ограничение факт. момента")] + public double? RotorTorqueSp { get; set; } + + [Column("rotor_torque_limit_max"), Comment("Максимально допустимый момент")] + public double? RotorTorqueLimitMax { get; set; } + + [Column("id_feed_regulator"), Comment("Работа при достижении ограничения")] + public short? IdFeedRegulator { get; set; } + + [Column("rotor_speed"), Comment("Фактическая скорость оборотов ВСП")] + public double RotorSpeed { get; set; } + + [Column("detected_operation_category_id"), Comment("Название автоопределённой операции")] + public int DetectedOperationCategoryId { get; set; } + + [Column("enabled_subsystems"), Comment("Флаги подсистем")] + public int EnabledSubsystems { get; set; } + + [Column("has_oscillation"), Comment("Наличие или отсутствие осцилляции")] + public bool HasOscillation { get; set; } + + [Column("id_telemetry"), Comment("Ключ телеметрии")] + public int IdTelemetry { get; set; } + + [ForeignKey(nameof(IdTelemetry))] + public virtual Telemetry Telemetry { get; set; } = null!; + } +} diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index a451fc45..1b38b23f 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -80,7 +80,7 @@ namespace AsbCloudDb.Model DbSet DrillTests { get; } DbSet TrajectoriesFact { get; } DbSet WellSectionsPlan { get; } - DbSet ProcessMapDrillingCache { get; } + DbSet DataSaubStat { get; } DatabaseFacade Database { get; } Task RefreshMaterializedViewAsync(string mwName, CancellationToken token); diff --git a/AsbCloudDb/Model/ProcessMapDrillingCache.cs b/AsbCloudDb/Model/ProcessMapDrillingCache.cs deleted file mode 100644 index dc1da405..00000000 --- a/AsbCloudDb/Model/ProcessMapDrillingCache.cs +++ /dev/null @@ -1,142 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -namespace AsbCloudDb.Model -{ - [Table("t_process_map_drilling_cache"), Comment("Кеш-таблица для хранения данных для РТК-отчета")] - public class ProcessMapDrillingCache : IId - { - [Key] - [Column("id")] - public int Id { get; set; } - - [Column("date_from", TypeName = "timestamp with time zone"), Comment("Дата начала")] - public DateTimeOffset DateFrom { get; set; } - - [Column("date_to", TypeName = "timestamp with time zone"), Comment("Дата окончания")] - public DateTimeOffset DateTo { get; set; } - - /// - /// Дата и время начала бурения - /// - [Column("date_drilling_start", TypeName = "timestamp with time zone"), Comment("Дата и время начала бурения")] - public DateTimeOffset DateDrillingStart { get; set; } - - /// - /// Дата и время окончания бурения - /// - [Column("date_drilling_end", TypeName = "timestamp with time zone"), Comment("Дата и время окончания бурения")] - public DateTimeOffset DateDrillingEnd { get; set; } - - /// - /// Глубина забоя по стволу начальная - /// - [Column("depth_start"), Comment("Глубина забоя по стволу начальная")] - public double DepthStart { get; set; } - - /// - /// Глубина забоя по стволу конечная - /// - [Column("depth_end"), Comment("Глубина забоя по стволу конечная")] - public double DepthEnd { get; set; } - - /// - /// Скорость бурения - /// - [Column("speed"), Comment("Скорость бурения")] - public double Speed { get; set; } - - /// - /// Ограничение скорости блока - /// - [Column("block_speed_sp"), Comment("Ограничение скорости блока")] - public float? BlockSpeedSp { get; set; } - - /// - /// Давление - /// - [Column("pressure"), Comment("Давление")] - public double Pressure { get; set; } - - /// - /// Давление холостого хода - /// - [Column("pressure_idle"), Comment("Давление холостого хода")] - public float? PressureIdle { get; set; } - - /// - /// Ограничение фактического давления - /// - [Column("pressure_sp"), Comment("Ограничение фактического давления")] - public float? PressureSp { get; set; } - - /// - /// Фактическая нагрузка - /// - [Column("axial_load"), Comment("Фактическая нагрузка")] - public double AxialLoad { get; set; } - - /// - /// Ограничение факт. нагрузки - /// - [Column("axial_load_sp"), Comment("Ограничение факт. нагрузки")] - public float? AxialLoadSp { get; set; } - - /// - /// Максимально допустимая нагрузка - /// - [Column("axial_load_limit_max"), Comment("Максимально допустимая нагрузка")] - public float? AxialLoadLimitMax { get; set; } - - /// - /// Фактический момент - /// - [Column("rotor_torque"), Comment("Фактический момент")] - public double RotorTorque { get; set; } - - /// - /// Ограничение факт. момента - /// - [Column("rotor_torque_sp"), Comment("Ограничение факт. момента")] - public float? RotorTorqueSp { get; set; } - - /// - /// Максимально допустимый момент - /// - [Column("rotor_torque_limit_max"), Comment("Максимально допустимый момент")] - public float? RotorTorqueLimitMax { get; set; } - - /// - /// Работа при достижении ограничения - /// - [Column("id_feed_regulator"), Comment("Работа при достижении ограничения")] - public short? IdFeedRegulator { get; set; } - - /// - /// Фактическая скорость оборотов ВСП - /// - [Column("rotor_speed"), Comment("Фактическая скорость оборотов ВСП")] - public double RotorSpeed { get; set; } - - /// - /// Название автоопределённой операции - /// - [Column("detected_operation_category_id"), Comment("Название автоопределённой операции")] - public int DetectedOperationCategoryId { get; set; } - - /// - /// Флаги подсистем - /// - [Column("enabled_subsystems"), Comment("Флаги подсистем")] - public int EnabledSubsystems { get; set; } - - /// - /// Наличие или отсутствие осцилляции - /// - - [Column("has_oscillation"), Comment("Наличие или отсутствие осцилляции")] - public bool HasOscillation { get; set; } - } -} diff --git a/AsbCloudInfrastructure/Background/PeriodicWorks/WorkProcessMapDrillingCache.cs b/AsbCloudInfrastructure/Background/PeriodicWorks/WorkProcessMapDrillingCache.cs index 1c18196b..42796fc9 100644 --- a/AsbCloudInfrastructure/Background/PeriodicWorks/WorkProcessMapDrillingCache.cs +++ b/AsbCloudInfrastructure/Background/PeriodicWorks/WorkProcessMapDrillingCache.cs @@ -38,16 +38,15 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks // параметры метода: массив из using var db = services.GetRequiredService(); - - var dateFrom = db.ProcessMapDrillingCache - .OrderByDescending(c => c.DateTo) - .FirstOrDefault()?.DateTo + var dateEnd = db.Set() + .OrderByDescending(c => c.DateEnd) + .FirstOrDefault()?.DateEnd ?? DateTimeOffset.MinValue; //а остальные операции, которые не вошли в 500 первых? - var detectedOperations = db.DetectedOperations - .Where(o => o.DateStart > dateFrom) + var detectedOperations = db.Set() + .Where(o => o.DateStart > dateEnd) .Where(o => o.OperationCategory.IdParent == MechanicalDrillingCategoryId) .OrderBy(o => o.DateStart) .Take(500) @@ -56,7 +55,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks var minDate = detectedOperations.FirstOrDefault()?.DateStart; var maxDate = detectedOperations.OrderByDescending(d =>d.DateEnd).FirstOrDefault()?.DateEnd; - var telemetryDataSaub = db.TelemetryDataSaub + var telemetryDataSaub = db.Set() .Where(t => t.DateTime >= minDate) .Where(t => t.DateTime <= maxDate) .Where(t => Math.Abs(t.BitDepth - t.WellDepth) < 0.0001) @@ -67,16 +66,15 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks var indexEnd = 0; foreach (var operation in detectedOperations) { - indexStart = Array.FindIndex(telemetryDataSaub, indexEnd, t => t.DateTime >= operation.DateStart ); + indexStart = Array.FindIndex(telemetryDataSaub, indexEnd, t => t.DateTime >= operation.DateStart); indexEnd = Array.FindIndex(telemetryDataSaub, indexStart, t => t.DateTime > operation.DateEnd) - 1; - if(indexStart >= 0 && indexEnd >= indexStart) + if (indexStart >= 0 && indexEnd >= indexStart) { var length = indexEnd - indexStart; var subset = telemetryDataSaub.AsSpan(indexStart, length + 1); var result = CalcStats(operation, subset); - } } @@ -98,13 +96,12 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks var span = telemetryDataSaub.Slice(indexStart, length); indexStart = i; var processMapDrillingCacheItem = CalcStat(operation, span); - } } return null; } - private ProcessMapDrillingCache CalcStat(DetectedOperation operation, Span span) + private DataSaubStat CalcStat(DetectedOperation operation, Span span) { var depthStart = span[0].WellDepth; var depthEnd = span[^1].WellDepth; @@ -113,31 +110,30 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks if (operation.ExtraData.TryGetValue(DetectorDrilling.ExtraDataKeyHasOscillation, out object? HasOscillation)) hasOscillation = Convert.ToBoolean(HasOscillation); - var processMapDrillingCacheItem = new ProcessMapDrillingCache + var wavg = CalcWavg(span); + var processMapDrillingCacheItem = new DataSaubStat { - DateDrillingStart = operation.DateStart, - DateDrillingEnd = operation.DateEnd, + DateStart = operation.DateStart, + DateEnd = operation.DateEnd, DepthStart = depthStart, DepthEnd = depthEnd, Speed = (depthEnd - depthStart) / ((operation.DateEnd - operation.DateStart).TotalHours), BlockSpeedSp = span[0].BlockSpeedSp, - Pressure = CalcValue(span, depthEnd - depthStart).Pressure, + Pressure = wavg.Pressure, PressureIdle = span[0].PressureIdle, PressureSp = span[0].PressureSp, - AxialLoad = CalcValue(span, depthEnd - depthStart).AxialLoad, + AxialLoad = wavg.AxialLoad, AxialLoadSp = span[0].AxialLoadSp, AxialLoadLimitMax = span[0].AxialLoadLimitMax, - RotorTorque = CalcValue(span, depthEnd - depthStart).RotorTorque, + RotorTorque = wavg.RotorTorque, RotorTorqueSp = span[0].RotorTorqueSp, RotorTorqueLimitMax = span[0].RotorTorqueLimitMax, - //Значение столбца id_feed_regulator из таблицы “Фильтрованная телеметрия” - //в границах временного интервала (диапазоне). IdFeedRegulator = span[0].IdFeedRegulator, - RotorSpeed = CalcValue(span, depthEnd - depthStart).RotorSpeed, - //? + RotorSpeed = wavg.RotorSpeed, DetectedOperationCategoryId = operation.IdCategory, EnabledSubsystems = operation.EnabledSubsystems, - HasOscillation = hasOscillation + HasOscillation = hasOscillation, + IdTelemetry = operation.IdTelemetry, }; return processMapDrillingCacheItem; } @@ -147,7 +143,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks double AxialLoad, double RotorTorque, double RotorSpeed - ) CalcValue(Span span) + ) CalcWavg(Span span) { var sumPressure = 0.0; var sumAxialLoad = 0.0; @@ -157,10 +153,10 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks for (var i = 0; i < span.Length - 1; i++) { var weigth = span[i + 1].WellDepth - span[i].WellDepth; - sumPressure += () * span[i].Pressure; - sumAxialLoad += (span[i + 1].WellDepth - span[i].WellDepth) * span[i].AxialLoad; - sumRotorTorque += (span[i + 1].WellDepth - span[i].WellDepth) * span[i].RotorTorque; - sumRotorSpeed += (span[i + 1].WellDepth - span[i].WellDepth) * span[i].RotorSpeed; + sumPressure += weigth * span[i].Pressure; + sumAxialLoad += weigth * span[i].AxialLoad; + sumRotorTorque += weigth * span[i].RotorTorque; + sumRotorSpeed += weigth * span[i].RotorSpeed; } return ( Pressure: sumPressure / diffDepthTotal,