forked from ddrilling/AsbCloudServer
Fix calculations
This commit is contained in:
parent
4e905cf421
commit
5e8df2e29f
@ -23,7 +23,7 @@ namespace AsbCloudApp.Data.ProcessMap
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Id режима 1-ротор, 2 - слайд
|
/// Id режима 1-ротор, 2 - слайд
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Range(1, 2, ErrorMessage = "Id режима должен быть либо 1-ротор либо 2-слайд")]
|
[Range(0, 2, ErrorMessage = "Id режима должен быть либо 0-ручной либо, 1-ротор либо 2-слайд")]
|
||||||
public int IdMode { get; set; }
|
public int IdMode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -6,6 +6,7 @@ using AsbCloudApp.Services;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -144,15 +145,11 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
|
|||||||
Span<TelemetryDataSaubStatDto> telemetryRowSpan,
|
Span<TelemetryDataSaubStatDto> telemetryRowSpan,
|
||||||
IDictionary<int, string> sectionTypes)
|
IDictionary<int, string> sectionTypes)
|
||||||
{
|
{
|
||||||
var telemetryFirst = telemetryRowSpan[0];
|
var telemetryStat = new TelemetryStat(telemetryRowSpan);
|
||||||
var telemetryLast = telemetryRowSpan[^1];
|
var processMapByMode = processMap.FirstOrDefault(p => p.IdMode == telemetryStat.IdMode);
|
||||||
var mode = GetIdMode(telemetryRowSpan);
|
|
||||||
var processMapByMode = processMap.FirstOrDefault(p => p.IdMode == mode.IdMode);
|
|
||||||
var processMapFirst = processMap.First();
|
var processMapFirst = processMap.First();
|
||||||
var idWellSectionType = processMapByMode?.IdWellSectionType ?? processMapFirst.IdWellSectionType;
|
var idWellSectionType = processMapByMode?.IdWellSectionType ?? processMapFirst.IdWellSectionType;
|
||||||
|
|
||||||
var telemetryStat = AnalyzeTelemetry(telemetryRowSpan);
|
|
||||||
|
|
||||||
var result = new ProcessMapReportDto
|
var result = new ProcessMapReportDto
|
||||||
{
|
{
|
||||||
IdWell = processMapByMode?.IdWell ?? processMapFirst.IdWell,
|
IdWell = processMapByMode?.IdWell ?? processMapFirst.IdWell,
|
||||||
@ -161,17 +158,17 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
|
|||||||
|
|
||||||
DepthStart = subInterval.DepthStart,
|
DepthStart = subInterval.DepthStart,
|
||||||
DepthEnd = subInterval.DepthEnd,
|
DepthEnd = subInterval.DepthEnd,
|
||||||
DateStart = telemetryFirst.DateMin,
|
DateStart = telemetryStat.DateStart,
|
||||||
|
|
||||||
MechDrillingHours = (telemetryLast.DateMax - telemetryFirst.DateMin).TotalHours,
|
MechDrillingHours = telemetryStat.MechDrillingHours,
|
||||||
DrillingMode = mode.ModeName,
|
DrillingMode = telemetryStat.ModeName,
|
||||||
|
|
||||||
DeltaDepth = telemetryLast.WellDepthMax - telemetryFirst.WellDepthMin,
|
DeltaDepth = telemetryStat.DeltaDepth,
|
||||||
|
|
||||||
PressureDiff = telemetryStat.Pressure.MakeParams(processMapByMode?.Pressure.Plan, telemetryStat.SpUsageDepthTotal),
|
PressureDiff = telemetryStat.Pressure.MakeParams(processMapByMode?.Pressure.Plan),
|
||||||
AxialLoad = telemetryStat.AxialLoad.MakeParams(processMapByMode?.AxialLoad.Plan, telemetryStat.SpUsageDepthTotal),
|
AxialLoad = telemetryStat.AxialLoad.MakeParams(processMapByMode?.AxialLoad.Plan),
|
||||||
TopDriveTorque = telemetryStat.RotorTorque.MakeParams(processMapByMode?.TopDriveTorque.Plan, telemetryStat.SpUsageDepthTotal),
|
TopDriveTorque = telemetryStat.RotorTorque.MakeParams(processMapByMode?.TopDriveTorque.Plan),
|
||||||
SpeedLimit = telemetryStat.BlockSpeed.MakeParams(processMapByMode?.RopPlan, telemetryStat.SpUsageDepthTotal),
|
SpeedLimit = telemetryStat.BlockSpeed.MakeParams(processMapByMode?.RopPlan),
|
||||||
|
|
||||||
Rop = telemetryStat.Rop,
|
Rop = telemetryStat.Rop,
|
||||||
Usage = telemetryStat.UsageSaub,
|
Usage = telemetryStat.UsageSaub,
|
||||||
@ -179,40 +176,6 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TelemetryStat AnalyzeTelemetry(Span<TelemetryDataSaubStatDto> 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<TelemetryDataSaubStatDto> 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)
|
private static bool IsDifferent(TelemetryDataSaubStatDto intervalStart, TelemetryDataSaubStatDto current)
|
||||||
{
|
{
|
||||||
if (intervalStart.WellDepthMin > current.WellDepthMin)
|
if (intervalStart.WellDepthMin > current.WellDepthMin)
|
||||||
@ -259,20 +222,24 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
|
|||||||
private readonly Func<TelemetryDataSaubStatDto, double>? getterLimitMax;
|
private readonly Func<TelemetryDataSaubStatDto, double>? getterLimitMax;
|
||||||
|
|
||||||
private readonly int idFeedRegulator;
|
private readonly int idFeedRegulator;
|
||||||
|
private readonly int idMode;
|
||||||
private TelemetryDataSaubStatDto? previous;
|
private TelemetryDataSaubStatDto? previous;
|
||||||
|
|
||||||
public double SpUsageDepth { get; private set; }
|
public double SpUsageDepth { get; private set; }
|
||||||
|
private static double spUsageTotal;
|
||||||
|
|
||||||
public ParamStat(Func<TelemetryDataSaubStatDto, double> getterSp,
|
public ParamStat(Func<TelemetryDataSaubStatDto, double> getterSp,
|
||||||
Func<TelemetryDataSaubStatDto, double> getterPv,
|
Func<TelemetryDataSaubStatDto, double> getterPv,
|
||||||
Func<TelemetryDataSaubStatDto, double>? getterLimitMax,
|
Func<TelemetryDataSaubStatDto, double>? getterLimitMax,
|
||||||
int idFeedRegulator)
|
int idFeedRegulator,
|
||||||
|
int idMode)
|
||||||
{
|
{
|
||||||
this.getterSp = getterSp;
|
this.getterSp = getterSp;
|
||||||
this.getterPv = getterPv;
|
this.getterPv = getterPv;
|
||||||
this.getterLimitMax = getterLimitMax;
|
this.getterLimitMax = getterLimitMax;
|
||||||
this.idFeedRegulator = idFeedRegulator;
|
this.idFeedRegulator = idFeedRegulator;
|
||||||
|
this.idMode = idMode;
|
||||||
|
spUsageTotal = 0d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateStat(TelemetryDataSaubStatDto current)
|
public void UpdateStat(TelemetryDataSaubStatDto current)
|
||||||
@ -292,14 +259,20 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
|
|||||||
|
|
||||||
if (current.IdFeedRegulator is not null)
|
if (current.IdFeedRegulator is not null)
|
||||||
{
|
{
|
||||||
if(current.IdFeedRegulator == idFeedRegulator)
|
if (current.IdFeedRegulator == idFeedRegulator)
|
||||||
|
{
|
||||||
SpUsageDepth += deltaDepth;
|
SpUsageDepth += deltaDepth;
|
||||||
|
spUsageTotal += deltaDepth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var pvErr = (getterSp(current) - getterPv(current)) / getterSp(current);
|
var pvErr = (getterSp(current) - getterPv(current)) / getterSp(current);
|
||||||
if (pvErr < 0.03d) //3%
|
if (pvErr < 0.03d) //3%
|
||||||
|
{
|
||||||
SpUsageDepth += deltaDepth;
|
SpUsageDepth += deltaDepth;
|
||||||
|
spUsageTotal += deltaDepth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deltaDepthSum += deltaDepth;
|
deltaDepthSum += deltaDepth;
|
||||||
@ -309,16 +282,30 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
|
|||||||
previous = current;
|
previous = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessMapReportParamsDto MakeParams(double? spPlan, double SpUsageDepthTotal)
|
public ProcessMapReportParamsDto MakeParams(double? spPlan)
|
||||||
=> new ProcessMapReportParamsDto
|
{
|
||||||
|
var result = new ProcessMapReportParamsDto
|
||||||
{
|
{
|
||||||
SetpointPlan = spPlan,
|
SetpointPlan = spPlan,
|
||||||
SetpointFact = DivideValByDepth(spWSum),
|
|
||||||
Fact = DivideValByDepth(pvWSum),
|
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)
|
private double? DivideValByDepth(double? val)
|
||||||
{
|
{
|
||||||
if(val is null || val == 0d || deltaDepthSum == 0d)
|
if(val is null || val == 0d || deltaDepthSum == 0d)
|
||||||
@ -333,8 +320,6 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
|
|||||||
public ParamStat RotorTorque {get; }
|
public ParamStat RotorTorque {get; }
|
||||||
public ParamStat BlockSpeed {get; }
|
public ParamStat BlockSpeed {get; }
|
||||||
|
|
||||||
public double SpUsageDepthTotal => Pressure.SpUsageDepth + AxialLoad.SpUsageDepth + RotorTorque.SpUsageDepth + BlockSpeed.SpUsageDepth;
|
|
||||||
|
|
||||||
private TelemetryDataSaubStatDto? previous;
|
private TelemetryDataSaubStatDto? previous;
|
||||||
private double depthSum = 0d;
|
private double depthSum = 0d;
|
||||||
private double hoursSum = 0d;
|
private double hoursSum = 0d;
|
||||||
@ -342,17 +327,37 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
|
|||||||
public double? Rop => hoursSum == 0d ? null : depthSum / hoursSum;
|
public double? Rop => hoursSum == 0d ? null : depthSum / hoursSum;
|
||||||
|
|
||||||
private double depthWithSaub = 0d;
|
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<TelemetryDataSaubStatDto> telemetry)
|
||||||
{
|
{
|
||||||
BlockSpeed = new(t => t.BlockSpeedSp, t => t.BlockSpeed, null, 1);
|
var telemetryFirst = telemetry[0];
|
||||||
Pressure = new(t => t.PressureSp, t => t.Pressure, t=>t.PressureDeltaLimitMax, 2);
|
var telemetryLast = telemetry[^1];
|
||||||
RotorTorque = new(t => t.RotorTorqueSp, t => t.RotorTorque, t=>t.RotorTorqueLimitMax, 3);
|
|
||||||
AxialLoad = new(t => t.AxialLoadSp, t => t.AxialLoad, t=>t.AxialLoadLimitMax, 4);
|
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)
|
if(previous is not null)
|
||||||
{
|
{
|
||||||
@ -367,14 +372,21 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
|
|||||||
depthWithSaub += deltaDepth;
|
depthWithSaub += deltaDepth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
previous = current;
|
|
||||||
|
|
||||||
|
previous = current;
|
||||||
Pressure.UpdateStat(current);
|
Pressure.UpdateStat(current);
|
||||||
AxialLoad.UpdateStat(current);
|
AxialLoad.UpdateStat(current);
|
||||||
RotorTorque.UpdateStat(current);
|
RotorTorque.UpdateStat(current);
|
||||||
BlockSpeed.UpdateStat(current);
|
BlockSpeed.UpdateStat(current);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
private static string GetModeName(int idMode)
|
||||||
|
=> idMode switch
|
||||||
|
{
|
||||||
|
1 => "Ротор",
|
||||||
|
3 => "Слайд",
|
||||||
|
_ => "Ручной",
|
||||||
|
};
|
||||||
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user