nit refactoring by VS recommendations
This commit is contained in:
ngfrolov 2023-12-05 14:48:56 +05:00
parent e67e260f35
commit 17c13b7a7b
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
30 changed files with 273 additions and 273 deletions

View File

@ -6,7 +6,7 @@ namespace System.Collections.Generic
/// Цикличный массив
/// </summary>
/// <typeparam name="T"></typeparam>
public class CyclycArray<T> : IEnumerable<T>
public class CyclicArray<T> : IEnumerable<T>
{
readonly T[] array;
int used, current = -1;
@ -15,7 +15,7 @@ namespace System.Collections.Generic
/// constructor
/// </summary>
/// <param name="capacity"></param>
public CyclycArray(int capacity)
public CyclicArray(int capacity)
{
array = new T[capacity];
}

View File

@ -94,5 +94,5 @@ public class ProcessMapReportWellDrillingDto
/// <summary>
/// Механическая скорость, м/ч
/// </summary>
public PlanFactDto<double?> Rop { get; set; }
public PlanFactDto<double?> Rop { get; set; } = new();
}

View File

@ -35,14 +35,18 @@ public class SectionByOperationsDto
public DateTimeOffset DateStart { get; set; }
/// <summary>
/// Глубина после завершения последней операции операции в секции, м
/// Глубина после завершения последней операции в секции, м
/// </summary>
[Range(0, 50_000)]
public double DepthEnd { get; set; }
/// <summary>
/// Дата после завершения последней операции операции в секции
/// Дата после завершения последней операции в секции
/// </summary>
public DateTimeOffset DateEnd { get; set; }
public string Caption { get; set; }
/// <summary>
/// Название
/// </summary>
public string Caption { get; set; } = string.Empty;
}

View File

@ -20,7 +20,7 @@ namespace AsbCloudApp.Repositories
void AddRange(int idTelemetry, IEnumerable<TDto> range);
/// <summary>
/// вернуть последнюю записть
/// вернуть последнюю запись
/// </summary>
/// <param name="idTelemetry"></param>
/// <returns></returns>
@ -49,7 +49,7 @@ namespace AsbCloudApp.Repositories
/// </summary>
/// <param name="idTelemetry"></param>
/// <returns></returns>
DatesRangeDto? GetOrDefaultCachedaDateRange(int idTelemetry);
DatesRangeDto? GetOrDefaultCachedDateRange(int idTelemetry);
/// <summary>
/// Получить диапазон дат телеметрии.

View File

@ -18,7 +18,7 @@ namespace AsbCloudApp.Services
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto>? dtos, CancellationToken token);
Task<int> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto> dtos, CancellationToken token);
/// <summary>
/// Получение истории файлов

View File

