forked from ddrilling/AsbCloudServer
Merge branch 'dev' into SubsystemsOperationTime
This commit is contained in:
commit
89bfea38d7
@ -1,5 +1,6 @@
|
|||||||
namespace AsbCloudApp.Data.DailyReport
|
namespace AsbCloudApp.Data.DailyReport
|
||||||
{
|
{
|
||||||
|
#nullable enable
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Блоки для формирования суточного рапорта
|
/// Блоки для формирования суточного рапорта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -35,4 +36,5 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public SignDto Sign { get; set; } = new();
|
public SignDto Sign { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,9 @@ namespace AsbCloudApp.Data
|
|||||||
public int IdWell { get; set; }
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ãëóáèíà íà÷àëà èíòåðâàëà äëÿ ýòèõ ïàðàìåòðîâ
|
/// Ãëóáèíà èíòåðâàëà
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double DepthStart { get; set; }
|
public MinMaxDto<double> Depth { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ãëóáèíà îêîí÷àíèÿ èíòåðâàëà äëÿ ýòèõ ïàðàìåòðîâ
|
|
||||||
/// </summary>
|
|
||||||
public double DepthEnd { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// id well section type.
|
/// id well section type.
|
||||||
@ -28,78 +23,28 @@ namespace AsbCloudApp.Data
|
|||||||
public int IdWellSectionType { get; set; }
|
public int IdWellSectionType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// axial load min.
|
/// axial load
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double AxialLoadMin { get; set; }
|
public MinMaxExtendedViewDto AxialLoad { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// axial load avg.
|
/// pressure
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double AxialLoadAvg { get; set; }
|
public MinMaxExtendedViewDto Pressure { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// axial load max.
|
/// rotor torque
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double AxialLoadMax { get; set; }
|
public MinMaxExtendedViewDto RotorTorque { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// pressure min.
|
/// rotor speed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double PressureMin { get; set; }
|
public MinMaxExtendedViewDto RotorSpeed { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// pressure avg.
|
/// flow
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double PressureAvg { get; set; }
|
public MinMaxExtendedViewDto Flow { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// pressure max.
|
|
||||||
/// </summary>
|
|
||||||
public double PressureMax { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// rotor torque min.
|
|
||||||
/// </summary>
|
|
||||||
public double RotorTorqueMin { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// rotor torque avg.
|
|
||||||
/// </summary>
|
|
||||||
public double RotorTorqueAvg { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// rotor torque max.
|
|
||||||
/// </summary>
|
|
||||||
public double RotorTorqueMax { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// rotor speed min.
|
|
||||||
/// </summary>
|
|
||||||
public double RotorSpeedMin { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// rotor speed avg.
|
|
||||||
/// </summary>
|
|
||||||
public double RotorSpeedAvg { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// rotor speed max.
|
|
||||||
/// </summary>
|
|
||||||
public double RotorSpeedMax { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// flow min.
|
|
||||||
/// </summary>
|
|
||||||
public double FlowMin { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// flow avg.
|
|
||||||
/// </summary>
|
|
||||||
public double FlowAvg { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// flow max.
|
|
||||||
/// </summary>
|
|
||||||
public double FlowMax { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
26
AsbCloudApp/Data/MinMaxDto.cs
Normal file
26
AsbCloudApp/Data/MinMaxDto.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Data
|
||||||
|
{
|
||||||
|
#nullable enable
|
||||||
|
/// <summary>
|
||||||
|
/// Минимальное и максимальное значение
|
||||||
|
/// </summary>
|
||||||
|
public class MinMaxDto<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Минимальное значение
|
||||||
|
/// </summary>
|
||||||
|
public T? Min { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Максимальное значение
|
||||||
|
/// </summary>
|
||||||
|
public T? Max { get; set; }
|
||||||
|
}
|
||||||
|
#nullable disable
|
||||||
|
}
|
31
AsbCloudApp/Data/MinMaxExtendedViewDto.cs
Normal file
31
AsbCloudApp/Data/MinMaxExtendedViewDto.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Data
|
||||||
|
{
|
||||||
|
#nullable enable
|
||||||
|
/// <summary>
|
||||||
|
/// Расширение для класса MinMaxDto
|
||||||
|
/// </summary>
|
||||||
|
public class MinMaxExtendedViewDto : MinMaxDto<double>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Среднее значение
|
||||||
|
/// </summary>
|
||||||
|
public double Avg { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Является максимальным
|
||||||
|
/// </summary>
|
||||||
|
public bool IsMax { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Является минимальным
|
||||||
|
/// </summary>
|
||||||
|
public bool IsMin { get; set; }
|
||||||
|
}
|
||||||
|
#nullable disable
|
||||||
|
}
|
@ -124,10 +124,26 @@ namespace AsbCloudInfrastructure.Services.DailyReport
|
|||||||
ClusterName = well?.Cluster ?? "",
|
ClusterName = well?.Cluster ?? "",
|
||||||
},
|
},
|
||||||
TimeBalance = await MakeTimeBalanceAsync(idWell, date, token),
|
TimeBalance = await MakeTimeBalanceAsync(idWell, date, token),
|
||||||
|
Bha = await GetPrevOrNewBhaAsync(idWell, date, token)
|
||||||
};
|
};
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<BhaDto> GetPrevOrNewBhaAsync(int idWell, DateTime date, CancellationToken token)
|
||||||
|
{
|
||||||
|
var dateOffset = date.Date;
|
||||||
|
var entity = await db.DailyReports
|
||||||
|
.Where(x => x.IdWell == idWell)
|
||||||
|
.OrderByDescending(x => x.StartDate)
|
||||||
|
.FirstOrDefaultAsync(r => r.StartDate <= dateOffset, token);
|
||||||
|
|
||||||
|
if (entity is null)
|
||||||
|
return new BhaDto();
|
||||||
|
|
||||||
|
var dto = Convert(entity);
|
||||||
|
return dto.Bha;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<TimeBalanceDto> MakeTimeBalanceAsync(int idWell, DateTime date, CancellationToken token)
|
private async Task<TimeBalanceDto> MakeTimeBalanceAsync(int idWell, DateTime date, CancellationToken token)
|
||||||
{
|
{
|
||||||
var stat = await detectedOperationService.GetOperationsStatAsync(new DetectedOperationRequest
|
var stat = await detectedOperationService.GetOperationsStatAsync(new DetectedOperationRequest
|
||||||
|
@ -11,6 +11,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
|
#nullable enable
|
||||||
public class DrillParamsService : CrudServiceBase<DrillParamsDto, DrillParams>, IDrillParamsService
|
public class DrillParamsService : CrudServiceBase<DrillParamsDto, DrillParams>, IDrillParamsService
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
@ -23,7 +24,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell,
|
public async Task<DrillParamsDto?> GetDefaultDrillParamsAsync(int idWell,
|
||||||
double startDepth, double endDepth, CancellationToken token = default)
|
double startDepth, double endDepth, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var idTelemetry = telemetryService.GetIdTelemetryByIdWell(idWell);
|
var idTelemetry = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||||
@ -39,28 +40,46 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
select new DrillParamsDto()
|
select new DrillParamsDto()
|
||||||
{
|
{
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
DepthStart = startDepth,
|
Depth = new MinMaxDto<double>
|
||||||
DepthEnd = endDepth,
|
{
|
||||||
|
Min = endDepth,
|
||||||
|
Max = startDepth
|
||||||
|
},
|
||||||
IdWellSectionType = 0,
|
IdWellSectionType = 0,
|
||||||
AxialLoadMin = g.Min(t => t.AxialLoad) ?? double.NaN,
|
AxialLoad = new MinMaxExtendedViewDto
|
||||||
AxialLoadAvg = g.Average(t => t.AxialLoad) ?? double.NaN,
|
{
|
||||||
AxialLoadMax = g.Max(t => t.AxialLoad) ?? double.NaN,
|
Min = g.Min(t => t.AxialLoad) ?? double.NaN,
|
||||||
PressureMin = g.Min(t => t.Pressure) ?? double.NaN,
|
Avg = g.Average(t => t.AxialLoad) ?? double.NaN,
|
||||||
PressureAvg = g.Average(t => t.Pressure) ?? double.NaN,
|
Max = g.Max(t => t.AxialLoad) ?? double.NaN
|
||||||
PressureMax = g.Max(t => t.Pressure) ?? double.NaN,
|
},
|
||||||
RotorTorqueMin = g.Min(t => t.RotorTorque) ?? double.NaN,
|
Pressure = new MinMaxExtendedViewDto
|
||||||
RotorTorqueAvg = g.Average(t => t.RotorTorque) ?? double.NaN,
|
{
|
||||||
RotorTorqueMax = g.Max(t => t.RotorTorque) ?? double.NaN,
|
Min = g.Min(t => t.Pressure) ?? double.NaN,
|
||||||
RotorSpeedMin = g.Min(t => t.RotorSpeed) ?? double.NaN,
|
Avg = g.Average(t => t.Pressure) ?? double.NaN,
|
||||||
RotorSpeedAvg = g.Average(t => t.RotorSpeed) ?? double.NaN,
|
Max = g.Max(t => t.Pressure) ?? double.NaN
|
||||||
RotorSpeedMax = g.Max(t => t.RotorSpeed) ?? double.NaN,
|
},
|
||||||
FlowMin = g.Min(t => t.Flow) ?? double.NaN,
|
RotorTorque = new MinMaxExtendedViewDto
|
||||||
FlowAvg = g.Min(t => t.Flow) ?? double.NaN,
|
{
|
||||||
FlowMax = g.Min(t => t.Flow) ?? double.NaN
|
Min = g.Min(t => t.RotorTorque) ?? double.NaN,
|
||||||
|
Avg = g.Average(t => t.RotorTorque) ?? double.NaN,
|
||||||
|
Max = g.Max(t => t.RotorTorque) ?? double.NaN
|
||||||
|
},
|
||||||
|
RotorSpeed = new MinMaxExtendedViewDto
|
||||||
|
{
|
||||||
|
Min = g.Min(t => t.RotorSpeed) ?? double.NaN,
|
||||||
|
Avg = g.Average(t => t.RotorSpeed) ?? double.NaN,
|
||||||
|
Max = g.Max(t => t.RotorSpeed) ?? double.NaN
|
||||||
|
},
|
||||||
|
Flow = new MinMaxExtendedViewDto
|
||||||
|
{
|
||||||
|
Min = g.Min(t => t.Flow) ?? double.NaN,
|
||||||
|
Avg = g.Min(t => t.Flow) ?? double.NaN,
|
||||||
|
Max = g.Min(t => t.Flow) ?? double.NaN
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.DefaultIfEmpty()
|
.DefaultIfEmpty()
|
||||||
.OrderBy(t => t.AxialLoadMin)
|
.OrderBy(t => t.AxialLoad.Min)
|
||||||
.FirstOrDefaultAsync(token)
|
.FirstOrDefaultAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
@ -70,35 +89,62 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public async Task<IEnumerable<DrillParamsDto>> GetAllAsync(int idWell,
|
public async Task<IEnumerable<DrillParamsDto>> GetAllAsync(int idWell,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var entities = await (from p in db.DrillParams
|
var entities = await db.DrillParams
|
||||||
where p.IdWell == idWell
|
.Where(p => p.IdWell == idWell)
|
||||||
orderby p.Id
|
.OrderBy(p=> p.Id)
|
||||||
select p)
|
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToListAsync(token)
|
.ToArrayAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
var dto = entities.Adapt<IEnumerable<DrillParamsDto>>();
|
var dtos = entities.Select(p =>
|
||||||
|
{
|
||||||
|
var dto = new DrillParamsDto
|
||||||
|
{
|
||||||
|
IdWell = p.IdWell,
|
||||||
|
Id = p.Id,
|
||||||
|
IdWellSectionType = p.IdWellSectionType,
|
||||||
|
Depth = new MinMaxDto<double> { Max = p.PressureMax, Min = p.PressureMin },
|
||||||
|
Pressure = MakeMinMaxExtended(p.PressureAvg, p.PressureMax, p.PressureMin),
|
||||||
|
AxialLoad = MakeMinMaxExtended(p.AxialLoadAvg, p.AxialLoadMax, p.AxialLoadMin),
|
||||||
|
Flow = MakeMinMaxExtended(p.FlowAvg, p.FlowMax, p.FlowMin),
|
||||||
|
RotorSpeed = MakeMinMaxExtended(p.RotorSpeedAvg, p.RotorSpeedMax, p.RotorSpeedMin),
|
||||||
|
RotorTorque = MakeMinMaxExtended(p.RotorTorqueAvg, p.RotorTorqueMax, p.RotorTorqueMin)
|
||||||
|
};
|
||||||
return dto;
|
return dto;
|
||||||
|
});
|
||||||
|
|
||||||
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<DrillParamsDto>> GetCompositeAllAsync(int idWell,
|
public async Task<IEnumerable<DrillParamsDto>> GetCompositeAllAsync(int idWell,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var compositeWellDrillParams =
|
var allDrillParamsQuery = db.WellComposites
|
||||||
await (from p in db.DrillParams
|
.Where(c => c.IdWell == idWell)
|
||||||
from c in db.WellComposites
|
.Join(db.DrillParams,
|
||||||
where c.IdWell == idWell &&
|
c => c.IdWellSrc,
|
||||||
p.IdWell == c.IdWellSrc &&
|
p => p.IdWell,
|
||||||
p.IdWellSectionType == c.IdWellSectionType
|
(c, p) => p);
|
||||||
select p)
|
|
||||||
|
var allDrillParams = await allDrillParamsQuery
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
var compositeDrillParamsDtos = compositeWellDrillParams.Adapt<IEnumerable<DrillParamsDto>>();
|
var compositeWellDrillParamsQuery = db.WellComposites
|
||||||
|
.Where(c => c.IdWell == idWell)
|
||||||
|
.Join(db.DrillParams,
|
||||||
|
c => new { IdWell = c.IdWellSrc, IdSection = c.IdWellSectionType },
|
||||||
|
p => new { IdWell = p.IdWell, IdSection = p.IdWellSectionType },
|
||||||
|
(c, p) => p);
|
||||||
|
|
||||||
return compositeDrillParamsDtos;
|
var compositeWellDrillParams = await compositeWellDrillParamsQuery
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToListAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
var result = compositeWellDrillParams.Select(x => Convert(x, allDrillParams));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> InsertAsync(int idWell, DrillParamsDto dto,
|
public async Task<int> InsertAsync(int idWell, DrillParamsDto dto,
|
||||||
@ -143,5 +189,34 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var result = await base.UpdateAsync(dto, token).ConfigureAwait(false);
|
var result = await base.UpdateAsync(dto, token).ConfigureAwait(false);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static DrillParamsDto Convert(DrillParams entity, IEnumerable<DrillParams> drillParams)
|
||||||
|
{
|
||||||
|
return new DrillParamsDto
|
||||||
|
{
|
||||||
|
Id = entity.Id,
|
||||||
|
IdWellSectionType = entity.IdWellSectionType,
|
||||||
|
AxialLoad = MakeMinMaxExtended(entity.AxialLoadAvg, entity.AxialLoadMax, entity.AxialLoadMin, drillParams.Select(x => (x.AxialLoadMin, x.AxialLoadMax))),
|
||||||
|
Depth = new MinMaxDto<double> {
|
||||||
|
Min = entity.DepthEnd,
|
||||||
|
Max = entity.DepthStart
|
||||||
|
},
|
||||||
|
Flow = MakeMinMaxExtended(entity.FlowAvg, entity.FlowMax, entity.FlowMin, drillParams.Select(x => (x.FlowMin, x.FlowMax))),
|
||||||
|
IdWell = entity.IdWell,
|
||||||
|
Pressure = MakeMinMaxExtended(entity.PressureAvg, entity.PressureMax, entity.PressureMin, drillParams.Select(x => (x.PressureMin, x.PressureMax))),
|
||||||
|
RotorSpeed = MakeMinMaxExtended(entity.RotorSpeedAvg, entity.RotorSpeedMax, entity.RotorSpeedMin, drillParams.Select(x => (x.RotorSpeedMin, x.RotorSpeedMax))),
|
||||||
|
RotorTorque = MakeMinMaxExtended(entity.RotorTorqueAvg, entity.RotorTorqueMax, entity.RotorTorqueMin, drillParams.Select(x => (x.RotorTorqueMin, x.RotorTorqueMax)))
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static MinMaxExtendedViewDto MakeMinMaxExtended(double avg, double max, double min, IEnumerable<(double min, double max)>? allDrillParams = null)
|
||||||
|
=> new MinMaxExtendedViewDto {
|
||||||
|
Avg = avg,
|
||||||
|
Max = max,
|
||||||
|
Min = min,
|
||||||
|
IsMax = allDrillParams?.Any(mx => mx.max > max) ?? false,
|
||||||
|
IsMin = allDrillParams?.Any(mn => mn.min < min) ?? false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user