Добавление в базу таблицу статистики по "Качеству"

This commit is contained in:
Olga Nemt 2024-10-04 15:22:43 +05:00
parent 97cca9cb5a
commit af43828d57
15 changed files with 259 additions and 309 deletions

View File

@ -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; }
}

View File

@ -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!;
}

View File

@ -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);
}

View File

@ -1,4 +1,4 @@
using AsbCloudApp.Data.DataSaubStat; using AsbCloudApp.Data;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@ -110,6 +110,7 @@ namespace AsbCloudDb.Model
public DbSet<DrillTest> DrillTests => Set<DrillTest>(); public DbSet<DrillTest> DrillTests => Set<DrillTest>();
public DbSet<DataSaubStat> DataSaubStat => Set<DataSaubStat>(); public DbSet<DataSaubStat> DataSaubStat => Set<DataSaubStat>();
public DbSet<DataSaubStatDrillingQuality> DataSaubStatDrillingQuality => Set<DataSaubStatDrillingQuality>();
public AsbCloudDbContext() : base() public AsbCloudDbContext() : base()
{ {
Interlocked.Increment(ref referenceCount); Interlocked.Increment(ref referenceCount);

View File

@ -81,6 +81,7 @@ namespace AsbCloudDb.Model
DbSet<TrajectoryFact> TrajectoriesFact { get; } DbSet<TrajectoryFact> TrajectoriesFact { get; }
DbSet<WellSectionPlan> WellSectionsPlan { get; } DbSet<WellSectionPlan> WellSectionsPlan { get; }
DbSet<DataSaubStat> DataSaubStat { get; } DbSet<DataSaubStat> DataSaubStat { get; }
DbSet<DataSaubStatDrillingQuality> DataSaubStatDrillingQuality { get; }
DatabaseFacade Database { get; } DatabaseFacade Database { get; }
DbSet<ProcessMapPlanRotor> ProcessMapPlanRotor { get; } DbSet<ProcessMapPlanRotor> ProcessMapPlanRotor { get; }
DbSet<ProcessMapPlanSlide> ProcessMapPlanSlide { get; } DbSet<ProcessMapPlanSlide> ProcessMapPlanSlide { get; }

View 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!;
}
}

View File

@ -1,4 +1,4 @@
using AsbCloudApp.Data.DataSaubStat; using AsbCloudApp.Data;
using AsbCloudApp.Data.DetectedOperation; using AsbCloudApp.Data.DetectedOperation;
using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;

View File

@ -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);
}
}

View File

@ -1,4 +1,4 @@
using AsbCloudApp.Data.DataSaubStat; using AsbCloudApp.Data;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;

View File