@ -12,14 +12,13 @@ using System.Threading.Tasks;
namespace AsbCloudDb
{
public static class EFExtentions
public static class EFExtensions
{
private static readonly System.Text.Json.JsonSerializerOptions jsonSerializerOptions = new()
private static readonly JsonSerializerOptions jsonSerializerOptions = new()
{
AllowTrailingCommas = true,
WriteIndented = true,
NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString |
System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals,
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.AllowNamedFloatingPointLiterals,
};
public static Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasJsonConversion<TProperty>(
@ -28,11 +27,11 @@ namespace AsbCloudDb
public static Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> HasJsonConversion<TProperty>(
this Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<TProperty> builder,
System.Text.Json.JsonSerializerOptions jsonSerializerOptions)
JsonSerializerOptions jsonSerializerOptions)
{
builder.HasConversion(
s => System.Text.Json.JsonSerializer.Serialize(s, jsonSerializerOptions),
s => System.Text.Json.JsonSerializer.Deserialize<TProperty>(s, jsonSerializerOptions)!);
s => JsonSerializer.Serialize(s, jsonSerializerOptions),
s => JsonSerializer.Deserialize<TProperty>(s, jsonSerializerOptions)!);
ValueComparer<TProperty> valueComparer = new (
(a,b) =>
@ -102,7 +101,7 @@ namespace AsbCloudDb
return factory.Columns;
}
public static Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<T> Upsert<T>(this DbSet<T> dbSet, T value)
public static EntityEntry<T> Upsert<T>(this DbSet<T> dbSet, T value)
where T : class
{
return dbSet.Contains(value)

View File

@ -5,9 +5,9 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
namespace AsbCloudDb
{
public static class EFExtentionsInnitialization
public static class EFExtensionsInitialization
{
public static void EnshureCreatedAndMigrated(this DatabaseFacade db)
public static void EnsureCreatedAndMigrated(this DatabaseFacade db)
{
db.SetCommandTimeout(TimeSpan.FromMinutes(5));
if (db.EnsureCreated())

View File

@ -349,6 +349,10 @@ namespace AsbCloudDb.Model
.HasJsonConversion();
});
modelBuilder.Entity<DetectedOperation>(entity => entity
.Property(p=>p.ExtraData)
.HasJsonConversion());
modelBuilder.Entity<TelemetryDataSaubStat>(entity =>
{
entity.HasNoKey()

View File

@ -42,7 +42,7 @@ namespace AsbCloudDb.Model
/// <summary>
/// КНБК
/// </summary>
public const int IdKnbk = 4000;
public const int IdBha = 4000;
/// <summary>
/// Механическое. бурение
@ -246,7 +246,7 @@ namespace AsbCloudDb.Model
/// Виды работ
/// </summary>
public static WellOperationCategory[] WorkTypes { get; } = new WellOperationCategory[]{
new () {Id = IdKnbk, IdParent = 3000, Name = "КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = IdBha, IdParent = 3000, Name = "КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = IdMechanicalDrilling, IdParent = 3000, Name = "Механическое. бурение", KeyValueName = "dT", KeyValueUnits = "м/ч" },
new () {Id = IdMeasurementStat, IdParent = 3000, Name = "Статический замер", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = IdNormalizedWellDiameter, IdParent = 3000, Name = "Нормализация диаметра скважины", KeyValueName = "dT", KeyValueUnits = "мин" },

View File

@ -36,12 +36,12 @@ public class BackgroundWorker : BackgroundService
/// <summary>
/// последние 16 завершившиеся с ошибкой
/// </summary>
public CyclycArray<Work> Felled { get; } = new(16);
public CyclicArray<Work> Felled { get; } = new(16);
/// <summary>
/// последние 16 успешно завершенных
/// </summary>
public CyclycArray<Work> Done { get; } = new(16);
public CyclicArray<Work> Done { get; } = new(16);
/// <summary>
/// Ошибка в главном цикле, никогда не должна появляться

View File

@ -167,7 +167,6 @@ public class WorkSubsystemOscillationOperationTimeCalc : WorkSubsystemOperationT
.Where(d => d.IdTelemetry == idTelemetry)
.Where(d => d.DateTime >= dateBegin)
.Where(d => d.DateTime <= dateEnd)
.Where(d => d.WellDepth != null)
.Where(d => d.WellDepth > 0)
.GroupBy(d => Math.Ceiling(d.WellDepth * 10))
.Select(g => new

View File

@ -111,7 +111,8 @@ public class WellOperationRepository : IWellOperationRepository
.ConfigureAwait(false);
if (lastFactOperation is not null)
return DateTime.SpecifyKind(lastFactOperation.OperationPlan.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified);
return DateTime.SpecifyKind(lastFactOperation.OperationPlan!.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified);
return null;
}

View File

@ -95,12 +95,10 @@ public class DailyReportService : IDailyReportService
public async Task<DailyReportDto> GetAsync(int idWell, DateTime dateDailyReport, CancellationToken cancellationToken)
{
var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken);
var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken)
?? throw new ArgumentNullException(nameof(idWell), $"Скважина с Id: {idWell} не найдена");
if (well is null)
throw new ArgumentNullException(nameof(idWell), $"Скважина с Id: {idWell} не найдена");
if (!await IsDateDailyReportInRangeAsync(idWell, dateDailyReport, cancellationToken))
if (!await IsDateDailyReportInRangeAsync(idWell, dateDailyReport, cancellationToken))
throw new ArgumentInvalidException(nameof(dateDailyReport), "Невозможно получить суточный отчёт");

View File

@ -61,10 +61,12 @@ public class DetectorDrilling : DetectorAbstract
{
var (avgRotorSpeed, dispersionOfNormalizedRotorSpeed) = CalcCriteries(telemetry, begin, end);
var idCategory = GetIdOperation(avgRotorSpeed, dispersionOfNormalizedRotorSpeed);
var extraData = new Dictionary<string, object>();
extraData[ExtraDataKeyAvgRotorSpeed] = avgRotorSpeed;
extraData[ExtraDataKeyDispersionOfNormalizedRotorSpeed] = dispersionOfNormalizedRotorSpeed;
extraData[ExtraDataKeyHasOscillation] = dispersionOfNormalizedRotorSpeed > dispersionOfNormalizedRotorSpeedThreshold;
var extraData = new Dictionary<string, object>
{
[ExtraDataKeyAvgRotorSpeed] = avgRotorSpeed,
[ExtraDataKeyDispersionOfNormalizedRotorSpeed] = dispersionOfNormalizedRotorSpeed,
[ExtraDataKeyHasOscillation] = dispersionOfNormalizedRotorSpeed > dispersionOfNormalizedRotorSpeedThreshold
};
return (idCategory, extraData);
}

View File

@ -118,6 +118,7 @@ public class WorkOperationDetection: Work
{
var data = await query
.Where(d => d.DateTime > startDate)
.Take(take)
.ToArrayAsync(token);
if (data.Length < gap)

View File

@ -13,203 +13,201 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
namespace AsbCloudInfrastructure.Services;
public class ReportService : IReportService
{
private readonly IAsbCloudDbContext db;
private readonly ITelemetryService telemetryService;
private readonly FileService fileService;
private readonly IWellService wellService;
private readonly BackgroundWorker backgroundWorkerService;
public class ReportService : IReportService
public int ReportCategoryId { get; private set; }
public ReportService(IAsbCloudDbContext db,
ITelemetryService telemetryService,
IWellService wellService,
FileService fileService,
BackgroundWorker backgroundWorkerService)
{
private readonly IAsbCloudDbContext db;
private readonly ITelemetryService telemetryService;
private readonly FileService fileService;
private readonly IWellService wellService;
private readonly BackgroundWorker backgroundWorkerService;
public int ReportCategoryId { get; private set; }
public ReportService(IAsbCloudDbContext db,
ITelemetryService telemetryService,
IWellService wellService,
FileService fileService,
BackgroundWorker backgroundWorkerService)
{
this.db = db;
this.wellService = wellService;
this.backgroundWorkerService = backgroundWorkerService;
this.telemetryService = telemetryService;
this.fileService = fileService;
ReportCategoryId = db.FileCategories
.AsNoTracking()
.First(c => c.Name.Equals("Рапорт"))
.Id;
}
public string EnqueueCreateReportWork(int idWell, int idUser, int stepSeconds, int format, DateTime begin,
DateTime end, Action<object, string> progressHandler)
{
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
var beginUtc = begin.ToUtcDateTimeOffset(timezoneOffset);
var endUtc = end.ToUtcDateTimeOffset(timezoneOffset);
var beginRemote = begin.ToTimeZoneOffsetHours(timezoneOffset);
var endRemote = end.ToTimeZoneOffsetHours(timezoneOffset);
var workId = $"create report by wellid:{idWell} for userid:{idUser} requested at {DateTime.Now}";
var workAction = async (string id, IServiceProvider serviceProvider, Action<string, double?> onProgress, CancellationToken token) =>
{
using var context = serviceProvider.GetRequiredService<IAsbCloudDbContext>();
var fileService = serviceProvider.GetRequiredService<FileService>();
var tempDir = Path.Combine(Path.GetTempPath(), "report");
var generator = GetReportGenerator(idWell, beginRemote, endRemote, stepSeconds, format, context);
var reportFileName = Path.Combine(tempDir, generator.GetReportDefaultFileName());
var totalPages = generator.GetPagesCount();
generator.OnProgress += (s, e) =>
{
var arg = e.Adapt<ReportProgressDto>();
onProgress(arg.Operation?? string.Empty, arg.Progress);
progressHandler.Invoke(arg, id);
};
generator.Make(reportFileName);
var fileInfo = (await fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName, token))!;
progressHandler.Invoke(new
{
Operation = "done",
Progress = 100f,
TotalPages = totalPages,
CurrentPage = totalPages,
file = fileInfo,
}, id);
var newReportProperties = new ReportProperty
{
IdWell = idWell,
IdFile = fileInfo.Id,
Begin = beginUtc,
End = endUtc,
Step = stepSeconds,
Format = format
};
context.ReportProperties.Add(newReportProperties);
context.SaveChanges();
};
var work = Work.CreateByDelegate(workId, workAction);
work.OnErrorAsync = (message, exception, token) => Task.Run(() => progressHandler.Invoke(new
{
Operation = "error",
Progress = 100f,
Message = string.IsNullOrEmpty(message)
? exception.Message
: message,
Exception = exception,
}, workId)
, token);
backgroundWorkerService.Enqueue(work);
progressHandler.Invoke(new ReportProgressDto
{
Operation = "Ожидает начала в очереди.",
Progress = 0f,
}, workId);
return workId;
}
public int GetReportPagesCount(int idWell, DateTime begin, DateTime end, int stepSeconds, int format)
{
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
var beginRemote = begin.ToTimeZoneOffsetHours(timezoneOffset);
var endRemote = end.ToTimeZoneOffsetHours(timezoneOffset);
var generator = GetReportGenerator(idWell, beginRemote, endRemote, stepSeconds, format, db);
var pagesCount = generator.GetPagesCount();
return pagesCount;
}
public DatesRangeDto? GetDatesRangeOrDefault(int idWell)
{
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
if (telemetry is null)
return null;
var range = telemetryService.GetDatesRange(telemetry.Id);
return range;
}
public async Task<IEnumerable<ReportPropertiesDto>> GetAllReportsByWellAsync(int idWell, CancellationToken token)
{
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
var propertiesQuery = db.ReportProperties.Include(r => r.File)
.Where(p => p.IdWell == idWell)
.OrderBy(o => o.File.UploadDate)
this.db = db;
this.wellService = wellService;
this.backgroundWorkerService = backgroundWorkerService;
this.telemetryService = telemetryService;
this.fileService = fileService;
ReportCategoryId = db.FileCategories
.AsNoTracking()
.Take(1024);
var entities = await propertiesQuery.ToListAsync(token);
var dtos = entities.Select(p => new ReportPropertiesDto
{
Id = p.Id,
Name = p.File.Name,
File = new FileInfoDto
{
Id = p.File.Id,
Author = null,
IdAuthor = p.File.IdAuthor ?? 0,
IdCategory = p.File.IdCategory,
IdWell = p.File.IdWell,
Name = p.File.Name,
Size = p.File.Size,
UploadDate = p.File.UploadDate.ToRemoteDateTime(timezoneOffset),
},
IdWell = p.IdWell,
Date = p.File.UploadDate.ToRemoteDateTime(timezoneOffset),
Begin = p.Begin.ToRemoteDateTime(timezoneOffset),
End = p.End.ToRemoteDateTime(timezoneOffset),
Step = p.Step,
Format = p.Format == 0 ? ".pdf" : ".las"
});
return dtos;
}
.First(c => c.Name.Equals("Рапорт"))
.Id;
}
private static IReportGenerator GetReportGenerator(int idWell, DateTime begin,
DateTime end, int stepSeconds, int format, IAsbCloudDbContext context)
public string EnqueueCreateReportWork(int idWell, int idUser, int stepSeconds, int format, DateTime begin,
DateTime end, Action<object, string> progressHandler)
{
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
var beginUtc = begin.ToUtcDateTimeOffset(timezoneOffset);
var endUtc = end.ToUtcDateTimeOffset(timezoneOffset);
var beginRemote = begin.ToTimeZoneOffsetHours(timezoneOffset);
var endRemote = end.ToTimeZoneOffsetHours(timezoneOffset);
var workId = $"create report by wellid:{idWell} for userid:{idUser} requested at {DateTime.Now}";
var workAction = async (string id, IServiceProvider serviceProvider, Action<string, double?> onProgress, CancellationToken token) =>
{
var dataSource = new ReportDataSourcePgCloud(context, idWell);
IReportGenerator generator = format switch
using var context = serviceProvider.GetRequiredService<IAsbCloudDbContext>();
var fileService = serviceProvider.GetRequiredService<FileService>();
var tempDir = Path.Combine(Path.GetTempPath(), "report");
var generator = GetReportGenerator(idWell, beginRemote, endRemote, stepSeconds, format, context);
var reportFileName = Path.Combine(tempDir, generator.GetReportDefaultFileName());
var totalPages = generator.GetPagesCount();
generator.OnProgress += (s, e) =>
{
//LAS
1 => new AsbSaubReportLas.ReprotGeneratorLas(dataSource),
//PDF
_ => new AsbSaubReportPdf.ReprotGeneratorPdf(dataSource),
var arg = e.Adapt<ReportProgressDto>();
onProgress(arg.Operation?? string.Empty, arg.Progress);
progressHandler.Invoke(arg, id);
};
generator.Make(reportFileName);
if(begin == default || end == default)
var fileInfo = (await fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName, token))!;
progressHandler.Invoke(new
{
var analyzeResult = dataSource.Analyze();
begin = begin == default ? analyzeResult.MinDate : begin;
end = end == default ? begin.AddDays(1) : end;
}
Operation = "done",
Progress = 100f,
TotalPages = totalPages,
CurrentPage = totalPages,
file = fileInfo,
}, id);
generator.Begin = begin;
generator.End = end;
generator.Step = TimeSpan.FromSeconds(stepSeconds);
generator.WithCharts = true;
generator.WithEvents = true;
var newReportProperties = new ReportProperty
{
IdWell = idWell,
IdFile = fileInfo.Id,
Begin = beginUtc,
End = endUtc,
Step = stepSeconds,
Format = format
};
context.ReportProperties.Add(newReportProperties);
context.SaveChanges();
};
return generator;
}
var work = Work.CreateByDelegate(workId, workAction);
work.OnErrorAsync = (message, exception, token) => Task.Run(() => progressHandler.Invoke(new
{
Operation = "error",
Progress = 100f,
Message = string.IsNullOrEmpty(message)
? exception.Message
: message,
Exception = exception,
}, workId)
, token);
public async Task<int> DeleteAllOldReportsAsync(TimeSpan lifetime, CancellationToken token)
backgroundWorkerService.Enqueue(work);
progressHandler.Invoke(new ReportProgressDto
{
var lifeTimeStartDate = DateTime.UtcNow.Date - lifetime;
var fileIds = await db.ReportProperties
.Where(r => r.File.UploadDate.Date < lifeTimeStartDate)
.Select(r => r.IdFile)
.ToArrayAsync(token);
Operation = "Ожидает начала в очереди.",
Progress = 0f,
}, workId);
return workId;
}
return await fileService.DeleteAsync(fileIds, token);
public int GetReportPagesCount(int idWell, DateTime begin, DateTime end, int stepSeconds, int format)
{
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
var beginRemote = begin.ToTimeZoneOffsetHours(timezoneOffset);
var endRemote = end.ToTimeZoneOffsetHours(timezoneOffset);
var generator = GetReportGenerator(idWell, beginRemote, endRemote, stepSeconds, format, db);
var pagesCount = generator.GetPagesCount();
return pagesCount;
}
public DatesRangeDto? GetDatesRangeOrDefault(int idWell)
{
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
if (telemetry is null)
return null;
var range = telemetryService.GetDatesRange(telemetry.Id);
return range;
}
public async Task<IEnumerable<ReportPropertiesDto>> GetAllReportsByWellAsync(int idWell, CancellationToken token)
{
var timezoneOffset = wellService.GetTimezone(idWell).Hours;
var propertiesQuery = db.ReportProperties.Include(r => r.File)
.Where(p => p.IdWell == idWell)
.OrderBy(o => o.File.UploadDate)
.AsNoTracking()
.Take(1024);
var entities = await propertiesQuery.ToListAsync(token);
var dtos = entities.Select(p => new ReportPropertiesDto
{
Id = p.Id,
Name = p.File.Name,
File = new FileInfoDto
{
Id = p.File.Id,
Author = null,
IdAuthor = p.File.IdAuthor ?? 0,
IdCategory = p.File.IdCategory,
IdWell = p.File.IdWell,
Name = p.File.Name,
Size = p.File.Size,
UploadDate = p.File.UploadDate.ToRemoteDateTime(timezoneOffset),
},
IdWell = p.IdWell,
Date = p.File.UploadDate.ToRemoteDateTime(timezoneOffset),
Begin = p.Begin.ToRemoteDateTime(timezoneOffset),
End = p.End.ToRemoteDateTime(timezoneOffset),
Step = p.Step,
Format = p.Format == 0 ? ".pdf" : ".las"
});
return dtos;
}
private static IReportGenerator GetReportGenerator(int idWell, DateTime begin,
DateTime end, int stepSeconds, int format, IAsbCloudDbContext context)
{
var dataSource = new ReportDataSourcePgCloud(context, idWell);
IReportGenerator generator = format switch
{
//LAS
1 => new AsbSaubReportLas.ReprotGeneratorLas(dataSource),
//PDF
_ => new AsbSaubReportPdf.ReprotGeneratorPdf(dataSource),
};
if(begin == default || end == default)
{
var analyzeResult = dataSource.Analyze();
begin = begin == default ? analyzeResult.MinDate : begin;
end = end == default ? begin.AddDays(1) : end;
}
generator.Begin = begin;
generator.End = end;
generator.Step = TimeSpan.FromSeconds(stepSeconds);
generator.WithCharts = true;
generator.WithEvents = true;
return generator;
}
public async Task<int> DeleteAllOldReportsAsync(TimeSpan lifetime, CancellationToken token)
{
var lifeTimeStartDate = DateTime.UtcNow.Date - lifetime;
var fileIds = await db.ReportProperties
.Where(r => r.File.UploadDate.Date < lifeTimeStartDate)
.Select(r => r.IdFile)
.ToArrayAsync(token);
return await fileService.DeleteAsync(fileIds, token);
}
}

View File

@ -213,7 +213,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
if ((DateTimeOffset.UtcNow - geDate) < TimeSpan.FromHours(12))
{
// пробуем обойтись кешем
var cechedRange = telemetryDataCache.GetOrDefaultCachedaDateRange(telemetry.Id);
var cechedRange = telemetryDataCache.GetOrDefaultCachedDateRange(telemetry.Id);
if (cechedRange?.From <= geDate)
{
var datesRange = new DatesRangeDto

View File

@ -20,7 +20,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
class TelemetryDataCacheItem
{
public TDto FirstByDate { get; init; } = default!;
public CyclycArray<TDto> LastData { get; init; } = null!;
public CyclicArray<TDto> LastData { get; init; } = null!;
public double TimezoneHours { get; init; } = 5;
}
@ -85,7 +85,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
cacheItem = caches.GetOrAdd(idTelemetry, _ => new TelemetryDataCacheItem()
{
FirstByDate = range.ElementAt(0),
LastData = new CyclycArray<TDto>(activeWellCapacity)
LastData = new CyclicArray<TDto>(activeWellCapacity)
});
}
@ -159,7 +159,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
return new DatesRangeDto { From = from.Value, To = to };
}
public DatesRangeDto? GetOrDefaultCachedaDateRange(int idTelemetry)
public DatesRangeDto? GetOrDefaultCachedDateRange(int idTelemetry)
{
if (!caches.TryGetValue(idTelemetry, out TelemetryDataCacheItem? cacheItem))
return null;
@ -260,7 +260,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
return dto;
});
var cacheItem = new CyclycArray<TDto>(capacity);
var cacheItem = new CyclicArray<TDto>(capacity);
cacheItem.AddRange(dtos);
var item = new TelemetryDataCacheItem

View File

@ -43,7 +43,6 @@ namespace AsbCloudInfrastructure.Services.SAUB
.Where(t => t.IdTelemetry == idTelemetry)
.Where(t => t.BlockPosition > 0.0001)
.Where(t => t.WellDepth > 0.0001)
.Where(t => t.Mode != null)
.Where(t => modes.Contains(t.Mode))
.Where(t => t.WellDepth - t.BitDepth < 0.01)
.GroupBy(t => new {

View File

@ -13,7 +13,7 @@ abstract class TrajectoryBaseService<TGeo, TCartesian>
where TGeo : TrajectoryGeoDto
where TCartesian : TrajectoryCartesianDto, new()
{
ITrajectoryRepository<TGeo> repository;
private readonly ITrajectoryRepository<TGeo> repository;
public TrajectoryBaseService(ITrajectoryRepository<TGeo> repository)
{
@ -31,16 +31,16 @@ abstract class TrajectoryBaseService<TGeo, TCartesian>
public async Task<IEnumerable<TCartesian>?> GetAsync(int idWell, CancellationToken token)
{
var geoCoords = await repository.GetAsync(idWell, token);
var locs = GetTrajectoryVisualisation(geoCoords);
var locs = TrajectoryBaseService<TGeo, TCartesian>.GetTrajectoryVisualisation(geoCoords);
var dtos = locs.Select(l => Convert(l));
return dtos;
}
private IEnumerable<Location> GetTrajectoryVisualisation(IEnumerable<TrajectoryGeoDto> geoCoordinates)
private static IEnumerable<Location> GetTrajectoryVisualisation(IEnumerable<TrajectoryGeoDto> geoCoordinates)
{
var geoCoordinatesLength = geoCoordinates.Count();
if (geoCoordinatesLength < 2)
return new Location[0];
return Enumerable.Empty<Location>();
var cartesianCoordinates = new Location[geoCoordinatesLength];
cartesianCoordinates[0] = new();
@ -48,7 +48,7 @@ abstract class TrajectoryBaseService<TGeo, TCartesian>
var geoCoordinatesArray = geoCoordinates.OrderBy(c => c.WellboreDepth).ToArray();
for (var i = 1; i < geoCoordinatesLength; i++)
{
var coordinates = Calculate(cartesianCoordinates[i - 1],
var coordinates = TrajectoryBaseService<TGeo, TCartesian>.Calculate(cartesianCoordinates[i - 1],
geoCoordinatesArray[i - 1],
geoCoordinatesArray[i]);
@ -58,7 +58,7 @@ abstract class TrajectoryBaseService<TGeo, TCartesian>
return cartesianCoordinates;
}
protected Location Calculate(Location prevlocation, TrajectoryGeoDto prev, TrajectoryGeoDto current)
protected static Location Calculate(Location prevLocation, TrajectoryGeoDto prev, TrajectoryGeoDto current)
{
var intervalGeoParams = prev;
var deltaWellLength = current.WellboreDepth - intervalGeoParams.WellboreDepth;
@ -70,9 +70,9 @@ abstract class TrajectoryBaseService<TGeo, TCartesian>
return new()
{
North = prevlocation.North + dNorth,
East = prevlocation.East + dEast,
Depth = prevlocation.Depth + dDepth,
North = prevLocation.North + dNorth,
East = prevLocation.East + dEast,
Depth = prevLocation.Depth + dDepth,
Trajectory = current,
};
}
@ -125,9 +125,9 @@ class TrajectoryNnbService : TrajectoryBaseService<TrajectoryGeoFactDto, Traject
public class TrajectoryService
{
private TrajectoryPlanService trajectoryPlanService;
private TrajectoryFactService trajectoryFactService;
private TrajectoryNnbService trajectoryNnbService;
private readonly TrajectoryPlanService trajectoryPlanService;
private readonly TrajectoryFactService trajectoryFactService;
private readonly TrajectoryNnbService trajectoryNnbService;
public TrajectoryService(
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> planRepository,
@ -147,11 +147,12 @@ public class TrajectoryService
/// <returns></returns>
public async Task<TrajectoryPlanFactDto<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>> GetTrajectoryCartesianAsync(int idWell, CancellationToken token)
{
var result = new TrajectoryPlanFactDto<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>();
result.Plan = await trajectoryPlanService.GetAsync(idWell, token);
result.FactManual = await trajectoryFactService.GetAsync(idWell, token);
result.FactNnb = await trajectoryNnbService.GetAsync(idWell, token);
var result = new TrajectoryPlanFactDto<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>>
{
Plan = await trajectoryPlanService.GetAsync(idWell, token),
FactManual = await trajectoryFactService.GetAsync(idWell, token),
FactNnb = await trajectoryNnbService.GetAsync(idWell, token)
};
return result;
}

View File

@ -28,8 +28,6 @@ namespace AsbCloudInfrastructure.Services
private readonly IWellFinalDocumentsRepository wellFinalDocumentsRepository;
private readonly NotificationService notificationService;
private const int FileServiceThrewException = -1;
public WellFinalDocumentsService(FileService fileService,
IUserRepository userRepository,
IWellService wellService,
@ -48,7 +46,7 @@ namespace AsbCloudInfrastructure.Services
}
///<inheritdoc/>
public async Task<int> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto>? dtos, CancellationToken token)
public async Task<int> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto> dtos, CancellationToken token)
{
var data = await wellFinalDocumentsRepository.UpdateRangeAsync(idWell, dtos, token);

View File

@ -22,7 +22,7 @@ namespace AsbCloudInfrastructure
var provider = scope.ServiceProvider;
var context = provider.GetRequiredService<IAsbCloudDbContext>();
context.Database.EnshureCreatedAndMigrated();
context.Database.EnsureCreatedAndMigrated();
// TODO: Сделать инициализацию кеша телеметрии более явной.
_ = provider.GetRequiredService<ITelemetryDataCache<TelemetryDataSaubDto>>();

View File

@ -3,7 +3,7 @@ using System.Linq;
namespace AsbCloudWebApi.Tests
{
public static class AspExtentions
public static class AspExtensions
{
public static IServiceCollection ReplaceService<T>(this IServiceCollection services, T instance)
where T : notnull

View File

@ -20,15 +20,16 @@ namespace AsbCloudWebApi.Controllers
public class ReportController : ControllerBase
{
private readonly IReportService reportService;
private readonly FileService fileService;
private readonly IWellService wellService;
private readonly IHubContext<ReportsHub, IReportHubClient> reportsHubContext;
public ReportController(IReportService reportService, IWellService wellService,
FileService fileService, IHubContext<ReportsHub, IReportHubClient> reportsHubContext)
public ReportController(
IReportService reportService,
IWellService wellService,
IHubContext<ReportsHub,
IReportHubClient> reportsHubContext)
{
this.reportService = reportService;
this.fileService = fileService;
this.wellService = wellService;
this.reportsHubContext = reportsHubContext;
}

View File

@ -21,7 +21,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
public abstract class TrajectoryController<TDto> : ControllerBase
where TDto : TrajectoryGeoDto
{
protected abstract string fileName { get; set; }
protected abstract string fileName { get; }
private readonly IWellService wellService;
private readonly TrajectoryExportService<TDto> trajectoryExportService;

View File

@ -19,19 +19,17 @@ namespace AsbCloudWebApi.Controllers.Trajectory
/// </summary>
[ApiController]
[Authorize]
public abstract class TrajectoryEditableController<Tdto> : TrajectoryController<Tdto>
where Tdto : TrajectoryGeoDto
public abstract class TrajectoryEditableController<TDto> : TrajectoryController<TDto>
where TDto : TrajectoryGeoDto
{
protected override string fileName { get; set; }
private readonly TrajectoryParserService<Tdto> trajectoryImportService;
private readonly TrajectoryExportService<Tdto> trajectoryExportService;
private readonly ITrajectoryEditableRepository<Tdto> trajectoryRepository;
private readonly TrajectoryParserService<TDto> trajectoryImportService;
private readonly TrajectoryExportService<TDto> trajectoryExportService;
private readonly ITrajectoryEditableRepository<TDto> trajectoryRepository;
public TrajectoryEditableController(IWellService wellService,
TrajectoryParserService<Tdto> trajectoryImportService,
TrajectoryExportService<Tdto> trajectoryExportService,
ITrajectoryEditableRepository<Tdto> trajectoryRepository)
TrajectoryParserService<TDto> trajectoryImportService,
TrajectoryExportService<TDto> trajectoryExportService,
ITrajectoryEditableRepository<TDto> trajectoryRepository)
: base(
wellService,
trajectoryExportService,
@ -118,7 +116,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
/// <returns>количество успешно записанных строк в БД</returns>
[HttpPost]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> AddAsync(int idWell, [FromBody] Tdto row,
public async Task<IActionResult> AddAsync(int idWell, [FromBody] TDto row,
CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
@ -141,7 +139,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
/// <returns>количество успешно записанных строк в БД</returns>
[HttpPost("range")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> AddRangeAsync(int idWell, [FromBody] IEnumerable<Tdto> rows,
public async Task<IActionResult> AddRangeAsync(int idWell, [FromBody] IEnumerable<TDto> rows,
CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
@ -169,7 +167,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
[HttpPut("{idRow}")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> UpdateAsync(int idWell, int idRow,
[FromBody] Tdto row, CancellationToken token)
[FromBody] TDto row, CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();

View File

@ -14,7 +14,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory;
[Route("api/well/{idWell}/[controller]")]
public class TrajectoryFactManualController : TrajectoryEditableController<TrajectoryGeoFactDto>
{
protected override string fileName { get; set; }
protected override string fileName => "ЕЦП_шаблон_файлаактическая_траектория.xlsx";
public TrajectoryFactManualController(IWellService wellService,
TrajectoryFactManualParserService factTrajectoryImportService,
TrajectoryFactManualExportService factTrajectoryExportService,
@ -24,7 +24,5 @@ public class TrajectoryFactManualController : TrajectoryEditableController<Traje
factTrajectoryImportService,
factTrajectoryExportService,
trajectoryFactRepository)
{
fileName = "ЕЦП_шаблон_файлаактическая_траектория.xlsx";
}
{ }
}

View File

@ -15,7 +15,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory;
[Route("api/well/{idWell}/[controller]")]
public class TrajectoryFactNnbController : TrajectoryController<TrajectoryGeoFactDto>
{
protected override string fileName { get; set; }
protected override string fileName => "ЕЦП_шаблон_файлаактическая_ннбраектория.xlsx";
public TrajectoryFactNnbController(
ITrajectoryNnbRepository trajectoryNnbRepository,
TrajectoryFactNnbExportService trajectoryExportService,
@ -24,7 +24,5 @@ public class TrajectoryFactNnbController : TrajectoryController<TrajectoryGeoFac
wellService,
trajectoryExportService,
trajectoryNnbRepository)
{
fileName = "ЕЦП_шаблон_файлаактическая_ннбраектория.xlsx";
}
{ }
}

View File

@ -21,6 +21,8 @@ namespace AsbCloudWebApi.Controllers.Trajectory
{
private readonly TrajectoryService trajectoryVisualizationService;
protected override string fileName => "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
public TrajectoryPlanController(IWellService wellService,
TrajectoryPlanParserService trajectoryPlanImportService,
TrajectoryPlanExportService trajectoryPlanExportService,
@ -32,7 +34,6 @@ namespace AsbCloudWebApi.Controllers.Trajectory
trajectoryPlanExportService,
trajectoryPlanRepository)
{
fileName = "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
this.trajectoryVisualizationService = trajectoryVisualizationService;
}

View File

@ -6,7 +6,7 @@ namespace SignalRTestClient;
internal class Program
{
static void Main(string[] args)
static void Main()
{
var connectionBuilder = new HubConnectionBuilder();
var connection = connectionBuilder
@ -47,7 +47,7 @@ internal class Program
builder.AddProvider(provider);
}
private static Task<string?> AccessTokenProvider()
private static Task<string> AccessTokenProvider()
{
return Task.FromResult("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJpZCI6IjEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZGV2IiwiaWRDb21wYW55IjoiMSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6InJvb3QiLCJuYmYiOjE2NjI1NDgxNjIsImV4cCI6MTY5NDEwNTc2MiwiaXNzIjoiYSIsImF1ZCI6ImEifQ.OEAlNzxi7Jat6pzDBTAjTbChskc-tdJthJexyWwwUKE");
}