2021-10-12 11:30:07 +05:00
|
|
|
|
using System.Linq;
|
2021-10-11 15:21:26 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
2021-10-11 16:43:10 +05:00
|
|
|
|
public class DrillParamsService : CrudServiceBase<DrillParamsDto, DrillParams>, IDrillParamsService
|
2021-10-11 15:21:26 +05:00
|
|
|
|
{
|
|
|
|
|
private readonly IAsbCloudDbContext db;
|
|
|
|
|
private readonly ITelemetryService telemetryService;
|
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
public DrillParamsService(IAsbCloudDbContext context, ITelemetryService telemetryService)
|
|
|
|
|
: base(context)
|
2021-10-11 15:21:26 +05:00
|
|
|
|
{
|
2021-10-12 11:30:07 +05:00
|
|
|
|
this.db = context;
|
2021-10-11 15:21:26 +05:00
|
|
|
|
this.telemetryService = telemetryService;
|
|
|
|
|
}
|
2021-10-12 11:30:07 +05:00
|
|
|
|
public async Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell,
|
|
|
|
|
double startDepth, double endDepth, CancellationToken token = default)
|
2021-10-11 15:21:26 +05:00
|
|
|
|
{
|
|
|
|
|
var idTelemetry = telemetryService.GetIdTelemetryByIdWell(idWell);
|
|
|
|
|
|
|
|
|
|
if (idTelemetry is null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2021-10-12 11:30:07 +05:00
|
|
|
|
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);
|
2021-10-11 15:21:26 +05:00
|
|
|
|
|
2021-10-12 11:30:07 +05:00
|
|
|
|
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 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);
|
2021-10-11 15:21:26 +05:00
|
|
|
|
|
2021-10-12 11:30:07 +05:00
|
|
|
|
return new DrillParamsDto()
|
2021-10-11 15:21:26 +05:00
|
|
|
|
{
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
DepthStart = startDepth,
|
|
|
|
|
DepthEnd = endDepth,
|
2021-10-12 11:30:07 +05:00
|
|
|
|
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,
|
2021-10-11 15:21:26 +05:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 11:30:07 +05:00
|
|
|
|
private IQueryable<IGrouping<int, TelemetryDataSaub>> GetTelemetryGroupQuery(int idTelemetry,
|
|
|
|
|
double startDepth, double endDepth)
|
2021-10-11 15:21:26 +05:00
|
|
|
|
{
|
2021-10-12 11:30:07 +05:00
|
|
|
|
return from telemetry in db.TelemetryDataSaub
|
|
|
|
|
where telemetry.IdTelemetry == idTelemetry &&
|
|
|
|
|
telemetry.WellDepth >= startDepth &&
|
|
|
|
|
telemetry.WellDepth <= endDepth
|
|
|
|
|
group telemetry by telemetry.IdTelemetry;
|
2021-10-11 15:21:26 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|