forked from ddrilling/AsbCloudServer
Из сервиса телеметрии удалён метод получения дат телеметрии, даты в бекграунд сервисе получаются из кэша.
This commit is contained in:
parent
e29f21c291
commit
ccffb5e8e5
@ -56,4 +56,13 @@ public class TelemetryDataRequest
|
|||||||
[Range(1, MaxTake)]
|
[Range(1, MaxTake)]
|
||||||
public int Take { get; set; } = 1024;
|
public int Take { get; set; } = 1024;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Больше или равно высоте талевого блока
|
||||||
|
/// </summary>
|
||||||
|
public double? GeBlockPosition { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Меньше или равно высоте талевого блока
|
||||||
|
/// </summary>
|
||||||
|
public double? LeBlockPosition { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,5 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<Stream> GetZippedCsv(int idWell, DateTime beginDate, DateTime endDate, CancellationToken token);
|
Task<Stream> GetZippedCsv(int idWell, DateTime beginDate, DateTime endDate, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получение диапозона дат телеметрий
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<IDictionary<int, DatesRangeDto>> GetDateRangesAsync(CancellationToken token);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Data.SAUB;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
@ -15,7 +16,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations;
|
|||||||
|
|
||||||
public class WorkOperationDetection : Work
|
public class WorkOperationDetection : Work
|
||||||
{
|
{
|
||||||
private static readonly IDictionary<int, DateTime> CacheOfStartDatesByTelemetryId = new Dictionary<int, DateTime>();
|
private static readonly IDictionary<int, DateTimeOffset> CacheOfStartDatesByTelemetryId = new Dictionary<int, DateTimeOffset>();
|
||||||
|
|
||||||
public WorkOperationDetection()
|
public WorkOperationDetection()
|
||||||
: base("Operation detection")
|
: base("Operation detection")
|
||||||
@ -37,28 +38,28 @@ public class WorkOperationDetection : Work
|
|||||||
var telemetryRepository = services.GetRequiredService<ICrudRepository<TelemetryDto>>();
|
var telemetryRepository = services.GetRequiredService<ICrudRepository<TelemetryDto>>();
|
||||||
var detectedOperationRepository = services.GetRequiredService<IDetectedOperationRepository>();
|
var detectedOperationRepository = services.GetRequiredService<IDetectedOperationRepository>();
|
||||||
var detectedOperationService = services.GetRequiredService<IDetectedOperationService>();
|
var detectedOperationService = services.GetRequiredService<IDetectedOperationService>();
|
||||||
var telemetryDataSaubService = services.GetRequiredService<ITelemetryDataSaubService>();
|
var telemetryDataCache = services.GetRequiredService<ITelemetryDataCache<TelemetryDataSaubDto>>();
|
||||||
|
|
||||||
var idsTelemetry = (await telemetryRepository.GetAllAsync(token))
|
var idsTelemetry = (await telemetryRepository.GetAllAsync(token))
|
||||||
.Select(t => t.Id)
|
.Select(t => t.Id)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
var telemetriesDateRanges = await telemetryDataSaubService.GetDateRangesAsync(token);
|
|
||||||
|
|
||||||
var lastDetectedOperations = await detectedOperationRepository.GetLastDetectedOperationsAsync(token);
|
var lastDetectedOperations = await detectedOperationRepository.GetLastDetectedOperationsAsync(token);
|
||||||
|
|
||||||
for (int i = 0; i < idsTelemetry.Length; i++)
|
for (int i = 0; i < idsTelemetry.Length; i++)
|
||||||
{
|
{
|
||||||
var idTelemetry = idsTelemetry[i];
|
var idTelemetry = idsTelemetry[i];
|
||||||
|
|
||||||
if (!telemetriesDateRanges.TryGetValue(idTelemetry, out var telemetryDateRange))
|
var telemetryDateRange = telemetryDataCache.GetOrDefaultWellDataDateRange(idTelemetry);
|
||||||
|
|
||||||
|
if(telemetryDateRange == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var dateBegin = telemetryDateRange.From.DateTime;
|
var dateBegin = telemetryDateRange.From;
|
||||||
var dateEnd = telemetryDateRange.To.DateTime;
|
var dateEnd = telemetryDateRange.To;
|
||||||
|
|
||||||
if (lastDetectedOperations.TryGetValue(idTelemetry, out var lastDetectedOperation))
|
if (lastDetectedOperations.TryGetValue(idTelemetry, out var lastDetectedOperation))
|
||||||
dateBegin = lastDetectedOperation.DateEnd.UtcDateTime;
|
dateBegin = lastDetectedOperation.DateEnd;
|
||||||
|
|
||||||
if (CacheOfStartDatesByTelemetryId.TryGetValue(idTelemetry, out var dateBeginFromCahce))
|
if (CacheOfStartDatesByTelemetryId.TryGetValue(idTelemetry, out var dateBeginFromCahce))
|
||||||
dateBegin = dateBeginFromCahce;
|
dateBegin = dateBeginFromCahce;
|
||||||
@ -80,7 +81,7 @@ public class WorkOperationDetection : Work
|
|||||||
var detectedOperations =
|
var detectedOperations =
|
||||||
await detectedOperationService.DetectOperationsAsync(idTelemetry, request, lastDetectedOperation, token);
|
await detectedOperationService.DetectOperationsAsync(idTelemetry, request, lastDetectedOperation, token);
|
||||||
|
|
||||||
dateBegin = detectedOperations.LastDate.UtcDateTime;
|
dateBegin = detectedOperations.LastDate;
|
||||||
|
|
||||||
CacheOfStartDatesByTelemetryId[idTelemetry] = dateBegin;
|
CacheOfStartDatesByTelemetryId[idTelemetry] = dateBegin;
|
||||||
|
|
||||||
|
@ -152,9 +152,9 @@ public class TelemetryDataCache<TDto> : ITelemetryDataCache<TDto> where TDto : A
|
|||||||
|
|
||||||
if (cacheItem.LastData.Count == 0)
|
if (cacheItem.LastData.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var to = FromDate(cacheItem.FirstByDate.DateTime, cacheItem.TimezoneOffset);
|
var to = FromDate(cacheItem.LastData[^1].DateTime, cacheItem.TimezoneOffset);
|
||||||
var from = FromDate(cacheItem.LastData[^1].DateTime, cacheItem.TimezoneOffset);
|
var from = FromDate(cacheItem.FirstByDate.DateTime, cacheItem.TimezoneOffset);
|
||||||
|
|
||||||
return new DatesRangeDto { From = from, To = to };
|
return new DatesRangeDto { From = from, To = to };
|
||||||
}
|
}
|
||||||
|
@ -177,22 +177,6 @@ public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSa
|
|||||||
return outStream;
|
return outStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IDictionary<int, DatesRangeDto>> GetDateRangesAsync(CancellationToken token)
|
|
||||||
{
|
|
||||||
return await db.Set<TelemetryDataSaub>().GroupBy(x => x.IdTelemetry)
|
|
||||||
.Select(g => new
|
|
||||||
{
|
|
||||||
IdTelemetry = g.Key,
|
|
||||||
From = g.Min(x => x.DateTime),
|
|
||||||
To = g.Max(x => x.DateTime)
|
|
||||||
})
|
|
||||||
.ToDictionaryAsync(x => x.IdTelemetry, x => new DatesRangeDto
|
|
||||||
{
|
|
||||||
From = x.From,
|
|
||||||
To = x.To
|
|
||||||
}, token);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IQueryable<TelemetryDataSaub> BuildQuery(int idTelemetry, TelemetryDataRequest request)
|
protected override IQueryable<TelemetryDataSaub> BuildQuery(int idTelemetry, TelemetryDataRequest request)
|
||||||
{
|
{
|
||||||
var query = base.BuildQuery(idTelemetry, request);
|
var query = base.BuildQuery(idTelemetry, request);
|
||||||
|
Loading…
Reference in New Issue
Block a user