From 2334beb9714f42167b2b9d7993f80272c5e78bca Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Mon, 19 Sep 2022 15:55:53 +0500 Subject: [PATCH 1/7] =?UTF-8?q?#5996638=20=D0=9F=D0=BE=D0=B4=D1=81=D0=B2?= =?UTF-8?q?=D0=B5=D1=87=D0=B8=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=BE=D0=BF=D1=82=D0=B8=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5=20=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/DrillParamsDto.cs | 25 ++++++++ AsbCloudApp/Data/MinMaxDto.cs | 26 +++++++++ AsbCloudApp/Data/MinMaxExtendedViewDto.cs | 31 ++++++++++ .../Services/DrillParamsService.cs | 58 ++++++++++++++++++- 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 AsbCloudApp/Data/MinMaxDto.cs create mode 100644 AsbCloudApp/Data/MinMaxExtendedViewDto.cs diff --git a/AsbCloudApp/Data/DrillParamsDto.cs b/AsbCloudApp/Data/DrillParamsDto.cs index 0d667a58..76a39b71 100644 --- a/AsbCloudApp/Data/DrillParamsDto.cs +++ b/AsbCloudApp/Data/DrillParamsDto.cs @@ -42,6 +42,11 @@ namespace AsbCloudApp.Data /// public double AxialLoadMax { get; set; } + /// + /// axial load + /// + public MinMaxExtendedViewDto AxialLoad { get; set; } + /// /// pressure min. /// @@ -57,6 +62,11 @@ namespace AsbCloudApp.Data /// public double PressureMax { get; set; } + /// + /// pressure + /// + public MinMaxExtendedViewDto Pressure { get; set; } + /// /// rotor torque min. /// @@ -72,6 +82,11 @@ namespace AsbCloudApp.Data /// public double RotorTorqueMax { get; set; } + /// + /// rotor torque + /// + public MinMaxExtendedViewDto RotorTorque { get; set; } + /// /// rotor speed min. /// @@ -87,6 +102,11 @@ namespace AsbCloudApp.Data /// public double RotorSpeedMax { get; set; } + /// + /// rotor speed + /// + public MinMaxExtendedViewDto RotorSpeed { get; set; } + /// /// flow min. /// @@ -101,5 +121,10 @@ namespace AsbCloudApp.Data /// flow max. /// public double FlowMax { get; set; } + + /// + /// flow + /// + public MinMaxExtendedViewDto Flow { get; set; } } } \ No newline at end of file diff --git a/AsbCloudApp/Data/MinMaxDto.cs b/AsbCloudApp/Data/MinMaxDto.cs new file mode 100644 index 00000000..59ba90b0 --- /dev/null +++ b/AsbCloudApp/Data/MinMaxDto.cs @@ -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 + /// + /// Минимальное и максимальное значение + /// + public class MinMaxDto + { + /// + /// Минимальное значение + /// + public double Min { get; set; } + + /// + /// максимальное значение + /// + public double Max { get; set; } + } +#nullable disable +} diff --git a/AsbCloudApp/Data/MinMaxExtendedViewDto.cs b/AsbCloudApp/Data/MinMaxExtendedViewDto.cs new file mode 100644 index 00000000..f3e91b88 --- /dev/null +++ b/AsbCloudApp/Data/MinMaxExtendedViewDto.cs @@ -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 + /// + /// Расширение для класса MinMaxDto + /// + public class MinMaxExtendedViewDto : MinMaxDto + { + /// + /// Среднее значение + /// + public double Avg { get; set; } + + /// + /// Является максимальным + /// + public bool IsMax { get; set; } + + /// + /// Является минимальным + /// + public bool IsMin { get; set; } + } +#nullable disable +} diff --git a/AsbCloudInfrastructure/Services/DrillParamsService.cs b/AsbCloudInfrastructure/Services/DrillParamsService.cs index 1af54956..5eb813c8 100644 --- a/AsbCloudInfrastructure/Services/DrillParamsService.cs +++ b/AsbCloudInfrastructure/Services/DrillParamsService.cs @@ -4,6 +4,7 @@ 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; @@ -85,6 +86,16 @@ 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 compositeWellDrillParams = await (from p in db.DrillParams from c in db.WellComposites @@ -98,7 +109,8 @@ namespace AsbCloudInfrastructure.Services var compositeDrillParamsDtos = compositeWellDrillParams.Adapt>(); - return compositeDrillParamsDtos; + var result = compositeDrillParamsDtos.Select(x => Convert(x, allDrillParams)); + return result; } public async Task InsertAsync(int idWell, DrillParamsDto dto, @@ -143,5 +155,49 @@ namespace AsbCloudInfrastructure.Services var result = await base.UpdateAsync(dto, token).ConfigureAwait(false); return result; } + + private static DrillParamsDto Convert(DrillParamsDto dto, 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 + }; + } + + private static MinMaxExtendedViewDto GetMinMaxExtended(DrillParamsDto x, IEnumerable<(double min, double max)> allDrillParams) + { + return new MinMaxExtendedViewDto + { + Avg = x.AxialLoadAvg, + Max = x.AxialLoadMax, + Min = x.AxialLoadMin, + IsMax = allDrillParams.Max(mx => mx.max) < x.AxialLoadMax, + IsMin = allDrillParams.Min(mn => mn.min) > x.AxialLoadMin + }; + } } } From c87acfdd59ab162392f2eb7a9a3800000f79948e Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 20 Sep 2022 09:47:54 +0500 Subject: [PATCH 2/7] =?UTF-8?q?#5996638=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=87=D0=B0=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/DrillParamsDto.cs | 84 +---------- AsbCloudApp/Data/MinMaxDto.cs | 8 +- AsbCloudApp/Data/MinMaxExtendedViewDto.cs | 2 +- .../Services/DrillParamsService.cs | 133 +++++++++--------- 4 files changed, 72 insertions(+), 155 deletions(-) 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 } From 07eb1bd8784b46ceb1500eea0da46b6884619f3d Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Tue, 20 Sep 2022 10:52:57 +0500 Subject: [PATCH 3/7] =?UTF-8?q?#5996638=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=87=D0=B0=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/DrillParamsService.cs | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DrillParamsService.cs b/AsbCloudInfrastructure/Services/DrillParamsService.cs index d0f914d1..6dfc40f2 100644 --- a/AsbCloudInfrastructure/Services/DrillParamsService.cs +++ b/AsbCloudInfrastructure/Services/DrillParamsService.cs @@ -24,7 +24,7 @@ namespace AsbCloudInfrastructure.Services this.telemetryService = telemetryService; } - public async Task GetDefaultDrillParamsAsync(int idWell, + public async Task GetDefaultDrillParamsAsync(int idWell, double startDepth, double endDepth, CancellationToken token = default) { var idTelemetry = telemetryService.GetIdTelemetryByIdWell(idWell); @@ -40,32 +40,38 @@ namespace AsbCloudInfrastructure.Services select new DrillParamsDto() { IdWell = idWell, - Depth = new MinMaxDto { + Depth = new MinMaxDto + { Min = endDepth, Max = startDepth }, IdWellSectionType = 0, - AxialLoad = new MinMaxExtendedViewDto { + 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 { + 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 { + 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 { + 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 { + 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 @@ -170,31 +176,27 @@ namespace AsbCloudInfrastructure.Services { Id = entity.Id, IdWellSectionType = entity.IdWellSectionType, - AxialLoad = GetMinMaxExtended(entity, drillParams.Select(x => (x.AxialLoadMin, x.AxialLoadMax))), - Depth = new MinMaxDto - { + AxialLoad = GetMinMaxExtended(entity.AxialLoadAvg, entity.AxialLoadMax, entity.AxialLoadMin, 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))), + Flow = GetMinMaxExtended(entity.FlowAvg, entity.FlowMax, entity.FlowMin, 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))) + Pressure = GetMinMaxExtended(entity.PressureAvg, entity.PressureMax, entity.PressureMin, drillParams.Select(x => (x.PressureMin, x.PressureMax))), + RotorSpeed = GetMinMaxExtended(entity.RotorSpeedAvg, entity.RotorSpeedMax, entity.RotorSpeedMin, drillParams.Select(x => (x.RotorSpeedMin, x.RotorSpeedMax))), + RotorTorque = GetMinMaxExtended(entity.RotorTorqueAvg, entity.RotorTorqueMax, entity.RotorTorqueMin, drillParams.Select(x => (x.RotorTorqueMin, x.RotorTorqueMax))) }; } - private static MinMaxExtendedViewDto GetMinMaxExtended(DrillParams x, IEnumerable<(double min, double max)> allDrillParams) - { - return new MinMaxExtendedViewDto - { - Avg = x.AxialLoadAvg, - Max = x.AxialLoadMax, - Min = x.AxialLoadMin, - IsMax = allDrillParams.Max(mx => mx.max) < x.AxialLoadMax, - IsMin = allDrillParams.Min(mn => mn.min) > x.AxialLoadMin - }; - } + private static MinMaxExtendedViewDto GetMinMaxExtended(double avg, double max, double min, IEnumerable<(double min, double max)> allDrillParams) + => new MinMaxExtendedViewDto { + Avg = avg, + Max = max, + Min = min, + IsMax = allDrillParams.Any(mx => mx.max > max), + IsMin = allDrillParams.Any(mn => mn.min < min) + }; } #nullable disable } From ed5f181754d1c9dc87fd529a6bdccac0e8c23c80 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Tue, 20 Sep 2022 12:29:55 +0500 Subject: [PATCH 4/7] =?UTF-8?q?#5996638=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D0=B0=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=20=D0=B1=D1=83=D1=80=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D1=81=D0=B5=D1=85=20=D1=81=D0=B5?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D0=B9=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=B7?= =?UTF-8?q?=D0=B8=D1=82=D0=BD=D0=BE=D0=B9=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6?= =?UTF-8?q?=D0=B8=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/DrillParamsService.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DrillParamsService.cs b/AsbCloudInfrastructure/Services/DrillParamsService.cs index 6dfc40f2..bc488e6e 100644 --- a/AsbCloudInfrastructure/Services/DrillParamsService.cs +++ b/AsbCloudInfrastructure/Services/DrillParamsService.cs @@ -104,21 +104,26 @@ namespace AsbCloudInfrastructure.Services public async Task> GetCompositeAllAsync(int idWell, CancellationToken token = default) { - var allDrillParams = await db.WellComposites + var allDrillParamsQuery = 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) + c => c.IdWellSrc, + p => p.IdWell, + (c, p) => p); + + var allDrillParams = await allDrillParamsQuery .AsNoTracking() .ToListAsync(token) .ConfigureAwait(false); - var compositeWellDrillParams = await db.WellComposites + 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) + (c, p) => p); + + var compositeWellDrillParams = await compositeWellDrillParamsQuery .AsNoTracking() .ToListAsync(token) .ConfigureAwait(false); From df5c98838d80247eb170662a86d98140880585b2 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Tue, 20 Sep 2022 15:09:01 +0500 Subject: [PATCH 5/7] Fix DrillParamsService.GetAllAsync(..) --- .../Services/DrillParamsService.cs | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DrillParamsService.cs b/AsbCloudInfrastructure/Services/DrillParamsService.cs index bc488e6e..a081bdd9 100644 --- a/AsbCloudInfrastructure/Services/DrillParamsService.cs +++ b/AsbCloudInfrastructure/Services/DrillParamsService.cs @@ -89,16 +89,31 @@ namespace AsbCloudInfrastructure.Services public async Task> 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>(); - return dto; + var dtos = entities.Select(p => + { + var dto = new DrillParamsDto + { + IdWell = p.IdWell, + Id = p.Id, + IdWellSectionType = p.IdWellSectionType, + Depth = new MinMaxDto { 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> GetCompositeAllAsync(int idWell, @@ -181,27 +196,27 @@ namespace AsbCloudInfrastructure.Services { Id = entity.Id, IdWellSectionType = entity.IdWellSectionType, - AxialLoad = GetMinMaxExtended(entity.AxialLoadAvg, entity.AxialLoadMax, entity.AxialLoadMin, drillParams.Select(x => (x.AxialLoadMin, x.AxialLoadMax))), + AxialLoad = MakeMinMaxExtended(entity.AxialLoadAvg, entity.AxialLoadMax, entity.AxialLoadMin, drillParams.Select(x => (x.AxialLoadMin, x.AxialLoadMax))), Depth = new MinMaxDto { Min = entity.DepthEnd, Max = entity.DepthStart }, - Flow = GetMinMaxExtended(entity.FlowAvg, entity.FlowMax, entity.FlowMin, drillParams.Select(x => (x.FlowMin, x.FlowMax))), + Flow = MakeMinMaxExtended(entity.FlowAvg, entity.FlowMax, entity.FlowMin, drillParams.Select(x => (x.FlowMin, x.FlowMax))), IdWell = entity.IdWell, - Pressure = GetMinMaxExtended(entity.PressureAvg, entity.PressureMax, entity.PressureMin, drillParams.Select(x => (x.PressureMin, x.PressureMax))), - RotorSpeed = GetMinMaxExtended(entity.RotorSpeedAvg, entity.RotorSpeedMax, entity.RotorSpeedMin, drillParams.Select(x => (x.RotorSpeedMin, x.RotorSpeedMax))), - RotorTorque = GetMinMaxExtended(entity.RotorTorqueAvg, entity.RotorTorqueMax, entity.RotorTorqueMin, drillParams.Select(x => (x.RotorTorqueMin, x.RotorTorqueMax))) + 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 GetMinMaxExtended(double avg, double max, double min, IEnumerable<(double min, double max)> allDrillParams) + 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), - IsMin = allDrillParams.Any(mn => mn.min < min) - }; + IsMax = allDrillParams?.Any(mx => mx.max > max) ?? false, + IsMin = allDrillParams?.Any(mn => mn.min < min) ?? false + }; } #nullable disable } From 67e4913c846237c47f7a707df4ce9d682e152055 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Wed, 21 Sep 2022 09:41:01 +0500 Subject: [PATCH 6/7] =?UTF-8?q?#5908066=20=D0=A1=D1=83=D1=82=D0=BE=D1=87?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D1=80=D0=B0=D0=BF=D0=BE=D1=80=D1=82.=20?= =?UTF-8?q?=D0=91=D0=BB=D0=BE=D0=BA=20=D0=9A=D0=9D=D0=91=D0=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/DailyReport/DailyReportDto.cs | 4 +++- .../Services/DailyReport/DailyReportService.cs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs index c47b8934..781a6717 100644 --- a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs +++ b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs @@ -1,5 +1,6 @@ namespace AsbCloudApp.Data.DailyReport { +#nullable enable /// /// Блоки для формирования суточного рапорта /// @@ -13,7 +14,7 @@ /// /// блок КНБК /// - public BhaDto Bha { get; set; } = new(); + public BhaDto? Bha { get; set; } = new(); /// /// блок безметражные работы @@ -35,4 +36,5 @@ /// public SignDto Sign { get; set; } = new(); } +#nullable disable } diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs index 1c30ba0b..ecdd7d15 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs @@ -124,10 +124,26 @@ namespace AsbCloudInfrastructure.Services.DailyReport ClusterName = well?.Cluster ?? "", }, TimeBalance = await MakeTimeBalanceAsync(idWell, date, token), + Bha = await GetPrevBhaAsync(idWell, date, token) }; return dto; } + private async Task GetPrevBhaAsync(int idWell, DateTime date, CancellationToken token) + { + var dateOffset = date.Date; + var entity = await db.DailyReports + .OrderByDescending(x => x.StartDate) + .FirstOrDefaultAsync(r => r.IdWell == idWell && + r.StartDate.Year <= dateOffset.Year && + r.StartDate.DayOfYear <= dateOffset.DayOfYear, token); + + if (entity is null) + return null; + var dto = Convert(entity); + return dto?.Bha; + } + private async Task MakeTimeBalanceAsync(int idWell, DateTime date, CancellationToken token) { var stat = await detectedOperationService.GetOperationsStatAsync(new DetectedOperationRequest From 6cac72259c39fca0c81c3855f91e2c353cd33ca3 Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Wed, 21 Sep 2022 12:56:18 +0500 Subject: [PATCH 7/7] =?UTF-8?q?#5908066=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/DailyReport/DailyReportDto.cs | 2 +- .../Services/DailyReport/DailyReportService.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs index 781a6717..920aeb54 100644 --- a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs +++ b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs @@ -14,7 +14,7 @@ /// /// блок КНБК /// - public BhaDto? Bha { get; set; } = new(); + public BhaDto Bha { get; set; } = new(); /// /// блок безметражные работы diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs index ecdd7d15..807b10ca 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs @@ -124,24 +124,24 @@ namespace AsbCloudInfrastructure.Services.DailyReport ClusterName = well?.Cluster ?? "", }, TimeBalance = await MakeTimeBalanceAsync(idWell, date, token), - Bha = await GetPrevBhaAsync(idWell, date, token) + Bha = await GetPrevOrNewBhaAsync(idWell, date, token) }; return dto; } - private async Task GetPrevBhaAsync(int idWell, DateTime date, CancellationToken token) + private async Task 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.IdWell == idWell && - r.StartDate.Year <= dateOffset.Year && - r.StartDate.DayOfYear <= dateOffset.DayOfYear, token); + .FirstOrDefaultAsync(r => r.StartDate <= dateOffset, token); if (entity is null) - return null; + return new BhaDto(); + var dto = Convert(entity); - return dto?.Bha; + return dto.Bha; } private async Task MakeTimeBalanceAsync(int idWell, DateTime date, CancellationToken token)