This commit is contained in:
ngfrolov 2024-07-26 16:56:36 +05:00
parent b6b1220561
commit fad3688640
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
12 changed files with 786 additions and 792 deletions

View File

@ -6,8 +6,8 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsbCloudApp.Data.WellOperation; using AsbCloudApp.Data.WellOperation;
namespace AsbCloudApp.Services namespace AsbCloudApp.Services;
{
/// <summary> /// <summary>
/// Сервис автоматически определенных по телеметрии операций /// Сервис автоматически определенных по телеметрии операций
/// </summary> /// </summary>
@ -88,4 +88,3 @@ namespace AsbCloudApp.Services
DetectedOperationDto? lastDetectedOperation, DetectedOperationDto? lastDetectedOperation,
CancellationToken token); CancellationToken token);
} }
}

View File

@ -4,10 +4,9 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsbCloudApp.Data;
namespace AsbCloudApp.Services namespace AsbCloudApp.Services;
{
/// <summary> /// <summary>
/// Телеметрия САУБ /// Телеметрия САУБ
/// </summary> /// </summary>
@ -37,7 +36,7 @@ namespace AsbCloudApp.Services
Task<IEnumerable<TelemetryDataSaubStatDto>> GetTelemetryDataStatAsync(int idTelemetry, CancellationToken token); Task<IEnumerable<TelemetryDataSaubStatDto>> GetTelemetryDataStatAsync(int idTelemetry, CancellationToken token);
/// <summary> /// <summary>
/// Получить упакованый csv файл /// Получить упакованный csv файл
/// </summary> /// </summary>
/// <param name="idWell"></param> /// <param name="idWell"></param>
/// <param name="beginDate"></param> /// <param name="beginDate"></param>
@ -46,4 +45,3 @@ namespace AsbCloudApp.Services
/// <returns></returns> /// <returns></returns>
Task<Stream> GetZippedCsv(int idWell, DateTime beginDate, DateTime endDate, CancellationToken token); Task<Stream> GetZippedCsv(int idWell, DateTime beginDate, DateTime endDate, CancellationToken token);
} }
}

View File

@ -1,6 +1,5 @@
using AsbCloudDb.Model; using AsbCloudDb.Model;
using ClosedXML.Excel; using ClosedXML.Excel;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;

View File

