доработки по ревью "разделение АПД на АПД в роторе и слайде"

This commit is contained in:
Olga Nemt 2023-09-15 14:51:15 +05:00
parent 451d7207bd
commit 97ba9b2a8c
3 changed files with 103 additions and 114 deletions

View File

@ -23,9 +23,8 @@ namespace AsbCloudInfrastructure.Services.Subsystems
private const int idSubsytemTorqueMaster = 65537;
private const int idSubsytemSpinMaster = 65536;
private const int idSubsytemAkb = 1;
private const int idSubsytemAkbRototor = 11;
private const int idSubsytemAkbSlide = 12;
private const int idSubsystemAPDRotor = 11;
private const int idSubsystemAPDSlide = 12;
private const int idSubsytemMse = 2;
public static WorkPeriodic MakeWork()
@ -103,32 +102,11 @@ namespace AsbCloudInfrastructure.Services.Subsystems
private static async Task<IEnumerable<SubsystemOperationTime>> OperationTimeSaubAsync(int idTelemetry, DateTimeOffset begin, IAsbCloudDbContext db, CancellationToken token)
{
static bool isSubsytemAkbRotor(short? mode)
{
if (mode is null)
return false;
if (mode == 1)
return true;
return false;
}
static bool isSubsytemAkbRotor(short? mode) => mode == 1;
static bool isSubsytemAkbSlide(short? mode)
{
if (mode is null)
return false;
if (mode == 3)
return true;
return false;
}
static bool isSubsytemAkbSlide(short? mode) => mode == 3;
static bool IsSubsystemMse(short? state)
{
if (state is null)
return false;
if ((state & 1) > 0)
return true;
return false;
}
static bool IsSubsystemMse(short? state) => (state & 1) > 0;
var query =
$"select tt.date, tt.mode, tt.well_depth, tt.mse_state " +
@ -149,10 +127,9 @@ namespace AsbCloudInfrastructure.Services.Subsystems
using var result = await ExecuteReaderAsync(db, query, token);
var subsystemsOperationTimes = new List<SubsystemOperationTime>();
(bool isEnable, DateTimeOffset date, float depth) akbPreRotor = default;
(bool isEnable, DateTimeOffset date, float depth) akbPreSlide = default;
(bool isEnable, DateTimeOffset date, float depth) msePre = default;
var detectorRotor = new SubsystemDetector(idTelemetry, idSubsystemAPDRotor, isSubsytemAkbRotor, IsValid);
var detectorSlide = new SubsystemDetector(idTelemetry, idSubsystemAPDSlide, isSubsytemAkbSlide, IsValid);
var detectorMse = new SubsystemDetector(idTelemetry, idSubsytemMse, IsSubsystemMse, IsValid);
while (result.Read())
{
@ -165,66 +142,17 @@ namespace AsbCloudInfrastructure.Services.Subsystems
var date = result.GetFieldValue<DateTimeOffset>(0);
var depth = result.GetFieldValue<float>(2);
if (!akbPreRotor.isEnable && isAkbRotorEnable)
{
akbPreRotor = (true, date, depth);
}
else if (akbPreRotor.isEnable && !isAkbRotorEnable)
{
var subsystemOperationTime = new SubsystemOperationTime
{
IdTelemetry = idTelemetry,
IdSubsystem = idSubsytemAkbRototor,
DateStart = akbPreRotor.date,
DateEnd = date,
DepthStart = akbPreRotor.depth,
DepthEnd = depth,
};
if (IsValid(subsystemOperationTime))
subsystemsOperationTimes.Add(subsystemOperationTime);
akbPreRotor.isEnable = false;
}
var rotorSubsystemOperationTime = detectorRotor.Detect(mode, date, depth);
if (rotorSubsystemOperationTime != null)
subsystemsOperationTimes.Add(rotorSubsystemOperationTime);
if (!akbPreSlide.isEnable && isAkbSlideEnable)
{
akbPreSlide = (true, date, depth);
}
else if (akbPreSlide.isEnable && !isAkbSlideEnable)
{
var subsystemOperationTime = new SubsystemOperationTime
{
IdTelemetry = idTelemetry,
IdSubsystem = idSubsytemAkbSlide,
DateStart = akbPreSlide.date,
DateEnd = date,
DepthStart = akbPreSlide.depth,
DepthEnd = depth,
};
if (IsValid(subsystemOperationTime))
subsystemsOperationTimes.Add(subsystemOperationTime);
akbPreSlide.isEnable = false;
}
var slideSubsystemOperationTime = detectorSlide.Detect(mode, date, depth);
if (slideSubsystemOperationTime != null)
subsystemsOperationTimes.Add(slideSubsystemOperationTime);
if (!msePre.isEnable && isMseEnable)
{
msePre = (true, date, depth);
}
else if (msePre.isEnable && !isMseEnable)
{
var subsystemOperationTime = new SubsystemOperationTime
{
IdTelemetry = idTelemetry,
IdSubsystem = idSubsytemMse,
DateStart = akbPreRotor.date < akbPreSlide.date ? akbPreRotor.date : akbPreSlide.date,
DateEnd = date,
DepthStart = akbPreRotor.depth < akbPreSlide.depth ? akbPreRotor.depth : akbPreSlide.depth,
DepthEnd = depth,
};
if (IsValid(subsystemOperationTime))
subsystemsOperationTimes.Add(subsystemOperationTime);
msePre.isEnable = false;
}
var mseSubsystemOperationTime = detectorMse.Detect(mode, date, depth);
if (mseSubsystemOperationTime != null)
subsystemsOperationTimes.Add(mseSubsystemOperationTime);
}
return subsystemsOperationTimes;

View File

@ -0,0 +1,55 @@
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 SubsystemOperationTime? Detect(short? mode, DateTimeOffset date, float depth)
{
var isEnable = this.isEnable(mode);
if (!pre.isEnable && isEnable)
{
pre = (true, date, depth);
}
else if (pre.isEnable && !isEnable)
{
var subsystemOperationTime = new SubsystemOperationTime
{
IdTelemetry = idTelemetry,
IdSubsystem = idSubsystem,
DateStart = pre.date,
DateEnd = date,
DepthStart = pre.depth,
DepthEnd = depth,
};
pre.isEnable = false;
if (!isValid(subsystemOperationTime))
return null;
return subsystemOperationTime;
}
return null;
}
}
}

