Fix ScheduleReportService correct deltaDepth

This commit is contained in:
ngfrolov 2022-03-18 16:54:40 +05:00
parent 3f2a7406d2
commit b12c3efffc
4 changed files with 61 additions and 37 deletions

View File

@ -16,7 +16,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private readonly IWellService wellService;
const string sheetNameSchedule = "Сетевой график";
const string sheetNameTvd = "ГГД";
const int maxChartsToWrap = 89;
const int maxChartsToWrap = 88;
public ScheduleReportService(IOperationsStatService operationsStatService, IWellService wellService)
{
@ -43,7 +43,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
return memoryStream;
}
private void FillScheduleSheetToWorkbook(XLWorkbook workbook, IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd, WellDto well)
private static void FillScheduleSheetToWorkbook(XLWorkbook workbook, IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd, WellDto well)
{
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameSchedule);
if (sheet is null)
@ -54,25 +54,36 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
const int columnRowNumber = 2;
const int columnCaption = 3;
const int columnWellDepthPlan = 4;
const int columnWellDepthFact = 5;
const int columnWellDepthPredict = 6;
const int columnDeltaWellDepthPerDay = 7;
const int columnDurationPlan = 8;
const int columnDurationFact = 9;
const int columnDurationPredict = 10;
const int columnDateEndPlan = 11;
const int columnDateEndFact = 12;
const int columnDateEndPredict = 13;
const int columnGuilty = 14;
const int columnNpt = 15;
const int columnWellDepthStartPlan = 4;
const int columnWellDepthStartFact = 5;
const int columnWellDepthStartPredict = 6;
const int columnWellDepthEndPlan = 7;
const int columnWellDepthEndFact = 8;
const int columnWellDepthEndPredict = 9;
const int columnDeltaWellDepthPerDay = 10;
const int columnDurationPlan = 11;
const int columnDurationFact = 12;
const int columnDurationPredict = 13;
const int columnDateStartPlan = 14;
const int columnDateStartFact = 15;
const int columnDateStartPredict = 16;
const int columnDateEndPlan = 17;
const int columnDateEndFact = 18;
const int columnDateEndPredict = 19;
const int columnGuilty = 20;
const int columnNpt = 21;
var subTitle = $"на строительство скважины №{well.Caption}, куст: {well.Cluster}, м/р: {well.Deposit}";
sheet.Row(rowTitle).Cell(3).Value = subTitle;
var tvdList = tvd.ToList();
double dayStartDepth = 0d;
double dayNum = 0;
var facts = tvd
.Where(t=>t.Fact is not null)
.Select(t=>t.Fact)
.ToList();
DateTime lastFactDate = default;
var lastFactI = 0;
int i = 0;
for (; i < tvdList.Count; i++)
@ -86,33 +97,46 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
SetCell(row, columnRowNumber, $"{1 + i}");
SetCell(row, columnCaption, $"{operation.CategoryName} {operation.CategoryInfo}".Trim());
SetCell(row, columnWellDepthPlan, tvdItem.Plan?.DepthEnd);
SetCell(row, columnWellDepthFact, tvdItem.Fact?.DepthEnd);
SetCell(row, columnWellDepthPredict, tvdItem.Predict?.DepthEnd);
SetCell(row, columnWellDepthStartPlan, tvdItem.Plan?.DepthStart);
SetCell(row, columnWellDepthStartFact, tvdItem.Fact?.DepthStart);
SetCell(row, columnWellDepthStartPredict, tvdItem.Predict?.DepthStart);
SetCell(row, columnWellDepthEndPlan, tvdItem.Plan?.DepthEnd);
SetCell(row, columnWellDepthEndFact, tvdItem.Fact?.DepthEnd);
SetCell(row, columnWellDepthEndPredict, tvdItem.Predict?.DepthEnd);
SetCell(row, columnDeltaWellDepthPerDay, null);
if (tvdItem.Fact is not null)
{
if (dayStartDepth == 0d)
{
dayStartDepth = tvdItem.Fact.DepthStart;
dayNum = tvdItem.Fact.DateStart.DayOfYear;
}
var fact = tvdItem.Fact;
if (lastFactDate == default)
lastFactDate = fact.DateStart;
if (i > 0 && tvdItem.Fact.DateStart.DayOfYear > dayNum)
if (i > 0 && fact.DateStart.DayOfYear != lastFactDate.DayOfYear)
{
double? delta = tvdItem.Fact.DepthStart - dayStartDepth;
delta = delta > 0 ? delta : null;
SetCell(sheet.Row(0 + i + headerRowsCount), columnDeltaWellDepthPerDay, delta);
dayStartDepth = tvdItem.Fact.DepthStart;
dayNum = tvdItem.Fact.DateStart.DayOfYear;
var daylyOperations = facts
.Where(t => t.DateStart >= lastFactDate && t.DateStart < fact.DateStart);
if (daylyOperations.Any())
{
var depthDayStart = daylyOperations.Min(o => o.DepthStart);
var depthDayEnd = daylyOperations.Max(o => o.DepthEnd);
var delta = depthDayEnd - depthDayStart;
SetCell(sheet.Row(1 + lastFactI + headerRowsCount), columnDeltaWellDepthPerDay, delta);
lastFactDate = fact.DateStart;
}
}
lastFactI = i;
}
SetCell(row, columnDurationPlan, tvdItem.Plan?.DurationHours);
SetCell(row, columnDurationFact, tvdItem.Fact?.DurationHours);
SetCell(row, columnDurationPredict, tvdItem.Predict?.DurationHours);
SetCell(row, columnDateStartPlan, tvdItem.Plan?.DateStart);
SetCell(row, columnDateStartFact, tvdItem.Fact?.DateStart);
SetCell(row, columnDateStartPredict, tvdItem.Predict?.DateStart);
SetCell(row, columnDateEndPlan, tvdItem.Plan?.DateStart.AddHours(tvdItem.Plan?.DurationHours ?? 0));
SetCell(row, columnDateEndFact, tvdItem.Fact?.DateStart.AddHours(tvdItem.Fact?.DurationHours ?? 0));
SetCell(row, columnDateEndPredict, tvdItem.Predict?.DateStart.AddHours(tvdItem.Predict?.DurationHours ?? 0));
@ -171,7 +195,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
SetBorder(rowSummary2.Cells(true).Style);
}
private void FillTvdSheetToWorkbook(XLWorkbook workbook, IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd, WellDto well)
private static void FillTvdSheetToWorkbook(XLWorkbook workbook, IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd, WellDto well)
{
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameTvd);
if (sheet is null)
@ -206,7 +230,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
var factLast = Fact.LastOrDefault();
var predictLast = Predict.LastOrDefault();
DateTime GetEndDate(WellOperationDto operation)
static DateTime GetEndDate(WellOperationDto operation)
=> operation is not null
? operation.DateStart.AddHours(operation.DurationHours)
: default;
@ -232,7 +256,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
SetCell(sheet.Row(rowTopStatTitle + 1), colTopStatvalue - 1, "+")
.Style.Font.SetFontColor(XLColor.Green);
else
SetCell(sheet.Row(rowTopStatTitle + 1), colTopStatvalue - 1, "-")
SetCell(sheet.Row(rowTopStatTitle + 1), colTopStatvalue - 1, "")
.Style.Font.SetFontColor(XLColor.Red);
}
}
@ -287,7 +311,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
if (value is string valueString && valueString.Length > maxChartsToWrap)
{
var baseHeight = row.Height;
row.Height = Math.Ceiling(0.85d * valueString.Length / maxChartsToWrap) * baseHeight;
row.Height = 0.82d * baseHeight * Math.Ceiling(1d + valueString.Length / maxChartsToWrap);
}
if (value is DateTime)

View File

@ -46,7 +46,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
new User { Id = 3005, IdCompany = 3003, Login = "wrong 2", Email = "aa@aa.aa", IdState = 2 },
};
private static readonly FileInfo file1001 = new FileInfo
private static readonly FileInfo file1001 = new ()
{
Id = 3001,
IdWell = idWell,
@ -58,7 +58,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
UploadDate = System.DateTimeOffset.UtcNow,
};
private static readonly FileInfo file1002 = new FileInfo
private static readonly FileInfo file1002 = new ()
{
Id = 3002,
IdWell = idWell,

View File

@ -67,7 +67,7 @@ namespace ConsoleApp1
var wellService = new WellService(db, cacheDb, telemetryService, timeZoneService);
var operationService = new OperationsStatService(db, cacheDb, wellService);
var scheduleReportService = new ScheduleReportService(operationService, wellService);
var stream = scheduleReportService.MakeReportAsync(4).Result;
var stream = scheduleReportService.MakeReportAsync(44).Result;
var outStream = System.IO.File.OpenWrite(@"c:\temp\1.xlsx");
stream.CopyTo(outStream);
outStream.Flush();