diff --git a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs
index c47b8934..920aeb54 100644
--- a/AsbCloudApp/Data/DailyReport/DailyReportDto.cs
+++ b/AsbCloudApp/Data/DailyReport/DailyReportDto.cs
@@ -1,5 +1,6 @@
namespace AsbCloudApp.Data.DailyReport
{
+#nullable enable
///
/// Блоки для формирования суточного рапорта
///
@@ -35,4 +36,5 @@
///
public SignDto Sign { get; set; } = new();
}
+#nullable disable
}
diff --git a/AsbCloudApp/Data/DrillParamsDto.cs b/AsbCloudApp/Data/DrillParamsDto.cs
index 0d667a58..d79f2451 100644
--- a/AsbCloudApp/Data/DrillParamsDto.cs
+++ b/AsbCloudApp/Data/DrillParamsDto.cs
@@ -13,14 +13,9 @@ 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.
@@ -28,78 +23,28 @@ namespace AsbCloudApp.Data
public int IdWellSectionType { get; set; }
///
- /// axial load min.
+ /// axial load
///
- public double AxialLoadMin { get; set; }
+ public MinMaxExtendedViewDto AxialLoad { get; set; }
///
- /// axial load avg.
+ /// pressure
///
- public double AxialLoadAvg { get; set; }
+ public MinMaxExtendedViewDto Pressure { get; set; }
///
- /// axial load max.
+ /// rotor torque
///
- public double AxialLoadMax { get; set; }
+ public MinMaxExtendedViewDto RotorTorque { get; set; }
///
- /// pressure min.
+ /// rotor speed
///
- public double PressureMin { get; set; }
+ public MinMaxExtendedViewDto RotorSpeed { get; set; }
///
- /// pressure avg.
+ /// flow
///
- public double PressureAvg { get; set; }
-
- ///
- /// pressure max.
- ///
- public double PressureMax { 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 speed min.
- ///
- public double RotorSpeedMin { get; set; }
-
- ///
- /// rotor speed avg.
- ///
- public double RotorSpeedAvg { get; set; }
-
- ///
- /// rotor speed max.
- ///
- public double RotorSpeedMax { get; set; }
-
- ///
- /// flow min.
- ///
- public double FlowMin { get; set; }
-
- ///
- /// flow avg.
- ///
- public double FlowAvg { get; set; }
-
- ///
- /// flow max.
- ///
- public double FlowMax { get; set; }
+ 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..291574bc
--- /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 T? Min { get; set; }
+
+ ///
+ /// Максимальное значение
+ ///
+ public T? Max { get; set; }
+ }
+#nullable disable
+}
diff --git a/AsbCloudApp/Data/MinMaxExtendedViewDto.cs b/AsbCloudApp/Data/MinMaxExtendedViewDto.cs
new file mode 100644
index 00000000..cb66e60d
--- /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/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs
index 1c30ba0b..807b10ca 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 GetPrevOrNewBhaAsync(idWell, date, token)
};
return dto;
}
+ 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.StartDate <= dateOffset, token);
+
+ if (entity is null)
+ return new BhaDto();
+
+ var dto = Convert(entity);
+ return dto.Bha;
+ }
+
private async Task MakeTimeBalanceAsync(int idWell, DateTime date, CancellationToken token)
{
var stat = await detectedOperationService.GetOperationsStatAsync(new DetectedOperationRequest
diff --git a/AsbCloudInfrastructure/Services/DrillParamsService.cs b/AsbCloudInfrastructure/Services/DrillParamsService.cs
index 1af54956..a081bdd9 100644
--- a/AsbCloudInfrastructure/Services/DrillParamsService.cs
+++ b/AsbCloudInfrastructure/Services/DrillParamsService.cs
@@ -11,6 +11,7 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
+#nullable enable
public class DrillParamsService : CrudServiceBase, IDrillParamsService
{
private readonly IAsbCloudDbContext db;
@@ -23,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);
@@ -39,28 +40,46 @@ 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);
@@ -70,35 +89,62 @@ 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,
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>();
+ 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 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)
+ {
+ 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 {
+ 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
}