#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; } 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.
/// </summary> /// </summary>
public int IdWellSectionType { get; set; } 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> /// <summary>
/// axial load /// axial load
/// </summary> /// </summary>
public MinMaxExtendedViewDto AxialLoad { get; set; } 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> /// <summary>
/// pressure /// pressure
/// </summary> /// </summary>
public MinMaxExtendedViewDto Pressure { get; set; } 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> /// <summary>
/// rotor torque /// rotor torque
/// </summary> /// </summary>
public MinMaxExtendedViewDto RotorTorque { get; set; } 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> /// <summary>
/// rotor speed /// rotor speed
/// </summary> /// </summary>
public MinMaxExtendedViewDto RotorSpeed { get; set; } 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> /// <summary>
/// flow /// flow
/// </summary> /// </summary>

View File

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

View File

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

View File

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