@ -110,7 +110,7 @@ public class DetectedOperationService : IDetectedOperationService
private async Task<int> GetIdTelemetryByWell(int idWell, CancellationToken token) private async Task<int> GetIdTelemetryByWell(int idWell, CancellationToken token)
{ {
var well = await wellService.GetOrDefaultAsync(idWell, token) ?? var well = await wellService.GetOrDefaultAsync(idWell, token) ??
throw new ArgumentInvalidException(nameof(idWell), "Well doesn`t exist"); throw new ArgumentInvalidException(nameof(idWell), "Well doesn't exist");
var idTelemetry = well.IdTelemetry ?? var idTelemetry = well.IdTelemetry ??
throw new ArgumentInvalidException(nameof(idWell), "У скважины отсутствует телеметрия"); throw new ArgumentInvalidException(nameof(idWell), "У скважины отсутствует телеметрия");
@ -193,12 +193,12 @@ public class DetectedOperationService : IDetectedOperationService
if (count == 0) if (count == 0)
throw new InvalidOperationException("InvalidOperation_EmptyTelemetries"); throw new InvalidOperationException("InvalidOperation_EmptyTelemetries");
var timezone = telemetryService.GetTimezone(idTelemetry); var timeZone = telemetryService.GetTimezone(idTelemetry);
if (telemetries.Count() <= gap) if (telemetries.Count() <= gap)
{ {
var lastTelemetry = telemetries.Last(); var lastTelemetry = telemetries.Last();
var lastDateTelemetry = new DateTimeOffset(lastTelemetry.DateTime, timezone.Offset); var lastDateTelemetry = new DateTimeOffset(lastTelemetry.DateTime, timeZone.Offset);
return (lastDateTelemetry, Enumerable.Empty<DetectedOperationDto>()); return (lastDateTelemetry, Enumerable.Empty<DetectedOperationDto>());
} }
@ -208,7 +208,7 @@ public class DetectedOperationService : IDetectedOperationService
.Where(t => t.BlockPosition >= 0) .Where(t => t.BlockPosition >= 0)
.Select(t => new DetectableTelemetry .Select(t => new DetectableTelemetry
{ {
DateTime = new DateTimeOffset(t.DateTime, timezone.Offset), DateTime = new DateTimeOffset(t.DateTime, timeZone.Offset),
IdUser = t.IdUser, IdUser = t.IdUser,
Mode = t.Mode, Mode = t.Mode,
WellDepth = t.WellDepth, WellDepth = t.WellDepth,
@ -270,8 +270,10 @@ public class DetectedOperationService : IDetectedOperationService
EqualParameter(telemetryBegin.RotorSpeed, telemetryEnd.RotorSpeed, 0.01f) && EqualParameter(telemetryBegin.RotorSpeed, telemetryEnd.RotorSpeed, 0.01f) &&
EqualParameter(telemetryBegin.AxialLoad, telemetryEnd.AxialLoad, 0.1f); EqualParameter(telemetryBegin.AxialLoad, telemetryEnd.AxialLoad, 0.1f);
bool EqualParameter(float value, float origin, float tolerance) => static bool EqualParameter(float value, float origin, float tolerance)
value <= origin + tolerance && value >= origin - tolerance; {
return value <= origin + tolerance && value >= origin - tolerance;
}
} }
private static IEnumerable<DetectedOperationDrillersStatDto> GetOperationsDrillersStat(IEnumerable<DetectedOperationWithDrillerDto> operations) private static IEnumerable<DetectedOperationDrillersStatDto> GetOperationsDrillersStat(IEnumerable<DetectedOperationWithDrillerDto> operations)
@ -323,7 +325,6 @@ public class DetectedOperationService : IDetectedOperationService
}; };
} }
private static DetectedOperationWithDrillerDto Convert(DetectedOperationDto operation, IEnumerable<OperationValueDto> operationValues, IEnumerable<ScheduleDto> schedules) private static DetectedOperationWithDrillerDto Convert(DetectedOperationDto operation, IEnumerable<OperationValueDto> operationValues, IEnumerable<ScheduleDto> schedules)
{ {
var dto = operation.Adapt<DetectedOperationWithDrillerDto>(); var dto = operation.Adapt<DetectedOperationWithDrillerDto>();

View File

@ -2,8 +2,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using AsbCloudApp.Data.DetectedOperation; using AsbCloudApp.Data.DetectedOperation;
namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors;
{
public abstract class DetectorAbstract public abstract class DetectorAbstract
{ {
protected const int IdReasonOfEnd_NotDetected = 0; protected const int IdReasonOfEnd_NotDetected = 0;
@ -30,11 +30,11 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
protected const int IdReasonOfEnd_Drilling = 600; protected const int IdReasonOfEnd_Drilling = 600;
protected const int IdReasonOfEnd_ChangeBithDepthAndAxiloadLessHookWeight = 700; protected const int IdReasonOfEnd_ChangeBitDepthAndAxiLoadLessHookWeight = 700;
protected const int IdReasonOfEnd_DeltaWellDepthAndBithDepthIsLo = 800; protected const int IdReasonOfEnd_DeltaWellDepthAndBitDepthIsLo = 800;
protected const int IdReasonOfEnd_BithDepthIsLo = 900; protected const int IdReasonOfEnd_BitDepthIsLo = 900;
public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end, DetectedOperationDto? previousOperation, public bool TryDetect(int idTelemetry, DetectableTelemetry[] telemetry, int begin, int end, DetectedOperationDto? previousOperation,
out OperationDetectorResult? result) out OperationDetectorResult? result)
@ -409,5 +409,3 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
return false; return false;
} }
} }
}

View File

@ -41,9 +41,9 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
if (currentPoint.RotorSpeed <=8) if (currentPoint.RotorSpeed <=8)
return IdReasonOfEnd_RotorSpeedIsHi; return IdReasonOfEnd_RotorSpeedIsHi;
if ((currentPoint.WellDepth - currentPoint.BitDepth) < 0.03d) if ((currentPoint.WellDepth - currentPoint.BitDepth) < 0.03d)
return IdReasonOfEnd_DeltaWellDepthAndBithDepthIsLo; return IdReasonOfEnd_DeltaWellDepthAndBitDepthIsLo;
if (currentPoint.BitDepth < 150) if (currentPoint.BitDepth < 150)
return IdReasonOfEnd_BithDepthIsLo; return IdReasonOfEnd_BitDepthIsLo;
return IdReasonOfEnd_NotDetected; return IdReasonOfEnd_NotDetected;
} }

View File

@ -48,11 +48,11 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
if (currentPoint.Pressure < 10) if (currentPoint.Pressure < 10)
return IdReasonOfEnd_PressureIsLo; return IdReasonOfEnd_PressureIsLo;
if ((currentPoint.WellDepth - currentPoint.BitDepth) < 0.01d) if ((currentPoint.WellDepth - currentPoint.BitDepth) < 0.01d)
return IdReasonOfEnd_DeltaWellDepthAndBithDepthIsLo; return IdReasonOfEnd_DeltaWellDepthAndBitDepthIsLo;
if (currentPoint.RotorSpeed > 8) if (currentPoint.RotorSpeed > 8)
return IdReasonOfEnd_RotorSpeedIsHi; return IdReasonOfEnd_RotorSpeedIsHi;
if (currentPoint.BitDepth < 150) if (currentPoint.BitDepth < 150)
return IdReasonOfEnd_BithDepthIsLo; return IdReasonOfEnd_BitDepthIsLo;
return IdReasonOfEnd_NotDetected; return IdReasonOfEnd_NotDetected;
} }

