forked from ddrilling/AsbCloudServer
Добавление в базу таблицу статистики по "Качеству"
This commit is contained in:
parent
97cca9cb5a
commit
af43828d57
@ -1,36 +0,0 @@
|
||||
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; }
|
||||
public object DepthDrillingQuality { get; set; }
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
using System;
|
||||
using AsbCloudApp.Data.WellOperation;
|
||||
|
||||
namespace AsbCloudApp.Data.DataSaubStat;
|
||||
|
||||
/// <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!;
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Репозиторий работы с данными из таблицы t_data_daub_stat_drilling_quality
|
||||
/// </summary>
|
||||
public interface IDataSaubStatDrillingQualityRepository : ITelemetryDataEditorService
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение записей по ключу телеметрии
|
||||
/// </summary>
|
||||
/// <param name="idTelemetry">ключ телеметрии</param>
|
||||
/// <param name="geDate">начальная дата</param>
|
||||
/// <param name="leDate">конечная дата</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Вставка записей статистики
|
||||
/// </summary>
|
||||
/// <param name="dataSaubStats"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> InsertRangeAsync(IEnumerable<DataSaubStatDrillingQualityDto> dataSaubStats, CancellationToken token);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data.DataSaubStat;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -110,6 +110,7 @@ namespace AsbCloudDb.Model
|
||||
public DbSet<DrillTest> DrillTests => Set<DrillTest>();
|
||||
|
||||
public DbSet<DataSaubStat> DataSaubStat => Set<DataSaubStat>();
|
||||
public DbSet<DataSaubStatDrillingQuality> DataSaubStatDrillingQuality => Set<DataSaubStatDrillingQuality>();
|
||||
public AsbCloudDbContext() : base()
|
||||
{
|
||||
Interlocked.Increment(ref referenceCount);
|
||||
|
@ -81,6 +81,7 @@ namespace AsbCloudDb.Model
|
||||
DbSet<TrajectoryFact> TrajectoriesFact { get; }
|
||||
DbSet<WellSectionPlan> WellSectionsPlan { get; }
|
||||
DbSet<DataSaubStat> DataSaubStat { get; }
|
||||
DbSet<DataSaubStatDrillingQuality> DataSaubStatDrillingQuality { get; }
|
||||
DatabaseFacade Database { get; }
|
||||
DbSet<ProcessMapPlanRotor> ProcessMapPlanRotor { get; }
|
||||
DbSet<ProcessMapPlanSlide> ProcessMapPlanSlide { get; }
|
||||
|
34
AsbCloudDb/Model/SaubStat/DataSaubStatDrillingQuality.cs
Normal file
34
AsbCloudDb/Model/SaubStat/DataSaubStatDrillingQuality.cs
Normal file
@ -0,0 +1,34 @@
|
||||
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_drilling_quality"), Comment("Кеш-таблица для хранения данных для построения страницы \"Качество\"")]
|
||||
public class DataSaubStatDrillingQuality : IId
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("id_telemetry"), Comment("Ключ телеметрии")]
|
||||
public int IdTelemetry { 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; }
|
||||
|
||||
[ForeignKey(nameof(IdTelemetry))]
|
||||
public virtual Telemetry Telemetry { get; set; } = null!;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data.DataSaubStat;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.DetectedOperation;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Repositories;
|
||||
|
@ -0,0 +1,114 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository;
|
||||
|
||||
public class DataSaubStatDrillingQualityRepository : IDataSaubStatDrillingQualityRepository
|
||||
{
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
|
||||
public DataSaubStatDrillingQualityRepository(IAsbCloudDbContext dbContext, ITelemetryService telemetryService)
|
||||
{
|
||||
db = dbContext;
|
||||
this.telemetryService = telemetryService;
|
||||
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<DataSaubStatDto>> 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>()
|
||||
.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;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<DataSaubStatDto>> GetAsync(int idTelemetry, DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken token)
|
||||
{
|
||||
var timeSpan = TimeSpan.FromHours(telemetryService.GetTimezone(idTelemetry).Hours);
|
||||
var geDateUtc = geDate.ToUniversalTime();
|
||||
var leDateUtc = leDate.ToUniversalTime();
|
||||
|
||||
var stats = await db.Set<DataSaubStat>()
|
||||
.Where(s => s.IdTelemetry == idTelemetry)
|
||||
.Where(s => s.DateStart >= geDateUtc)
|
||||
.Where(s => s.DateEnd <= leDateUtc)
|
||||
.ToArrayAsync(token);
|
||||
//todo
|
||||
//var result = stats.Select(s => ConvertToDto(s, timeSpan));
|
||||
|
||||
//return result;
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<int> InsertRangeAsync(IEnumerable<DataSaubStatDrillingQualityDto> dataSaubStats, CancellationToken token)
|
||||
{
|
||||
var entities = dataSaubStats.Select(data => ConvertToEntity(data));
|
||||
db.Set<DataSaubStatDrillingQuality>().AddRange(entities);
|
||||
return await db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
private static DataSaubStatDrillingQualityDto ConvertToDto(DataSaubStatDrillingQuality entity, TimeSpan timeSpan)
|
||||
{
|
||||
var dto = entity.Adapt<DataSaubStatDrillingQualityDto>();
|
||||
dto.DateStart = dto.DateStart.ToOffset(timeSpan);
|
||||
dto.DateEnd = dto.DateEnd.ToOffset(timeSpan);
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private static DataSaubStatDrillingQuality ConvertToEntity(DataSaubStatDrillingQualityDto dto)
|
||||
{
|
||||
var entity = dto.Adapt<DataSaubStatDrillingQuality>();
|
||||
entity.DateStart = dto.DateStart.ToUniversalTime();
|
||||
entity.DateEnd = dto.DateEnd.ToUniversalTime();
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private IQueryable<DataSaubStat> BuildQuery(TelemetryPartDeleteRequest request)
|
||||
{
|
||||
var query = db.Set<DataSaubStat>()
|
||||
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
||||
|
||||
if (request.LeDate is not null)
|
||||
{
|
||||
var leDate = request.LeDate.Value.ToUniversalTime();
|
||||
query = query.Where(o => o.DateStart <= leDate);
|
||||
}
|
||||
|
||||
if (request.GeDate is not null)
|
||||
{
|
||||
var geDate = request.GeDate.Value.ToUniversalTime();
|
||||
query = query.Where(o => o.DateEnd >= geDate);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||
{
|
||||
var query = BuildQuery(request);
|
||||
db.Set<DataSaubStat>().RemoveRange(query);
|
||||
return await db.SaveChangesAsync(token);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data.DataSaubStat;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
|
@ -1,11 +1,8 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.DataSaubStat;
|
||||
using AsbCloudApp.Data.DetectedOperation;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -17,21 +14,43 @@ namespace AsbCloudInfrastructure.Services;
|
||||
|
||||
public class DataSaubStatDrillingQualityService : IDataSaubStatService
|
||||
{
|
||||
private IDataSaubStatRepository dataSaubStatRepository;
|
||||
private IDataSaubStatDrillingQualityRepository dataSaubStatDrillingQualityRepository;
|
||||
private ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
|
||||
private ITelemetryDataSaubService dataSaubService;
|
||||
private IDetectedOperationRepository detectedOperationRepository;
|
||||
|
||||
public Dictionary<int, Predicate<TelemetryDataSaubDto>> QualitySettingsForFeedRegulators { get; }
|
||||
|
||||
public DataSaubStatDrillingQualityService(
|
||||
IDataSaubStatRepository dataSaubStatRepository,
|
||||
IDataSaubStatDrillingQualityRepository dataSaubStatDrillingQualityRepository,
|
||||
ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache,
|
||||
ITelemetryDataSaubService dataSaubService,
|
||||
IDetectedOperationRepository detectedOperationRepository)
|
||||
ITelemetryDataSaubService dataSaubService)
|
||||
{
|
||||
this.dataSaubStatRepository = dataSaubStatRepository;
|
||||
this.dataSaubStatDrillingQualityRepository = dataSaubStatDrillingQualityRepository;
|
||||
this.telemetryDataCache = telemetryDataCache;
|
||||
this.dataSaubService = dataSaubService;
|
||||
this.detectedOperationRepository = detectedOperationRepository;
|
||||
|
||||
Predicate<TelemetryDataSaubDto> hasQualityWithIdFeedRegulator1 = (TelemetryDataSaubDto spanItem)
|
||||
=> (spanItem.BlockSpeed >= spanItem.BlockSpeedSp * 0.95
|
||||
&& spanItem.BlockSpeed <= spanItem.BlockSpeedSp * 1.05);
|
||||
|
||||
Predicate<TelemetryDataSaubDto> hasQualityWithIdFeedRegulator2 = (TelemetryDataSaubDto spanItem)
|
||||
=> (spanItem.Pressure >= (spanItem.PressureSp - spanItem.PressureIdle) - 5
|
||||
&& spanItem.Pressure <= (spanItem.PressureSp - spanItem.PressureIdle) + 5);
|
||||
|
||||
Predicate<TelemetryDataSaubDto> hasQualityWithIdFeedRegulator3 = (TelemetryDataSaubDto spanItem)
|
||||
=> (spanItem.AxialLoad >= (spanItem.AxialLoadSp - 0.5)
|
||||
&& spanItem.AxialLoad <= (spanItem.AxialLoadSp + 0.5));
|
||||
|
||||
Predicate<TelemetryDataSaubDto> hasQualityWithIdFeedRegulator4 = (TelemetryDataSaubDto spanItem)
|
||||
=> (spanItem.RotorTorque >= (spanItem.RotorTorqueSp - 0.5)
|
||||
&& spanItem.RotorTorque <= (spanItem.RotorTorqueSp + 0.5));
|
||||
|
||||
QualitySettingsForFeedRegulators = new Dictionary<int, Predicate<TelemetryDataSaubDto>>() {
|
||||
{ 1, hasQualityWithIdFeedRegulator1 },
|
||||
{ 2, hasQualityWithIdFeedRegulator2 },
|
||||
{ 3, hasQualityWithIdFeedRegulator3 },
|
||||
{ 4, hasQualityWithIdFeedRegulator4 },
|
||||
};
|
||||
}
|
||||
|
||||
public async Task CreateStatAsync(int lastDaysFilter, Action<string, double?> onProgressCallback, CancellationToken token)
|
||||
@ -47,19 +66,19 @@ public class DataSaubStatDrillingQualityService : IDataSaubStatService
|
||||
return;
|
||||
|
||||
var stats = new List<DataSaubStatDto>();
|
||||
//await dataSaubStatRepository.GetLastsAsync(idTelemetries, token);
|
||||
//await dataSaubStatRepository.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 CreateStatForTelemetryFromDate(idTelemetry, lastDate, token);
|
||||
// if(onProgressCallback != null)
|
||||
// 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> CreateStatForTelemetryFromDate(
|
||||
private async Task<int> CreateStatDrillingQualityForTelemetry(
|
||||
int idTelemetry,
|
||||
DateTimeOffset geDate,
|
||||
CancellationToken token)
|
||||
@ -74,14 +93,20 @@ public class DataSaubStatDrillingQualityService : IDataSaubStatService
|
||||
if (dataSaub is not TelemetryDataSaubDto[] dataSaubArray)
|
||||
dataSaubArray = dataSaub.ToArray();
|
||||
|
||||
var dataSaubStats = CreateDataSaubStat(dataSaubArray);
|
||||
var result = new List<DataSaubStatDrillingQualityDto>();
|
||||
foreach (var item in QualitySettingsForFeedRegulators)
|
||||
{
|
||||
var data = CreateDataSaubStatDrillingQuality(item.Key, item.Value, dataSaubArray);
|
||||
result.AddRange(data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
//return await dataSaubStatRepository.InsertRangeAsync(dataSaubStats, token);
|
||||
return await dataSaubStatDrillingQualityRepository.InsertRangeAsync(result, token);
|
||||
}
|
||||
|
||||
private static IEnumerable<DataSaubStatDrillingQualityDto> CreateDataSaubStat2(int idFeedRegulator, TelemetryDataSaubDto[] dataSaub)
|
||||
private static IEnumerable<DataSaubStatDrillingQualityDto> CreateDataSaubStatDrillingQuality(
|
||||
int idFeedRegulator,
|
||||
Predicate<TelemetryDataSaubDto> checkQuality,
|
||||
TelemetryDataSaubDto[] dataSaub)
|
||||
{
|
||||
var result = new List<DataSaubStatDrillingQualityDto>();
|
||||
|
||||
@ -100,140 +125,47 @@ public class DataSaubStatDrillingQualityService : IDataSaubStatService
|
||||
indexEnd = dataSaub.Length - 1;
|
||||
|
||||
if (indexEnd == indexStart)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
var length = indexEnd - indexStart + 1;
|
||||
|
||||
var subset = dataSaub.AsSpan(indexStart, length);
|
||||
|
||||
if (length <= 2 || (subset[^1].WellDepth - subset[0].WellDepth) < 0.001)
|
||||
if (length <= 2 || (subset[^1].WellDepth - subset[0].WellDepth) < 0.3)
|
||||
continue; // мелкие выборки не учитываем.
|
||||
|
||||
var stats = CalcStats(subset);
|
||||
|
||||
var stats = CalcStatsDrillingQuality(idFeedRegulator, subset, checkQuality);
|
||||
result.Add(stats);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Dictionary<int, List<DataSaubStatDrillingQualityDto>> CreateDataSaubStat(TelemetryDataSaubDto[] dataSaub)
|
||||
private static DataSaubStatDrillingQualityDto CalcStatsDrillingQuality(
|
||||
int idFeedRegulator,
|
||||
Span<TelemetryDataSaubDto> dataSaub,
|
||||
Predicate<TelemetryDataSaubDto> predicate
|
||||
)
|
||||
{
|
||||
|
||||
var dict = new Dictionary<int, List<DataSaubStatDrillingQualityDto>>() {
|
||||
{ 1, new List<DataSaubStatDrillingQualityDto>() },
|
||||
{ 2, new List<DataSaubStatDrillingQualityDto>() },
|
||||
{ 3, new List<DataSaubStatDrillingQualityDto>() },
|
||||
{ 4, new List<DataSaubStatDrillingQualityDto>() },
|
||||
};
|
||||
|
||||
foreach (var item in dict)
|
||||
{
|
||||
var data = CreateDataSaubStat2(item.Key, dataSaub);
|
||||
item.Value.AddRange(data);
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
private static DataSaubStatDrillingQualityDto CalcStats(Span<TelemetryDataSaubDto> dataSaub)
|
||||
{
|
||||
var depthDrillingQuality = CalcAggregate(dataSaub);
|
||||
|
||||
var result = new DataSaubStatDrillingQualityDto();
|
||||
result.IdTelemetry = dataSaub[0].IdTelemetry;
|
||||
result.IdFeedRegulator = idFeedRegulator;
|
||||
result.DepthStart = dataSaub[0].WellDepth;
|
||||
result.DepthEnd = dataSaub[^1].WellDepth;
|
||||
result.DateStart = dataSaub[0].DateTime;
|
||||
result.DateEnd = dataSaub[^1].DateTime;
|
||||
|
||||
var depthDrillingQuality = 0.0;
|
||||
for (var i = 0; i < dataSaub.Length - 1; i++)
|
||||
{
|
||||
if (predicate(dataSaub[i]))
|
||||
{
|
||||
depthDrillingQuality += dataSaub[i + 1].WellDepth - dataSaub[i].WellDepth;
|
||||
}
|
||||
}
|
||||
result.DepthDrillingQuality = depthDrillingQuality;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static DataSaubStatDto CalcStat(DetectedOperationDto operation, Span<TelemetryDataSaubDto> span)
|
||||
{
|
||||
var aggregatedValues = CalcAggregate(span);
|
||||
var dateStart = span[0].DateTime;
|
||||
var dateEnd = span[^1].DateTime;
|
||||
var depthStart = span[0].WellDepth;
|
||||
var depthEnd = span[^1].WellDepth;
|
||||
var speed = ((depthEnd - depthStart) / (dateEnd - dateStart).TotalHours);
|
||||
|
||||
var processMapDrillingCacheItem = new DataSaubStatDto
|
||||
{
|
||||
DateStart = dateStart,
|
||||
DateEnd = dateEnd,
|
||||
DepthStart = depthStart,
|
||||
DepthEnd = depthEnd,
|
||||
Speed = speed,
|
||||
BlockSpeedSp = span[0].BlockSpeedSp,
|
||||
Pressure = aggregatedValues.Pressure,
|
||||
PressureIdle = span[0].PressureIdle,
|
||||
PressureSp = span[0].PressureSp,
|
||||
AxialLoad = aggregatedValues.AxialLoad,
|
||||
AxialLoadSp = span[0].AxialLoadSp,
|
||||
AxialLoadLimitMax = span[0].AxialLoadLimitMax,
|
||||
RotorTorque = aggregatedValues.RotorTorque,
|
||||
RotorTorqueSp = span[0].RotorTorqueSp,
|
||||
RotorTorqueLimitMax = span[0].RotorTorqueLimitMax,
|
||||
IdFeedRegulator = span[0].IdFeedRegulator,
|
||||
RotorSpeed = aggregatedValues.RotorSpeed,
|
||||
IdCategory = operation.IdCategory,
|
||||
EnabledSubsystems = operation.EnabledSubsystems,
|
||||
HasOscillation = operation.EnabledSubsystems.IsAutoOscillation,
|
||||
IdTelemetry = operation.IdTelemetry,
|
||||
Flow = aggregatedValues.Flow
|
||||
};
|
||||
return processMapDrillingCacheItem;
|
||||
}
|
||||
|
||||
private static (
|
||||
double Pressure,
|
||||
double AxialLoad,
|
||||
double RotorTorque,
|
||||
double RotorSpeed,
|
||||
double Flow
|
||||
) CalcAggregate(Span<TelemetryDataSaubDto> span)
|
||||
{
|
||||
var sumPressure = 0.0;
|
||||
var sumAxialLoad = 0.0;
|
||||
var sumRotorTorque = 0.0;
|
||||
var sumRotorSpeed = 0.0;
|
||||
var flow = span[0].Flow ?? 0.0;
|
||||
var diffDepthTotal = span[^1].WellDepth - span[0].WellDepth;
|
||||
for (var i = 0; i < span.Length - 1; i++)
|
||||
{
|
||||
var diffDepth = span[i + 1].WellDepth - span[i].WellDepth;
|
||||
sumPressure += diffDepth * span[i].Pressure;
|
||||
sumAxialLoad += diffDepth * span[i].AxialLoad;
|
||||
sumRotorTorque += diffDepth * span[i].RotorTorque;
|
||||
sumRotorSpeed += diffDepth * span[i].RotorSpeed;
|
||||
flow = span[i + 1].Flow > flow ? span[i + 1].Flow ?? 0.0 : flow;
|
||||
}
|
||||
return (
|
||||
Pressure: sumPressure / diffDepthTotal,
|
||||
AxialLoad: sumAxialLoad / diffDepthTotal,
|
||||
RotorTorque: sumRotorTorque / diffDepthTotal,
|
||||
RotorSpeed: sumRotorSpeed / diffDepthTotal,
|
||||
Flow: flow
|
||||
);
|
||||
}
|
||||
|
||||
private static bool IsNewCacheItem(TelemetryDataSaubDto previous, TelemetryDataSaubDto current)
|
||||
{
|
||||
return !(current.Mode == previous.Mode)
|
||||
|| !(current.WellDepth >= previous.WellDepth)
|
||||
|| !(current.BlockSpeedSp == previous.BlockSpeedSp)
|
||||
|| !(current.PressureIdle == previous.PressureIdle)
|
||||
|| !(current.PressureSp == previous.PressureSp)
|
||||
|| !(current.AxialLoadSp == previous.AxialLoadSp)
|
||||
|| !(current.AxialLoadLimitMax == previous.AxialLoadLimitMax)
|
||||
|| !(current.HookWeightIdle == previous.HookWeightIdle)
|
||||
|| !(current.RotorTorqueIdle == previous.RotorTorqueIdle)
|
||||
|| !(current.RotorTorqueSp == previous.RotorTorqueSp)
|
||||
|| !(current.RotorTorqueLimitMax == previous.RotorTorqueLimitMax)
|
||||
|| !(current.IdFeedRegulator == previous.IdFeedRegulator);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data.DataSaubStat;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.DetectedOperation;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Repositories;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.DataSaubStat;
|
||||
using AsbCloudApp.Data.ProcessMaps;
|
||||
using AsbCloudApp.Data.ProcessMaps.Operations;
|
||||
using AsbCloudApp.Data.ProcessMaps.Report;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data.DataSaubStat;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
|
Loading…
Reference in New Issue
Block a user