#5996638 Исправление замечаний

This commit is contained in:
ai.astrakhantsev 2022-09-20 09:47:54 +05:00
parent 2334beb971
commit c87acfdd59
4 changed files with 72 additions and 155 deletions

View File

@ -13,115 +13,35 @@ 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.
/// </summary>
public int IdWellSectionType { get; set; }
/// <summary>
/// axial load min.
/// </summary>
public double AxialLoadMin { get; set; }
/// <summary>
/// axial load avg.
/// </summary>
public double AxialLoadAvg { get; set; }
/// <summary>
/// axial load max.
/// </summary>
public double AxialLoadMax { get; set; }
/// <summary>
/// axial load
/// </summary>
public MinMaxExtendedViewDto AxialLoad { get; set; }
/// <summary>
/// pressure min.
/// </summary>
public double PressureMin { get; set; }
/// <summary>
/// pressure avg.
/// </summary>
public double PressureAvg { get; set; }
/// <summary>
/// pressure max.
/// </summary>
public double PressureMax { get; set; }
/// <summary>
/// pressure
/// </summary>
public MinMaxExtendedViewDto Pressure { 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 torque
/// </summary>
public MinMaxExtendedViewDto RotorTorque { 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>
/// rotor speed
/// </summary>
public MinMaxExtendedViewDto RotorSpeed { 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; }
/// <summary>
/// flow
/// </summary>

View File

@ -10,17 +10,17 @@ namespace AsbCloudApp.Data
/// <summary>
/// Минимальное и максимальное значение
/// </summary>
public class MinMaxDto
public class MinMaxDto<T>
{
/// <summary>
/// Минимальное значение
/// </summary>
public double Min { get; set; }
public T? Min { get; set; }
/// <summary>
/// максимальное значение
/// Максимальное значение
/// </summary>
public double Max { get; set; }
public T? Max { get; set; }
}
#nullable disable
}

View File

@ -10,7 +10,7 @@ namespace AsbCloudApp.Data
/// <summary>
/// Расширение для класса MinMaxDto
/// </summary>
public class MinMaxExtendedViewDto : MinMaxDto
public class MinMaxExtendedViewDto : MinMaxDto<double>
{
/// <summary>
/// Среднее значение

View File

@ -4,7 +4,6 @@ using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
using Mapster;
using Microsoft.EntityFrameworkCore;
using Org.BouncyCastle.Crypto;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -12,6 +11,7 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
#nullable enable
public class DrillParamsService : CrudServiceBase<DrillParamsDto, DrillParams>, IDrillParamsService
{
private readonly IAsbCloudDbContext db;
@ -40,28 +40,40 @@ 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);
@ -86,30 +98,26 @@ namespace AsbCloudInfrastructure.Services
public async Task<IEnumerable<DrillParamsDto>> GetCompositeAllAsync(int idWell,
CancellationToken token = default)
{
var allDrillParams =
await (from p in db.DrillParams
from c in db.WellComposites
where p.IdWell == c.IdWellSrc &&
p.IdWellSectionType == c.IdWellSectionType
select p)
.AsNoTracking()
.ToListAsync(token)
.ConfigureAwait(false);
var allDrillParams = await db.WellComposites
.Join(db.DrillParams,
c => new { IdWell = c.IdWellSrc, IdSection = c.IdWellSectionType },
p => new { IdWell = p.IdWell, IdSection = p.IdWellSectionType },
(c, p) => p)
.AsNoTracking()
.ToListAsync(token)
.ConfigureAwait(false);
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 compositeWellDrillParams = await 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)
.AsNoTracking()
.ToListAsync(token)
.ConfigureAwait(false);
var compositeDrillParamsDtos = compositeWellDrillParams.Adapt<IEnumerable<DrillParamsDto>>();
var result = compositeDrillParamsDtos.Select(x => Convert(x, allDrillParams));
var result = compositeWellDrillParams.Select(x => Convert(x, allDrillParams));
return result;
}
@ -156,39 +164,27 @@ namespace AsbCloudInfrastructure.Services
return result;
}
private static DrillParamsDto Convert(DrillParamsDto dto, IEnumerable<DrillParams> drillParams)
private static DrillParamsDto Convert(DrillParams entity, IEnumerable<DrillParams> drillParams)
{
return new DrillParamsDto
{
Id = dto.Id,
IdWellSectionType = dto.IdWellSectionType,
AxialLoad = GetMinMaxExtended(dto, drillParams.Select(x => (x.AxialLoadMin, x.AxialLoadMax))),
AxialLoadAvg = dto.AxialLoadAvg,
AxialLoadMax = dto.AxialLoadMax,
AxialLoadMin = dto.AxialLoadMin,
DepthEnd = dto.DepthEnd,
DepthStart = dto.DepthStart,
Flow = GetMinMaxExtended(dto, drillParams.Select(x => (x.FlowMin, x.FlowMax))),
FlowAvg = dto.FlowAvg,
FlowMax = dto.FlowMax,
FlowMin = dto.FlowMin,
IdWell = dto.IdWell,
Pressure = GetMinMaxExtended(dto, drillParams.Select(x => (x.PressureMin, x.PressureMax))),
PressureAvg = dto.PressureAvg,
PressureMax = dto.PressureMax,
PressureMin = dto.PressureMin,
RotorSpeed = GetMinMaxExtended(dto, drillParams.Select(x => (x.RotorSpeedMin, x.RotorSpeedMax))),
RotorSpeedAvg = dto.RotorSpeedAvg,
RotorSpeedMax = dto.RotorSpeedMax,
RotorSpeedMin = dto.RotorSpeedMin,
RotorTorque = GetMinMaxExtended(dto, drillParams.Select(x => (x.RotorTorqueMin, x.RotorTorqueMax))),
RotorTorqueAvg = dto.RotorTorqueAvg,
RotorTorqueMax = dto.RotorTorqueMax,
RotorTorqueMin = dto.RotorTorqueMin
Id = entity.Id,
IdWellSectionType = entity.IdWellSectionType,
AxialLoad = GetMinMaxExtended(entity, drillParams.Select(x => (x.AxialLoadMin, x.AxialLoadMax))),
Depth = new MinMaxDto<double>
{
Min = entity.DepthEnd,
Max = entity.DepthStart
},
Flow = GetMinMaxExtended(entity, drillParams.Select(x => (x.FlowMin, x.FlowMax))),
IdWell = entity.IdWell,
Pressure = GetMinMaxExtended(entity, drillParams.Select(x => (x.PressureMin, x.PressureMax))),
RotorSpeed = GetMinMaxExtended(entity, drillParams.Select(x => (x.RotorSpeedMin, x.RotorSpeedMax))),
RotorTorque = GetMinMaxExtended(entity, drillParams.Select(x => (x.RotorTorqueMin, x.RotorTorqueMax)))
};
}
private static MinMaxExtendedViewDto GetMinMaxExtended(DrillParamsDto x, IEnumerable<(double min, double max)> allDrillParams)
private static MinMaxExtendedViewDto GetMinMaxExtended(DrillParams x, IEnumerable<(double min, double max)> allDrillParams)
{
return new MinMaxExtendedViewDto
{
@ -200,4 +196,5 @@ namespace AsbCloudInfrastructure.Services
};
}
}
#nullable disable
}