forked from ddrilling/AsbCloudServer
Merge pull request 'Разделение АПД на ротор и слайд' (#104) from feature/APD into dev
Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/104
This commit is contained in:
commit
536cc55c97
8403
AsbCloudDb/Migrations/20230906090612_Add_separated_subsystems.Designer.cs
generated
Normal file
8403
AsbCloudDb/Migrations/20230906090612_Add_separated_subsystems.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,34 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace AsbCloudDb.Migrations
|
||||||
|
{
|
||||||
|
public partial class Add_separated_subsystems : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.InsertData(
|
||||||
|
table: "t_subsystem",
|
||||||
|
columns: new[] { "id", "description", "name" },
|
||||||
|
values: new object[,]
|
||||||
|
{
|
||||||
|
{ 11, "Режим работы \"Бурение в роторе\"", "АПД ротор" },
|
||||||
|
{ 12, "Режим работы \"Бурение в слайде\"", "АПД слайд" }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "t_subsystem",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 11);
|
||||||
|
|
||||||
|
migrationBuilder.DeleteData(
|
||||||
|
table: "t_subsystem",
|
||||||
|
keyColumn: "id",
|
||||||
|
keyValue: 12);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4346,6 +4346,18 @@ namespace AsbCloudDb.Migrations
|
|||||||
Name = "АКБ"
|
Name = "АКБ"
|
||||||
},
|
},
|
||||||
new
|
new
|
||||||
|
{
|
||||||
|
Id = 11,
|
||||||
|
Description = "Режим работы \"Бурение в роторе\"",
|
||||||
|
Name = "АПД ротор"
|
||||||
|
},
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Id = 12,
|
||||||
|
Description = "Режим работы \"Бурение в слайде\"",
|
||||||
|
Name = "АПД слайд"
|
||||||
|
},
|
||||||
|
new
|
||||||
{
|
{
|
||||||
Id = 2,
|
Id = 2,
|
||||||
Description = "Алгоритм поиска оптимальных параметров бурения САУБ",
|
Description = "Алгоритм поиска оптимальных параметров бурения САУБ",
|
||||||
|
@ -6,6 +6,8 @@ namespace AsbCloudDb.Model.DefaultData
|
|||||||
public override Subsystem[] GetData() => new Subsystem[]{
|
public override Subsystem[] GetData() => new Subsystem[]{
|
||||||
// САУБ - ид подсистем с 1 до 65_535
|
// САУБ - ид подсистем с 1 до 65_535
|
||||||
new () {Id = 1, Name = "АКБ", Description = "Совместная работа режимов \"Бурение в роторе\" и \"Бурение в слайде\""},
|
new () {Id = 1, Name = "АКБ", Description = "Совместная работа режимов \"Бурение в роторе\" и \"Бурение в слайде\""},
|
||||||
|
new () {Id = 11, Name = "АПД ротор", Description = "Режим работы \"Бурение в роторе\""},
|
||||||
|
new () {Id = 12, Name = "АПД слайд", Description = "Режим работы \"Бурение в слайде\""},
|
||||||
new () {Id = 2, Name = "MSE", Description = "Алгоритм поиска оптимальных параметров бурения САУБ"},
|
new () {Id = 2, Name = "MSE", Description = "Алгоритм поиска оптимальных параметров бурения САУБ"},
|
||||||
//Spin master - id подсистем с 65_536 до 131_071
|
//Spin master - id подсистем с 65_536 до 131_071
|
||||||
new () {Id = 65536, Name = "Spin master", Description = "Spin master"},
|
new () {Id = 65536, Name = "Spin master", Description = "Spin master"},
|
||||||
|
@ -15,7 +15,6 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.Subsystems
|
namespace AsbCloudInfrastructure.Services.Subsystems
|
||||||
{
|
{
|
||||||
|
|
||||||
internal static class SubsystemOperationTimeCalcWorkFactory
|
internal static class SubsystemOperationTimeCalcWorkFactory
|
||||||
{
|
{
|
||||||
private const string workId = "Subsystem operation time calc";
|
private const string workId = "Subsystem operation time calc";
|
||||||
@ -23,7 +22,8 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
private const int idSubsytemTorqueMaster = 65537;
|
private const int idSubsytemTorqueMaster = 65537;
|
||||||
private const int idSubsytemSpinMaster = 65536;
|
private const int idSubsytemSpinMaster = 65536;
|
||||||
private const int idSubsytemAkb = 1;
|
private const int idSubsystemAPDRotor = 11;
|
||||||
|
private const int idSubsystemAPDSlide = 12;
|
||||||
private const int idSubsytemMse = 2;
|
private const int idSubsytemMse = 2;
|
||||||
|
|
||||||
public static WorkPeriodic MakeWork()
|
public static WorkPeriodic MakeWork()
|
||||||
@ -101,23 +101,11 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSaubAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSaubAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
|
||||||
{
|
{
|
||||||
static bool isSubsytemAkb(short? mode)
|
static bool isSubsytemAkbRotor(short? mode) => mode == 1;
|
||||||
{
|
|
||||||
if (mode is null)
|
|
||||||
return false;
|
|
||||||
if (mode == 1 | mode == 3)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsSubsystemMse(short? state)
|
static bool isSubsytemAkbSlide(short? mode) => mode == 3;
|
||||||
{
|
|
||||||
if (state is null)
|
static bool IsSubsystemMse(short? state) => (state & 1) > 0;
|
||||||
return false;
|
|
||||||
if ((state & 1) > 0)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var query =
|
var query =
|
||||||
$"select tt.date, tt.mode, tt.well_depth, tt.mse_state " +
|
$"select tt.date, tt.mode, tt.well_depth, tt.mse_state " +
|
||||||
@ -138,60 +126,29 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
using var result = await ExecuteReaderAsync(db, query, token);
|
using var result = await ExecuteReaderAsync(db, query, token);
|
||||||
|
|
||||||
var subsystemsOperationTimes = new List<SubsystemOperationTime>();
|
var subsystemsOperationTimes = new List<SubsystemOperationTime>();
|
||||||
|
var detectorRotor = new SubsystemDetector(idTelemetry, idSubsystemAPDRotor, isSubsytemAkbRotor, IsValid);
|
||||||
(bool isEnable, DateTimeOffset date, float depth) akbPre = default;
|
var detectorSlide = new SubsystemDetector(idTelemetry, idSubsystemAPDSlide, isSubsytemAkbSlide, IsValid);
|
||||||
(bool isEnable, DateTimeOffset date, float depth) msePre = default;
|
var detectorMse = new SubsystemDetector(idTelemetry, idSubsytemMse, IsSubsystemMse, IsValid);
|
||||||
|
|
||||||
while (result.Read())
|
while (result.Read())
|
||||||
{
|
{
|
||||||
var mode = result.GetFieldValue<short?>(1);
|
var mode = result.GetFieldValue<short?>(1);
|
||||||
var state = result.GetFieldValue<short?>(3);
|
var state = result.GetFieldValue<short?>(3);
|
||||||
|
|
||||||
var isAkbEnable = isSubsytemAkb(mode);
|
var isAkbRotorEnable = isSubsytemAkbRotor(mode);
|
||||||
|
var isAkbSlideEnable = isSubsytemAkbSlide(mode);
|
||||||
var isMseEnable = IsSubsystemMse(state);
|
var isMseEnable = IsSubsystemMse(state);
|
||||||
var date = result.GetFieldValue<DateTimeOffset>(0);
|
var date = result.GetFieldValue<DateTimeOffset>(0);
|
||||||
var depth = result.GetFieldValue<float>(2);
|
var depth = result.GetFieldValue<float>(2);
|
||||||
|
|
||||||
if (!akbPre.isEnable && isAkbEnable)
|
if (detectorRotor.TryDetect(mode, date, depth, out var detectedRotor))
|
||||||
{
|
subsystemsOperationTimes.Add(detectedRotor!);
|
||||||
akbPre = (true, date, depth);
|
|
||||||
}
|
|
||||||
else if (akbPre.isEnable && !isAkbEnable)
|
|
||||||
{
|
|
||||||
var subsystemOperationTime = new SubsystemOperationTime
|
|
||||||
{
|
|
||||||
IdTelemetry = idTelemetry,
|
|
||||||
IdSubsystem = idSubsytemAkb,
|
|
||||||
DateStart = akbPre.date,
|
|
||||||
DateEnd = date,
|
|
||||||
DepthStart = akbPre.depth,
|
|
||||||
DepthEnd = depth,
|
|
||||||
};
|
|
||||||
if (IsValid(subsystemOperationTime))
|
|
||||||
subsystemsOperationTimes.Add(subsystemOperationTime);
|
|
||||||
akbPre.isEnable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!msePre.isEnable && isMseEnable)
|
if (detectorSlide.TryDetect(mode, date, depth, out var detectedSlide))
|
||||||
{
|
subsystemsOperationTimes.Add(detectedSlide!);
|
||||||
msePre = (true, date, depth);
|
|
||||||
}
|
|
||||||
else if (msePre.isEnable && !isMseEnable)
|
|
||||||
{
|
|
||||||
var subsystemOperationTime = new SubsystemOperationTime
|
|
||||||
{
|
|
||||||
IdTelemetry = idTelemetry,
|
|
||||||
IdSubsystem = idSubsytemMse,
|
|
||||||
DateStart = akbPre.date,
|
|
||||||
DateEnd = date,
|
|
||||||
DepthStart = akbPre.depth,
|
|
||||||
DepthEnd = depth,
|
|
||||||
};
|
|
||||||
if (IsValid(subsystemOperationTime))
|
|
||||||
subsystemsOperationTimes.Add(subsystemOperationTime);
|
|
||||||
|
|
||||||
msePre.isEnable = false;
|
if (detectorMse.TryDetect(mode, date, depth, out var detectedMse))
|
||||||
}
|
subsystemsOperationTimes.Add(detectedMse!);
|
||||||
}
|
}
|
||||||
|
|
||||||
return subsystemsOperationTimes;
|
return subsystemsOperationTimes;
|
||||||
@ -231,7 +188,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
$"order by date;";
|
$"order by date;";
|
||||||
|
|
||||||
var rows = new List<(int? IdSubsystem, DateTimeOffset Date)>(32);
|
var rows = new List<(int? IdSubsystem, DateTimeOffset Date)>(32);
|
||||||
{
|
|
||||||
using var resultSpin = await ExecuteReaderAsync(db, querySpin, token);
|
using var resultSpin = await ExecuteReaderAsync(db, querySpin, token);
|
||||||
int? idSubsystemLast = null;
|
int? idSubsystemLast = null;
|
||||||
while (resultSpin.Read())
|
while (resultSpin.Read())
|
||||||
@ -247,7 +204,6 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
await resultSpin.DisposeAsync();
|
await resultSpin.DisposeAsync();
|
||||||
}
|
|
||||||
|
|
||||||
if (rows.Count < 2)
|
if (rows.Count < 2)
|
||||||
return Enumerable.Empty<SubsystemOperationTime>();
|
return Enumerable.Empty<SubsystemOperationTime>();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.DetectedOperation;
|
using AsbCloudApp.Data.DetectedOperation;
|
||||||
using AsbCloudApp.Data.Subsystems;
|
using AsbCloudApp.Data.Subsystems;
|
||||||
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudApp.Services.Subsystems;
|
using AsbCloudApp.Services.Subsystems;
|
||||||
@ -17,15 +18,15 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.Subsystems
|
namespace AsbCloudInfrastructure.Services.Subsystems
|
||||||
{
|
{
|
||||||
|
|
||||||
internal class SubsystemOperationTimeService : ISubsystemOperationTimeService
|
internal class SubsystemOperationTimeService : ISubsystemOperationTimeService
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
private readonly ICrudRepository<SubsystemDto> subsystemService;
|
private readonly ICrudRepository<SubsystemDto> subsystemService;
|
||||||
private readonly IDetectedOperationService detectedOperationService;
|
private readonly IDetectedOperationService detectedOperationService;
|
||||||
public const int IdSubsystemAKB = 1;
|
public const int IdSubsystemAKB = 1;
|
||||||
|
public const int IdSubsystemAKBRotor = 11;
|
||||||
|
public const int IdSubsystemAKBSlide = 12;
|
||||||
public const int IdSubsystemMSE = 2;
|
public const int IdSubsystemMSE = 2;
|
||||||
public const int IdSubsystemSpin = 65536;
|
public const int IdSubsystemSpin = 65536;
|
||||||
public const int IdSubsystemTorque = 65537;
|
public const int IdSubsystemTorque = 65537;
|
||||||
@ -143,9 +144,12 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<SubsystemStatDto> CalcStat(IEnumerable<SubsystemOperationTimeDto> dtos, (double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
private IEnumerable<SubsystemStatDto> CalcStat(
|
||||||
|
IEnumerable<SubsystemOperationTimeDto> dtos,
|
||||||
|
(double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
||||||
{
|
{
|
||||||
var groupedDataSubsystems = dtos
|
var groupedDataSubsystems = dtos
|
||||||
|
.OrderBy(o => o.Id)
|
||||||
.GroupBy(o => o.IdSubsystem);
|
.GroupBy(o => o.IdSubsystem);
|
||||||
var periodGroupTotal = dtos.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
var periodGroupTotal = dtos.Sum(o => (o.DateEnd - o.DateStart).TotalHours);
|
||||||
|
|
||||||
@ -159,17 +163,35 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
IdSubsystem = g.Key,
|
IdSubsystem = g.Key,
|
||||||
SubsystemName = subsystemService.GetOrDefault(g.Key)?.Name ?? "unknown",
|
SubsystemName = subsystemService.GetOrDefault(g.Key)?.Name ?? "unknown",
|
||||||
UsedTimeHours = periodGroup,
|
UsedTimeHours = periodGroup,
|
||||||
|
//% использования = суммарная проходка АПД в слайде
|
||||||
|
/// суммарную проходку автоопределенных операций в слайде.
|
||||||
KUsage = periodGroupDepth / depthIntervalSubsystem,
|
KUsage = periodGroupDepth / depthIntervalSubsystem,
|
||||||
SumDepthInterval = periodGroupDepth,
|
SumDepthInterval = periodGroupDepth,
|
||||||
OperationCount = g.Count()
|
OperationCount = g.Count(),
|
||||||
};
|
};
|
||||||
if (subsystemStat.KUsage > 1)
|
if (subsystemStat.KUsage > 1)
|
||||||
subsystemStat.KUsage = 1;
|
subsystemStat.KUsage = 1;
|
||||||
return subsystemStat;
|
return subsystemStat;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var apdParts = result.Where(x => x.IdSubsystem == 11 || x.IdSubsystem == 12);
|
||||||
|
if (apdParts.Any())
|
||||||
|
{
|
||||||
|
var apdSum = new SubsystemStatDto()
|
||||||
|
{
|
||||||
|
IdSubsystem = IdSubsystemAKB,
|
||||||
|
SubsystemName = "АПД",
|
||||||
|
UsedTimeHours = apdParts.Sum(part => part.UsedTimeHours),
|
||||||
|
KUsage = apdParts.Sum(part => part.KUsage),
|
||||||
|
SumDepthInterval = apdParts.Sum(part => part.SumDepthInterval),
|
||||||
|
OperationCount = apdParts.Sum(part => part.OperationCount),
|
||||||
|
};
|
||||||
|
result = result.Append(apdSum).OrderBy(m => m.IdSubsystem);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static (double depthIntervalRotor, double depthIntervalSlide) GetDepthInterval (IEnumerable<DetectedOperationDto> detectedOperations)
|
private static (double depthIntervalRotor, double depthIntervalSlide) GetDepthInterval (IEnumerable<DetectedOperationDto> detectedOperations)
|
||||||
{
|
{
|
||||||
var depthIntervalRotor = detectedOperations.Where(o => o.IdCategory == WellOperationCategory.IdRotor)
|
var depthIntervalRotor = detectedOperations.Where(o => o.IdCategory == WellOperationCategory.IdRotor)
|
||||||
@ -180,6 +202,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
return depthInterval;
|
return depthInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double GetDepthIntervalSubsystem(int idSubsystem, (double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
private static double GetDepthIntervalSubsystem(int idSubsystem, (double depthIntervalRotor, double depthIntervalSlide) depthInterval)
|
||||||
{
|
{
|
||||||
var depthIntervalSubsystem = 0d;
|
var depthIntervalSubsystem = 0d;
|
||||||
@ -188,6 +211,16 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
{
|
{
|
||||||
depthIntervalSubsystem = depthInterval.depthIntervalRotor + depthInterval.depthIntervalSlide;
|
depthIntervalSubsystem = depthInterval.depthIntervalRotor + depthInterval.depthIntervalSlide;
|
||||||
}
|
}
|
||||||
|
//AKB - Rotor
|
||||||
|
if (idSubsystem == IdSubsystemAKBRotor)
|
||||||
|
{
|
||||||
|
depthIntervalSubsystem = depthInterval.depthIntervalRotor;
|
||||||
|
}
|
||||||
|
//AKB - Slide
|
||||||
|
if (idSubsystem == IdSubsystemAKBSlide)
|
||||||
|
{
|
||||||
|
depthIntervalSubsystem = depthInterval.depthIntervalSlide;
|
||||||
|
}
|
||||||
//Spin
|
//Spin
|
||||||
if (idSubsystem == IdSubsystemSpin)
|
if (idSubsystem == IdSubsystemSpin)
|
||||||
{
|
{
|
||||||
@ -301,11 +334,11 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IQueryable<SubsystemOperationTime>? BuildQuery(SubsystemOperationTimeRequest request)
|
private IQueryable<SubsystemOperationTime> BuildQuery(SubsystemOperationTimeRequest request)
|
||||||
{
|
{
|
||||||
var well = wellService.GetOrDefault(request.IdWell);
|
var well = wellService.GetOrDefault(request.IdWell);
|
||||||
if (well?.IdTelemetry is null || well.Timezone is null)
|
if (well?.IdTelemetry is null || well.Timezone is null)
|
||||||
return null;
|
throw new ArgumentInvalidException($"Not valid IdWell = {request.IdWell}", nameof(request.IdWell));
|
||||||
|
|
||||||
var query = db.SubsystemOperationTimes
|
var query = db.SubsystemOperationTimes
|
||||||
.Include(o => o.Subsystem)
|
.Include(o => o.Subsystem)
|
||||||
@ -352,8 +385,6 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
|
|
||||||
if (request?.Take > 0)
|
if (request?.Take > 0)
|
||||||
query = query.Take((int)request.Take);
|
query = query.Take((int)request.Take);
|
||||||
else
|
|
||||||
query = query.Take(3000);
|
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
@ -366,8 +397,5 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
dto.DateEnd = operationTime.DateEnd.ToRemoteDateTime(hours);
|
dto.DateEnd = operationTime.DateEnd.ToRemoteDateTime(hours);
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
using AsbCloudDb.Model.Subsystems;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Services.Subsystems
|
||||||
|
{
|
||||||
|
public class SubsystemDetector
|
||||||
|
{
|
||||||
|
private readonly int idTelemetry;
|
||||||
|
private readonly int idSubsystem;
|
||||||
|
private readonly Func<short?, bool> isEnable;
|
||||||
|
private readonly Func<SubsystemOperationTime, bool> isValid;
|
||||||
|
(bool isEnable, DateTimeOffset date, float depth) pre = default;
|
||||||
|
|
||||||
|
public SubsystemDetector(
|
||||||
|
int idTelemetry,
|
||||||
|
int idSubsystem,
|
||||||
|
Func<short?, bool> isEnable,
|
||||||
|
Func<SubsystemOperationTime, bool> isValid)
|
||||||
|
{
|
||||||
|
this.idTelemetry = idTelemetry;
|
||||||
|
this.idSubsystem = idSubsystem;
|
||||||
|
this.isEnable = isEnable;
|
||||||
|
this.isValid = isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryDetect(short? mode, DateTimeOffset date, float depth, out SubsystemOperationTime? subsystemOperationTime)
|
||||||
|
{
|
||||||
|
var isEnable = this.isEnable(mode);
|
||||||
|
|
||||||
|
if (!pre.isEnable && isEnable)
|
||||||
|
{
|
||||||
|
pre = (true, date, depth);
|
||||||
|
}
|
||||||
|
else if (pre.isEnable && !isEnable)
|
||||||
|
{
|
||||||
|
var detected = new SubsystemOperationTime
|
||||||
|
{
|
||||||
|
IdTelemetry = idTelemetry,
|
||||||
|
IdSubsystem = idSubsystem,
|
||||||
|
DateStart = pre.date,
|
||||||
|
DateEnd = date,
|
||||||
|
DepthStart = pre.depth,
|
||||||
|
DepthEnd = depth,
|
||||||
|
};
|
||||||
|
pre.isEnable = false;
|
||||||
|
if (isValid(detected))
|
||||||
|
{
|
||||||
|
subsystemOperationTime = detected;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subsystemOperationTime = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,16 @@
|
|||||||
using AsbCloudApp.Data.Subsystems;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Data.Subsystems;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudApp.Services.Subsystems;
|
using AsbCloudApp.Services.Subsystems;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudInfrastructure;
|
|
||||||
using System;
|
|
||||||
using AsbCloudApp.Data;
|
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers.Subsystems
|
namespace AsbCloudWebApi.Controllers.Subsystems
|
||||||
{
|
{
|
||||||
@ -22,6 +23,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
|||||||
public class SubsystemOperationTimeController : ControllerBase
|
public class SubsystemOperationTimeController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
||||||
|
private readonly ITelemetryDataSaubService telemetryDataSaubService;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
private readonly ISubsystemService subsystemService;
|
private readonly ISubsystemService subsystemService;
|
||||||
|
|
||||||
@ -32,11 +34,16 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
|||||||
{ 65536, "Spin Master" }
|
{ 65536, "Spin Master" }
|
||||||
};
|
};
|
||||||
|
|
||||||
public SubsystemOperationTimeController(ISubsystemOperationTimeService subsystemOperationTimeService, IWellService wellService, ISubsystemService subsystemService)
|
public SubsystemOperationTimeController(
|
||||||
|
ISubsystemOperationTimeService subsystemOperationTimeService,
|
||||||
|
IWellService wellService,
|
||||||
|
ISubsystemService subsystemService,
|
||||||
|
ITelemetryDataSaubService telemetryDataSaubService)
|
||||||
{
|
{
|
||||||
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
this.subsystemService = subsystemService;
|
this.subsystemService = subsystemService;
|
||||||
|
this.telemetryDataSaubService = telemetryDataSaubService;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// получить статистику
|
/// получить статистику
|
||||||
@ -53,6 +60,21 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
|||||||
return Ok(subsystemResult);
|
return Ok(subsystemResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получить период, за который будет рассчитываться статистика
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("operationsPeriod/{idWell}")]
|
||||||
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetStatDateRangeAsync([FromRoute] int idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await UserHasAccesToWellAsync(idWell, token))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var dateRange = await telemetryDataSaubService.GetRangeAsync(idWell, DateTimeOffset.MinValue, DateTimeOffset.MaxValue, token);
|
||||||
|
|
||||||
|
return Ok(dateRange);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// получить статистику по активным скважинам
|
/// получить статистику по активным скважинам
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user