Process map some nit refactoring

This commit is contained in:
ngfrolov 2023-10-17 10:20:27 +05:00
parent 278913b9be
commit fb307ccceb
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
13 changed files with 203 additions and 204 deletions

View File

@ -62,11 +62,6 @@ public class ProcessMapPlanWellReamDto : ProcessMapPlanBaseDto, IValidatableObje
[Range(0, 99999.9, ErrorMessage = "Крутящий момент должен быть в пределах от 0 до 99999.9")]
public double Torque { get; set; }
/// <summary>
/// Комментарий
/// </summary>
public string? Comment { get; set; }
/// <inheritdoc/>
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{

View File

@ -37,8 +37,8 @@
<EmbeddedResource Include="Services\WellOperationImport\Files\Dictionaries\Operations.txt" />
<EmbeddedResource Include="Services\WellOperationImport\Files\Dictionaries\Sections.txt" />
<EmbeddedResource Include="Services\WellOperationImport\Files\Dictionaries\OperationAttributes.txt" />
<EmbeddedResource Include="Services\ProcessMaps\Files\DrillingProcessMapReportTemplate.xlsx" />
<EmbeddedResource Include="Services\ProcessMaps\Files\DrillingProcessMapTemplate.xlsx" />
<EmbeddedResource Include="Services\ProcessMaps\Report\ProcessMapReportTemplate.xlsx" />
<EmbeddedResource Include="Services\ProcessMaps\WellDrilling\ProcessMapPlanImportWellDrillingTemplate.xlsx" />
</ItemGroup>
<ItemGroup>

View File

@ -24,8 +24,8 @@ using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
using AsbCloudInfrastructure.Services.DailyReport;
using AsbCloudInfrastructure.Services.DetectOperations;
using AsbCloudInfrastructure.Services.DrillingProgram;
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap;
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report;
using AsbCloudInfrastructure.Services.ProcessMaps.Report;
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling;
using AsbCloudInfrastructure.Services.SAUB;
using AsbCloudInfrastructure.Services.Subsystems;
using AsbCloudInfrastructure.Services.Trajectory;
@ -197,7 +197,7 @@ namespace AsbCloudInfrastructure
services.AddTransient<IFileCategoryService, FileCategoryService>();
services.AddTransient<ILimitingParameterService, LimitingParameterService>();
services.AddTransient<IProcessMapReportWellDrillingService, ProcessMapReportWellDrillingService>();
services.AddTransient<IProcessMapPlanImportService, ProcessMapPlanWellDrillingImportService>();
services.AddTransient<IProcessMapPlanImportService, ProcessMapPlanImportWellDrillingService>();
services.AddTransient<WellInfoService>();
services.AddTransient<IHelpPageService, HelpPageService>();

View File

@ -15,7 +15,7 @@ namespace AsbCloudInfrastructure.Repository
{
protected readonly IMemoryCache memoryCache;
protected string CacheTag = typeof(TEntity).Name;
protected TimeSpan CacheOlescence = TimeSpan.FromMinutes(5);
protected TimeSpan CacheObsolescence = TimeSpan.FromMinutes(5);
public CacheBase(IAsbCloudDbContext context, IMemoryCache memoryCache)
: base(context)
@ -36,8 +36,8 @@ namespace AsbCloudInfrastructure.Repository
{
var cache = memoryCache.GetOrCreate(CacheTag, cacheEntry =>
{
cacheEntry.AbsoluteExpirationRelativeToNow = CacheOlescence;
cacheEntry.SlidingExpiration = CacheOlescence;
cacheEntry.AbsoluteExpirationRelativeToNow = CacheObsolescence;
cacheEntry.SlidingExpiration = CacheObsolescence;
var entities = this.GetQuery().ToArray();
cacheEntry.Value = entities;
@ -50,8 +50,8 @@ namespace AsbCloudInfrastructure.Repository
{
var cache = memoryCache.GetOrCreateAsync(CacheTag, async (cacheEntry) =>
{
cacheEntry.AbsoluteExpirationRelativeToNow = CacheOlescence;
cacheEntry.SlidingExpiration = CacheOlescence;
cacheEntry.AbsoluteExpirationRelativeToNow = CacheObsolescence;
cacheEntry.SlidingExpiration = CacheObsolescence;
var entities = await this.GetQuery().ToArrayAsync(token);
cacheEntry.Value = entities;

View File

@ -0,0 +1,110 @@
using System;
using AsbCloudApp.Data.ProcessMaps.Report;
using AsbCloudApp.Data.SAUB;
namespace AsbCloudInfrastructure.Services.ProcessMaps.Report.Data;
internal class ParamStat
{
private double spWSum;
private double pvWSum;
private double limitMaxWSum;
private double deltaDepthSum;
private readonly Func<TelemetryDataSaubStatDto, double> getterSp;
private readonly Func<TelemetryDataSaubStatDto, double> getterPv;
private readonly Func<TelemetryDataSaubStatDto, double>? 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<TelemetryDataSaubStatDto, double> getterSp,
Func<TelemetryDataSaubStatDto, double> getterPv,
Func<TelemetryDataSaubStatDto, double>? 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<TelemetryDataSaubStatDto, double> 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 ProcessMapReportWellDrillingParamsDto MakeParams(double? spPlan)
{
var result = new ProcessMapReportWellDrillingParamsDto
{
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;
}
}

View File

@ -1,8 +1,7 @@
using System;
using AsbCloudApp.Data.SAUB;
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling.Report.Data;
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report.Data;
namespace AsbCloudInfrastructure.Services.ProcessMaps.Report.Data;
internal class TelemetryStat
{
@ -24,7 +23,7 @@ internal class TelemetryStat
public float DeltaDepth { get; }
public int IdMode { get; }
public string ModeName { get; }
public double MechDrillingHours { get; }
public double DrillingHours { get; }
public TelemetryStat(Span<TelemetryDataSaubStatDto> telemetry)
{
@ -35,7 +34,7 @@ internal class TelemetryStat
ModeName = GetModeName(IdMode);
DateStart = telemetryFirst.DateMin;
DeltaDepth = telemetryLast.WellDepthMax - telemetryFirst.WellDepthMin;
MechDrillingHours = (telemetryLast.DateMax - telemetryFirst.DateMin).TotalHours;
DrillingHours = (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);

View File

@ -9,7 +9,7 @@ using AsbCloudApp.Services;
using AsbCloudApp.Services.ProcessMaps.WellDrilling;
using ClosedXML.Excel;
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report;
namespace AsbCloudInfrastructure.Services.ProcessMaps.Report;
public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDrillingExportService
{
@ -208,7 +208,7 @@ public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDr
{
var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(
"AsbCloudInfrastructure.Services.ProcessMaps.Files.DrillingProcessMapReportTemplate.xlsx");
"AsbCloudInfrastructure.Services.ProcessMaps.Report.ProcessMapReportTemplate.xlsx");
return stream!;
}

View File

@ -10,9 +10,9 @@ using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudApp.Services.ProcessMaps.WellDrilling;
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report.Data;
using AsbCloudInfrastructure.Services.ProcessMaps.Report.Data;
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report;
namespace AsbCloudInfrastructure.Services.ProcessMaps.Report;
public class ProcessMapReportWellDrillingService : IProcessMapReportWellDrillingService
{
@ -178,7 +178,7 @@ public class ProcessMapReportWellDrillingService : IProcessMapReportWellDrilling
DepthEnd = subInterval.DepthEnd,
DateStart = telemetryStat.DateStart,
MechDrillingHours = telemetryStat.MechDrillingHours,
MechDrillingHours = telemetryStat.DrillingHours,
DrillingMode = telemetryStat.ModeName,
DeltaDepth = telemetryStat.DeltaDepth,

View File

@ -13,12 +13,12 @@ using AsbCloudApp.Services;
using AsbCloudApp.Services.ProcessMaps;
using ClosedXML.Excel;
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap;
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling;
/*
* password for ProcessMapImportTemplate.xlsx is ASB2020!
*/
public class ProcessMapPlanWellDrillingImportService : IProcessMapPlanImportService
public class ProcessMapPlanImportWellDrillingService : IProcessMapPlanImportService
{
private readonly IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository;
private readonly ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository;
@ -49,7 +49,7 @@ public class ProcessMapPlanWellDrillingImportService : IProcessMapPlanImportServ
private WellSectionTypeDto[] sections = null!;
public ProcessMapPlanWellDrillingImportService(IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository,
public ProcessMapPlanImportWellDrillingService(IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository,
ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository,
IWellService wellService)
{
@ -100,7 +100,7 @@ public class ProcessMapPlanWellDrillingImportService : IProcessMapPlanImportServ
{
var resourceName = Assembly.GetExecutingAssembly()
.GetManifestResourceNames()
.FirstOrDefault(n => n.EndsWith("DrillingProcessMapTemplate.xlsx"))!;
.FirstOrDefault(n => n.EndsWith("ProcessMapPlanImportWellDrillingTemplate.xlsx"))!;
using var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(resourceName)!;
@ -225,6 +225,10 @@ public class ProcessMapPlanWellDrillingImportService : IProcessMapPlanImportServ
?? throw new FileFormatException(
$"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указана некорректная секция");
if(string.IsNullOrEmpty(modeName))
throw new FileFormatException(
$"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} не указан режим");
var idMode = GetIdMode(modeName)
?? throw new FileFormatException(
$"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указан некорректный режим");

View File

@ -1,110 +0,0 @@
using System;
using AsbCloudApp.Data.ProcessMaps.Report;
using AsbCloudApp.Data.SAUB;
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling.Report.Data;
internal class ParamStat
{
private double spWSum;
private double pvWSum;
private double limitMaxWSum;
private double deltaDepthSum;
private readonly Func<TelemetryDataSaubStatDto, double> getterSp;
private readonly Func<TelemetryDataSaubStatDto, double> getterPv;
private readonly Func<TelemetryDataSaubStatDto, double>? 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<TelemetryDataSaubStatDto, double> getterSp,
Func<TelemetryDataSaubStatDto, double> getterPv,
Func<TelemetryDataSaubStatDto, double>? 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<TelemetryDataSaubStatDto, double> 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 ProcessMapReportWellDrillingParamsDto MakeParams(double? spPlan)
{
var result = new ProcessMapReportWellDrillingParamsDto
{
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;
}
}

View File

@ -172,13 +172,16 @@ public abstract class ProcessMapBaseController<T> : ControllerBase
if (!idWell.HasValue)
return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}");
var wellDrillingProcessMaps = await repository.GetAsync(new[] { new ProcessMapPlanRequest
var requests = new[] { new ProcessMapPlanRequest
{
IdWell = idWell.Value,
UpdateFrom = updateFrom
}}, cancellationToken);
}
};
return Ok(wellDrillingProcessMaps);
var processMaps = await repository.GetAsync(requests, cancellationToken);
return Ok(processMaps);
}
protected async Task AssertUserHasAccessToEditProcessMapAsync(int idWell, CancellationToken cancellationToken)
@ -207,9 +210,7 @@ public abstract class ProcessMapBaseController<T> : ControllerBase
private async Task CheckIsExistsWellSectionTypeAsync(int idWellSectionType, CancellationToken cancellationToken)
{
var wellSection = await wellSectionRepository.GetOrDefaultAsync(idWellSectionType, cancellationToken);
if (wellSection is null)
throw new ArgumentInvalidException(nameof(ProcessMapPlanWellDrillingDto.IdWellSectionType), $"Тип секции с Id: {idWellSectionType} не найден");
_ = await wellSectionRepository.GetOrDefaultAsync(idWellSectionType, cancellationToken)
?? throw new ArgumentInvalidException(nameof(ProcessMapPlanWellDrillingDto.IdWellSectionType), $"Тип секции с Id: {idWellSectionType} не найден");
}
}