forked from ddrilling/AsbCloudServer
доработки по ревью "разделение АПД на АПД в роторе и слайде"
This commit is contained in:
parent
451d7207bd
commit
97ba9b2a8c
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +1,19 @@
|
||||
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
|
||||
{
|
||||
{
|
||||
/// <summary>
|
||||
/// Наработка подсистем
|
||||
/// </summary>
|
||||
@ -21,7 +22,8 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
[Authorize]
|
||||
public class SubsystemOperationTimeController : ControllerBase
|
||||
{
|
||||
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
||||
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);
|
||||
}
|
||||
|
||||
@ -94,10 +100,10 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
[ProducesResponseType(typeof(IEnumerable<SubsystemDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetSubsystemAsync([FromQuery] int? idWell, CancellationToken token)
|
||||
{
|
||||
if (idWell.HasValue)
|
||||
if (idWell.HasValue)
|
||||
if (!await UserHasAccesToWellAsync(idWell.Value, token))
|
||||
return Forbid();
|
||||
var result = await subsystemService.GetSubsystemAsync(idWell, token);
|
||||
return Forbid();
|
||||
var result = await subsystemService.GetSubsystemAsync(idWell, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -109,7 +115,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
public async Task<IActionResult> GetDateRangeOperationTimeAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token)
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
return Forbid();
|
||||
var result = await subsystemOperationTimeService.GetDateRangeOperationTimeAsync(request, token);
|
||||
return Ok(result);
|
||||
}
|
||||
@ -119,7 +125,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
/// </summary>
|
||||
[HttpGet("operationTime")]
|
||||
[ProducesResponseType(typeof(IEnumerable<SubsystemOperationTimeDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
|
||||
|
||||
public async Task<IActionResult> GetOperationTimeAsync(
|
||||
[FromQuery] SubsystemOperationTimeRequest request,
|
||||
CancellationToken token)
|
||||
@ -151,7 +157,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
if (!await IsValidRequest(request, token))
|
||||
return BadRequest("Запрашиваемый диапазон должен заканчиваться за 2 часа до текущего времени(после приведения к UTC).");
|
||||
var result = await subsystemOperationTimeService.DeleteAsync(request, token);
|
||||
return Ok(result);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -161,7 +167,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
[HttpGet("names")]
|
||||
[ProducesResponseType(typeof(Dictionary<int, string>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetSubsystemsNames()
|
||||
{
|
||||
{
|
||||
return Ok(subsystemNames);
|
||||
}
|
||||
|
||||
@ -181,11 +187,11 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
{
|
||||
var ltDate = (DateTimeOffset)request.LtDate;
|
||||
var utcDateRequest = ltDate.ToRemoteDateTime(well.Timezone.Hours);
|
||||
|
||||
|
||||
if (utcDateRequest.AddHours(2) > DateTime.UtcNow)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user