From c8a5afa095bacaa97a2faa74fe55b4e6cdae03e1 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?= Date: Mon, 9 Oct 2023 17:09:40 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Удалены старые реализации сервисов 2. Поправлен WellInfoService 3. Поправлен csproj, добавлены ресурсы 4. Поправлена регистрация зависимостей --- .../AsbCloudInfrastructure.csproj | 5 +- AsbCloudInfrastructure/DependencyInjection.cs | 18 +- .../ProcessMap/ProcessMapPlanImportService.cs | 345 --------------- .../ProcessMap/ProcessMapPlanTemplate.xlsx | Bin 12433 -> 0 bytes .../ProcessMapReportMakerService.cs | 209 --------- .../Services/ProcessMap/ProcessMapService.cs | 399 ------------------ .../ProcessMapWellboreDevelopmentService.cs | 67 --- .../Services/ProcessMap/XLExtentions.cs | 52 --- .../Services/WellInfoService.cs | 28 +- 9 files changed, 26 insertions(+), 1097 deletions(-) delete mode 100644 AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanImportService.cs delete mode 100644 AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanTemplate.xlsx delete mode 100644 AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportMakerService.cs delete mode 100644 AsbCloudInfrastructure/Services/ProcessMap/ProcessMapService.cs delete mode 100644 AsbCloudInfrastructure/Services/ProcessMap/ProcessMapWellboreDevelopment/ProcessMapWellboreDevelopmentService.cs delete mode 100644 AsbCloudInfrastructure/Services/ProcessMap/XLExtentions.cs diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index e14fb012..955fcf7d 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -14,7 +14,6 @@ - @@ -32,14 +31,14 @@ - - + + diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 01eea5cc..bf6b3564 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -12,7 +12,6 @@ using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.DailyReport; using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.DrillingProgram; -using AsbCloudInfrastructure.Services.ProcessMap; using AsbCloudInfrastructure.Services.SAUB; using AsbCloudInfrastructure.Services.Subsystems; using AsbCloudInfrastructure.Services.Trajectory; @@ -24,15 +23,19 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; using AsbCloudApp.Data.Manuals; +using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.Services.AutoGeneratedDailyReports; using AsbCloudApp.Services.Notifications; using AsbCloudDb.Model.Manuals; using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports; using AsbCloudApp.Services.WellOperationImport; using AsbCloudInfrastructure.Services.WellOperationImport; -using AsbCloudInfrastructure.Services.ProcessMap.ProcessMapWellboreDevelopment; using AsbCloudApp.Data.WellOperationImport.Options; using AsbCloudInfrastructure.Services.WellOperationImport.FileParser; +using AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap; +using AsbCloudApp.Services.ProcessMaps; +using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap; +using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report; namespace AsbCloudInfrastructure { @@ -122,10 +125,9 @@ namespace AsbCloudInfrastructure services.AddSingleton(provider => ReduceSamplingService.GetInstance(configuration)); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -139,7 +141,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -152,8 +154,8 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanImportService.cs b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanImportService.cs deleted file mode 100644 index 7ff6ecf2..00000000 --- a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanImportService.cs +++ /dev/null @@ -1,345 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Threading; -using System.Threading.Tasks; -using AsbCloudApp.Data.ProcessMap; -using AsbCloudApp.Repositories; -using AsbCloudApp.Services; -using ClosedXML.Excel; -using System; -using AsbCloudApp.Data; - -namespace AsbCloudInfrastructure.Services.ProcessMap; - -/* -* password for ProcessMapImportTemplate.xlsx is ASB2020! -*/ -public class ProcessMapPlanImportService : IProcessMapPlanImportService -{ - private readonly IProcessMapPlanRepository processMapPlanRepository; - private readonly ICrudRepository wellSectionTypeRepository; - - private const string sheetNamePlan = "План"; - - private const int headerRowsCount = 2; - - private const int columnWellSectionType = 1; - private const int columnMode = 2; - private const int columnDepthStart = 3; - private const int columnDepthEnd = 4; - private const int columnPressurePlan = 5; - private const int columnPressureLimitMax = 6; - private const int columnAxialLoadPlan = 7; - private const int columnAxialLoadLimitMax = 8; - private const int columnTopDriveTorquePlan = 9; - private const int columnTopDriveTorqueLimitMax = 10; - private const int columnTopDriveSpeedPlan = 11; - private const int columnTopDriveSpeedLimitMax = 12; - private const int columnFlowPlan = 13; - private const int columnFlowLimitMax = 14; - private const int columnRopPlan = 15; - private const int columnUsageSaub = 16; - private const int columnUsageSpin = 17; - - private WellSectionTypeDto[] sections = null!; - - public ProcessMapPlanImportService(IProcessMapPlanRepository processMapPlanRepository, - ICrudRepository wellSectionTypeRepository) - { - this.processMapPlanRepository = processMapPlanRepository; - this.wellSectionTypeRepository = wellSectionTypeRepository; - } - - public async Task ImportAsync(int idWell, int idUser, bool deleteProcessMapPlansBeforeImport, Stream stream, - CancellationToken cancellationToken) - { - sections = (await wellSectionTypeRepository.GetAllAsync(cancellationToken)).ToArray(); - - using var workBook = new XLWorkbook(stream); - - var processPlanMaps = ParseWorkBook(workBook); - - if (deleteProcessMapPlansBeforeImport) - await processMapPlanRepository.RemoveByWellAsync(idWell, cancellationToken); - - foreach (var processPlanMap in processPlanMaps) - { - processPlanMap.IdWell = idWell; - processPlanMap.IdUser = idUser; - } - - await processMapPlanRepository.InsertRangeAsync(processPlanMaps, cancellationToken); - } - - public async Task ExportAsync(int idWell, CancellationToken cancellationToken) - { - sections = (await wellSectionTypeRepository.GetAllAsync(cancellationToken)).ToArray(); - - var processMapPlans = (await processMapPlanRepository.GetByIdWellAsync(idWell, - cancellationToken)).ToArray(); - - return await GenerateExcelFileStreamAsync(processMapPlans, - cancellationToken); - } - - public async Task GetExcelTemplateStreamAsync(CancellationToken cancellationToken) - { - var resourceName = Assembly.GetExecutingAssembly() - .GetManifestResourceNames() - .FirstOrDefault(n => n.EndsWith("ProcessMapPlanTemplate.xlsx"))!; - - using var stream = Assembly.GetExecutingAssembly() - .GetManifestResourceStream(resourceName)!; - - var memoryStream = new MemoryStream(); - await stream.CopyToAsync(memoryStream, cancellationToken); - memoryStream.Position = 0; - - return memoryStream; - } - - private void AddToWorkbook(XLWorkbook workbook, ProcessMapPlanDto[] processMapPlans) - { - if (!processMapPlans.Any()) - return; - - var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlan) - ?? throw new FileFormatException($"Книга excel не содержит листа {sheetNamePlan}."); - - AddToSheet(sheet, processMapPlans); - } - - private void AddToSheet(IXLWorksheet sheet, ProcessMapPlanDto[] processMapPlans) - { - for (int i = 0; i < processMapPlans.Length; i++) - { - var row = sheet.Row(1 + i + headerRowsCount); - AddToRow(row, processMapPlans[i]); - } - } - - private void AddToRow(IXLRow row, ProcessMapPlanDto processMap) - { - row.Cell(columnWellSectionType).Value = sections.First(x => x.Id == processMap.IdWellSectionType).Caption; - row.Cell(columnMode).Value = GetModeCaption(processMap.IdMode); - row.Cell(columnDepthStart).Value = processMap.DepthStart; - row.Cell(columnDepthEnd).Value = processMap.DepthEnd; - row.Cell(columnPressurePlan).Value = processMap.Pressure.Plan; - row.Cell(columnPressureLimitMax).Value = processMap.Pressure.LimitMax; - row.Cell(columnAxialLoadPlan).Value = processMap.AxialLoad.Plan; - row.Cell(columnAxialLoadLimitMax).Value = processMap.AxialLoad.LimitMax; - row.Cell(columnTopDriveTorquePlan).Value = processMap.TopDriveTorque.Plan; - row.Cell(columnTopDriveTorqueLimitMax).Value = processMap.TopDriveTorque.LimitMax; - row.Cell(columnTopDriveSpeedPlan).Value = processMap.TopDriveSpeed.Plan; - row.Cell(columnTopDriveSpeedLimitMax).Value = processMap.TopDriveSpeed.LimitMax; - row.Cell(columnFlowPlan).Value = processMap.Flow.Plan; - row.Cell(columnFlowLimitMax).Value = processMap.Flow.LimitMax; - row.Cell(columnRopPlan).Value = processMap.RopPlan; - row.Cell(columnUsageSaub).Value = processMap.UsageSaub; - row.Cell(columnUsageSpin).Value = processMap.UsageSpin; - } - - private ProcessMapPlanDto[] ParseWorkBook(IXLWorkbook workbook) - { - var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlan) - ?? throw new FileFormatException($"Книга excel не содержит листа {sheetNamePlan}."); - - return ParseSheet(sheet); - } - - private ProcessMapPlanDto[] ParseSheet(IXLWorksheet sheet) - { - const int columnsCount = 17; - - if (sheet.RangeUsed().RangeAddress.LastAddress.ColumnNumber < columnsCount) - throw new FileFormatException($"Лист {sheet.Name} содержит меньшее количество столбцов."); - - var rowsCount = sheet.RowsUsed().Count() - headerRowsCount; - - if (rowsCount <= 0) - return Array.Empty(); - - var processMapPlans = new ProcessMapPlanDto[rowsCount]; - - var parseErrors = new List(); - - for (int i = 0; i < processMapPlans.Length; i++) - { - var row = sheet.Row(1 + i + headerRowsCount); - - try - { - processMapPlans[i] = ParseRow(row); - } - catch (FileFormatException ex) - { - parseErrors.Add(ex.Message); - } - } - - if (parseErrors.Any()) - throw new FileFormatException(string.Join("\r\n", parseErrors)); - - return processMapPlans; - } - - private ProcessMapPlanDto ParseRow(IXLRow row) - { - var wellSectionTypeCaption = row.Cell(columnWellSectionType).GetCellValue().Trim().ToLower(); - var modeName = row.Cell(columnMode).GetCellValue().Trim().ToLower(); - var depthStart = row.Cell(columnDepthStart).GetCellValue(); - var depthEnd = row.Cell(columnDepthEnd).GetCellValue(); - var pressurePlan = row.Cell(columnPressurePlan).GetCellValue(); - var pressureLimitMax = row.Cell(columnPressureLimitMax).GetCellValue(); - var axialLoadPlan = row.Cell(columnAxialLoadPlan).GetCellValue(); - var axialLoadLimitMax = row.Cell(columnAxialLoadLimitMax).GetCellValue(); - var topDriveTorquePlan = row.Cell(columnTopDriveTorquePlan).GetCellValue(); - var topDriveTorqueLimitMax = row.Cell(columnTopDriveTorqueLimitMax).GetCellValue(); - var topDriveSpeedPlan = row.Cell(columnTopDriveSpeedPlan).GetCellValue(); - var topDriveSpeedLimitMax = row.Cell(columnTopDriveSpeedLimitMax).GetCellValue(); - var flowPlan = row.Cell(columnFlowPlan).GetCellValue(); - var flowLimitMax = row.Cell(columnFlowLimitMax).GetCellValue(); - var ropPlan = row.Cell(columnRopPlan).GetCellValue(); - var usageSaub = row.Cell(columnUsageSaub).GetCellValue(); - var usageSpin = row.Cell(columnUsageSpin).GetCellValue(); - - var wellSection = sections.FirstOrDefault(s => s.Caption.Trim().ToLower() == wellSectionTypeCaption) - ?? throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указана некорректная секция"); - - var idMode = GetIdMode(modeName) - ?? throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указан некорректный режим"); - - if (depthStart is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указана некорректная стартовая глубина"); - - if (depthEnd is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указана некорректная конечная глубина"); - - if (pressurePlan is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное плановое значение перепада давления"); - - if (pressureLimitMax is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное ограничение перепада давления"); - - if (axialLoadPlan is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное плановое значение нагрузки"); - - if (axialLoadLimitMax is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное ограничение нагрузки"); - - if (topDriveTorquePlan is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное плановое значение момента на ВСП"); - - if (topDriveTorqueLimitMax is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное ограничение момента на ВСП"); - - if (topDriveSpeedPlan is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное плановое значение оборотов на ВСП"); - - if (topDriveSpeedLimitMax is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное ограничения оборота на ВСП"); - - if (flowPlan is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное плановое значение расхода"); - - if (flowLimitMax is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное ограничение расхода"); - - if (ropPlan is < 0 or > 50000) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указано некорректное плановое значение механической скорости"); - - if (usageSaub is < 0 or > 100) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указан некорректный плановый процент использования АКБ"); - - if (usageSpin is < 0 or > 100) - throw new FileFormatException( - $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указан некорректные плановый процент использования spin master"); - - return new() - { - IdWellSectionType = wellSection.Id, - IdMode = idMode, - DepthStart = depthStart, - LastUpdate = DateTime.UtcNow, - DepthEnd = depthEnd, - Pressure = new() - { - Plan = pressurePlan, - LimitMax = pressureLimitMax - }, - AxialLoad = new() - { - Plan = axialLoadPlan, - LimitMax = axialLoadLimitMax - }, - TopDriveTorque = new() - { - Plan = topDriveTorquePlan, - LimitMax = topDriveTorqueLimitMax - }, - TopDriveSpeed = new() - { - Plan = topDriveSpeedPlan, - LimitMax = topDriveSpeedLimitMax - }, - Flow = new() - { - Plan = flowPlan, - LimitMax = flowLimitMax - }, - RopPlan = ropPlan, - UsageSaub = usageSaub, - UsageSpin = usageSpin - }; - } - - private async Task GenerateExcelFileStreamAsync(ProcessMapPlanDto[] processMapPlans, - CancellationToken cancellationToken) - { - using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken); - - using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled); - - AddToWorkbook(workbook, processMapPlans); - - MemoryStream memoryStream = new MemoryStream(); - workbook.SaveAs(memoryStream, new SaveOptions { }); - memoryStream.Seek(0, SeekOrigin.Begin); - return memoryStream; - } - - private static int? GetIdMode(string modeName) => - modeName switch - { - "ручной" => 0, - "ротор" => 1, - "слайд" => 2, - _ => null - }; - - private static string GetModeCaption(int idMode) - => idMode switch - { - 1 => "Ротор", - 2 => "Слайд", - _ => "Ручной", - }; -} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanTemplate.xlsx b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanTemplate.xlsx deleted file mode 100644 index be2c62e979333fc5a80f845a8f8e2ec6f11c4246..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12433 zcmeHt1zTKOvNkTkT@&1)(clo=-7UCFBaH@kcY?dS1_|yG+#P~@f&~wJoij7{oXMQ~ z{ee6Cd3Nu$x_7<3rK;XqRiz{g4TB8<2Y~M*G9 zW0)|nq2>6=aKr69;9mJ|hHI;-Gm4P@NT97du)C4-ZLvN!MTCrQ_RSg#Utz`?OQIL04CrtDMS%maHj*M=1V8U_Mh} zTy0M3nKe>?}em=)@35@<>oX%WPt+5SWjZF5?i zZ~B%POM#CvA_e=PgyNY}q2trWlEce2sSv0~C?7>@lT^pIPII?oo^&zaQ5Uyh0Mn@? z`8~%OebXiG!owRIV?WBV&;`Z)WG6QFAe8|}C^o#!(iH^RRi}9Lb>R){L41j%->B+R zqqT0<2e<$sxSR10hcn*^Jg)U#^L=WN4;1WX+F^YC1Xi<`7ib8jf3wv_bry+`=h`hVCk|8nb<3G#}4EXX0>rJh2EZ|B$J&_!h3gr(ZZ)O`G; z*U%cH3n+=!yJ(2f)d&NjC4D=5p1!QE^G6>Klih4{R7PTA^HDUpRfVKHIJ&^oQ#&O~ zI96`;W4O-$n7>Jrl<}Z-?TDqXXerH;9oeLin7t6IL!Sg_5+Y(15r^Okr1|R%%4=^J z-&I4-i>RJeh1524wqRLe7DC$2KWBM3wu)SLYMQ#b}mCKNn(O#qjw^KqN`& z2AH<~(@12>ij5w?Pec+L0)h|%0n*);`5$)TX76NUY;SM#i_-pOGmv0j1Ec)k-r5t! zt@~M!gT4oM22OW4COj*B;q{~o?r2(tXQ{&smA5r1d*|_(p7f2gwl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vh?bR z1s&XN)h@d0xp)MHqr+3JgmetqFOzWt%p9o>Hj%t>ZX88yarlbCt=0~?{Rs+3zsG|j zv(U8R7&3fy>?KxWb8P9G13luy-1}+(udChGI!FS1t;WUWV4q`8|fTcHA-(~D`a zIT4EewoBg-CUoxDM!&3ns;%F<(!6hq>CW6!n%5z9khnDhDj({pcPr-eQ=V$Sx1oX^ z{CKV@!+T;EK5`WeGk&;a>X-yOY*XSeswy!=rz@4W#i(+wVu=>@4b~MhfBjsK_JBus z#});%O1Aw2o*O^a2+>xa+2pVeHx=?A!Aia0k@0&^XMQilwtdm7y8AIp#=`*s@nVe0 zk5t9B0DNNHCX^3xmc-=yuioA*?&)zq;W-XXU2U*#1m$e$w!Fqdt=zJ?TW^oOxjnDA z#|HKRo)FqR`nF}UJlER9Ng{0PFi|7iGq%tJy8+uVS-_0UsvvEV zi{|~#X~D>f=YsPcn#5~mLT14k{B>W%=l}6QkWftEi16ao4*VGd*|9;1*gHukpI1p?RT8t`_sy>#*?N(s&% zD8Cm{eh2tH9rY(b67k<&#vjS4-%);FfBcDZME(cLf2>A+NBH-k?oW9Lhy^MzXZ{}I z{Vx7Hx&8?dP5Z|M{6?*ROSQj){yS6r2?+s#L;sg+`X_HF$-;s)`Bxtj3WP1#7|@u0 G&Hf)lNw(4e diff --git a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportMakerService.cs b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportMakerService.cs deleted file mode 100644 index b33bef19..00000000 --- a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapReportMakerService.cs +++ /dev/null @@ -1,209 +0,0 @@ -using AsbCloudApp.Data.ProcessMap; -using AsbCloudApp.Services; -using ClosedXML.Excel; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace AsbCloudInfrastructure.Services.ProcessMap -{ - - public class ProcessMapReportMakerService : IProcessMapReportMakerService - { - const int firstColumn = 2; - const int lastColumn = 42; - - const int headerRowsCount = 5; - - private readonly IProcessMapService processMapService; - - public ProcessMapReportMakerService(IProcessMapService processMapService) - { - this.processMapService = processMapService; - } - - public async Task MakeReportAsync(int idWell, CancellationToken token) - { - var stream = GetExcelTemplateStream(); - using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled); - - var data = await processMapService.GetProcessMapReportAsync(idWell, token); - - FillProcessMapToWorkbook(workbook, data); - - MemoryStream memoryStream = new MemoryStream(); - workbook.SaveAs(memoryStream, new SaveOptions { }); - memoryStream.Seek(0, SeekOrigin.Begin); - return memoryStream; - } - - private static void FillProcessMapToWorkbook(XLWorkbook workbook, IEnumerable data) - { - var sheet = workbook.Worksheets.FirstOrDefault(); - if (sheet is null) - return; - var dataBySections = data.GroupBy(p => p.IdWellSectionType); - FillSheet(sheet, dataBySections); - } - - private static void FillSheet(IXLWorksheet sheet, IEnumerable> dataBySections) - { - var startRow = headerRowsCount + 1; - foreach (var sectionData in dataBySections) - { - if(sectionData.Any()) - startRow = FillSection(sheet, sectionData, startRow); - } - } - - private static int FillSection(IXLWorksheet sheet, IGrouping sectionData, int row) - { - var rowStart = row; - - var sectionName = sectionData.FirstOrDefault()?.WellSectionTypeName - ?? sectionData.Key.ToString(); - - sheet.Range(row, firstColumn, row, lastColumn) - .Merge() - .FirstCell() - .SetVal(sectionName) - .Style - .Fill.SetBackgroundColor(XLColor.LightGray); - - row++; - - foreach (var interval in sectionData) - row = FillIntervalData(sheet, interval, row); - - var sectionStyle = sheet.Range(rowStart, firstColumn, row - 1, lastColumn).Style; - SetBorders(sectionStyle); - return row; - } - - private static int FillIntervalData(IXLWorksheet sheet, ProcessMapReportDto interval, int row) - { - const int columnDepth = firstColumn + 1; - const int columnDate = firstColumn + 2; - const int columnRopTime = firstColumn + 3; - const int columnMode = firstColumn + 4; - - sheet.Cell(row, firstColumn) - .SetVal(interval.DepthStart, "0.0"); - - sheet.Cell(row, columnDepth) - .SetVal(interval.DepthEnd, "0.0"); - - sheet.Cell(row, columnDate) - .SetVal(interval.DateStart); - - sheet.Cell(row, columnRopTime) - .SetVal(interval.MechDrillingHours); - - row = FillIntervalModeData(sheet, interval, columnMode, row); - - return row; - } - - private static int FillIntervalModeData(IXLWorksheet sheet, ProcessMapReportDto modeData, int column, int row) - { - int columnDeltaDepth = column + 1; - int columnPressure = columnDeltaDepth + 1; - int columnLoad = columnPressure + 5; - int columnTorque = columnLoad + 5; - int columnSpeed = columnTorque + 5; - int columnUsagePlan = columnSpeed + 5; - int columnUsageFact = columnUsagePlan + 1; - int columnRop = columnUsageFact + 12; - - sheet.Cell(row, column) - .SetVal(modeData.DrillingMode); - - sheet.Cell(row, columnDeltaDepth) - .SetVal(modeData.DeltaDepth); - - FillIntervalModeDataParam(sheet, modeData.PressureDiff, columnPressure, row); - FillIntervalModeDataParam(sheet, modeData.AxialLoad, columnLoad, row); - FillIntervalModeDataParam(sheet, modeData.TopDriveTorque, columnTorque, row); - FillIntervalModeDataSpeed(sheet, modeData.SpeedLimit, columnSpeed, row); - - sheet.Cell(row, columnUsagePlan) - .SetVal(modeData.UsagePlan); - - sheet.Cell(row, columnUsageFact) - .SetVal(modeData.UsageFact); - - sheet.Cell(row, columnRop) - .SetVal(modeData.Rop); - - return row + 1; - } - - private static void FillIntervalModeDataParam(IXLWorksheet sheet, ProcessMapReportParamsDto dataParam, int column, int row) - { - const int columnOffsetSpPlan = 0; - const int columnOffsetSpFact = 1; - const int columnOffsetFact = 2; - const int columnOffsetLimit = 3; - const int columnOffsetPercent = 4; - - sheet.Cell(row, column + columnOffsetSpPlan) - .SetVal(dataParam.SetpointPlan); - - sheet.Cell(row, column + columnOffsetSpFact) - .SetVal(dataParam.SetpointFact); - - sheet.Cell(row, column + columnOffsetFact) - .SetVal(dataParam.Fact); - - sheet.Cell(row, column + columnOffsetLimit) - .SetVal(dataParam.Limit); - - sheet.Cell(row, column + columnOffsetPercent) - .SetVal(dataParam.SetpointUsage, format: "0.0"); - } - - private static void FillIntervalModeDataSpeed(IXLWorksheet sheet, ProcessMapReportParamsDto dataParam, int column, int row) - { - const int columnOffsetSpPlan = 0; - const int columnOffsetSpFact = 1; - const int columnOffsetFact = 2; - const int columnOffsetLimit = 3; - const int columnOffsetPercent = 4; - - sheet.Cell(row, column + columnOffsetSpPlan) - .SetVal(dataParam.SetpointPlan); - - sheet.Cell(row, column + columnOffsetSpFact) - .SetVal(dataParam.SetpointFact); - - sheet.Cell(row, column + columnOffsetFact) - .SetVal(dataParam.Fact); - - sheet.Cell(row, column + columnOffsetLimit) - .SetVal(dataParam.Limit); - - sheet.Cell(row, column + columnOffsetPercent) - .SetVal(dataParam.SetpointUsage, format: "0.0"); - } - - private static Stream GetExcelTemplateStream() - { - var stream = System.Reflection.Assembly.GetExecutingAssembly() - .GetManifestResourceStream("AsbCloudInfrastructure.Services.ProcessMap.ProcessMapReportTemplate.xlsx"); - return stream!; - } - - private static IXLStyle SetBorders(IXLStyle style) - { - style.Border.RightBorder = XLBorderStyleValues.Thin ; - style.Border.LeftBorder = XLBorderStyleValues.Thin; - style.Border.TopBorder = XLBorderStyleValues.Thin ; - style.Border.BottomBorder = XLBorderStyleValues.Thin ; - style.Border.InsideBorder = XLBorderStyleValues.Thin ; - return style; - } - } - -} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapService.cs b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapService.cs deleted file mode 100644 index 97df17ed..00000000 --- a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapService.cs +++ /dev/null @@ -1,399 +0,0 @@ -using AsbCloudApp.Data.ProcessMap; -using AsbCloudApp.Data.SAUB; -using AsbCloudApp.Exceptions; -using AsbCloudApp.Repositories; -using AsbCloudApp.Services; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace AsbCloudInfrastructure.Services.ProcessMap -{ - - public partial class ProcessMapService : IProcessMapService - { - private readonly IWellService wellService; - private readonly IWellOperationRepository wellOperationRepository; - private readonly IProcessMapPlanRepository processMapPlanRepository; - private readonly ITelemetryDataSaubService telemetryDataSaubService; - - public ProcessMapService( - IWellService wellService, - IWellOperationRepository wellOperationRepository, - IProcessMapPlanRepository processMapPlanRepository, - ITelemetryDataSaubService telemetryDataSaubService) - { - this.wellService = wellService; - this.wellOperationRepository = wellOperationRepository; - this.processMapPlanRepository = processMapPlanRepository; - this.telemetryDataSaubService = telemetryDataSaubService; - } - - /// - public async Task> GetProcessMapReportAsync(int idWell, CancellationToken token) - { - var well = wellService.GetOrDefault(idWell) - ?? throw new ArgumentInvalidException(nameof(idWell), "idWell not found"); - - var idTelemetry = well.IdTelemetry - ?? throw new ArgumentInvalidException(nameof(idWell), "telemetry by well not found"); - - var processMapPlan = await processMapPlanRepository.GetByIdWellAsync(idWell, token); - - if (!processMapPlan.Any()) - return Enumerable.Empty(); - - var telemetryDataStat = (await telemetryDataSaubService.GetTelemetryDataStatAsync(idTelemetry, token)).ToArray(); - if (!telemetryDataStat.Any()) - return Enumerable.Empty(); - - var result = CalcByIntervals(processMapPlan, telemetryDataStat); - - return result; - } - - private IEnumerable CalcByIntervals(IEnumerable processMapPlan, TelemetryDataSaubStatDto[] telemetryDataStat) - { - var processMapIntervals = CalcDepthIntervals(processMapPlan); - - var result = new List(processMapIntervals.Count() * 4); - - var telemetryIndexStart = Array.FindIndex(telemetryDataStat, t => t.WellDepthMin >= processMapIntervals.First().DepthStart); - if (telemetryIndexStart < 0) - return Enumerable.Empty(); - - IDictionary sectionTypes = wellOperationRepository - .GetSectionTypes() - .ToDictionary(s => s.Id, s => s.Caption); - - foreach (var interval in processMapIntervals) - { - // plans [ ][ ] - // interval [ ] - var processMapPlanInterval = processMapPlan - .Where(p => p.DepthStart <= interval.DepthEnd && p.DepthEnd >= interval.DepthStart); - - if (!processMapPlanInterval.Any()) - continue; - - var telemetryIndexEnd = Array.FindIndex(telemetryDataStat, telemetryIndexStart, t => t.WellDepthMin >= interval.DepthEnd); - if (telemetryIndexEnd < 0) - telemetryIndexEnd = telemetryDataStat.Length - 1; - var telemetryDataInterval = telemetryDataStat.AsSpan(telemetryIndexStart, telemetryIndexEnd - telemetryIndexStart); - - IEnumerable subIntervalsResult = CalcSubIntervals(interval, processMapPlanInterval, telemetryDataInterval, sectionTypes); - - result.AddRange(subIntervalsResult); - telemetryIndexStart = telemetryIndexEnd; - } - - return result; - } - - private static IEnumerable<(double DepthStart, double DepthEnd)> CalcDepthIntervals(IEnumerable processMapPlan) - { - if(!processMapPlan.Any()) - yield break; - - var intervalStarts = processMapPlan - .OrderBy(i => i.DepthStart) - .Select(p => p.DepthStart) - .Distinct() - .ToArray(); - - for (var i = 1; i < intervalStarts.Length; i++) - yield return (intervalStarts[i - 1], intervalStarts[i]); - - yield return (intervalStarts[^1], processMapPlan.Max(p=>p.DepthEnd)); - } - - private static IEnumerable CalcSubIntervals( - (double DepthStart, double DepthEnd) interval, - IEnumerable processMapPlanInterval, - Span telemetryDataInterval, - IDictionary sectionTypes) - { - var telemetryDataIntervalLength = telemetryDataInterval.Length; - if (telemetryDataInterval.Length == 0) - return Enumerable.Empty(); - - var result = new List(); - var telemetryIndexStart = 0; - var subInterval = interval; - - for (var i = telemetryIndexStart + 1; i < telemetryDataIntervalLength; i++) - { - if (IsDifferent(telemetryDataInterval[telemetryIndexStart], telemetryDataInterval[i])) - { - subInterval.DepthEnd = telemetryDataInterval[i - 1].WellDepthMax; - var telemetryRowSpan = telemetryDataInterval[telemetryIndexStart..(i - 1)]; - if (!telemetryRowSpan.IsEmpty) - { - var intervalReportRow = CalcSubIntervalReportRow(subInterval, processMapPlanInterval, telemetryRowSpan, sectionTypes); - result.Add(intervalReportRow); - } - telemetryIndexStart = i; - subInterval.DepthStart = subInterval.DepthEnd; - } - } - - subInterval.DepthEnd = interval.DepthEnd; - var intervalReportRowLast = CalcSubIntervalReportRow(subInterval, processMapPlanInterval, telemetryDataInterval[telemetryIndexStart..telemetryDataIntervalLength], sectionTypes); - result.Add(intervalReportRowLast); - return result; - } - - private static ProcessMapReportDto CalcSubIntervalReportRow( - (double DepthStart, double DepthEnd) subInterval, - IEnumerable processMap, - Span telemetryRowSpan, - IDictionary sectionTypes) - { - var telemetryStat = new TelemetryStat(telemetryRowSpan); - var processMapByMode = processMap.FirstOrDefault(p => p.IdMode == telemetryStat.IdMode); - var processMapFirst = processMap.First(); - var idWellSectionType = processMapByMode?.IdWellSectionType ?? processMapFirst.IdWellSectionType; - - var result = new ProcessMapReportDto - { - IdWell = processMapByMode?.IdWell ?? processMapFirst.IdWell, - IdWellSectionType = idWellSectionType, - WellSectionTypeName = sectionTypes[idWellSectionType], - - DepthStart = subInterval.DepthStart, - DepthEnd = subInterval.DepthEnd, - DateStart = telemetryStat.DateStart, - - MechDrillingHours = telemetryStat.MechDrillingHours, - DrillingMode = telemetryStat.ModeName, - - DeltaDepth = telemetryStat.DeltaDepth, - - PressureDiff = telemetryStat.Pressure.MakeParams(processMapByMode?.Pressure.Plan), - AxialLoad = telemetryStat.AxialLoad.MakeParams(processMapByMode?.AxialLoad.Plan), - TopDriveTorque = telemetryStat.RotorTorque.MakeParams(processMapByMode?.TopDriveTorque.Plan), - SpeedLimit = telemetryStat.BlockSpeed.MakeParams(processMapByMode?.RopPlan), - - Rop = telemetryStat.Rop, - UsagePlan = processMapByMode?.UsageSaub ?? telemetryStat.UsagePredictPlan, - UsageFact = telemetryStat.UsageSaub, - }; - return result; - } - - private static bool IsDifferent(TelemetryDataSaubStatDto intervalStart, TelemetryDataSaubStatDto current) - { - if (intervalStart.WellDepthMin > current.WellDepthMin) - return true; - - if (intervalStart.IdMode != current.IdMode) - return true; - - if (Math.Abs(intervalStart.PressureSp - current.PressureSp) > 5d) - return true; - - if (Math.Abs(intervalStart.AxialLoadSp - current.AxialLoadSp) > 1d) - return true; - - if (Math.Abs(intervalStart.RotorTorqueSp - current.RotorTorqueSp) > 5d) - return true; - - var blockSpeedSpDiff = Math.Abs(intervalStart.BlockSpeedSp - current.BlockSpeedSp); - if (blockSpeedSpDiff > 5d) - { - if (intervalStart.BlockSpeedSp <= 30) - return true; - else if (intervalStart.BlockSpeedSp > 30 && blockSpeedSpDiff > 15d) - return true; - else if (intervalStart.BlockSpeedSp > 80 && blockSpeedSpDiff > 20d) - return true; - } - - return false; - } - } - - class ParamStat - { - private double spWSum; - private double pvWSum; - private double limitMaxWSum; - - private double deltaDepthSum; - - private readonly Func getterSp; - private readonly Func getterPv; - private readonly Func? getterLimitMax; - - private readonly int idFeedRegulator; - private readonly int idMode; - private TelemetryDataSaubStatDto? previous; - - public double SpUsageDepth { get; private set; } - private static double spUsageTotal; - - public ParamStat(Func getterSp, - Func getterPv, - Func? getterLimitMax, - int idFeedRegulator, - int idMode) - { - this.getterSp = getterSp; - this.getterPv = getterPv; - this.getterLimitMax = getterLimitMax; - this.idFeedRegulator = idFeedRegulator; - this.idMode = idMode; - spUsageTotal = 0d; - } - - public void UpdateStat(TelemetryDataSaubStatDto current) - { - if(previous is not null) - { - var deltaDepth = current.WellDepthMin - previous.WellDepthMin; - if (deltaDepth > 0) - { - var deltaDepthHalf = deltaDepth / 2; - double CalculateWeight(Func getter) => (getter(previous!) + getter(current)) * deltaDepthHalf; - - spWSum += CalculateWeight(getterSp); - pvWSum += CalculateWeight(getterPv); - if(getterLimitMax is not null) - limitMaxWSum += CalculateWeight(getterLimitMax!); - - if (current.IdFeedRegulator is not null) - { - if (current.IdFeedRegulator == idFeedRegulator) - { - SpUsageDepth += deltaDepth; - spUsageTotal += deltaDepth; - } - } - else - { - var pvErr = (getterSp(current) - getterPv(current)) / getterSp(current); - if (pvErr < 0.03d) //3% - { - SpUsageDepth += deltaDepth; - spUsageTotal += deltaDepth; - } - } - - deltaDepthSum += deltaDepth; - } - } - - previous = current; - } - - public ProcessMapReportParamsDto MakeParams(double? spPlan) - { - var result = new ProcessMapReportParamsDto - { - SetpointPlan = spPlan, - Fact = DivideValByDepth(pvWSum), - }; - - if (idMode == 0) - { - result.SetpointFact = null; - result.Limit = null; - result.SetpointUsage = null; - } - else - { - result.SetpointFact = DivideValByDepth(spWSum); - result.Limit = (getterLimitMax is not null) ? DivideValByDepth(limitMaxWSum) : null; - result.SetpointUsage = deltaDepthSum > 0d ? 100d * SpUsageDepth / spUsageTotal : null; - } - - return result; - } - - private double? DivideValByDepth(double? val) - { - if(val is null || val == 0d || deltaDepthSum == 0d) - return null; - return val / deltaDepthSum; - } - } - - class TelemetryStat { - public ParamStat Pressure { get; } - public ParamStat AxialLoad {get; } - public ParamStat RotorTorque {get; } - public ParamStat BlockSpeed {get; } - - private TelemetryDataSaubStatDto? previous; - private double depthSum = 0d; - private double hoursSum = 0d; - - public double? Rop => hoursSum == 0d ? null : depthSum / hoursSum; - - private double depthWithSaub = 0d; - public double UsageSaub { get; } - public double UsagePredictPlan { get; } - public DateTime DateStart { get; } - public float DeltaDepth { get; } - public int IdMode { get; } - public string ModeName { get; } - public double MechDrillingHours { get; } - - public TelemetryStat(Span telemetry) - { - var telemetryFirst = telemetry[0]; - var telemetryLast = telemetry[^1]; - - IdMode = telemetryFirst.IdMode; - ModeName = GetModeName(IdMode); - DateStart = telemetryFirst.DateMin; - DeltaDepth = telemetryLast.WellDepthMax - telemetryFirst.WellDepthMin; - MechDrillingHours = (telemetryLast.DateMax - telemetryFirst.DateMin).TotalHours; - - BlockSpeed = new(t => t.BlockSpeedSp, t => t.BlockSpeed, null, 1, IdMode); - Pressure = new(t => t.PressureSpDelta, t => t.PressureDelta, t=>t.PressureDeltaLimitMax, 2, IdMode); - RotorTorque = new(t => t.RotorTorqueSp, t => t.RotorTorque, t=>t.RotorTorqueLimitMax, 3, IdMode); - AxialLoad = new(t => t.AxialLoadSp, t => t.AxialLoad, t=>t.AxialLoadLimitMax, 4, IdMode); - - for (int i = 0; i < telemetry.Length; i++) - UpdateStat(telemetry[i]); - - UsageSaub = 100d * depthWithSaub / depthSum; - UsagePredictPlan = IdMode != 0 ? 100d : 0d; - } - - private void UpdateStat(TelemetryDataSaubStatDto current) - { - if(previous is not null) - { - var deltaDepth = current.WellDepthMin - previous.WellDepthMin; - if(deltaDepth > 0) - { - var deltaHours = (current.DateMin - previous.DateMax).TotalHours; - depthSum += deltaDepth; - hoursSum += deltaHours; - - if(current.IdMode == 1 || current.IdMode == 3) - depthWithSaub += deltaDepth; - } - } - - previous = current; - Pressure.UpdateStat(current); - AxialLoad.UpdateStat(current); - RotorTorque.UpdateStat(current); - BlockSpeed.UpdateStat(current); - } - - private static string GetModeName(int idMode) - => idMode switch - { - 1 => "Ротор", - 3 => "Слайд", - _ => "Ручной", - }; - } - -} diff --git a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapWellboreDevelopment/ProcessMapWellboreDevelopmentService.cs b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapWellboreDevelopment/ProcessMapWellboreDevelopmentService.cs deleted file mode 100644 index 1a709cda..00000000 --- a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapWellboreDevelopment/ProcessMapWellboreDevelopmentService.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using AsbCloudApp.Data.ProcessMap; -using AsbCloudApp.Exceptions; -using AsbCloudApp.Repositories; -using AsbCloudApp.Services; - -namespace AsbCloudInfrastructure.Services.ProcessMap.ProcessMapWellboreDevelopment; - -public class ProcessMapWellboreDevelopmentService : IProcessMapWellboreDevelopmentService -{ - private readonly ITelemetryService telemetryService; - private readonly IWellService wellService; - private readonly IProcessMapWellboreDevelopmentRepository processMapWellboreDevelopmentRepository; - - public ProcessMapWellboreDevelopmentService(ITelemetryService telemetryService, - IWellService wellService, - IProcessMapWellboreDevelopmentRepository processMapWellboreDevelopmentRepository) - { - this.telemetryService = telemetryService; - this.wellService = wellService; - this.processMapWellboreDevelopmentRepository = processMapWellboreDevelopmentRepository; - } - - public async Task InsertAsync(ProcessMapWellboreDevelopmentDto processMapWellboreDevelopment, CancellationToken cancellationToken) - { - var well = await wellService.GetOrDefaultAsync(processMapWellboreDevelopment.IdWell, cancellationToken) - ?? throw new ArgumentInvalidException(nameof(processMapWellboreDevelopment.IdWell), - $"Скважины с Id: {processMapWellboreDevelopment.IdWell} не существует"); - - processMapWellboreDevelopment.LastUpdate = DateTimeOffset.UtcNow; - - return await processMapWellboreDevelopmentRepository.InsertAsync(processMapWellboreDevelopment, cancellationToken); - } - - public async Task UpdateAsync(ProcessMapWellboreDevelopmentDto processMapWellboreDevelopment, CancellationToken cancellationToken) - { - var well = await wellService.GetOrDefaultAsync(processMapWellboreDevelopment.IdWell, cancellationToken); - - if (well is null) - throw new ArgumentInvalidException(nameof(processMapWellboreDevelopment.IdWell), - $"Скважины с Id: {processMapWellboreDevelopment.IdWell} не существует"); - - processMapWellboreDevelopment.LastUpdate = DateTimeOffset.UtcNow; - - var result = await processMapWellboreDevelopmentRepository.UpdateAsync(processMapWellboreDevelopment, cancellationToken); - - if (result == ICrudRepository.ErrorIdNotFound) - throw new ArgumentInvalidException(nameof(processMapWellboreDevelopment.Id), - $"Проработки с Id: {processMapWellboreDevelopment.Id} не существует"); - - return result; - } - - public async Task> GetByTelemetryAsync(string uid, DateTime updateFrom, - CancellationToken cancellationToken) - { - var idWell = telemetryService.GetIdWellByTelemetryUid(uid); - - if (!idWell.HasValue) - throw new ArgumentInvalidException(nameof(uid), $"Неправильный телеметрии. Uid: {uid}"); - - return await processMapWellboreDevelopmentRepository.GetAllAsync(idWell.Value, updateFrom, cancellationToken); - } -} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/ProcessMap/XLExtentions.cs b/AsbCloudInfrastructure/Services/ProcessMap/XLExtentions.cs deleted file mode 100644 index fdf830e7..00000000 --- a/AsbCloudInfrastructure/Services/ProcessMap/XLExtentions.cs +++ /dev/null @@ -1,52 +0,0 @@ -using ClosedXML.Excel; -using System; - -namespace AsbCloudInfrastructure.Services.ProcessMap; - -internal static class XLExtentions -{ - - public static IXLCell SetVal(this IXLCell cell, string value, bool adaptRowHeight = false) - { - cell.Value = value; - if (adaptRowHeight) - { - var colWidth = cell.WorksheetColumn().Width; - var maxCharsToWrap = colWidth / (0.1d * cell.Style.Font.FontSize); - if (value.Length > maxCharsToWrap) - { - var row = cell.WorksheetRow(); - var baseHeight = row.Height; - row.Height = 0.5d * baseHeight * Math.Ceiling(1d + value.Length / maxCharsToWrap); - } - } - - return cell; - } - - public static IXLCell SetVal(this IXLCell cell, DateTime value, string dateFormat = "DD.MM.YYYY HH:MM:SS") - { - cell.Value = value; - cell.DataType = XLDataType.DateTime; - cell.Style.DateFormat.Format = dateFormat; - - return cell; - } - - public static IXLCell SetVal(this IXLCell cell, int? value, string format = "0.00") - { - cell.Value = value; - cell.DataType = XLDataType.Number; - cell.Style.NumberFormat.Format = format; - return cell; - } - - public static IXLCell SetVal(this IXLCell cell, double? value, string format = "0.00") - { - cell.Value = (value is not null && double.IsFinite(value.Value)) ? value : null; - cell.DataType = XLDataType.Number; - cell.Style.NumberFormat.Format = format; - return cell; - } - -} diff --git a/AsbCloudInfrastructure/Services/WellInfoService.cs b/AsbCloudInfrastructure/Services/WellInfoService.cs index eea573cc..bbe261bf 100644 --- a/AsbCloudInfrastructure/Services/WellInfoService.cs +++ b/AsbCloudInfrastructure/Services/WellInfoService.cs @@ -1,5 +1,4 @@ using AsbCloudApp.Data; -using AsbCloudApp.Data.ProcessMap; using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.WITS; using AsbCloudApp.Repositories; @@ -15,6 +14,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.IntegrationEvents; using AsbCloudApp.IntegrationEvents.Interfaces; @@ -66,7 +66,7 @@ namespace AsbCloudInfrastructure.Services { var wellService = serviceProvider.GetRequiredService(); var operationsStatService = serviceProvider.GetRequiredService(); - var processMapRepository = serviceProvider.GetRequiredService(); + var wellDrillingProcessMapRepository = serviceProvider.GetRequiredService(); var subsystemOperationTimeService = serviceProvider.GetRequiredService(); var telemetryDataSaubCache = serviceProvider.GetRequiredService>(); var messageHub = serviceProvider.GetRequiredService>(); @@ -75,10 +75,10 @@ namespace AsbCloudInfrastructure.Services var wellsIds = wells.Select(w => w.Id); - var processMapRequests = wellsIds.Select(id => new ProcessMapRequest { IdWell = id }); - var processMaps = await processMapRepository.GetProcessMapAsync(processMapRequests, token); + var wellDrillingProcessMapRequests = wellsIds.Select(id => new WellDrillingProcessMapRequest { IdWell = id }); + var wellDrillingProcessMaps = await wellDrillingProcessMapRepository.GetAsync(wellDrillingProcessMapRequests, token); - var wellDepthByProcessMap = processMaps + var wellDepthByProcessMap = wellDrillingProcessMaps .GroupBy(p => p.IdWell) .Select(g => new { @@ -113,20 +113,20 @@ namespace AsbCloudInfrastructure.Services var wellLastFactSection = wellOperationsStat?.Sections.LastOrDefault(s => s.Fact is not null); currentDepth ??= wellLastFactSection?.Fact?.WellDepthEnd; - var wellProcessMaps = processMaps + var wellProcessMaps = wellDrillingProcessMaps .Where(p => p.IdWell == well.Id) .OrderBy(p => p.DepthEnd); int? idSection = wellLastFactSection?.Id; - ProcessMapPlanDto? wellProcessMap = null; + WellDrillingProcessMapDto? wellDrillingProcessMap = null; if (idSection.HasValue) { - wellProcessMap = wellProcessMaps.FirstOrDefault(p => p.IdWellSectionType == idSection); + wellDrillingProcessMap = wellProcessMaps.FirstOrDefault(p => p.IdWellSectionType == idSection); } else if(currentDepth.HasValue) { - wellProcessMap = wellProcessMaps.FirstOrDefault(p => p.DepthStart <= currentDepth.Value && p.DepthEnd >= currentDepth.Value); + wellDrillingProcessMap = wellProcessMaps.FirstOrDefault(p => p.DepthStart <= currentDepth.Value && p.DepthEnd >= currentDepth.Value); } double? planTotalDepth = null; @@ -142,25 +142,25 @@ namespace AsbCloudInfrastructure.Services wellMapInfo.AxialLoad = new() { - Plan = wellProcessMap?.AxialLoad.Plan, + Plan = wellDrillingProcessMap?.AxialLoad.Plan, Fact = lastSaubTelemetry?.AxialLoad }; wellMapInfo.TopDriveSpeed = new() { - Plan = wellProcessMap?.TopDriveSpeed.Plan, + Plan = wellDrillingProcessMap?.TopDriveSpeed.Plan, Fact = lastSaubTelemetry?.RotorSpeed }; wellMapInfo.TopDriveTorque = new() { - Plan = wellProcessMap?.TopDriveTorque.Plan, + Plan = wellDrillingProcessMap?.TopDriveTorque.Plan, Fact = lastSaubTelemetry?.RotorTorque }; wellMapInfo.Pressure = new() { - Plan = wellProcessMap?.Pressure.Plan, + Plan = wellDrillingProcessMap?.Pressure.Plan, Fact = lastSaubTelemetry?.Pressure }; @@ -174,7 +174,7 @@ namespace AsbCloudInfrastructure.Services wellMapInfo.ROP = new() { - Plan = wellProcessMap?.RopPlan, + Plan = wellDrillingProcessMap?.RopPlan, Fact = wellOperationsStat?.Total.Fact?.Rop, };