Миграция на создание таблицы для учета статистики Качества

This commit is contained in:
Olga Nemt 2024-10-04 16:54:18 +05:00
parent af43828d57
commit 73d60d1464
10 changed files with 12802 additions and 24 deletions

View File

@ -0,0 +1,50 @@
using System;
using AsbCloudApp.Data.WellOperation;
namespace AsbCloudApp.Data;
/// <summary>
/// dto для хранения данных статистики качества бурения
/// </summary>
public class DataSaubStatDrillingQualityDto : IId
{
/// <summary>
///
/// </summary>
public int Id { get; set; }
/// <summary>
/// Дата и время начала
/// </summary>
public DateTimeOffset DateStart { get; set; }
/// <summary>
/// Дата и время окончания
/// </summary>
public DateTimeOffset DateEnd { get; set; }
/// <summary>
/// Глубина забоя по стволу начальная
/// </summary>
public double DepthStart { get; set; }
/// <summary>
/// Глубина забоя по стволу конечная
/// </summary>
public double DepthEnd { get; set; }
/// <summary>
/// Качественная проходка
/// </summary>
public double DepthDrillingQuality { get; set; }
/// <summary>
/// Флаг
/// </summary>
public int IdFeedRegulator { get; set; }
/// <summary>
/// Ключ телеметрии
/// </summary>
public int IdTelemetry { get; set; }
}

View File

@ -0,0 +1,135 @@
using System;
using AsbCloudApp.Data.WellOperation;
namespace AsbCloudApp.Data;
/// <summary>
/// dto для хранения данных статистики сауб
/// </summary>
public class DataSaubStatDto : IId
{
/// <summary>
///
/// </summary>
public int Id { get; set; }
/// <summary>
/// Дата и время начала
/// </summary>
public DateTimeOffset DateStart { get; set; }
/// <summary>
/// Дата и время окончания
/// </summary>
public DateTimeOffset DateEnd { get; set; }
/// <summary>
/// Глубина забоя по стволу начальная
/// </summary>
public double DepthStart { get; set; }
/// <summary>
/// Глубина забоя по стволу конечная
/// </summary>
public double DepthEnd { get; set; }
/// <summary>
/// Скорость бурения
/// </summary>
public double Speed { get; set; }
/// <summary>
/// Ограничение скорости блока
/// </summary>
public double? BlockSpeedSp { get; set; }
/// <summary>
/// Давление
/// </summary>
public double Pressure { get; set; }
/// <summary>
/// Давление холостого хода
/// </summary>
public double? PressureIdle { get; set; }
/// <summary>
/// Ограничение фактического давления
/// </summary>
public double? PressureSp { get; set; }
/// <summary>
/// Фактическая нагрузка
/// </summary>
public double AxialLoad { get; set; }
/// <summary>
/// Ограничение факт. нагрузки
/// </summary>
public double? AxialLoadSp { get; set; }
/// <summary>
/// Максимально допустимая нагрузка
/// </summary>
public double? AxialLoadLimitMax { get; set; }
/// <summary>
/// Фактический момент
/// </summary>
public double RotorTorque { get; set; }
/// <summary>
/// Ограничение факт. момента
/// </summary>
public double? RotorTorqueSp { get; set; }
/// <summary>
/// Максимально допустимый момент
/// </summary>
public double? RotorTorqueLimitMax { get; set; }
/// <summary>
/// Работа при достижении ограничения
/// </summary>
public short? IdFeedRegulator { get; set; }
/// <summary>
/// Фактическая скорость оборотов ВСП
/// </summary>
public double RotorSpeed { get; set; }
/// <summary>
/// Название автоопределённой операции
/// </summary>
public int IdCategory { get; set; }
/// <summary>
/// Флаги подсистем
/// </summary>
public int EnabledSubsystems { get; set; }
/// <summary>
/// Наличие или отсутствие осцилляции
/// </summary>
public bool HasOscillation { get; set; }
/// <summary>
/// Фактический расход
/// </summary>
public double Flow { get; set; }
/// <summary>
/// Ключ телеметрии
/// </summary>
public int IdTelemetry { get; set; }
/// <summary>
/// Телеметрия
/// </summary>
public TelemetryDto Telemetry { get; set; } = null!;
/// <summary>
/// Категория автоопределенной операции
/// </summary>
public WellOperationCategoryDto OperationCategory { get; set; } = null!;
}

View File