@ -1,11 +1,8 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.DataSaubStat;
using AsbCloudApp.Data.DetectedOperation;
using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -17,21 +14,43 @@ namespace AsbCloudInfrastructure.Services;
public class DataSaubStatDrillingQualityService : IDataSaubStatService public class DataSaubStatDrillingQualityService : IDataSaubStatService
{ {
private IDataSaubStatRepository dataSaubStatRepository; private IDataSaubStatDrillingQualityRepository dataSaubStatDrillingQualityRepository;
private ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache; private ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
private ITelemetryDataSaubService dataSaubService; private ITelemetryDataSaubService dataSaubService;
private IDetectedOperationRepository detectedOperationRepository;
public Dictionary<int, Predicate<TelemetryDataSaubDto>> QualitySettingsForFeedRegulators { get; }
public DataSaubStatDrillingQualityService( public DataSaubStatDrillingQualityService(
IDataSaubStatRepository dataSaubStatRepository, IDataSaubStatDrillingQualityRepository dataSaubStatDrillingQualityRepository,
ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache, ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache,
ITelemetryDataSaubService dataSaubService, ITelemetryDataSaubService dataSaubService)
IDetectedOperationRepository detectedOperationRepository)
{ {
this.dataSaubStatRepository = dataSaubStatRepository; this.dataSaubStatDrillingQualityRepository = dataSaubStatDrillingQualityRepository;
this.telemetryDataCache = telemetryDataCache; this.telemetryDataCache = telemetryDataCache;
this.dataSaubService = dataSaubService; 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) public async Task CreateStatAsync(int lastDaysFilter, Action<string, double?> onProgressCallback, CancellationToken token)
@ -47,19 +66,19 @@ public class DataSaubStatDrillingQualityService : IDataSaubStatService
return; return;
var stats = new List<DataSaubStatDto>(); var stats = new List<DataSaubStatDto>();
//await dataSaubStatRepository.GetLastsAsync(idTelemetries, token); //await dataSaubStatRepository.GetLastsAsync(idTelemetries, token);
//for (var i = 0; i < idTelemetries.Length; i++) //for (var i = 0; i < idTelemetries.Length; i++)
//{ //{
// var idTelemetry = idTelemetries[i]; // var idTelemetry = idTelemetries[i];
// var lastDate = stats.FirstOrDefault(s => s.IdTelemetry == idTelemetry)?.DateEnd.ToUniversalTime() ?? DateTimeOffset.UnixEpoch; // var lastDate = stats.FirstOrDefault(s => s.IdTelemetry == idTelemetry)?.DateEnd.ToUniversalTime() ?? DateTimeOffset.UnixEpoch;
// var statsCount = await CreateStatForTelemetryFromDate(idTelemetry, lastDate, token); // var statsCount = await CreateStatDrillingQualityForTelemetry(idTelemetry, lastDate, token);
// if(onProgressCallback != null) // if (onProgressCallback != null)
// onProgressCallback($"Calculate stat for telemetry: {idTelemetry}; from {lastDate}; results count: {statsCount};", 1d * i / idTelemetries.Length); // 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, int idTelemetry,
DateTimeOffset geDate, DateTimeOffset geDate,
CancellationToken token) CancellationToken token)
@ -74,14 +93,20 @@ public class DataSaubStatDrillingQualityService : IDataSaubStatService
if (dataSaub is not TelemetryDataSaubDto[] dataSaubArray) if (dataSaub is not TelemetryDataSaubDto[] dataSaubArray)
dataSaubArray = dataSaub.ToArray(); 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 dataSaubStatDrillingQualityRepository.InsertRangeAsync(result, token);
//return await dataSaubStatRepository.InsertRangeAsync(dataSaubStats, 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>(); var result = new List<DataSaubStatDrillingQualityDto>();
@ -100,140 +125,47 @@ public class DataSaubStatDrillingQualityService : IDataSaubStatService
indexEnd = dataSaub.Length - 1; indexEnd = dataSaub.Length - 1;
if (indexEnd == indexStart) if (indexEnd == indexStart)
{
continue; continue;
}
var length = indexEnd - indexStart + 1; var length = indexEnd - indexStart + 1;
var subset = dataSaub.AsSpan(indexStart, length); 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; // мелкие выборки не учитываем. continue; // мелкие выборки не учитываем.
var stats = CalcStats(subset);
var stats = CalcStatsDrillingQuality(idFeedRegulator, subset, checkQuality);
result.Add(stats); result.Add(stats);
} }
return result; 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(); var result = new DataSaubStatDrillingQualityDto();
result.IdTelemetry = dataSaub[0].IdTelemetry;
result.IdFeedRegulator = idFeedRegulator;
result.DepthStart = dataSaub[0].WellDepth; result.DepthStart = dataSaub[0].WellDepth;
result.DepthEnd = dataSaub[^1].WellDepth; result.DepthEnd = dataSaub[^1].WellDepth;
result.DateStart = dataSaub[0].DateTime; result.DateStart = dataSaub[0].DateTime;
result.DateEnd = dataSaub[^1].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; result.DepthDrillingQuality = depthDrillingQuality;
return result; 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);
}
} }

View File

@ -1,4 +1,4 @@
using AsbCloudApp.Data.DataSaubStat; using AsbCloudApp.Data;
using AsbCloudApp.Data.DetectedOperation; using AsbCloudApp.Data.DetectedOperation;
using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;

View File

@ -1,5 +1,4 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.DataSaubStat;
using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Data.ProcessMaps.Operations; using AsbCloudApp.Data.ProcessMaps.Operations;
using AsbCloudApp.Data.ProcessMaps.Report; using AsbCloudApp.Data.ProcessMaps.Report;

View File

@ -1,4 +1,4 @@
using AsbCloudApp.Data.DataSaubStat; using AsbCloudApp.Data;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using Mapster; using Mapster;