diff --git a/AsbCloudApp/Data/ProcessMap/ProcessMapPlanDto.cs b/AsbCloudApp/Data/ProcessMap/ProcessMapPlanDto.cs index ce64f1a3..29a2a63e 100644 --- a/AsbCloudApp/Data/ProcessMap/ProcessMapPlanDto.cs +++ b/AsbCloudApp/Data/ProcessMap/ProcessMapPlanDto.cs @@ -23,7 +23,7 @@ namespace AsbCloudApp.Data.ProcessMap /// /// Id режима 1-ротор, 2 - слайд /// - [Range(1, 2, ErrorMessage = "Id режима должен быть либо 1-ротор либо 2-слайд")] + [Range(0, 2, ErrorMessage = "Id режима должен быть либо 0-ручной либо, 1-ротор либо 2-слайд")] public int IdMode { get; set; } /// diff --git a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportService.cs b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportService.cs index 1a444f32..ef9da1c4 100644 --- a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportService.cs @@ -6,6 +6,7 @@ using AsbCloudApp.Services; using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using System.Threading; using System.Threading.Tasks; @@ -144,15 +145,11 @@ namespace AsbCloudInfrastructure.Services.ProcessMap Span telemetryRowSpan, IDictionary sectionTypes) { - var telemetryFirst = telemetryRowSpan[0]; - var telemetryLast = telemetryRowSpan[^1]; - var mode = GetIdMode(telemetryRowSpan); - var processMapByMode = processMap.FirstOrDefault(p => p.IdMode == mode.IdMode); + var telemetryStat = new TelemetryStat(telemetryRowSpan); + var processMapByMode = processMap.FirstOrDefault(p => p.IdMode == telemetryStat.IdMode); var processMapFirst = processMap.First(); var idWellSectionType = processMapByMode?.IdWellSectionType ?? processMapFirst.IdWellSectionType; - - var telemetryStat = AnalyzeTelemetry(telemetryRowSpan); - + var result = new ProcessMapReportDto { IdWell = processMapByMode?.IdWell ?? processMapFirst.IdWell, @@ -161,17 +158,17 @@ namespace AsbCloudInfrastructure.Services.ProcessMap DepthStart = subInterval.DepthStart, DepthEnd = subInterval.DepthEnd, - DateStart = telemetryFirst.DateMin, + DateStart = telemetryStat.DateStart, - MechDrillingHours = (telemetryLast.DateMax - telemetryFirst.DateMin).TotalHours, - DrillingMode = mode.ModeName, + MechDrillingHours = telemetryStat.MechDrillingHours, + DrillingMode = telemetryStat.ModeName, - DeltaDepth = telemetryLast.WellDepthMax - telemetryFirst.WellDepthMin, + DeltaDepth = telemetryStat.DeltaDepth, - PressureDiff = telemetryStat.Pressure.MakeParams(processMapByMode?.Pressure.Plan, telemetryStat.SpUsageDepthTotal), - AxialLoad = telemetryStat.AxialLoad.MakeParams(processMapByMode?.AxialLoad.Plan, telemetryStat.SpUsageDepthTotal), - TopDriveTorque = telemetryStat.RotorTorque.MakeParams(processMapByMode?.TopDriveTorque.Plan, telemetryStat.SpUsageDepthTotal), - SpeedLimit = telemetryStat.BlockSpeed.MakeParams(processMapByMode?.RopPlan, telemetryStat.SpUsageDepthTotal), + PressureDiff = telemetryStat.Pressure.MakeParams(processMapByMode?.Pressure.Plan), + AxialLoad = telemetryStat.AxialLoad.MakeParams(processMapByMode?.AxialLoad.Plan), + TopDriveTorque = telemetryStat.RotorTorque.MakeParams(processMapByMode?.TopDriveTorque.Plan), + SpeedLimit = telemetryStat.BlockSpeed.MakeParams(processMapByMode?.RopPlan), Rop = telemetryStat.Rop, Usage = telemetryStat.UsageSaub, @@ -179,40 +176,6 @@ namespace AsbCloudInfrastructure.Services.ProcessMap return result; } - private static TelemetryStat AnalyzeTelemetry(Span telemetry) - { - var stat = new TelemetryStat(); - - for (int i = 0; i < telemetry.Length; i++) - stat.UpdateStat(telemetry[i]); - - return stat; - } - - private static (int IdMode, string ModeName) GetIdMode(Span telemetryRowSpan) - { - /// Режим работы САУБ в телеметрии: - /// 0 - "РУЧНОЙ" - /// 1 - "БУРЕНИЕ В РОТОРЕ" - /// 3 - "БУРЕНИЕ В СЛАЙДЕ" - - for (int i = 0; i < telemetryRowSpan.Length; i++) - { - var idMode = telemetryRowSpan[i].IdMode; - - if (idMode == 0) - return (0, "Ручной"); - - if (idMode == 1) - return (1, "Ротор"); - - if (idMode == 3) - return (2, "Слайд"); - } - - return (0, "Ручной"); - } - private static bool IsDifferent(TelemetryDataSaubStatDto intervalStart, TelemetryDataSaubStatDto current) { if (intervalStart.WellDepthMin > current.WellDepthMin) @@ -259,20 +222,24 @@ namespace AsbCloudInfrastructure.Services.ProcessMap private readonly Func? getterLimitMax; private readonly int idFeedRegulator; - + private readonly int idMode; private TelemetryDataSaubStatDto? previous; public double SpUsageDepth { get; private set; } + private static double spUsageTotal; public ParamStat(Func getterSp, Func getterPv, Func? getterLimitMax, - int idFeedRegulator) + int idFeedRegulator, + int idMode) { this.getterSp = getterSp; this.getterPv = getterPv; this.getterLimitMax = getterLimitMax; this.idFeedRegulator = idFeedRegulator; + this.idMode = idMode; + spUsageTotal = 0d; } public void UpdateStat(TelemetryDataSaubStatDto current) @@ -292,14 +259,20 @@ namespace AsbCloudInfrastructure.Services.ProcessMap if (current.IdFeedRegulator is not null) { - if(current.IdFeedRegulator == idFeedRegulator) + if (current.IdFeedRegulator == idFeedRegulator) + { SpUsageDepth += deltaDepth; + spUsageTotal += deltaDepth; + } } else { var pvErr = (getterSp(current) - getterPv(current)) / getterSp(current); if (pvErr < 0.03d) //3% + { SpUsageDepth += deltaDepth; + spUsageTotal += deltaDepth; + } } deltaDepthSum += deltaDepth; @@ -309,16 +282,30 @@ namespace AsbCloudInfrastructure.Services.ProcessMap previous = current; } - public ProcessMapReportParamsDto MakeParams(double? spPlan, double SpUsageDepthTotal) - => new ProcessMapReportParamsDto + public ProcessMapReportParamsDto MakeParams(double? spPlan) + { + var result = new ProcessMapReportParamsDto { SetpointPlan = spPlan, - SetpointFact = DivideValByDepth(spWSum), Fact = DivideValByDepth(pvWSum), - Limit = (getterLimitMax is not null) ? DivideValByDepth(limitMaxWSum) : null, - SetpointUsage = deltaDepthSum > 0d ? SpUsageDepth / SpUsageDepthTotal : null, }; + if (idMode == 0) + { + result.SetpointFact = null; + result.Limit = null; + result.SetpointUsage = null; + } + else + { + result.SetpointFact = DivideValByDepth(spWSum); + result.Limit = (getterLimitMax is not null) ? DivideValByDepth(limitMaxWSum) : null; + result.SetpointUsage = deltaDepthSum > 0d ? SpUsageDepth / spUsageTotal : null; + } + + return result; + } + private double? DivideValByDepth(double? val) { if(val is null || val == 0d || deltaDepthSum == 0d) @@ -333,8 +320,6 @@ namespace AsbCloudInfrastructure.Services.ProcessMap public ParamStat RotorTorque {get; } public ParamStat BlockSpeed {get; } - public double SpUsageDepthTotal => Pressure.SpUsageDepth + AxialLoad.SpUsageDepth + RotorTorque.SpUsageDepth + BlockSpeed.SpUsageDepth; - private TelemetryDataSaubStatDto? previous; private double depthSum = 0d; private double hoursSum = 0d; @@ -342,17 +327,37 @@ namespace AsbCloudInfrastructure.Services.ProcessMap public double? Rop => hoursSum == 0d ? null : depthSum / hoursSum; private double depthWithSaub = 0d; - public double UsageSaub => depthWithSaub / depthSum; + public double UsageSaub { get; private set; } + + public DateTime DateStart { get; private set; } + public float DeltaDepth { get; private set; } + public int IdMode { get; private set; } + public string ModeName { get; private set; } + public double MechDrillingHours { get; private set; } - public TelemetryStat() + public TelemetryStat(Span telemetry) { - BlockSpeed = new(t => t.BlockSpeedSp, t => t.BlockSpeed, null, 1); - Pressure = new(t => t.PressureSp, t => t.Pressure, t=>t.PressureDeltaLimitMax, 2); - RotorTorque = new(t => t.RotorTorqueSp, t => t.RotorTorque, t=>t.RotorTorqueLimitMax, 3); - AxialLoad = new(t => t.AxialLoadSp, t => t.AxialLoad, t=>t.AxialLoadLimitMax, 4); + var telemetryFirst = telemetry[0]; + var telemetryLast = telemetry[^1]; + + IdMode = telemetryFirst.IdMode; + ModeName = GetModeName(IdMode); + DateStart = telemetryFirst.DateMin; + DeltaDepth = telemetryLast.WellDepthMax - telemetryFirst.WellDepthMin; + MechDrillingHours = (telemetryLast.DateMax - telemetryFirst.DateMin).TotalHours; + + BlockSpeed = new(t => t.BlockSpeedSp, t => t.BlockSpeed, null, 1, IdMode); + Pressure = new(t => t.PressureSp, t => t.Pressure, t=>t.PressureDeltaLimitMax, 2, IdMode); + RotorTorque = new(t => t.RotorTorqueSp, t => t.RotorTorque, t=>t.RotorTorqueLimitMax, 3, IdMode); + AxialLoad = new(t => t.AxialLoadSp, t => t.AxialLoad, t=>t.AxialLoadLimitMax, 4, IdMode); + + for (int i = 0; i < telemetry.Length; i++) + UpdateStat(telemetry[i]); + + UsageSaub = depthWithSaub / depthSum; } - public void UpdateStat(TelemetryDataSaubStatDto current) + private void UpdateStat(TelemetryDataSaubStatDto current) { if(previous is not null) { @@ -367,14 +372,21 @@ namespace AsbCloudInfrastructure.Services.ProcessMap depthWithSaub += deltaDepth; } } - previous = current; + previous = current; Pressure.UpdateStat(current); AxialLoad.UpdateStat(current); RotorTorque.UpdateStat(current); BlockSpeed.UpdateStat(current); } - }; + private static string GetModeName(int idMode) + => idMode switch + { + 1 => "Ротор", + 3 => "Слайд", + _ => "Ручной", + }; + } #nullable disable }