View File

@ -1,15 +1,16 @@
using AsbCloudApp.Data.Subsystems;
using AsbCloudApp.Data;
using AsbCloudApp.Data.Subsystems;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudApp.Services.Subsystems;
using AsbCloudDb.Model;
using AsbCloudInfrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudInfrastructure;
using System;
using AsbCloudApp.Data;
namespace AsbCloudWebApi.Controllers.Subsystems
{
@ -22,6 +23,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
public class SubsystemOperationTimeController : ControllerBase
{
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
private readonly ITelemetryDataSaubService telemetryDataSaubService;
private readonly IWellService wellService;
private readonly ISubsystemService subsystemService;
@ -32,11 +34,16 @@ namespace AsbCloudWebApi.Controllers.Subsystems
{ 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.wellService = wellService;
this.subsystemService = subsystemService;
this.telemetryDataSaubService = telemetryDataSaubService;
}
/// <summary>
/// получить статистику
@ -54,18 +61,17 @@ namespace AsbCloudWebApi.Controllers.Subsystems
}
/// <summary>
/// получить период, за который будет расчитываться статистика
/// получить период, за который будет рассчитываться статистика
/// </summary>
[HttpGet("dateRange")]
[ProducesResponseType(typeof(IEnumerable<DateTime>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetStatDateRangeAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token)
[HttpGet("operationsPeriod/{idWell}")]
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetStatDateRangeAsync([FromRoute] int idWell, CancellationToken token)
{
if (!await UserHasAccesToWellAsync(request.IdWell, token))
if (!await UserHasAccesToWellAsync(idWell, token))
return Forbid();
if (!await IsValidRequest(request, token))
return BadRequest("Запрашиваемый диапазон должен заканчиваться за 2 часа до текущего времени(после приведения к UTC).");
var dateRange = await subsystemOperationTimeService.GetStatDateRangeAsync(request, token);
var dateRange = await telemetryDataSaubService.GetRangeAsync(idWell, DateTimeOffset.MinValue, DateTimeOffset.MaxValue, token);
return Ok(dateRange);
}