diff --git a/AsbCloudApp/Data/DrillParamsDto.cs b/AsbCloudApp/Data/DrillParamsDto.cs
index 76a39b71..d79f2451 100644
--- a/AsbCloudApp/Data/DrillParamsDto.cs
+++ b/AsbCloudApp/Data/DrillParamsDto.cs
@@ -13,115 +13,35 @@ namespace AsbCloudApp.Data
public int IdWell { get; set; }
///
- ///
+ ///
///
- public double DepthStart { get; set; }
-
- ///
- ///
- ///
- public double DepthEnd { get; set; }
+ public MinMaxDto Depth { get; set; }
///
/// id well section type.
///
public int IdWellSectionType { get; set; }
- ///
- /// axial load min.
- ///
- public double AxialLoadMin { get; set; }
-
- ///
- /// axial load avg.
- ///
- public double AxialLoadAvg { get; set; }
-
- ///
- /// axial load max.
- ///
- public double AxialLoadMax { get; set; }
-
///
/// axial load
///
public MinMaxExtendedViewDto AxialLoad { get; set; }
- ///
- /// pressure min.
- ///
- public double PressureMin { get; set; }
-
- ///
- /// pressure avg.
- ///
- public double PressureAvg { get; set; }
-
- ///
- /// pressure max.
- ///
- public double PressureMax { get; set; }
-
///
/// pressure
///
public MinMaxExtendedViewDto Pressure { get; set; }
- ///
- /// rotor torque min.
- ///
- public double RotorTorqueMin { get; set; }
-
- ///
- /// rotor torque avg.
- ///
- public double RotorTorqueAvg { get; set; }
-
- ///
- /// rotor torque max.
- ///
- public double RotorTorqueMax { get; set; }
-
///
/// rotor torque
///
public MinMaxExtendedViewDto RotorTorque { get; set; }
- ///
- /// rotor speed min.
- ///
- public double RotorSpeedMin { get; set; }
-
- ///
- /// rotor speed avg.
- ///
- public double RotorSpeedAvg { get; set; }
-
- ///
- /// rotor speed max.
- ///
- public double RotorSpeedMax { get; set; }
-
///
/// rotor speed
///
public MinMaxExtendedViewDto RotorSpeed { get; set; }
- ///
- /// flow min.
- ///
- public double FlowMin { get; set; }
-
- ///
- /// flow avg.
- ///
- public double FlowAvg { get; set; }
-
- ///
- /// flow max.
- ///
- public double FlowMax { get; set; }
-
///
/// flow
///
diff --git a/AsbCloudApp/Data/MinMaxDto.cs b/AsbCloudApp/Data/MinMaxDto.cs
index 59ba90b0..291574bc 100644
--- a/AsbCloudApp/Data/MinMaxDto.cs
+++ b/AsbCloudApp/Data/MinMaxDto.cs
@@ -10,17 +10,17 @@ namespace AsbCloudApp.Data
///
/// Минимальное и максимальное значение
///
- public class MinMaxDto
+ public class MinMaxDto
{
///
/// Минимальное значение
///
- public double Min { get; set; }
+ public T? Min { get; set; }
///
- /// максимальное значение
+ /// Максимальное значение
///
- public double Max { get; set; }
+ public T? Max { get; set; }
}
#nullable disable
}
diff --git a/AsbCloudApp/Data/MinMaxExtendedViewDto.cs b/AsbCloudApp/Data/MinMaxExtendedViewDto.cs
index f3e91b88..cb66e60d 100644
--- a/AsbCloudApp/Data/MinMaxExtendedViewDto.cs
+++ b/AsbCloudApp/Data/MinMaxExtendedViewDto.cs
@@ -10,7 +10,7 @@ namespace AsbCloudApp.Data
///
/// Расширение для класса MinMaxDto
///
- public class MinMaxExtendedViewDto : MinMaxDto
+ public class MinMaxExtendedViewDto : MinMaxDto
{
///
/// Среднее значение
diff --git a/AsbCloudInfrastructure/Services/DrillParamsService.cs b/AsbCloudInfrastructure/Services/DrillParamsService.cs
index 5eb813c8..d0f914d1 100644
--- a/AsbCloudInfrastructure/Services/DrillParamsService.cs
+++ b/AsbCloudInfrastructure/Services/DrillParamsService.cs
@@ -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, IDrillParamsService
{
private readonly IAsbCloudDbContext db;
@@ -40,28 +40,40 @@ namespace AsbCloudInfrastructure.Services
select new DrillParamsDto()
{
IdWell = idWell,
- DepthStart = startDepth,
- DepthEnd = endDepth,
+ Depth = new MinMaxDto {
+ 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> 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>();
-
- 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)
+ private static DrillParamsDto Convert(DrillParams entity, IEnumerable 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
+ {
+ 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
}