@ -23,15 +23,15 @@ public interface IDataSaubStatDrillingQualityRepository : ITelemetryDataEditorSe
Task<IEnumerable<DataSaubStatDto>> GetAsync(int idTelemetry, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token);
/// <summary>
/// Получение последних по дате окончания бурения записей в разрезе телеметрий
/// Получение последних по дате окончания бурения записей качества в разрезе телеметрий
/// </summary>
/// <param name="idTelemetries">ключи телеметрий</param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<DataSaubStatDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token);
Task<IEnumerable<DataSaubStatDrillingQualityDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token);
/// <summary>
/// Вставка записей статистики
/// Вставка записей статистики качества
/// </summary>
/// <param name="dataSaubStats"></param>
/// <param name="token"></param>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AsbCloudDb.Migrations
{
/// <inheritdoc />
public partial class Add_Table_DataSaubStatDrillingQuality : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "t_data_saub_stat_drilling_quality",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
id_telemetry = table.Column<int>(type: "integer", nullable: false, comment: "Ключ телеметрии"),
date_start = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата и время начала"),
date_end = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата и время окончания"),
depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина забоя по стволу начальная"),
depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина забоя по стволу конечная"),
id_feed_regulator = table.Column<int>(type: "integer", nullable: false, comment: "Флаг"),
depth_drilling_quality = table.Column<double>(type: "double precision", nullable: false, comment: "Качественная проходка")
},
constraints: table =>
{
table.PrimaryKey("PK_t_data_saub_stat_drilling_quality", x => x.id);
table.ForeignKey(
name: "FK_t_data_saub_stat_drilling_quality_t_telemetry_id_telemetry",
column: x => x.id_telemetry,
principalTable: "t_telemetry",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "Кеш-таблица для хранения данных для построения страницы \"Качество\"");
migrationBuilder.CreateIndex(
name: "IX_t_data_saub_stat_drilling_quality_id_telemetry",
table: "t_data_saub_stat_drilling_quality",
column: "id_telemetry");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_data_saub_stat_drilling_quality");
}
}
}

View File

@ -19,7 +19,7 @@ namespace AsbCloudDb.Migrations
#pragma warning disable 612, 618
modelBuilder
.UseCollation("Russian_Russia.1251")
.HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack");
@ -451,6 +451,60 @@ namespace AsbCloudDb.Migrations
});
});
modelBuilder.Entity("AsbCloudDb.Model.DataSaubStatDrillingQuality", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTimeOffset>("DateEnd")
.HasColumnType("timestamp with time zone")
.HasColumnName("date_end")
.HasComment("Дата и время окончания");
b.Property<DateTimeOffset>("DateStart")
.HasColumnType("timestamp with time zone")
.HasColumnName("date_start")
.HasComment("Дата и время начала");
b.Property<double>("DepthDrillingQuality")
.HasColumnType("double precision")
.HasColumnName("depth_drilling_quality")
.HasComment("Качественная проходка");
b.Property<double>("DepthEnd")
.HasColumnType("double precision")
.HasColumnName("depth_end")
.HasComment("Глубина забоя по стволу конечная");
b.Property<double>("DepthStart")
.HasColumnType("double precision")
.HasColumnName("depth_start")
.HasComment("Глубина забоя по стволу начальная");
b.Property<int>("IdFeedRegulator")
.HasColumnType("integer")
.HasColumnName("id_feed_regulator")
.HasComment("Флаг");
b.Property<int>("IdTelemetry")
.HasColumnType("integer")
.HasColumnName("id_telemetry")
.HasComment("Ключ телеметрии");
b.HasKey("Id");
b.HasIndex("IdTelemetry");
b.ToTable("t_data_saub_stat_drilling_quality", t =>
{
t.HasComment("Кеш-таблица для хранения данных для построения страницы \"Качество\"");
});
});
modelBuilder.Entity("AsbCloudDb.Model.Deposit", b =>
{
b.Property<int>("Id")
@ -10720,6 +10774,17 @@ namespace AsbCloudDb.Migrations
b.Navigation("Telemetry");
});
modelBuilder.Entity("AsbCloudDb.Model.DataSaubStatDrillingQuality", b =>
{
b.HasOne("AsbCloudDb.Model.Telemetry", "Telemetry")
.WithMany()
.HasForeignKey("IdTelemetry")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Telemetry");
});
modelBuilder.Entity("AsbCloudDb.Model.DetectedOperation", b =>
{
b.HasOne("AsbCloudDb.Model.WellOperationCategory", "OperationCategory")

View File

@ -28,7 +28,14 @@ namespace AsbCloudDb.Model
[Column("depth_end"), Comment("Глубина забоя по стволу конечная")]
public double DepthEnd { get; set; }
[Column("id_feed_regulator"), Comment("Флаг")]
public int IdFeedRegulator { get; set; }
[Column("depth_drilling_quality"), Comment("Качественная проходка")]
public double DepthDrillingQuality { get; set; }
[ForeignKey(nameof(IdTelemetry))]
public virtual Telemetry Telemetry { get; set; } = null!;
}
}

View File

