Создание сервиса DataSaubStat

This commit is contained in:
Olga Nemt 2024-08-01 09:53:31 +05:00
parent b2a31d92ec
commit 10497dcfbe
5 changed files with 758 additions and 204 deletions

View File

@ -0,0 +1,25 @@
using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Services
{
/// <summary>
/// Сервис записи данных в таблицу DataSaubStat, которая используется для построения РТК-отчета
/// </summary>
public interface IDataSaubStatService
{
/// <summary>
/// Создание записей таблицы DataSaubStat
/// </summary>
/// <param name="gap">Временной интервал, за который будет рассчитываться статистика DataSaubStat</param>
/// <param name="onProgressCallback"></param>
/// <param name="token"></param>
/// <returns></returns>
Task CreateStatAsync(int gap, Action<string, double?> onProgressCallback, CancellationToken token);
}
}

View File

@ -16,11 +16,11 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Background.PeriodicWorks
{
/// <summary>
/// задача по добавлению данных в таблицу DataSaubStat, которая используется дл построения РТК-отчета
/// задача по добавлению данных в таблицу DataSaubStat, которая используется для построения РТК-отчета
/// </summary>
internal class WorkDataSaubStat : Work
{
private int Gap = 60;
private int Gap = 1000;
public WorkDataSaubStat() : base("Generate DataSaubStat entries and save them into Db")
{
@ -29,209 +29,11 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
protected override async Task Action(string id, IServiceProvider services, Action<string, double?> onProgressCallback, CancellationToken token)
{
var dataSaubStatService = services.GetService<IDataSaubStatService>();
var telemetryDataCache = services.GetRequiredService<ITelemetryDataCache<TelemetryDataSaubDto>>();
if (dataSaubStatService != null )
await dataSaubStatService.CreateStatAsync(Gap, onProgressCallback, token);
var cacheRequest = new TelemetryDataRequest()
{
GeDate = DateTime.UtcNow.AddDays(-Gap)
};
var idTelemetries = telemetryDataCache.GetIds(cacheRequest).ToArray();
if (!idTelemetries.Any())
return;
var dataSaubStatRepo = services.GetRequiredService<IDataSaubStatRepository>();
var dataSaubService = services.GetRequiredService<ITelemetryDataSaubService>();
var detectedOperationRepository = services.GetRequiredService<IDetectedOperationRepository>();
var stats = await dataSaubStatRepo.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, dataSaubService, dataSaubStatRepo, detectedOperationRepository, token);
onProgressCallback($"Calculate stat for telemetry: {idTelemetry}; from {lastDate}; results count: {statsCount};", 100*i / idTelemetries.Length);
}
}
private static async Task<int> CreateStatForTelemetryFromDate(
int idTelemetry,
DateTimeOffset begin,
ITelemetryDataSaubService dataSaubService,
IDataSaubStatRepository dataSaubStatRepo,
IDetectedOperationRepository detectedOperationRepository,
CancellationToken token)
{
var detectedOperationRequest = new DetectedOperationByTelemetryRequest {
GeDateStart = begin,
IdTelemetry = idTelemetry,
IdsCategories = WellOperationCategory.MechanicalDrillingSubIds,
SortFields = new[] {nameof(DetectedOperation.DateStart) },
Take = 250,
};
var detectedOperations = await detectedOperationRepository.Get(detectedOperationRequest, token);
if (!detectedOperations.Any())
return 0;
var geDate = detectedOperations.First().DateStart;
var leDate = detectedOperations.OrderByDescending(d => d.DateEnd).First().DateEnd;
var dataSaub = await dataSaubService.Get(idTelemetry, true, geDate, leDate, 100_000, token);
if (!dataSaub.Any())
return 0;
if(dataSaub is not TelemetryDataSaubDto[] dataSaubArray)
dataSaubArray = dataSaub.ToArray();
var dataSaubStats = CreateDataSaubStat(detectedOperations, dataSaubArray);
return await dataSaubStatRepo.InsertRangeAsync(dataSaubStats, token);
}
private static IEnumerable<DataSaubStatDto> CreateDataSaubStat(IEnumerable<DetectedOperationDto> detectedOperations, TelemetryDataSaubDto[] dataSaub)
{
var indexStart = 0;
var indexEnd = 0;
var result = new List<DataSaubStatDto>();
if (!dataSaub.Any())
return result;
foreach (var operation in detectedOperations)
{
indexStart = Array.FindIndex(dataSaub, indexEnd, t => t.DateTime >= operation.DateStart);
if (indexStart < 0)
break;
indexEnd = Array.FindIndex(dataSaub, indexStart, t => t.DateTime > operation.DateEnd);
if (indexEnd < 0)
indexEnd = dataSaub.Length - 1;
if (indexEnd == indexStart)
continue;
var length = indexEnd - indexStart;
var subset = dataSaub.AsSpan(indexStart, length);
var stats = CalcStats(operation, subset);
result.AddRange(stats);
}
return result;
}
private static IEnumerable<DataSaubStatDto> CalcStats(DetectedOperationDto operation, Span<TelemetryDataSaubDto> dataSaub)
{
var result = new List<DataSaubStatDto>();
var indexStart = 0;
for (var i = 1; i < dataSaub.Length; i++)
{
var previous = dataSaub[i - 1];
var current = dataSaub[i];
if (IsNewCacheItem(previous, current) || i == dataSaub.Length - 1)
{
var length = i - indexStart;
var span = dataSaub.Slice(indexStart, length);
indexStart = i;
if (length <= 2 || (span[^1].WellDepth - span[0].WellDepth) < 0.001)
continue; // мелкие выборки не учитываем.
var stat = CalcStat(operation, span);
result.Add(stat);
}
}
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

@ -316,6 +316,7 @@ namespace AsbCloudInfrastructure
services.AddTransient<IHelpPageService, HelpPageService>();
services.AddTransient<IScheduleReportService, ScheduleReportService>();
services.AddTransient<IDataSaubStatRepository, DataSaubStatRepository>();
services.AddTransient<IDataSaubStatService, DataSaubStatService>();
services.AddTransient<
IChangeLogRepository<ProcessMapPlanRotorDto, ProcessMapPlanBaseRequestWithWell>,

View File

@ -0,0 +1,237 @@
using AsbCloudApp.Data;
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;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
public class DataSaubStatService : IDataSaubStatService
{
private IDataSaubStatRepository dataSaubStatRepository;
private ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
private ITelemetryDataSaubService dataSaubService;
private IDetectedOperationRepository detectedOperationRepository;
public DataSaubStatService(
IDataSaubStatRepository dataSaubStatRepository,
ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache,
ITelemetryDataSaubService dataSaubService,
IDetectedOperationRepository detectedOperationRepository)
{
this.dataSaubStatRepository = dataSaubStatRepository;
this.telemetryDataCache = telemetryDataCache;
this.dataSaubService = dataSaubService;
this.detectedOperationRepository = detectedOperationRepository;
}
public async Task CreateStatAsync(int gap, Action<string, double?> onProgressCallback, CancellationToken token)
{
var cacheRequest = new TelemetryDataRequest()
{
GeDate = DateTime.UtcNow.AddDays(-gap)
};
var idTelemetries = telemetryDataCache.GetIds(cacheRequest).ToArray();
if (!idTelemetries.Any())
return;
var stats = 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)
onProgressCallback($"Calculate stat for telemetry: {idTelemetry}; from {lastDate}; results count: {statsCount};", 100 * i / idTelemetries.Length);
}
}
private async Task<int> CreateStatForTelemetryFromDate(
int idTelemetry,
DateTimeOffset begin,
CancellationToken token)
{
var detectedOperationRequest = new DetectedOperationByTelemetryRequest
{
GeDateStart = begin,
IdTelemetry = idTelemetry,
IdsCategories = WellOperationCategory.MechanicalDrillingSubIds,
SortFields = new[] { nameof(DetectedOperation.DateStart) },
Take = 250,
};
var detectedOperations = await detectedOperationRepository.Get(detectedOperationRequest, token);
if (!detectedOperations.Any())
return 0;
var geDate = detectedOperations.First().DateStart;
var leDate = detectedOperations.OrderByDescending(d => d.DateEnd).First().DateEnd;
var dataSaub = await dataSaubService.Get(idTelemetry, true, geDate, leDate, 100_000, token);
if (!dataSaub.Any())
return 0;
if (dataSaub is not TelemetryDataSaubDto[] dataSaubArray)
dataSaubArray = dataSaub.ToArray();
var dataSaubStats = CreateDataSaubStat(detectedOperations, dataSaubArray);
return await dataSaubStatRepository.InsertRangeAsync(dataSaubStats, token);
}
private static IEnumerable<DataSaubStatDto> CreateDataSaubStat(IEnumerable<DetectedOperationDto> detectedOperations, TelemetryDataSaubDto[] dataSaub)
{
var indexStart = 0;
var indexEnd = 0;
var result = new List<DataSaubStatDto>();
if (!dataSaub.Any())
return result;
foreach (var operation in detectedOperations)
{
indexStart = Array.FindIndex(dataSaub, indexEnd, t => t.DateTime >= operation.DateStart);
if (indexStart < 0)
break;
indexEnd = Array.FindIndex(dataSaub, indexStart, t => t.DateTime > operation.DateEnd);
if (indexEnd < 0)
indexEnd = dataSaub.Length - 1;
if (indexEnd == indexStart)
continue;
var length = indexEnd - indexStart;
var subset = dataSaub.AsSpan(indexStart, length);
var stats = CalcStats(operation, subset);
result.AddRange(stats);
}
return result;
}
private static IEnumerable<DataSaubStatDto> CalcStats(DetectedOperationDto operation, Span<TelemetryDataSaubDto> dataSaub)
{
var result = new List<DataSaubStatDto>();
var indexStart = 0;
for (var i = 1; i < dataSaub.Length; i++)
{
var previous = dataSaub[i - 1];
var current = dataSaub[i];
if (IsNewCacheItem(previous, current) || i == dataSaub.Length - 1)
{
var length = i - indexStart;
var span = dataSaub.Slice(indexStart, length);
indexStart = i;
if (length <= 2 || (span[^1].WellDepth - span[0].WellDepth) < 0.001)
continue; // мелкие выборки не учитываем.
var stat = CalcStat(operation, span);
result.Add(stat);
}
}
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

@ -0,0 +1,489 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data.DetectedOperation;
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Data.User;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Repository;
using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.SAUB;
using NSubstitute;
using Xunit;
namespace AsbCloudWebApi.Tests.Services;
public class DataSaubStatServiceTest
{
private readonly IDataSaubStatRepository dataSaubStatRepositoryMock = Substitute.For<IDataSaubStatRepository>();
private readonly ITelemetryDataCache<TelemetryDataSaubDto> telemetryDataCacheMock = Substitute.For<ITelemetryDataCache<TelemetryDataSaubDto>>();
private readonly IDetectedOperationRepository detectedOperationRepositoryMock = Substitute.For<IDetectedOperationRepository>();
private readonly ITelemetryDataSaubService dataSaubServiceMock = Substitute.For<ITelemetryDataSaubService>();
private DataSaubStatService dataSaubStatService;
private int[] idTelemetries = [1, 2, 3];
private IEnumerable<DataSaubStatDto> dataSaubStatDtos = new List<DataSaubStatDto>()
{
new DataSaubStatDto {
Id = 1,
AxialLoad = 1,
AxialLoadLimitMax = 1,
AxialLoadSp = 1,
BlockSpeedSp = 1,
DateEnd = DateTime.UtcNow,
DateStart = DateTime.UtcNow.AddHours(-1),
DepthEnd = 2,
DepthStart = 1,
EnabledSubsystems = 1,
Flow = 1,
HasOscillation = true,
IdCategory = 1,
IdFeedRegulator = 1,
IdTelemetry = 1,
Pressure = 1,
PressureIdle = 1,
PressureSp = 1,
RotorSpeed = 1,
RotorTorque = 1,
RotorTorqueLimitMax = 1,
RotorTorqueSp = 1,
Speed = 1
},
new DataSaubStatDto {
Id = 2,
AxialLoad = 2,
AxialLoadLimitMax = 2,
AxialLoadSp = 2,
BlockSpeedSp = 2,
DateEnd = DateTime.UtcNow,
DateStart = DateTime.UtcNow.AddHours(-1),
DepthEnd = 3,
DepthStart = 2,
EnabledSubsystems = 2,
Flow = 2,
HasOscillation = true,
IdCategory = 2,
IdFeedRegulator = 2,
IdTelemetry = 2,
Pressure = 2,
PressureIdle = 2,
PressureSp = 2,
RotorSpeed = 2,
RotorTorque = 2,
RotorTorqueLimitMax = 2,
RotorTorqueSp = 2,
Speed = 2
},
new DataSaubStatDto {
Id = 3,
AxialLoad = 3,
AxialLoadLimitMax = 3,
AxialLoadSp = 3,
BlockSpeedSp = 3,
DateEnd = DateTime.UtcNow,
DateStart = DateTime.UtcNow.AddHours(-1),
DepthEnd = 4,
DepthStart = 3,
EnabledSubsystems = 3,
Flow = 3,
HasOscillation = true,
IdCategory = 3,
IdFeedRegulator = 3,
IdTelemetry = 3,
Pressure = 3,
PressureIdle = 3,
PressureSp = 3,
RotorSpeed = 3,
RotorTorque = 3,
RotorTorqueLimitMax = 3,
RotorTorqueSp = 3,
Speed = 3
},
};
private IEnumerable<DetectedOperationDto> detectedOperationDtos = new List<DetectedOperationDto>() {
new DetectedOperationDto {
Id = 1,
DateEnd = DateTimeOffset.UtcNow,
DateStart = DateTimeOffset.UtcNow.AddHours(-1),
DepthStart = 1,
DepthEnd = 2,
IdCategory = 5002,
IdTelemetry = 1,
Value = 1,
IdEditor = 1,
IdUserAtStart = 1
}
};
private IEnumerable<TelemetryDataSaubDto> telemetryDataSaubDtos1 = new List<TelemetryDataSaubDto> {
new TelemetryDataSaubDto()
{
IdTelemetry = 1,
DateTime = DateTime.UtcNow.AddMinutes(-30),
AxialLoad = 1,
AxialLoadLimitMax = 1,
AxialLoadSp = 1,
BitDepth = 1,
BlockPosition = 1,
BlockPositionMax = 1,
BlockPositionMin = 1,
BlockSpeed = 1,
BlockSpeedSp = 1,
BlockSpeedSpDevelop = 1,
BlockSpeedSpRotor = 1,
BlockSpeedSpSlide = 1,
Flow = 1,
FlowDeltaLimitMax = 1,
FlowIdle = 1,
HookWeight = 1,
HookWeightIdle = 1,
HookWeightLimitMax = 1,
HookWeightLimitMin = 1,
IdFeedRegulator = 1,
IdUser = 1,
Mode = 1,
Mse = 1,
MseState = 1,
Pressure = 1,
PressureDeltaLimitMax = 1,
PressureIdle = 1,
PressureSp = 1,
PressureSpDevelop = 1,
PressureSpRotor = 1,
PressureSpSlide = 1,
Pump0Flow = 1,
Pump1Flow = 1,
Pump2Flow = 1,
RotorSpeed = 1,
RotorTorque = 1,
RotorTorqueIdle = 1,
RotorTorqueSp = 1,
RotorTorqueLimitMax = 1,
WellDepth = 1,
},
new TelemetryDataSaubDto()
{
IdTelemetry = 1,
DateTime = DateTime.UtcNow.AddMinutes(-20),
AxialLoad = 1,
AxialLoadLimitMax = 1,
AxialLoadSp = 1,
BitDepth = 1,
BlockPosition = 1,
BlockPositionMax = 1,
BlockPositionMin = 1,
BlockSpeed = 1,
BlockSpeedSp = 1,
BlockSpeedSpDevelop = 1,
BlockSpeedSpRotor = 1,
BlockSpeedSpSlide = 1,
Flow = 1,
FlowDeltaLimitMax = 1,
FlowIdle = 1,
HookWeight = 1,
HookWeightIdle = 1,
HookWeightLimitMax = 1,
HookWeightLimitMin = 1,
IdFeedRegulator = 1,
IdUser = 1,
Mode = 1,
Mse = 1,
MseState = 1,
Pressure = 1,
PressureDeltaLimitMax = 1,
PressureIdle = 1,
PressureSp = 1,
PressureSpDevelop = 1,
PressureSpRotor = 1,
PressureSpSlide = 1,
Pump0Flow = 1,
Pump1Flow = 1,
Pump2Flow = 1,
RotorSpeed = 1,
RotorTorque = 1,
RotorTorqueIdle = 1,
RotorTorqueSp = 1,
RotorTorqueLimitMax = 1,
WellDepth = 1,
},
new TelemetryDataSaubDto()
{
IdTelemetry = 1,
DateTime = DateTime.UtcNow.AddMinutes(-10),
AxialLoad = 1,
AxialLoadLimitMax = 1,
AxialLoadSp = 1,
BitDepth = 1,
BlockPosition = 1,
BlockPositionMax = 1,
BlockPositionMin = 1,
BlockSpeed = 1,
BlockSpeedSp = 1,
BlockSpeedSpDevelop = 1,
BlockSpeedSpRotor = 1,
BlockSpeedSpSlide = 1,
Flow = 1,
FlowDeltaLimitMax = 1,
FlowIdle = 1,
HookWeight = 1,
HookWeightIdle = 1,
HookWeightLimitMax = 1,
HookWeightLimitMin = 1,
IdFeedRegulator = 1,
IdUser = 1,
Mode = 1,
Mse = 1,
MseState = 1,
Pressure = 1,
PressureDeltaLimitMax = 1,
PressureIdle = 1,
PressureSp = 1,
PressureSpDevelop = 1,
PressureSpRotor = 1,
PressureSpSlide = 1,
Pump0Flow = 1,
Pump1Flow = 1,
Pump2Flow = 1,
RotorSpeed = 1,
RotorTorque = 1,
RotorTorqueIdle = 1,
RotorTorqueSp = 1,
RotorTorqueLimitMax = 1,
WellDepth = 2,
},
new TelemetryDataSaubDto()
{
IdTelemetry = 1,
DateTime = DateTime.UtcNow.AddMinutes(-5),
AxialLoad = 1,
AxialLoadLimitMax = 1,
AxialLoadSp = 1,
BitDepth = 1,
BlockPosition = 1,
BlockPositionMax = 1,
BlockPositionMin = 1,
BlockSpeed = 1,
BlockSpeedSp = 1,
BlockSpeedSpDevelop = 1,
BlockSpeedSpRotor = 1,
BlockSpeedSpSlide = 1,
Flow = 1,
FlowDeltaLimitMax = 1,
FlowIdle = 1,
HookWeight = 1,
HookWeightIdle = 1,
HookWeightLimitMax = 1,
HookWeightLimitMin = 1,
IdFeedRegulator = 1,
IdUser = 1,
Mode = 1,
Mse = 1,
MseState = 1,
Pressure = 1,
PressureDeltaLimitMax = 1,
PressureIdle = 1,
PressureSp = 1,
PressureSpDevelop = 1,
PressureSpRotor = 1,
PressureSpSlide = 1,
Pump0Flow = 1,
Pump1Flow = 1,
Pump2Flow = 1,
RotorSpeed = 1,
RotorTorque = 1,
RotorTorqueIdle = 1,
RotorTorqueSp = 1,
RotorTorqueLimitMax = 1,
WellDepth = 3,
},
new TelemetryDataSaubDto()
{
IdTelemetry = 1,
DateTime = DateTime.UtcNow.AddMinutes(5),
AxialLoad = 1,
AxialLoadLimitMax = 1,
AxialLoadSp = 1,
BitDepth = 1,
BlockPosition = 1,
BlockPositionMax = 1,
BlockPositionMin = 1,
BlockSpeed = 1,
BlockSpeedSp = 1,
BlockSpeedSpDevelop = 1,
BlockSpeedSpRotor = 1,
BlockSpeedSpSlide = 1,
Flow = 1,
FlowDeltaLimitMax = 1,
FlowIdle = 1,
HookWeight = 1,
HookWeightIdle = 1,
HookWeightLimitMax = 1,
HookWeightLimitMin = 1,
IdFeedRegulator = 1,
IdUser = 1,
Mode = 1,
Mse = 1,
MseState = 1,
Pressure = 1,
PressureDeltaLimitMax = 1,
PressureIdle = 1,
PressureSp = 1,
PressureSpDevelop = 1,
PressureSpRotor = 1,
PressureSpSlide = 1,
Pump0Flow = 1,
Pump1Flow = 1,
Pump2Flow = 1,
RotorSpeed = 1,
RotorTorque = 1,
RotorTorqueIdle = 1,
RotorTorqueSp = 1,
RotorTorqueLimitMax = 1,
WellDepth = 1,
}
};
private IEnumerable<TelemetryDataSaubDto> telemetryDataSaubDtos2 = new List<TelemetryDataSaubDto> {
new TelemetryDataSaubDto()
{
IdTelemetry = 2,
DateTime = DateTime.Now.AddMinutes(-20),
AxialLoad = 1,
AxialLoadLimitMax = 1,
AxialLoadSp = 1,
BitDepth = 1,
BlockPosition = 1,
BlockPositionMax = 1,
BlockPositionMin = 1,
BlockSpeed = 1,
BlockSpeedSp = 1,
BlockSpeedSpDevelop = 1,
BlockSpeedSpRotor = 1,
BlockSpeedSpSlide = 1,
Flow = 1,
FlowDeltaLimitMax = 1,
FlowIdle = 1,
HookWeight = 1,
HookWeightIdle = 1,
HookWeightLimitMax = 1,
HookWeightLimitMin = 1,
IdFeedRegulator = 1,
IdUser = 1,
Mode = 1,
Mse = 1,
MseState = 1,
Pressure = 1,
PressureDeltaLimitMax = 1,
PressureIdle = 1,
PressureSp = 1,
PressureSpDevelop = 1,
PressureSpRotor = 1,
PressureSpSlide = 1,
Pump0Flow = 1,
Pump1Flow = 1,
Pump2Flow = 1,
RotorSpeed = 1,
RotorTorque = 1,
RotorTorqueIdle = 1,
RotorTorqueSp = 1,
RotorTorqueLimitMax = 1,
WellDepth = 1,
},
new TelemetryDataSaubDto()
{
IdTelemetry = 2,
DateTime = DateTime.Now.AddMinutes(-20),
AxialLoad = 1,
AxialLoadLimitMax = 1,
AxialLoadSp = 1,
BitDepth = 1,
BlockPosition = 1,
BlockPositionMax = 1,
BlockPositionMin = 1,
BlockSpeed = 1,
BlockSpeedSp = 1,
BlockSpeedSpDevelop = 1,
BlockSpeedSpRotor = 1,
BlockSpeedSpSlide = 1,
Flow = 1,
FlowDeltaLimitMax = 1,
FlowIdle = 1,
HookWeight = 1,
HookWeightIdle = 1,
HookWeightLimitMax = 1,
HookWeightLimitMin = 1,
IdFeedRegulator = 1,
IdUser = 1,
Mode = 1,
Mse = 1,
MseState = 1,
Pressure = 1,
PressureDeltaLimitMax = 1,
PressureIdle = 1,
PressureSp = 1,
PressureSpDevelop = 1,
PressureSpRotor = 1,
PressureSpSlide = 1,
Pump0Flow = 1,
Pump1Flow = 1,
Pump2Flow = 1,
RotorSpeed = 1,
RotorTorque = 1,
RotorTorqueIdle = 1,
RotorTorqueSp = 1,
RotorTorqueLimitMax = 1,
WellDepth = 1,
}
};
public DataSaubStatServiceTest()
{
telemetryDataCacheMock
.GetIds(Arg.Any<TelemetryDataRequest>())
.Returns(idTelemetries);
dataSaubStatRepositoryMock
.GetLastsAsync(Arg.Any<int[]>(), Arg.Any<CancellationToken>())
.Returns(dataSaubStatDtos);
detectedOperationRepositoryMock
.Get(Arg.Any<DetectedOperationByTelemetryRequest>(), Arg.Any<CancellationToken>())
.Returns(detectedOperationDtos);
dataSaubServiceMock
.Get(1, Arg.Any<bool>(), Arg.Any<DateTimeOffset>(), Arg.Any<DateTimeOffset>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(telemetryDataSaubDtos1);
dataSaubStatRepositoryMock
.InsertRangeAsync(Arg.Any<IEnumerable<DataSaubStatDto>>(), Arg.Any<CancellationToken>())
.Returns(2);
dataSaubStatService = new DataSaubStatService(
dataSaubStatRepositoryMock,
telemetryDataCacheMock,
dataSaubServiceMock,
detectedOperationRepositoryMock);
}
[Fact]
public async Task GetByMarkId_ShouldReturn_FileInfo()
{
//act
//var data = await fileService.GetByMarkId(idMark, CancellationToken.None);
Action<string, double?> action = async (a, b) => {
;
};
await dataSaubStatService.CreateStatAsync(5, action, CancellationToken.None);
//assert
Assert.NotNull("sd");
}
}