View File

@ -50,7 +50,7 @@ public class DetectorSlipsTime : DetectorAbstract
var deltaBitDepth = Math.Abs(currentPoint.BitDepth - prevPoint.BitDepth); var deltaBitDepth = Math.Abs(currentPoint.BitDepth - prevPoint.BitDepth);
if (deltaBitDepth > 0.001d && currentPoint.AxialLoad < currentPoint.HookWeight) if (deltaBitDepth > 0.001d && currentPoint.AxialLoad < currentPoint.HookWeight)
return IdReasonOfEnd_ChangeBithDepthAndAxiloadLessHookWeight; return IdReasonOfEnd_ChangeBitDepthAndAxiLoadLessHookWeight;
return IdReasonOfEnd_NotDetected; return IdReasonOfEnd_NotDetected;
} }

View File

@ -61,8 +61,8 @@ public class WorkOperationDetection : Work
if (lastDetectedOperations.TryGetValue(idTelemetry, out var lastDetectedOperation)) if (lastDetectedOperations.TryGetValue(idTelemetry, out var lastDetectedOperation))
dateBegin = lastDetectedOperation.DateEnd; dateBegin = lastDetectedOperation.DateEnd;
if (CacheOfStartDatesByTelemetryId.TryGetValue(idTelemetry, out var dateBeginFromCahce)) if (CacheOfStartDatesByTelemetryId.TryGetValue(idTelemetry, out var dateBeginFromCache))
dateBegin = dateBeginFromCahce; dateBegin = dateBeginFromCache;
onProgressCallback.Invoke($"Start detecting telemetry: {idTelemetry} from {dateBegin}", i / idsTelemetry.Length); onProgressCallback.Invoke($"Start detecting telemetry: {idTelemetry} from {dateBegin}", i / idsTelemetry.Length);

View File

@ -13,8 +13,8 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.SAUB namespace AsbCloudInfrastructure.Services.SAUB;
{
public abstract class TelemetryDataBaseService<TDto, TEntity> : ITelemetryDataService<TDto> public abstract class TelemetryDataBaseService<TDto, TEntity> : ITelemetryDataService<TDto>
where TDto : AsbCloudApp.Data.ITelemetryData where TDto : AsbCloudApp.Data.ITelemetryData
where TEntity : class, AsbCloudDb.Model.ITelemetryData where TEntity : class, AsbCloudDb.Model.ITelemetryData
@ -55,13 +55,13 @@ namespace AsbCloudInfrastructure.Services.SAUB
} }
var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid); var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid);
var timezone = telemetryService.GetTimezone(telemetry.Id); var timeZone = telemetryService.GetTimezone(telemetry.Id);
telemetryDataCache.AddRange(telemetry.Id, dtos); telemetryDataCache.AddRange(telemetry.Id, dtos);
var entities = dtosList.Select(dto => var entities = dtosList.Select(dto =>
{ {
var entity = Convert(dto, timezone.Hours); var entity = Convert(dto, timeZone.Hours);
entity.IdTelemetry = telemetry.Id; entity.IdTelemetry = telemetry.Id;
return entity; return entity;
}); });
@ -158,7 +158,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
public async Task<IEnumerable<TDto>> GetByTelemetryAsync(int idTelemetry, TelemetryDataRequest request, CancellationToken token) public async Task<IEnumerable<TDto>> GetByTelemetryAsync(int idTelemetry, TelemetryDataRequest request, CancellationToken token)
{ {
var timezone = telemetryService.GetTimezone(idTelemetry); var timeZone = telemetryService.GetTimezone(idTelemetry);
var cache = telemetryDataCache.GetOrDefault(idTelemetry, request); var cache = telemetryDataCache.GetOrDefault(idTelemetry, request);
@ -171,7 +171,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
.AsNoTracking() .AsNoTracking()
.ToArrayAsync(token); .ToArrayAsync(token);
var dtos = entities.Select(e => Convert(e, timezone.Hours)); var dtos = entities.Select(e => Convert(e, timeZone.Hours));
return dtos; return dtos;
} }
@ -297,9 +297,9 @@ namespace AsbCloudInfrastructure.Services.SAUB
return telemetryDataCache.GetOrDefaultWellDataDateRange(telemetry.Id); return telemetryDataCache.GetOrDefaultWellDataDateRange(telemetry.Id);
} }
protected abstract TDto Convert(TEntity src, double timezoneOffset); protected abstract TDto Convert(TEntity src, double timeZoneOffset);
protected abstract TEntity Convert(TDto src, double timezoneOffset); protected abstract TEntity Convert(TDto src, double timeZoneOffset);
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token) public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
{ {
@ -308,4 +308,3 @@ namespace AsbCloudInfrastructure.Services.SAUB
return await db.SaveChangesAsync(token); return await db.SaveChangesAsync(token);
} }
} }
}