@ -319,7 +319,8 @@ public static class DependencyInjection
services.AddTransient<IHelpPageService, HelpPageService>();
services.AddTransient<IScheduleReportService, ScheduleReportService>();
services.AddTransient<IDataSaubStatRepository, DataSaubStatRepository>();
//services.AddTransient<IDataSaubStatService, DataSaubStatService>();
services.AddTransient<IDataSaubStatDrillingQualityRepository, DataSaubStatDrillingQualityRepository>();
services.AddTransient<IDataSaubStatService, DataSaubStatService>();
services.AddTransient<IDataSaubStatService, DataSaubStatDrillingQualityService>();
services.AddTransient<IWellOperationService, WellOperationService>();

View File

@ -25,21 +25,20 @@ public class DataSaubStatDrillingQualityRepository : IDataSaubStatDrillingQualit
}
public async Task<IEnumerable<DataSaubStatDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token)
public async Task<IEnumerable<DataSaubStatDrillingQualityDto>> GetLastsAsync(int[] idTelemetries, CancellationToken token)
{
var timeZoneOffsets = idTelemetries
.Distinct()
.ToDictionary(idTelemetry => idTelemetry, idTelemetry => TimeSpan.FromHours(telemetryService.GetTimezone(idTelemetry).Hours));
var stats = await db.Set<DataSaubStat>()
var stats = await db.Set<DataSaubStatDrillingQuality>()
.Where(s => idTelemetries.Contains(s.IdTelemetry))
.GroupBy(s => s.IdTelemetry, (key, group) => group.OrderByDescending(el => el.DateEnd).First())
.ToArrayAsync(token);
//todo
//var result = stats.Select(s => ConvertToDto(s, timeZoneOffsets[s.IdTelemetry]));
//return result;
return null;
var result = stats.Select(s => ConvertToDto(s, timeZoneOffsets[s.IdTelemetry]));
return result;
}
public async Task<IEnumerable<DataSaubStatDto>> GetAsync(int idTelemetry, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token)

View File

@ -60,22 +60,22 @@ public class DataSaubStatDrillingQualityService : IDataSaubStatService
{
GeDate = DateTime.UtcNow.AddDays(-5000)
};
var idTelemetries = telemetryDataCache.GetIds(cacheRequest).ToArray();
var idTelemetries = new int[119];
//telemetryDataCache.GetIds(cacheRequest).ToArray();
if (!idTelemetries.Any())
return;
var stats = new List<DataSaubStatDto>();
//await dataSaubStatRepository.GetLastsAsync(idTelemetries, token);
var stats = await dataSaubStatDrillingQualityRepository.GetLastsAsync(idTelemetries, token);
//for (var i = 0; i < idTelemetries.Length; i++)
//{
// var idTelemetry = idTelemetries[i];
// var lastDate = stats.FirstOrDefault(s => s.IdTelemetry == idTelemetry)?.DateEnd.ToUniversalTime() ?? DateTimeOffset.UnixEpoch;
// var statsCount = await CreateStatDrillingQualityForTelemetry(idTelemetry, lastDate, token);
// if (onProgressCallback != null)
// onProgressCallback($"Calculate stat for telemetry: {idTelemetry}; from {lastDate}; results count: {statsCount};", 1d * i / idTelemetries.Length);
//}
for (var i = 0; i < idTelemetries.Length; i++)
{
var idTelemetry = idTelemetries[i];
var lastDate = stats.FirstOrDefault(s => s.IdTelemetry == idTelemetry)?.DateEnd.ToUniversalTime() ?? DateTimeOffset.UnixEpoch;
var statsCount = await CreateStatDrillingQualityForTelemetry(idTelemetry, lastDate, token);
if (onProgressCallback != null)
onProgressCallback($"Calculate stat for telemetry: {idTelemetry}; from {lastDate}; results count: {statsCount};", 1d * i / idTelemetries.Length);
}
}
private async Task<int> CreateStatDrillingQualityForTelemetry(
@ -100,7 +100,10 @@ public class DataSaubStatDrillingQualityService : IDataSaubStatService
result.AddRange(data);
}
if(result.Any())
return await dataSaubStatDrillingQualityRepository.InsertRangeAsync(result, token);
return 0;
}
private static IEnumerable<DataSaubStatDrillingQualityDto> CreateDataSaubStatDrillingQuality(
@ -113,7 +116,7 @@ public class DataSaubStatDrillingQualityService : IDataSaubStatService
var indexStart = 0;
var indexEnd = 0;
while (indexEnd < dataSaub.Count())
while (indexEnd < dataSaub.Count()-1)
{
indexStart = Array.FindIndex(dataSaub, indexEnd, t => t.IdFeedRegulator == idFeedRegulator);
if (indexStart < 0)