From 56b90e0952cdb2dc0f51f77f5ce32acf0a2d1ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 27 Jul 2023 11:43:21 +0500 Subject: [PATCH 1/2] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D1=83=D1=82=D0=BE=D1=87=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BE=D1=82=D1=87=D1=91=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Мелкие фиксы в сервисе + сделал более предсказуемый размер файлов отчёта. 2. Исправил получение ограничивающих параметров. Теперь не учитываются ограничивающие параметры если их начальная глубина больше конечной. --- .../AutoGeneratedDailyReportService.cs | 27 ++++++++++--------- .../Services/LimitingParameterService.cs | 13 ++++++--- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs index 4012ebdf..7e92e87b 100644 --- a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs +++ b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs @@ -94,13 +94,13 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService for (int day = result.Skip; (day - result.Skip) < result.Take && (datesRange.From.AddDays(day)) <= datesRange.To; day++) { - var dateFrom = datesRange.From.AddDays(day); + var reportDate = DateOnly.FromDateTime(datesRange.From.AddDays(day)); - reports.Add(new AutoGeneratedDailyReportDto + reports.Add(new AutoGeneratedDailyReportInfoDto { - FileName = string.Format(fileNameTemplate, well.Caption, well.Cluster, DateOnly.FromDateTime(dateFrom)), - ReportDate = DateOnly.FromDateTime(dateFrom), - FileSize = GetFileSize() / 1024, + FileName = string.Format(fileNameTemplate, well.Caption, well.Cluster, reportDate), + ReportDate = reportDate, + FileSize = GetFileSize(reportDate, idWell) / 1024, }); } @@ -127,9 +127,9 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService var report = new AutoGeneratedDailyReportDto { FileName = string.Format(fileNameTemplate, well.Caption, well.Cluster, reportDate), - FileSize = GetFileSize() / 1024, + FileSize = GetFileSize(reportDate, idWell) / 1024, ReportDate = reportDate, - Head = CreateHeadBlock(well, reportDate, factOperations), + Head = CreateHeadBlock(well, factOperations), Subsystems = (await CreateSubsystemBlockAsync(idWell, startDate, finishDate, cancellationToken)).ToArray(), LimitingParameters = (await CreateLimitingParameterBlockAsync(idWell, startDate, finishDate, cancellationToken)).ToArray(), TimeBalance = factOperations.GroupBy(w => w.CategoryName).Select(x => new TimeBalanceRecordDto @@ -144,7 +144,7 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService return (report.FileName, stream); } - private HeadBlockDto CreateHeadBlock(WellDto well, DateOnly reportDate, WellOperationDto[] factOperations) + private HeadBlockDto CreateHeadBlock(WellDto well, WellOperationDto[] factOperations) { var customer = well.Companies.FirstOrDefault(company => company.IdCompanyType == 1); @@ -188,12 +188,12 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService startDate, finishDate, cancellationToken)).ToArray(); var sumDepths = limitingParameterStats.Sum(x => x.Depth); - + return limitingParameterStats.Select(l => new LimitingParameterRecordDto { NameFeedRegulator = l.NameFeedRegulator, Hours = l.TotalMinutes, - PercentDepth = l.Depth / sumDepths, + PercentDepth = sumDepths != 0 ? l.Depth / sumDepths : 0, Depth = l.Depth, }); } @@ -239,10 +239,11 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService return limitingParameterService.GetStatAsync(request, cancellationToken); } - private int GetFileSize() + private int GetFileSize(DateOnly reportDate, int idWell) { const int fileSizeTemplate = 10240; - // TODO: Добавку размера сделать более предсказуемой на основе даты рапорта. что то типа `(Date.Ticks * idWell) % (fileSizeTemplate / 10)` - return new Random().Next(1, 8193) + fileSizeTemplate; + long ticks = new DateTime(reportDate.Year, reportDate.Month, reportDate.Day).Ticks * idWell; + int remainder = (int)(ticks % (fileSizeTemplate / 10)); + return fileSizeTemplate + remainder; } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/LimitingParameterService.cs b/AsbCloudInfrastructure/Services/LimitingParameterService.cs index b3aa7710..78587efb 100644 --- a/AsbCloudInfrastructure/Services/LimitingParameterService.cs +++ b/AsbCloudInfrastructure/Services/LimitingParameterService.cs @@ -43,10 +43,15 @@ namespace AsbCloudInfrastructure.Services List result = new List(data.Count()); foreach (var item in data) { - var trimData = TrimLimitingParameters(item, request); - - var allItemDepths = trimData.Sum(x => x.DepthEnd - x.DepthStart); - var allItemDates = trimData.Sum(x => (x.DateEnd - x.DateStart).TotalMinutes); + var trimData = TrimLimitingParameters(item, request).ToArray(); + + //TODO: временный фикс, нужно избежать отрицательных значений в ограничивающих параметрах. + //Проблема возникает при при формировании LimitingParameter в LimitingParameterCalcWorkFactory. + //Начальная глубина ограничивающего параметра не может быть больше конечной. + var allItemDepths = trimData.Where(x => x.DepthStart < x.DepthEnd) + .Sum(x => x.DepthEnd - x.DepthStart); + var allItemDates = trimData.Where(x => x.DepthStart < x.DepthEnd) + .Sum(x => (x.DateEnd - x.DateStart).TotalMinutes); result.Add(new LimitingParameterDto { From b63d1ebff8c338c6233e1edd07f749c475bc15f1 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 28 Jul 2023 11:14:45 +0500 Subject: [PATCH 2/2] =?UTF-8?q?AutoGeneratedDailyReportService=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=D1=8B=20=D1=84=D0=B8=D0=BA=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutoGeneratedDailyReportDto.cs | 9 ++++++--- .../AutoGeneratedDailyReportService.cs | 19 +++++++++--------- .../LimitingParameterExcelBlockWriter.cs | 17 +++++++--------- .../SubsystemExcelBlockWriter.cs | 17 +++++++--------- .../TimeBalanceExcelBlockWriter.cs | 20 ++++++++----------- 5 files changed, 38 insertions(+), 44 deletions(-) diff --git a/AsbCloudApp/Data/AutogeneratedDailyReport/AutoGeneratedDailyReportDto.cs b/AsbCloudApp/Data/AutogeneratedDailyReport/AutoGeneratedDailyReportDto.cs index ea3b3c53..9554c374 100644 --- a/AsbCloudApp/Data/AutogeneratedDailyReport/AutoGeneratedDailyReportDto.cs +++ b/AsbCloudApp/Data/AutogeneratedDailyReport/AutoGeneratedDailyReportDto.cs @@ -1,3 +1,6 @@ +using System.Collections; +using System.Collections.Generic; + namespace AsbCloudApp.Data.AutogeneratedDailyReport; /// @@ -14,15 +17,15 @@ public class AutoGeneratedDailyReportDto : AutoGeneratedDailyReportInfoDto /// /// Блок подсистем /// - public SubsystemRecordDto[] Subsystems { get; set; } = null!; + public IEnumerable Subsystems { get; set; } = null!; /// /// Блок ограничивающих параметров /// - public LimitingParameterRecordDto[] LimitingParameters { get; set; } = null!; + public IEnumerable LimitingParameters { get; set; } = null!; /// /// Баланс времени /// - public TimeBalanceRecordDto[] TimeBalance { get; set; } = null!; + public IEnumerable TimeBalance { get; set; } = null!; } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs index 7e92e87b..514b0b66 100644 --- a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs +++ b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs @@ -100,7 +100,7 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService { FileName = string.Format(fileNameTemplate, well.Caption, well.Cluster, reportDate), ReportDate = reportDate, - FileSize = GetFileSize(reportDate, idWell) / 1024, + FileSize = GetFileSize(reportDate, idWell), }); } @@ -121,13 +121,13 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService if (!well.IdTelemetry.HasValue) throw new ArgumentInvalidException("Телеметрия для скважины отсутствует", nameof(idWell)); - var factOperations = (await GetFactOperationsAsync(well.Id, startDate, finishDate, - cancellationToken)).ToArray(); + var factOperations = await GetFactOperationsAsync(well.Id, startDate, finishDate, + cancellationToken); var report = new AutoGeneratedDailyReportDto { FileName = string.Format(fileNameTemplate, well.Caption, well.Cluster, reportDate), - FileSize = GetFileSize(reportDate, idWell) / 1024, + FileSize = GetFileSize(reportDate, idWell), ReportDate = reportDate, Head = CreateHeadBlock(well, factOperations), Subsystems = (await CreateSubsystemBlockAsync(idWell, startDate, finishDate, cancellationToken)).ToArray(), @@ -144,18 +144,19 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService return (report.FileName, stream); } - private HeadBlockDto CreateHeadBlock(WellDto well, WellOperationDto[] factOperations) + private HeadBlockDto CreateHeadBlock(WellDto well, IEnumerable factOperations) { var customer = well.Companies.FirstOrDefault(company => company.IdCompanyType == 1); + var sortedFactOperations = factOperations.OrderBy(o => o.DateStart); - return new HeadBlockDto + return new HeadBlockDto { Customer = customer?.Caption ?? string.Empty, Deposit = well.Deposit ?? string.Empty, Cluster = well.Cluster ?? string.Empty, Well = well.Caption, - DepthFrom = factOperations.FirstOrDefault()?.DepthStart ?? 0.00, - DepthTo = factOperations.LastOrDefault()?.DepthEnd ?? 0.00 + DepthFrom = sortedFactOperations.FirstOrDefault()?.DepthStart ?? 0.00, + DepthTo = sortedFactOperations.LastOrDefault()?.DepthEnd ?? 0.00 }; } @@ -242,7 +243,7 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService private int GetFileSize(DateOnly reportDate, int idWell) { const int fileSizeTemplate = 10240; - long ticks = new DateTime(reportDate.Year, reportDate.Month, reportDate.Day).Ticks * idWell; + long ticks = 1L * reportDate.Year * reportDate.Month * reportDate.Day * idWell; int remainder = (int)(ticks % (fileSizeTemplate / 10)); return fileSizeTemplate + remainder; } diff --git a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/LimitingParameterExcelBlockWriter.cs b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/LimitingParameterExcelBlockWriter.cs index 8e99e755..30cf36f0 100644 --- a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/LimitingParameterExcelBlockWriter.cs +++ b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/LimitingParameterExcelBlockWriter.cs @@ -15,17 +15,14 @@ public class LimitingParameterExcelBlockWriter : IExcelBlockWriter public void Write(IXLWorksheet sheet, AutoGeneratedDailyReportDto report) { - if(!report.LimitingParameters.Any()) - return; - - for (int i = 0; i < report.LimitingParameters.Length; i++) + var i = 1; + foreach (var limitingParameter in report.LimitingParameters) { - var row = sheet.Row(1 + i + rowHeaderBlock); - - row.Cell(columnNameFeedRegulator).Value = report.LimitingParameters[i].NameFeedRegulator; - row.Cell(columnDepth).Value = report.LimitingParameters[i].Depth; - row.Cell(columnTotalHours).Value = report.LimitingParameters[i].Hours; - row.Cell(columnPercentDepth).Value = report.LimitingParameters[i].PercentDepth; + var row = sheet.Row( i++ + rowHeaderBlock); + row.Cell(columnNameFeedRegulator).Value = limitingParameter.NameFeedRegulator; + row.Cell(columnDepth).Value = limitingParameter.Depth; + row.Cell(columnTotalHours).Value = limitingParameter.Hours; + row.Cell(columnPercentDepth).Value = limitingParameter.PercentDepth; } } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/SubsystemExcelBlockWriter.cs b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/SubsystemExcelBlockWriter.cs index ec32c60e..a1b25c88 100644 --- a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/SubsystemExcelBlockWriter.cs +++ b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/SubsystemExcelBlockWriter.cs @@ -15,17 +15,14 @@ public class SubsystemExcelBlockWriter : IExcelBlockWriter public void Write(IXLWorksheet sheet, AutoGeneratedDailyReportDto report) { - if(!report.Subsystems.Any()) - return; - - for (int i = 0; i < report.Subsystems.Length; i++) + var i = 1; + foreach( var subsystem in report.Subsystems ) { - var row = sheet.Row(1 + i + rowHeaderBlock); - - row.Cell(columnName).Value = report.Subsystems[i].Name; - row.Cell(columnKUsage).Value = report.Subsystems[i].KUsage; - row.Cell(columnDepth).Value = report.Subsystems[i].Depth; - row.Cell(columnUsedTimeHours).Value = report.Subsystems[i].UsedTimeHours; + var row = sheet.Row(i++ + rowHeaderBlock); + row.Cell(columnName).Value = subsystem.Name; + row.Cell(columnKUsage).Value = subsystem.KUsage; + row.Cell(columnDepth).Value = subsystem.Depth; + row.Cell(columnUsedTimeHours).Value = subsystem.UsedTimeHours; } } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/TimeBalanceExcelBlockWriter.cs b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/TimeBalanceExcelBlockWriter.cs index c61fed8f..51e4643e 100644 --- a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/TimeBalanceExcelBlockWriter.cs +++ b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutogeneratedDailyReportBlocks/TimeBalanceExcelBlockWriter.cs @@ -13,22 +13,18 @@ public class TimeBalanceExcelBlockWriter : IExcelBlockWriter public void Write(IXLWorksheet sheet, AutoGeneratedDailyReportDto report) { - if(!report.TimeBalance.Any()) - return; - - for (int i = 0; i < report.TimeBalance.Length; i++) + var i = 1; + foreach(var timeBalance in report.TimeBalance) { - var row = sheet.Row(1 + i + rowHeaderBlock); - - row.Cell(columnName).Value = report.TimeBalance[i].Name; - row.Cell(columnDurationHours).Value = report.TimeBalance[i].DurationHours; - - AddBorderToCell(row.Cell(columnName)); - AddBorderToCell(row.Cell(columnDurationHours)); + var row = sheet.Row(i++ + rowHeaderBlock); + row.Cell(columnName).Value = timeBalance.Name; + row.Cell(columnDurationHours).Value = timeBalance.DurationHours; + AddBorderToCell(row.Cell(columnName)); + AddBorderToCell(row.Cell(columnDurationHours)); } } - private void AddBorderToCell(IXLCell cell) + private static void AddBorderToCell(IXLCell cell) { cell.Style.Border.TopBorder = XLBorderStyleValues.Thin; cell.Style.Border.BottomBorder = XLBorderStyleValues.Thin;