forked from ddrilling/AsbCloudServer
Merge branch 'dev' of https://bitbucket.org/autodrilling/asbcloudserver into dev
This commit is contained in:
commit
8362aa6ffa
@ -1,12 +0,0 @@
|
||||
using AsbCloudApp.Data;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface ISaubDataCache
|
||||
{
|
||||
TelemetryAnalysisDto CurrentAnalysis { get; set; }
|
||||
IEnumerable<TelemetryDataSaubDto> GetOrCreateCache(int telemetryId);
|
||||
void AddData(TelemetryDataSaubDto data);
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ namespace AsbCloudApp.Services
|
||||
Task<IEnumerable<TelemetryOperationInfoDto>> GetOperationsToIntervalAsync(int idWell,
|
||||
int intervalHoursTimestamp, int workBeginTimestamp,
|
||||
CancellationToken token = default);
|
||||
void SaveAnalytics();
|
||||
void CalculateAnalytics();
|
||||
Task<DatesRangeDto> GetOperationsDateRangeAsync(int idWell,
|
||||
CancellationToken token = default);
|
||||
}
|
||||
|
@ -66,10 +66,10 @@ namespace AsbCloudDb.Model
|
||||
public bool IsBlockPositionDecreasing { get; set; }
|
||||
|
||||
[Column("is_rotor_speed_lt_3"), Comment("Обороты ротора ниже 3")]
|
||||
public bool IsRotorSpeedLt3 { get; set; }
|
||||
public bool IsRotorSpeedLt5 { get; set; }
|
||||
|
||||
[Column("is_rotor_speed_gt_3"), Comment("Обороты ротора выше 3")]
|
||||
public bool IsRotorSpeedGt3 { get; set; }
|
||||
public bool IsRotorSpeedGt5 { get; set; }
|
||||
|
||||
[Column("is_pressure_lt_20"), Comment("Давление менее 20")]
|
||||
public bool IsPressureLt20 { get; set; }
|
||||
|
@ -13,6 +13,8 @@ namespace AsbCloudDevOperations
|
||||
{
|
||||
private readonly HttpClient client = new();
|
||||
|
||||
//Пример роута: "api/telemetryDataSaub/123123_";
|
||||
|
||||
public void TestControllerRoute(string route, CancellationToken token = default)
|
||||
{
|
||||
var host = "http://localhost:5000";
|
||||
|
@ -191,8 +191,8 @@ namespace AsbCloudDevOperations
|
||||
IsBitPositionLt20 = true,
|
||||
IsBlockPositionIncreasing = false,
|
||||
IsBlockPositionDecreasing = false,
|
||||
IsRotorSpeedLt3 = true,
|
||||
IsRotorSpeedGt3 = false,
|
||||
IsRotorSpeedLt5 = true,
|
||||
IsRotorSpeedGt5 = false,
|
||||
IsPressureLt20 = true,
|
||||
IsPressureGt20 = false,
|
||||
IsHookWeightNotChanges = true,
|
||||
@ -214,8 +214,8 @@ namespace AsbCloudDevOperations
|
||||
IsBitPositionLt20 = true,
|
||||
IsBlockPositionIncreasing = true,
|
||||
IsBlockPositionDecreasing = false,
|
||||
IsRotorSpeedLt3 = true,
|
||||
IsRotorSpeedGt3 = false,
|
||||
IsRotorSpeedLt5 = true,
|
||||
IsRotorSpeedGt5 = false,
|
||||
IsPressureLt20 = true,
|
||||
IsPressureGt20 = false,
|
||||
IsHookWeightNotChanges = true,
|
||||
@ -237,8 +237,8 @@ namespace AsbCloudDevOperations
|
||||
IsBitPositionLt20 = true,
|
||||
IsBlockPositionIncreasing = false,
|
||||
IsBlockPositionDecreasing = true,
|
||||
IsRotorSpeedLt3 = true,
|
||||
IsRotorSpeedGt3 = false,
|
||||
IsRotorSpeedLt5 = true,
|
||||
IsRotorSpeedGt5 = false,
|
||||
IsPressureLt20 = true,
|
||||
IsPressureGt20 = false,
|
||||
IsHookWeightNotChanges = true,
|
||||
@ -260,8 +260,8 @@ namespace AsbCloudDevOperations
|
||||
IsBitPositionLt20 = true,
|
||||
IsBlockPositionIncreasing = false,
|
||||
IsBlockPositionDecreasing = false,
|
||||
IsRotorSpeedLt3 = true,
|
||||
IsRotorSpeedGt3 = false,
|
||||
IsRotorSpeedLt5 = true,
|
||||
IsRotorSpeedGt5 = false,
|
||||
IsPressureLt20 = true,
|
||||
IsPressureGt20 = false,
|
||||
IsHookWeightNotChanges = true,
|
||||
@ -283,8 +283,8 @@ namespace AsbCloudDevOperations
|
||||
IsBitPositionLt20 = true,
|
||||
IsBlockPositionIncreasing = true,
|
||||
IsBlockPositionDecreasing = false,
|
||||
IsRotorSpeedLt3 = true,
|
||||
IsRotorSpeedGt3 = false,
|
||||
IsRotorSpeedLt5 = true,
|
||||
IsRotorSpeedGt5 = false,
|
||||
IsPressureLt20 = true,
|
||||
IsPressureGt20 = false,
|
||||
IsHookWeightNotChanges = true,
|
||||
|
@ -24,7 +24,6 @@ namespace AsbCloudInfrastructure
|
||||
services.AddSingleton(new CacheDb());
|
||||
services.AddSingleton<ITelemetryTracker, TelemetryTracker>();
|
||||
services.AddSingleton<IReportsBackgroundQueue, ReportsBackgroundQueue>();
|
||||
services.AddSingleton<ISaubDataCache, SaubDataCache>();
|
||||
|
||||
services.AddTransient<IAuthService, AuthService>();
|
||||
services.AddTransient<IWellService, WellService>();
|
||||
|
@ -1,62 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class InterpolationLine
|
||||
{
|
||||
private readonly decimal xSum;
|
||||
private readonly decimal ySum;
|
||||
private readonly decimal xySum;
|
||||
private readonly decimal x2Sum;
|
||||
private readonly IEnumerable<(double value, double timestamp)> rawData = new List<(double value, double timestamp)>();
|
||||
private readonly double xSum;
|
||||
private readonly double ySum;
|
||||
private readonly double xySum;
|
||||
private readonly double x2Sum;
|
||||
private readonly int count;
|
||||
|
||||
public InterpolationLine(IEnumerable<(double value, double timestamp)> rawData)
|
||||
public InterpolationLine(IEnumerable<(double Y, double X)> rawData)
|
||||
{
|
||||
var data = rawData.Select((d) => new
|
||||
{
|
||||
X = d.timestamp,
|
||||
Y = d.value
|
||||
});
|
||||
xSum = (decimal)data.Sum(d => d.X);
|
||||
ySum = (decimal)data.Sum(d => d.Y);
|
||||
xySum = (decimal)data.Sum(d => d.X * d.Y);
|
||||
x2Sum = (decimal)data.Sum(d => d.X * d.X);
|
||||
|
||||
this.rawData = rawData;
|
||||
}
|
||||
public double GetAForLinearFormula()
|
||||
{
|
||||
var result = (xSum * ySum - rawData.Count() * xySum) /
|
||||
(xSum * xSum - rawData.Count() * x2Sum);
|
||||
|
||||
return (double)result;
|
||||
xSum = rawData.Sum(d => d.X);
|
||||
ySum = rawData.Sum(d => d.Y);
|
||||
xySum = rawData.Sum(d => d.X * d.Y);
|
||||
x2Sum = rawData.Sum(d => d.X * d.X);
|
||||
count = rawData.Count();
|
||||
}
|
||||
|
||||
public double GetBForLinearFormula()
|
||||
{
|
||||
var result = (xSum * xySum - x2Sum * ySum) /
|
||||
(xSum * xSum - rawData.Count() * x2Sum);
|
||||
public double A =>
|
||||
(xSum * ySum - count * xySum) /
|
||||
(xSum * xSum - count * x2Sum);
|
||||
|
||||
return (double)result;
|
||||
}
|
||||
public double B =>
|
||||
(xSum * xySum - x2Sum * ySum) /
|
||||
(xSum * xSum - count * x2Sum);
|
||||
|
||||
public static bool IsValueNotChanges(double value,
|
||||
(double upperBound, double lowerBound) bounds) =>
|
||||
value < bounds.upperBound && value > bounds.lowerBound;
|
||||
|
||||
public static bool IsValueIncreases(double value, double bound) =>
|
||||
value > bound;
|
||||
public bool IsYNotChanges(double upperBound = 0d, double lowerBound = 0d) =>
|
||||
A < upperBound && A > lowerBound;
|
||||
|
||||
public static bool IsValueDecreases(double value, double bound) =>
|
||||
value < bound;
|
||||
public bool IsYIncreases(double bound = 0d) =>
|
||||
A > bound;
|
||||
|
||||
public static bool IsAverageLessThanBound(IEnumerable<(double Value, double TotalSeconds)> values,
|
||||
double bound) =>
|
||||
(values.Sum(s => s.Value) / values.Count()) < bound;
|
||||
public bool IsYDecreases(double bound = 0d) =>
|
||||
A < bound;
|
||||
|
||||
public static bool IsAverageMoreThanBound(IEnumerable<(double Value, double TotalSeconds)> values,
|
||||
double bound) =>
|
||||
(values.Sum(s => s.Value) / values.Count()) >= bound;
|
||||
public bool IsAverageYLessThanBound(double bound) =>
|
||||
(ySum / count) < bound;
|
||||
|
||||
public bool IsAverageYMoreThanBound(double bound) =>
|
||||
(ySum / count) >= bound;
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class SaubDataCache : ISaubDataCache
|
||||
{
|
||||
public TelemetryAnalysisDto CurrentAnalysis { get; set; }
|
||||
|
||||
private readonly Dictionary<int, List<TelemetryDataSaubDto>> saubData =
|
||||
new Dictionary<int, List<TelemetryDataSaubDto>>();
|
||||
|
||||
public IEnumerable<TelemetryDataSaubDto> GetOrCreateCache(int telemetryId)
|
||||
{
|
||||
if (!saubData.ContainsKey(telemetryId))
|
||||
saubData[telemetryId] = new List<TelemetryDataSaubDto>();
|
||||
|
||||
return saubData[telemetryId];
|
||||
}
|
||||
|
||||
public void AddData(TelemetryDataSaubDto data)
|
||||
{
|
||||
GetOrCreateCache(data.IdTelemetry);
|
||||
|
||||
saubData[data.IdTelemetry].Add(data);
|
||||
|
||||
if (saubData[data.IdTelemetry].Count > 10)
|
||||
saubData[data.IdTelemetry].RemoveAt(1);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,27 +12,15 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class TelemetryAnalyticsBackgroundService : BackgroundService
|
||||
{
|
||||
private static readonly DbContextOptions<AsbCloudDbContext> options =
|
||||
new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||
.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||
.Options;
|
||||
private readonly AsbCloudDbContext context = new AsbCloudDbContext(options);
|
||||
|
||||
private readonly CacheDb cacheDb;
|
||||
private readonly ISaubDataCache saubDataCache;
|
||||
|
||||
public TelemetryAnalyticsBackgroundService(ISaubDataCache saubDataCache, CacheDb cacheDb)
|
||||
public TelemetryAnalyticsBackgroundService(CacheDb cacheDb)
|
||||
{
|
||||
this.saubDataCache = saubDataCache;
|
||||
this.cacheDb = cacheDb;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken token = default)
|
||||
{
|
||||
var telemetryService = new TelemetryService(context, cacheDb);
|
||||
var analyticsService = new TelemetryAnalyticsService(context,
|
||||
telemetryService, saubDataCache, cacheDb);
|
||||
|
||||
var timeToStartAnalysis = DateTime.Now;
|
||||
|
||||
while (!token.IsCancellationRequested)
|
||||
@ -41,9 +29,18 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||
.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||
.Options;
|
||||
using var context = new AsbCloudDbContext(options);
|
||||
|
||||
var telemetryService = new TelemetryService(context, cacheDb);
|
||||
var analyticsService = new TelemetryAnalyticsService(context,
|
||||
telemetryService, cacheDb);
|
||||
|
||||
timeToStartAnalysis = DateTime.Now.AddHours(1);
|
||||
|
||||
await Task.Run(() => analyticsService.SaveAnalytics(), token)
|
||||
await Task.Run(() => analyticsService.CalculateAnalytics(), token)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -2,7 +2,6 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -16,17 +15,17 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly ISaubDataCache saubDataCache;
|
||||
private readonly CacheTable<WellOperationCategory> cacheOperations;
|
||||
private readonly TelemetryOperationDetectorService operationDetectorService;
|
||||
private readonly IEnumerable<WellOperationCategory> operations;
|
||||
|
||||
private const int intervalHours = 12;
|
||||
|
||||
public TelemetryAnalyticsService(IAsbCloudDbContext db, ITelemetryService telemetryService,
|
||||
ISaubDataCache saubDataCache, CacheDb cacheDb)
|
||||
CacheDb cacheDb)
|
||||
{
|
||||
this.db = db;
|
||||
this.telemetryService = telemetryService;
|
||||
this.saubDataCache = saubDataCache;
|
||||
cacheOperations = cacheDb.GetCachedTable<WellOperationCategory>((AsbCloudDbContext)db);
|
||||
operations = cacheOperations.Where();
|
||||
operationDetectorService = new TelemetryOperationDetectorService(operations);
|
||||
@ -231,7 +230,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
return groupedOperationsList;
|
||||
}
|
||||
|
||||
public void SaveAnalytics()
|
||||
public void CalculateAnalytics()
|
||||
{
|
||||
var allTelemetryIds = (from telemetry in db.TelemetryDataSaub
|
||||
select telemetry.IdTelemetry)
|
||||
@ -242,47 +241,58 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
var analyzeStartDate = GetAnalyzeStartDate(idTelemetry);
|
||||
|
||||
if(analyzeStartDate != default)
|
||||
if (analyzeStartDate == default)
|
||||
continue;
|
||||
|
||||
TelemetryAnalysis currentAnalysis = null;
|
||||
|
||||
while (TryGetDataSaubPart(idTelemetry, analyzeStartDate,
|
||||
out var dataSaubPart))
|
||||
{
|
||||
while (GetDataSaubsToAnalyze(idTelemetry, analyzeStartDate).Any())
|
||||
analyzeStartDate = dataSaubPart.Last().Date;
|
||||
|
||||
var count = dataSaubPart.Count();
|
||||
var skip = 0;
|
||||
var step = 10;
|
||||
var take = step * 2;
|
||||
|
||||
for(;skip < count; skip += step)
|
||||
{
|
||||
var dataSaubsToAnalyze = GetDataSaubsToAnalyze(idTelemetry, analyzeStartDate);
|
||||
var analyzingSaubs = dataSaubPart.Skip(skip).Take(take);
|
||||
|
||||
analyzeStartDate = dataSaubsToAnalyze.Last().Date;
|
||||
|
||||
foreach (var dataSaub in dataSaubsToAnalyze)
|
||||
if (analyzingSaubs.Count() <= 1)
|
||||
{
|
||||
var dataSaubDto = dataSaub.Adapt<TelemetryDataSaubDto>();
|
||||
|
||||
saubDataCache.AddData(dataSaubDto);
|
||||
|
||||
if (saubDataCache.GetOrCreateCache(dataSaubDto.IdTelemetry).Count() > 1)
|
||||
{
|
||||
var dataSaubs = saubDataCache.GetOrCreateCache(dataSaubDto.IdTelemetry)
|
||||
.OrderBy(d => d.Date);
|
||||
|
||||
var telemetryAnalysisDto = GetDrillingAnalysis(dataSaubs);
|
||||
|
||||
if (saubDataCache.CurrentAnalysis is null)
|
||||
saubDataCache.CurrentAnalysis = telemetryAnalysisDto;
|
||||
|
||||
if (saubDataCache.CurrentAnalysis.IdOperation == telemetryAnalysisDto.IdOperation)
|
||||
{
|
||||
saubDataCache.CurrentAnalysis.DurationSec +=
|
||||
telemetryAnalysisDto.DurationSec;
|
||||
saubDataCache.CurrentAnalysis.OperationEndDepth = dataSaubDto.WellDepth;
|
||||
}
|
||||
else
|
||||
{
|
||||
db.TelemetryAnalysis.Add(saubDataCache.CurrentAnalysis.Adapt<TelemetryAnalysis>());
|
||||
saubDataCache.CurrentAnalysis = telemetryAnalysisDto;
|
||||
saubDataCache.CurrentAnalysis.OperationStartDepth = dataSaubDto.WellDepth;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
db.SaveChanges();
|
||||
var dataSaub = analyzingSaubs.First();
|
||||
|
||||
var telemetryAnalysis = new TelemetryAnalysis();
|
||||
|
||||
telemetryAnalysis = GetDrillingAnalysis(analyzingSaubs);
|
||||
|
||||
if (currentAnalysis is null)
|
||||
{
|
||||
currentAnalysis = telemetryAnalysis;
|
||||
currentAnalysis.OperationStartDepth = dataSaub.WellDepth;
|
||||
}
|
||||
|
||||
if (currentAnalysis.IdOperation == telemetryAnalysis.IdOperation)
|
||||
{
|
||||
currentAnalysis.DurationSec += telemetryAnalysis.DurationSec;
|
||||
currentAnalysis.OperationEndDepth = dataSaub.WellDepth;
|
||||
}
|
||||
else
|
||||
{
|
||||
db.TelemetryAnalysis.Add(currentAnalysis);
|
||||
currentAnalysis = telemetryAnalysis;
|
||||
currentAnalysis.OperationStartDepth = dataSaub.WellDepth;
|
||||
}
|
||||
}
|
||||
|
||||
db.SaveChanges();
|
||||
|
||||
GC.Collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -332,24 +342,36 @@ namespace AsbCloudInfrastructure.Services
|
||||
? DateTimeOffset.MinValue
|
||||
: DateTimeOffset.FromUnixTimeSeconds(lastAnalysisUnixDate);
|
||||
|
||||
var firstDataSaub = (from ds in db.TelemetryDataSaub
|
||||
where ds.IdTelemetry == idTelemetry &&
|
||||
ds.Date >= analyzeStartDate
|
||||
select ds).FirstOrDefault();
|
||||
var firstDataSaub = GetFirstSaub(analyzeStartDate.DateTime, idTelemetry);
|
||||
|
||||
var firstSaubUtcTime = firstDataSaub?.Date.ToUniversalTime() ?? default;
|
||||
|
||||
return firstSaubUtcTime;
|
||||
}
|
||||
|
||||
private IEnumerable<TelemetryDataSaub> GetDataSaubsToAnalyze(int idTelemetry,
|
||||
DateTime analyzeStartDate)
|
||||
private bool TryGetDataSaubPart(int idTelemetry, DateTime analyzeStartDate,
|
||||
out IEnumerable<TelemetryDataSaub> dataSaubPart)
|
||||
{
|
||||
var query = (from ds in db.TelemetryDataSaub
|
||||
where ds.IdTelemetry == idTelemetry
|
||||
&& ds.Date > analyzeStartDate
|
||||
orderby ds.Date
|
||||
select ds)
|
||||
.Take(12 * 60* 60)
|
||||
.AsNoTracking();
|
||||
|
||||
dataSaubPart = query.ToList();
|
||||
|
||||
return dataSaubPart.Any();
|
||||
}
|
||||
|
||||
private TelemetryDataSaub GetFirstSaub(DateTime analyzeStartDate, int idTelemetry)
|
||||
{
|
||||
return (from ds in db.TelemetryDataSaub
|
||||
where ds.IdTelemetry == idTelemetry
|
||||
&& ds.Date > analyzeStartDate
|
||||
&& ds.Date < analyzeStartDate.AddHours(12)
|
||||
select ds).ToList();
|
||||
&& ds.Date > analyzeStartDate.AddHours(intervalHours)
|
||||
orderby ds.Date
|
||||
select ds).FirstOrDefault();
|
||||
}
|
||||
|
||||
private static IEnumerable<(long IntervalStart, string OperationName, int OperationDuration)> DivideOperationsByIntervalLength(
|
||||
@ -449,64 +471,66 @@ namespace AsbCloudInfrastructure.Services
|
||||
return groupedOperationsList;
|
||||
}
|
||||
|
||||
private TelemetryAnalysisDto GetDrillingAnalysis(IEnumerable<TelemetryDataSaubDto> dataSaubBases)
|
||||
private TelemetryAnalysis GetDrillingAnalysis(IEnumerable<TelemetryDataSaub> dataSaubBases)
|
||||
{
|
||||
var lastSaubDate = dataSaubBases.Last().Date;
|
||||
|
||||
var saubWellDepths = dataSaubBases.Where(sw => sw.WellDepth is not null)
|
||||
.Select(s => (Value: (double)s.WellDepth,
|
||||
(s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
.Select(s => (Y: (double)s.WellDepth,
|
||||
X: (s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
var saubBitDepths = dataSaubBases.Where(sw => sw.BitDepth is not null)
|
||||
.Select(s => (Value: (double)s.BitDepth,
|
||||
(s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
.Select(s => (Y: (double)s.BitDepth,
|
||||
X: (s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
var saubBlockPositions = dataSaubBases.Where(sw => sw.BlockPosition is not null)
|
||||
.Select(s => (Value: (double)s.BlockPosition,
|
||||
(s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
.Select(s => (Y: (double)s.BlockPosition,
|
||||
X: (s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
var saubRotorSpeeds = dataSaubBases.Where(sw => sw.RotorSpeed is not null)
|
||||
.Select(s => (Value: (double)s.RotorSpeed,
|
||||
(s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
.Select(s => (Y: (double)s.RotorSpeed,
|
||||
X: (s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
var saubPressures = dataSaubBases.Where(sw => sw.Pressure is not null)
|
||||
.Select(s => (Value: (double)s.Pressure,
|
||||
(s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
.Select(s => (Y: (double)s.Pressure,
|
||||
X: (s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
var saubHookWeights = dataSaubBases.Where(sw => sw.HookWeight is not null)
|
||||
.Select(s => (Value: (double)s.HookWeight,
|
||||
(s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
.Select(s => (Y: (double)s.HookWeight,
|
||||
X: (s.Date - dataSaubBases.First().Date).TotalSeconds));
|
||||
|
||||
var wellDepthChangingIndex = new InterpolationLine(saubWellDepths).GetAForLinearFormula();
|
||||
var bitPositionChangingIndex = new InterpolationLine(saubBitDepths).GetAForLinearFormula();
|
||||
var blockPositionChangingIndex = new InterpolationLine(saubBlockPositions).GetAForLinearFormula();
|
||||
var rotorSpeedChangingIndex = new InterpolationLine(saubRotorSpeeds).GetAForLinearFormula();
|
||||
var pressureChangingIndex = new InterpolationLine(saubPressures).GetAForLinearFormula();
|
||||
var hookWeightChangingIndex = new InterpolationLine(saubHookWeights).GetAForLinearFormula();
|
||||
var wellDepthLine = new InterpolationLine(saubWellDepths);
|
||||
var bitPositionLine = new InterpolationLine(saubBitDepths);
|
||||
var blockPositionLine = new InterpolationLine(saubBlockPositions);
|
||||
var rotorSpeedLine = new InterpolationLine(saubRotorSpeeds);
|
||||
var pressureLine = new InterpolationLine(saubPressures);
|
||||
var hookWeightLine = new InterpolationLine(saubHookWeights);
|
||||
|
||||
var IsBlockRising = InterpolationLine.IsValueDecreases(blockPositionChangingIndex, -0.0001);
|
||||
var IsBlockGoesDown = InterpolationLine.IsValueIncreases(blockPositionChangingIndex, 0.0001);
|
||||
var IsBlockStandsStill = InterpolationLine.IsValueNotChanges(blockPositionChangingIndex, (0.0001, -0.0001));
|
||||
var IsBlockRising = blockPositionLine.IsYDecreases(-0.0001);
|
||||
var IsBlockGoesDown = blockPositionLine.IsYIncreases(0.0001);
|
||||
var IsBlockStandsStill = blockPositionLine.IsYNotChanges(0.0001, -0.0001);
|
||||
|
||||
var drillingAnalysis = new TelemetryAnalysisDto
|
||||
var drillingAnalysis = new TelemetryAnalysis
|
||||
{
|
||||
IdTelemetry = dataSaubBases.First().IdTelemetry,
|
||||
UnixDate = (long)(lastSaubDate - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds,
|
||||
DurationSec = (int)(dataSaubBases.Last().Date - dataSaubBases.ElementAt(dataSaubBases.Count() - 2).Date).TotalSeconds,
|
||||
DurationSec = (int)(dataSaubBases.Last().Date -
|
||||
dataSaubBases.ElementAt(dataSaubBases.Count() - 2).Date).TotalSeconds,
|
||||
OperationStartDepth = null,
|
||||
OperationEndDepth = null,
|
||||
IsWellDepthDecreasing = InterpolationLine.IsValueDecreases(wellDepthChangingIndex, -0.0001),
|
||||
IsWellDepthIncreasing = InterpolationLine.IsValueIncreases(wellDepthChangingIndex, 0.0001),
|
||||
IsBitPositionDecreasing = InterpolationLine.IsValueDecreases(bitPositionChangingIndex, -0.0001),
|
||||
IsBitPositionIncreasing = InterpolationLine.IsValueIncreases(bitPositionChangingIndex, 0.0001),
|
||||
IsBitPositionLt20 = InterpolationLine.IsAverageLessThanBound(saubBitDepths, 20),
|
||||
IsBlockPositionDecreasing = InterpolationLine.IsValueDecreases(blockPositionChangingIndex, -0.0001),
|
||||
IsBlockPositionIncreasing = InterpolationLine.IsValueIncreases(blockPositionChangingIndex, 0.0001),
|
||||
IsRotorSpeedLt3 = InterpolationLine.IsAverageLessThanBound(saubRotorSpeeds, 3),
|
||||
IsRotorSpeedGt3 = InterpolationLine.IsAverageMoreThanBound(saubRotorSpeeds, 3),
|
||||
IsPressureLt20 = InterpolationLine.IsAverageLessThanBound(saubPressures, 20),
|
||||
IsPressureGt20 = InterpolationLine.IsAverageMoreThanBound(saubPressures, 20),
|
||||
IsHookWeightNotChanges = InterpolationLine.IsValueNotChanges(hookWeightChangingIndex, (0.0001, -0.0001)),
|
||||
IsHookWeightLt3 = InterpolationLine.IsAverageLessThanBound(saubHookWeights, 3),
|
||||
IsWellDepthDecreasing = wellDepthLine.IsYDecreases(-0.0001),
|
||||
IsWellDepthIncreasing = wellDepthLine.IsYIncreases( 0.0001),
|
||||
IsBitPositionDecreasing = bitPositionLine.IsYDecreases(-0.0001),
|
||||
IsBitPositionIncreasing = bitPositionLine.IsYIncreases(0.0001),
|
||||
IsBitPositionLt20 = bitPositionLine.IsAverageYLessThanBound(20),
|
||||
IsBlockPositionDecreasing = blockPositionLine.IsYDecreases(-0.0001),
|
||||
IsBlockPositionIncreasing = blockPositionLine.IsYIncreases(0.0001),
|
||||
IsRotorSpeedLt5 = rotorSpeedLine.IsAverageYLessThanBound(5),
|
||||
IsRotorSpeedGt5 = rotorSpeedLine.IsAverageYMoreThanBound(5),
|
||||
IsPressureLt20 = pressureLine.IsAverageYLessThanBound(20),
|
||||
IsPressureGt20 = pressureLine.IsAverageYMoreThanBound(20),
|
||||
IsHookWeightNotChanges = hookWeightLine.IsYNotChanges(0.0001, -0.0001),
|
||||
IsHookWeightLt3 = hookWeightLine.IsAverageYLessThanBound(3),
|
||||
IdOperation = 1
|
||||
};
|
||||
|
||||
drillingAnalysis.IdOperation = operationDetectorService.DetectOperation(drillingAnalysis).Id;
|
||||
drillingAnalysis.IdOperation =
|
||||
operationDetectorService.DetectOperation(drillingAnalysis).Id;
|
||||
|
||||
return drillingAnalysis;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudDb.Model;
|
||||
using System;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
@ -8,6 +7,6 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public int Order { get; set; }
|
||||
public WellOperationCategory Operation { get; set; }
|
||||
public Func<TelemetryAnalysisDto, bool> Detect { get; set; }
|
||||
public Func<TelemetryAnalysis, bool> Detect { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -16,16 +16,35 @@ namespace AsbCloudInfrastructure.Services
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 1,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("На поверхности")),
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Роторное бурение")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing
|
||||
&& data.IsBitPositionLt20 && data.IsHookWeightLt3;
|
||||
return data.IsWellDepthIncreasing && data.IsBitPositionIncreasing &&
|
||||
data.IsBlockPositionIncreasing && data.IsRotorSpeedGt5;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 2,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Слайдирование")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return data.IsWellDepthIncreasing && data.IsBitPositionIncreasing &&
|
||||
data.IsBlockPositionIncreasing && data.IsRotorSpeedLt5;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 3,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("На поверхности")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return data.IsBitPositionLt20 && data.IsHookWeightLt3;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 4,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Удержание в клиньях")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
@ -37,150 +56,150 @@ namespace AsbCloudInfrastructure.Services
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 3,
|
||||
Order = 5,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с проработкой")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing &&
|
||||
data.IsRotorSpeedGt3 && data.IsPressureGt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 4,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с проработкой")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
data.IsBitPositionIncreasing && data.IsBitPositionIncreasing &&
|
||||
data.IsRotorSpeedGt3 && data.IsPressureGt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 5,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с промывкой")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
data.IsBitPositionDecreasing && data.IsBitPositionDecreasing &&
|
||||
data.IsRotorSpeedLt3 && data.IsPressureGt20;
|
||||
data.IsBitPositionDecreasing && data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedGt5 && data.IsPressureGt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 6,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с промывкой")),
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с проработкой")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedLt3 && data.IsPressureGt20;
|
||||
data.IsBitPositionIncreasing && data.IsBlockPositionDecreasing &&
|
||||
data.IsRotorSpeedGt5 && data.IsPressureGt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 7,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск в скважину")),
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с промывкой")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedLt3 && data.IsPressureLt20;
|
||||
data.IsBitPositionDecreasing && data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedLt5 && data.IsPressureGt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 8,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с вращением")),
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с промывкой")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedGt3 && data.IsPressureLt20;
|
||||
data.IsBitPositionIncreasing && data.IsBlockPositionDecreasing &&
|
||||
data.IsRotorSpeedLt5 && data.IsPressureGt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 9,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем из скважины")),
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск в скважину")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing &&
|
||||
data.IsRotorSpeedLt3 && data.IsPressureLt20;
|
||||
data.IsBitPositionIncreasing && data.IsBlockPositionDecreasing &&
|
||||
data.IsRotorSpeedLt5 && data.IsPressureLt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 10,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с вращением")),
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с вращением")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing &&
|
||||
data.IsRotorSpeedGt3 && data.IsPressureLt20;
|
||||
data.IsBitPositionIncreasing && data.IsBlockPositionDecreasing &&
|
||||
data.IsRotorSpeedGt5 && data.IsPressureLt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 11,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем из скважины")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
data.IsBitPositionDecreasing && data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedLt5 && data.IsPressureLt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 12,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с вращением")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
data.IsBitPositionDecreasing && data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedGt5 && data.IsPressureLt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 13,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Промывка в покое")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
!data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing &&
|
||||
!data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedLt3 && data.IsPressureGt20;
|
||||
data.IsRotorSpeedLt5 && data.IsPressureGt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 12,
|
||||
Order = 14,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Промывка с вращением")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
!data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing &&
|
||||
!data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedGt3 && data.IsPressureGt20;
|
||||
data.IsRotorSpeedGt5 && data.IsPressureGt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 13,
|
||||
Order = 15,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Неподвижное состояние")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
!data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing &&
|
||||
!data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedLt3 && data.IsPressureLt20 && data.IsHookWeightNotChanges;
|
||||
data.IsRotorSpeedLt5 && data.IsPressureLt20 && data.IsHookWeightNotChanges;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 14,
|
||||
Order = 16,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Вращение без циркуляции")),
|
||||
Detect = (data) =>
|
||||
{
|
||||
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
||||
!data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing &&
|
||||
!data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing &&
|
||||
data.IsRotorSpeedGt3 && data.IsPressureLt20;
|
||||
data.IsRotorSpeedGt5 && data.IsPressureLt20;
|
||||
}
|
||||
},
|
||||
new TelemetryOperationDetector
|
||||
{
|
||||
Order = 15,
|
||||
Order = 17,
|
||||
Operation = operations.FirstOrDefault(o => o.Name.Equals("Невозможно определить операцию")),
|
||||
Detect = (data) => true
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public WellOperationCategory DetectOperation(TelemetryAnalysisDto data) =>
|
||||
public WellOperationCategory DetectOperation(TelemetryAnalysis data) =>
|
||||
detectors.OrderBy(d => d.Order).First(o => o.Detect(data)).Operation
|
||||
?? new WellOperationCategory { Id = 1, Name = "Невозможно определить операцию" };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user