2021-08-09 15:41:42 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudDb.Model;
|
2021-07-21 15:29:19 +05:00
|
|
|
|
using System.Collections.Generic;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
2021-07-27 13:32:00 +05:00
|
|
|
|
public class TelemetryOperationDetectorService
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
2021-07-27 13:32:00 +05:00
|
|
|
|
private readonly IEnumerable<TelemetryOperationDetector> detectors;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
|
2021-08-16 14:19:43 +05:00
|
|
|
|
public TelemetryOperationDetectorService(IEnumerable<WellOperationCategory> operations)
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
2021-07-27 13:32:00 +05:00
|
|
|
|
detectors = new List<TelemetryOperationDetector>()
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 1,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("На поверхности")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-21 15:29:19 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing
|
2021-07-21 17:57:59 +05:00
|
|
|
|
&& data.IsBitPositionLt20 && data.IsHookWeightLt3;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 2,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Удержание в клиньях")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
2021-07-21 15:29:19 +05:00
|
|
|
|
!data.IsBitPositionIncreasing && !data.IsBitPositionDecreasing &&
|
|
|
|
|
data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing &&
|
2021-07-19 15:31:50 +05:00
|
|
|
|
data.IsHookWeightLt3;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 3,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с проработкой")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
2021-07-21 15:29:19 +05:00
|
|
|
|
data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing &&
|
2021-07-19 15:31:50 +05:00
|
|
|
|
data.IsRotorSpeedGt3 && data.IsPressureGt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 4,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с проработкой")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
2021-07-21 15:29:19 +05:00
|
|
|
|
data.IsBitPositionIncreasing && data.IsBitPositionIncreasing &&
|
2021-07-19 15:31:50 +05:00
|
|
|
|
data.IsRotorSpeedGt3 && data.IsPressureGt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 5,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с промывкой")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
2021-07-21 15:29:19 +05:00
|
|
|
|
data.IsBitPositionDecreasing && data.IsBitPositionDecreasing &&
|
2021-07-19 15:31:50 +05:00
|
|
|
|
data.IsRotorSpeedLt3 && data.IsPressureGt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 6,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с промывкой")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-21 15:29:19 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
|
|
|
|
data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing &&
|
2021-07-19 15:31:50 +05:00
|
|
|
|
data.IsRotorSpeedLt3 && data.IsPressureGt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 7,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск в скважину")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-21 15:29:19 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
|
|
|
|
data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing &&
|
2021-07-19 15:31:50 +05:00
|
|
|
|
data.IsRotorSpeedLt3 && data.IsPressureLt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 8,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Спуск с вращением")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
|
|
|
|
data.IsBitPositionIncreasing && data.IsBlockPositionIncreasing &&
|
|
|
|
|
data.IsRotorSpeedGt3 && data.IsPressureLt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 9,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем из скважины")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
|
|
|
|
data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing &&
|
|
|
|
|
data.IsRotorSpeedLt3 && data.IsPressureLt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 10,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Подъем с вращением")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
|
|
|
|
data.IsBitPositionDecreasing && data.IsBlockPositionDecreasing &&
|
|
|
|
|
data.IsRotorSpeedGt3 && data.IsPressureLt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 11,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Промывка в покое")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
|
|
|
|
!data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing &&
|
2021-07-21 15:29:19 +05:00
|
|
|
|
!data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing &&
|
2021-07-19 15:31:50 +05:00
|
|
|
|
data.IsRotorSpeedLt3 && data.IsPressureGt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 12,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Промывка с вращением")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
|
|
|
|
!data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing &&
|
|
|
|
|
!data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing &&
|
|
|
|
|
data.IsRotorSpeedGt3 && data.IsPressureGt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 13,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Неподвижное состояние")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
|
|
|
|
!data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing &&
|
|
|
|
|
!data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing &&
|
|
|
|
|
data.IsRotorSpeedLt3 && data.IsPressureLt20 && data.IsHookWeightNotChanges;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 14,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Вращение без циркуляции")),
|
|
|
|
|
Detect = (data) =>
|
|
|
|
|
{
|
2021-07-19 15:31:50 +05:00
|
|
|
|
return !data.IsWellDepthDecreasing && !data.IsWellDepthIncreasing &&
|
|
|
|
|
!data.IsBitPositionDecreasing && !data.IsBitPositionIncreasing &&
|
|
|
|
|
!data.IsBlockPositionDecreasing && !data.IsBlockPositionIncreasing &&
|
|
|
|
|
data.IsRotorSpeedGt3 && data.IsPressureLt20;
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-27 13:32:00 +05:00
|
|
|
|
new TelemetryOperationDetector
|
2021-06-24 13:02:31 +05:00
|
|
|
|
{
|
|
|
|
|
Order = 15,
|
|
|
|
|
Operation = operations.FirstOrDefault(o => o.Name.Equals("Невозможно определить операцию")),
|
|
|
|
|
Detect = (data) => true
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-06-25 15:10:05 +05:00
|
|
|
|
|
2021-08-16 14:19:43 +05:00
|
|
|
|
public WellOperationCategory DetectOperation(TelemetryAnalysisDto data) =>
|
2021-06-25 15:10:05 +05:00
|
|
|
|
detectors.OrderBy(d => d.Order).First(o => o.Detect(data)).Operation
|
2021-08-16 14:19:43 +05:00
|
|
|
|
?? new WellOperationCategory { Id = 1, Name = "Невозможно определить операцию" };
|
2021-06-24 13:02:31 +05:00
|
|
|
|
}
|
|
|
|
|
}
|