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