forked from ddrilling/AsbCloudServer
Merge branch 'dev' into SubsystemsOperationTime
This commit is contained in:
commit
89bfea38d7
@ -1,5 +1,6 @@
|
||||
namespace AsbCloudApp.Data.DailyReport
|
||||
{
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// Блоки для формирования суточного рапорта
|
||||
/// </summary>
|
||||
@ -35,4 +36,5 @@
|
||||
/// </summary>
|
||||
public SignDto Sign { get; set; } = new();
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -13,14 +13,9 @@ namespace AsbCloudApp.Data
|
||||
public int IdWell { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ãëóáèíà íà÷àëà èíòåðâàëà äëÿ ýòèõ ïàðàìåòðîâ
|
||||
/// Ãëóáèíà èíòåðâàëà
|
||||
/// </summary>
|
||||
public double DepthStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ãëóáèíà îêîí÷àíèÿ èíòåðâàëà äëÿ ýòèõ ïàðàìåòðîâ
|
||||
/// </summary>
|
||||
public double DepthEnd { get; set; }
|
||||
public MinMaxDto<double> Depth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// id well section type.
|
||||
@ -28,78 +23,28 @@ namespace AsbCloudApp.Data
|
||||
public int IdWellSectionType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// axial load min.
|
||||
/// axial load
|
||||
/// </summary>
|
||||
public double AxialLoadMin { get; set; }
|
||||
public MinMaxExtendedViewDto AxialLoad { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// axial load avg.
|
||||
/// pressure
|
||||
/// </summary>
|
||||
public double AxialLoadAvg { get; set; }
|
||||
public MinMaxExtendedViewDto Pressure { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// axial load max.
|
||||
/// rotor torque
|
||||
/// </summary>
|
||||
public double AxialLoadMax { get; set; }
|
||||
public MinMaxExtendedViewDto RotorTorque { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// pressure min.
|
||||
/// rotor speed
|
||||
/// </summary>
|
||||
public double PressureMin { get; set; }
|
||||
public MinMaxExtendedViewDto RotorSpeed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// pressure avg.
|
||||
/// flow
|
||||
/// </summary>
|
||||
public double PressureAvg { 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; }
|
||||
public MinMaxExtendedViewDto Flow { 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 ?? "",
|
||||
},
|
||||
TimeBalance = await MakeTimeBalanceAsync(idWell, date, token),
|
||||
Bha = await GetPrevOrNewBhaAsync(idWell, date, token)
|
||||
};
|
||||
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)
|
||||
{
|
||||
var stat = await detectedOperationService.GetOperationsStatAsync(new DetectedOperationRequest
|
||||
|
@ -11,6 +11,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
#nullable enable
|
||||
public class DrillParamsService : CrudServiceBase<DrillParamsDto, DrillParams>, IDrillParamsService
|
||||
{
|
||||
private readonly IAsbCloudDbContext db;
|
||||
@ -23,7 +24,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
|
||||
public async Task<DrillParamsDto> GetDefaultDrillParamsAsync(int idWell,
|
||||
public async Task<DrillParamsDto?> GetDefaultDrillParamsAsync(int idWell,
|
||||
double startDepth, double endDepth, CancellationToken token = default)
|
||||
{
|
||||
var idTelemetry = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||
@ -39,28 +40,46 @@ namespace AsbCloudInfrastructure.Services
|
||||
select new DrillParamsDto()
|
||||
{
|
||||
IdWell = idWell,
|
||||
DepthStart = startDepth,
|
||||
DepthEnd = endDepth,
|
||||
Depth = new MinMaxDto<double>
|
||||
{
|
||||
Min = endDepth,
|
||||
Max = startDepth
|
||||
},
|
||||
IdWellSectionType = 0,
|
||||
AxialLoadMin = g.Min(t => t.AxialLoad) ?? double.NaN,
|
||||
AxialLoadAvg = g.Average(t => t.AxialLoad) ?? double.NaN,
|
||||
AxialLoadMax = g.Max(t => t.AxialLoad) ?? double.NaN,
|
||||
PressureMin = g.Min(t => t.Pressure) ?? double.NaN,
|
||||
PressureAvg = g.Average(t => t.Pressure) ?? double.NaN,
|
||||
PressureMax = g.Max(t => t.Pressure) ?? double.NaN,
|
||||
RotorTorqueMin = g.Min(t => t.RotorTorque) ?? double.NaN,
|
||||
RotorTorqueAvg = g.Average(t => t.RotorTorque) ?? double.NaN,
|
||||
RotorTorqueMax = g.Max(t => t.RotorTorque) ?? double.NaN,
|
||||
RotorSpeedMin = g.Min(t => t.RotorSpeed) ?? double.NaN,
|
||||
RotorSpeedAvg = g.Average(t => t.RotorSpeed) ?? double.NaN,
|
||||
RotorSpeedMax = g.Max(t => t.RotorSpeed) ?? double.NaN,
|
||||
FlowMin = g.Min(t => t.Flow) ?? double.NaN,
|
||||
FlowAvg = g.Min(t => t.Flow) ?? double.NaN,
|
||||
FlowMax = g.Min(t => t.Flow) ?? double.NaN
|
||||
AxialLoad = new MinMaxExtendedViewDto
|
||||
{
|
||||
Min = g.Min(t => t.AxialLoad) ?? double.NaN,
|
||||
Avg = g.Average(t => t.AxialLoad) ?? double.NaN,
|
||||
Max = g.Max(t => t.AxialLoad) ?? double.NaN
|
||||
},
|
||||
Pressure = new MinMaxExtendedViewDto
|
||||
{
|
||||
Min = g.Min(t => t.Pressure) ?? double.NaN,
|
||||
Avg = g.Average(t => t.Pressure) ?? double.NaN,
|
||||
Max = g.Max(t => t.Pressure) ?? double.NaN
|
||||
},
|
||||
RotorTorque = new MinMaxExtendedViewDto
|
||||
{
|
||||
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()
|
||||
.DefaultIfEmpty()
|
||||
.OrderBy(t => t.AxialLoadMin)
|
||||
.OrderBy(t => t.AxialLoad.Min)
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
@ -70,35 +89,62 @@ namespace AsbCloudInfrastructure.Services
|
||||
public async Task<IEnumerable<DrillParamsDto>> GetAllAsync(int idWell,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var entities = await (from p in db.DrillParams
|
||||
where p.IdWell == idWell
|
||||
orderby p.Id
|
||||
select p)
|
||||
.AsNoTracking()
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
var entities = await db.DrillParams
|
||||
.Where(p => p.IdWell == idWell)
|
||||
.OrderBy(p=> p.Id)
|
||||
.AsNoTracking()
|
||||
.ToArrayAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var dto = entities.Adapt<IEnumerable<DrillParamsDto>>();
|
||||
return dto;
|
||||
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 dtos;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<DrillParamsDto>> GetCompositeAllAsync(int idWell,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var compositeWellDrillParams =
|
||||
await (from p in db.DrillParams
|
||||
from c in db.WellComposites
|
||||
where c.IdWell == idWell &&
|
||||
p.IdWell == c.IdWellSrc &&
|
||||
p.IdWellSectionType == c.IdWellSectionType
|
||||
select p)
|
||||
.AsNoTracking()
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
var allDrillParamsQuery = db.WellComposites
|
||||
.Where(c => c.IdWell == idWell)
|
||||
.Join(db.DrillParams,
|
||||
c => c.IdWellSrc,
|
||||
p => p.IdWell,
|
||||
(c, p) => p);
|
||||
|
||||
var compositeDrillParamsDtos = compositeWellDrillParams.Adapt<IEnumerable<DrillParamsDto>>();
|
||||
var allDrillParams = await allDrillParamsQuery
|
||||
.AsNoTracking()
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return compositeDrillParamsDtos;
|
||||
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);
|
||||
|
||||
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,
|
||||
@ -143,5 +189,34 @@ namespace AsbCloudInfrastructure.Services
|
||||
var result = await base.UpdateAsync(dto, token).ConfigureAwait(false);
|
||||
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