forked from ddrilling/AsbCloudServer
CS2-94: Fixed DrillParamsService and Dto
This commit is contained in:
parent
a860bde21e
commit
99f8a36437
@ -6,12 +6,12 @@ namespace AsbCloudApp.Data
|
||||
|
||||
public int IdWell { get; set; }
|
||||
|
||||
public string WellSectionTypeName { get; set; }
|
||||
|
||||
public double DepthStart { get; set; }
|
||||
|
||||
public double DepthEnd { get; set; }
|
||||
|
||||
public int IdWellSectionType { get; set; }
|
||||
|
||||
public double AxialLoadMin { get; set; }
|
||||
|
||||
public double AxialLoadAvg { get; set; }
|
||||
@ -24,17 +24,17 @@ namespace AsbCloudApp.Data
|
||||
|
||||
public double PressureMax { get; set; }
|
||||
|
||||
public double TopDriveTorqueMin { get; set; }
|
||||
public double RotorTorqueMin { get; set; }
|
||||
|
||||
public double TopDriveTorqueAvg { get; set; }
|
||||
public double RotorTorqueAvg { get; set; }
|
||||
|
||||
public double TopDriveTorqueMax { get; set; }
|
||||
public double RotorTorqueMax { get; set; }
|
||||
|
||||
public double TopDriveSpeedMin { get; set; }
|
||||
public double RotorSpeedMin { get; set; }
|
||||
|
||||
public double TopDriveSpeedAvg { get; set; }
|
||||
public double RotorSpeedAvg { get; set; }
|
||||
|
||||
public double TopDriveSpeedMax { get; set; }
|
||||
public double RotorSpeedMax { get; set; }
|
||||
|
||||
public double FlowMin { get; set; }
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
@ -17,64 +16,109 @@ namespace AsbCloudInfrastructure.Services
|
||||
public DrillParamsService(IAsbCloudDbContext context, ITelemetryService telemetryService)
|
||||
: base(context)
|
||||
{
|
||||
this.db = context;
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
public async Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell, double startDepth,
|
||||
double endDepth, CancellationToken token = default)
|
||||
public async Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell,
|
||||
double startDepth, double endDepth, CancellationToken token = default)
|
||||
{
|
||||
var idTelemetry = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||
|
||||
if (idTelemetry is null)
|
||||
return null;
|
||||
|
||||
var axialLoads = await GetDrillParams(idWell, startDepth, endDepth,
|
||||
(telemetry) => telemetry.AxialLoad, token);
|
||||
var axialLoads = await GetTelemetryGroupQuery(idWell, startDepth, endDepth)
|
||||
.Select(g => new
|
||||
{
|
||||
Min = g.Min(t=> t.AxialLoad),
|
||||
Avg = g.Average(t => t.AxialLoad),
|
||||
Max = g.Max(t => t.AxialLoad)
|
||||
})
|
||||
.AsNoTracking()
|
||||
.DefaultIfEmpty()
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var pressures = await GetDrillParams(idWell, startDepth, endDepth,
|
||||
(telemetry) => telemetry.Pressure, token);
|
||||
var pressures = await GetTelemetryGroupQuery(idWell, startDepth, endDepth)
|
||||
.Select(g => new
|
||||
{
|
||||
Min = g.Min(t=> t.Pressure),
|
||||
Avg = g.Average(t => t.Pressure),
|
||||
Max = g.Max(t => t.Pressure)
|
||||
})
|
||||
.AsNoTracking()
|
||||
.DefaultIfEmpty()
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var drillParamsDto = new DrillParamsDto()
|
||||
var rotorTorques = await GetTelemetryGroupQuery(idWell, startDepth, endDepth)
|
||||
.Select(g => new
|
||||
{
|
||||
Min = g.Min(t=> t.RotorTorque),
|
||||
Avg = g.Average(t => t.RotorTorque),
|
||||
Max = g.Max(t => t.RotorTorque)
|
||||
})
|
||||
.AsNoTracking()
|
||||
.DefaultIfEmpty()
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var rotorSpeeds = await GetTelemetryGroupQuery(idWell, startDepth, endDepth)
|
||||
.Select(g => new
|
||||
{
|
||||
Min = g.Min(t=> t.RotorSpeed),
|
||||
Avg = g.Average(t => t.RotorSpeed),
|
||||
Max = g.Max(t => t.RotorSpeed)
|
||||
})
|
||||
.AsNoTracking()
|
||||
.DefaultIfEmpty()
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var flows = await GetTelemetryGroupQuery(idWell, startDepth, endDepth)
|
||||
.Select(g => new
|
||||
{
|
||||
Min = g.Min(t=> t.Flow),
|
||||
Avg = g.Average(t => t.Flow),
|
||||
Max = g.Max(t => t.Flow)
|
||||
})
|
||||
.AsNoTracking()
|
||||
.DefaultIfEmpty()
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return new DrillParamsDto()
|
||||
{
|
||||
IdWell = idWell,
|
||||
DepthStart = startDepth,
|
||||
DepthEnd = endDepth,
|
||||
AxialLoadMin = axialLoads.Min,
|
||||
AxialLoadAvg = axialLoads.Avg,
|
||||
AxialLoadMax = axialLoads.Max,
|
||||
PressureMin = pressures.Min,
|
||||
PressureAvg = pressures.Avg,
|
||||
PressureMax = pressures.Max,
|
||||
// TopDriveTorqueMin = topDriveTorques.Min ?? 0,
|
||||
// TopDriveTorqueAvg = topDriveTorques.Avg ?? 0,
|
||||
// TopDriveTorqueMax = topDriveTorques.Max ?? 0,
|
||||
// TopDriveSpeedMin = topDriveSpeeds.Min ?? 0,
|
||||
// TopDriveSpeedAvg = topDriveSpeeds.Avg ?? 0,
|
||||
// TopDriveSpeedMax = topDriveSpeeds.Max ?? 0,
|
||||
// ConsumptionMin = consumptions.Min ?? 0,
|
||||
// ConsumptionAvg = consumptions.Avg ?? 0,
|
||||
// ConsumptionMax = consumptions.Max ?? 0,
|
||||
IdWellSectionType = 0,
|
||||
AxialLoadMin = axialLoads.Min ?? 0,
|
||||
AxialLoadAvg = axialLoads.Avg ?? 0,
|
||||
AxialLoadMax = axialLoads.Max ?? 0,
|
||||
PressureMin = pressures.Min ?? 0,
|
||||
PressureAvg = pressures.Avg ?? 0,
|
||||
PressureMax = pressures.Max ?? 0,
|
||||
RotorTorqueMin = rotorTorques.Min ?? 0,
|
||||
RotorTorqueAvg = rotorTorques.Avg ?? 0,
|
||||
RotorTorqueMax = rotorTorques.Max ?? 0,
|
||||
RotorSpeedMin = rotorSpeeds.Min ?? 0,
|
||||
RotorSpeedAvg = rotorSpeeds.Avg ?? 0,
|
||||
RotorSpeedMax = rotorSpeeds.Max ?? 0,
|
||||
FlowMin = flows.Min ?? 0,
|
||||
FlowAvg = flows.Avg ?? 0,
|
||||
FlowMax = flows.Max ?? 0,
|
||||
};
|
||||
|
||||
return drillParamsDto;
|
||||
}
|
||||
|
||||
private async Task<(double Min, double Avg, double Max)> GetDrillParams(int idTelemetry,
|
||||
double startDepth, double endDepth, Func<TelemetryDataSaub, double?> func,
|
||||
CancellationToken token = default)
|
||||
private IQueryable<IGrouping<int, TelemetryDataSaub>> GetTelemetryGroupQuery(int idTelemetry,
|
||||
double startDepth, double endDepth)
|
||||
{
|
||||
var res = await (from telemetry in db.TelemetryDataSaub
|
||||
return from telemetry in db.TelemetryDataSaub
|
||||
where telemetry.IdTelemetry == idTelemetry &&
|
||||
telemetry.WellDepth >= startDepth &&
|
||||
telemetry.WellDepth <= endDepth
|
||||
group telemetry by telemetry.IdTelemetry into g
|
||||
select new { Min = g.Min(func), Avg = g.Average(func), Max = g.Max(func) })
|
||||
.DefaultIfEmpty()
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return (res.Min ?? 0, res.Avg ?? 0, res.Max ?? 0);
|
||||
group telemetry by telemetry.IdTelemetry;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// <returns> Значения по умолчанию для режимов бурения </returns>
|
||||
[HttpGet("idWell/autoParams")]
|
||||
[ProducesResponseType(typeof(DrillParamsDto), (int) System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetDefaultDrillParamsAsync(int idWell, double startDepth,
|
||||
double endDepth, CancellationToken token = default)
|
||||
public async Task<IActionResult> GetDefaultDrillParamsAsync(int idWell,
|
||||
double startDepth, double endDepth, CancellationToken token = default)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
|
||||
@ -50,7 +50,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает все значения для режимов бурения по секции на скважине
|
||||
/// Возвращает все значения для режимов бурения на скважине
|
||||
/// </summary>
|
||||
/// <param name="idWell"> id скважины </param>
|
||||
/// <param name="token"> Токен отмены задачи </param>
|
||||
|
Loading…
Reference in New Issue
Block a user