Таблица БД ProcessMapDrillingCache + код формирования диапазонов в экшене задачи WorkProcessMapDrillingCache

This commit is contained in:
Olga Nemt 2024-01-29 12:50:31 +05:00
parent 49a5225ff4
commit a0fc6af291
5 changed files with 39 additions and 15 deletions

View File

@ -90,6 +90,8 @@ namespace AsbCloudDb.Model
public DbSet<Contact> Contacts => Set<Contact>();
public DbSet<DrillTest> DrillTests => Set<DrillTest>();
public DbSet<ProcessMapDrillingCache> ProcessMapDrillingCache => Set<ProcessMapDrillingCache>();
public AsbCloudDbContext() : base()
{
Interlocked.Increment(ref referenceCount);

View File

@ -80,6 +80,7 @@ namespace AsbCloudDb.Model
DbSet<DrillTest> DrillTests { get; }
DbSet<TrajectoryFact> TrajectoriesFact { get; }
DbSet<WellSectionPlan> WellSectionsPlan { get; }
DbSet<ProcessMapDrillingCache> ProcessMapDrillingCache { get; }
DatabaseFacade Database { get; }
Task<int> RefreshMaterializedViewAsync(string mwName, CancellationToken token);

View File

@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model
{
[Table("t_process_map_drilling_cache"), Comment("Кеш-таблица для хранения данных для РТК-отчета")]
public class ProcessMapDrillingCache : IId
{
[Key]
[Column("id")]
public int Id { get; set; }
[Column("date_from", TypeName = "timestamp with time zone"), Comment("Дата начала")]
public DateTimeOffset DateFrom { get; set; }
[Column("date_to", TypeName = "timestamp with time zone"), Comment("Дата окончания")]
public DateTimeOffset DateTo { get; set; }
}
}

View File

@ -11,12 +11,12 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Background.PeriodicWorks
{
internal class WorkProcessMapDrillingCashe : Work
internal class WorkProcessMapDrillingCache : Work
{
private int MechanicalDrillingCategoryId = 4001;
public WorkProcessMapDrillingCashe() : base("Generate process map drilling cache table")
public WorkProcessMapDrillingCache() : base("Generate process map drilling cache table")
{
Timeout = TimeSpan.FromMinutes(1);
Timeout = TimeSpan.FromMinutes(10);
}
protected override Task Action(string id, IServiceProvider services, Action<string, double?> onProgressCallback, CancellationToken token)
@ -36,13 +36,13 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
//7/ разбивка диапазонов:
// параметры метода: массив из
var dateStart = DateTimeOffset.UtcNow.AddDays(-3500);
using var db = services.GetRequiredService<IAsbCloudDbContext>();
var dateFrom = db.ProcessMapDrillingCache.OrderByDescending(c => c.DateTo).FirstOrDefault()?.DateTo ?? DateTimeOffset.MinValue;
//а остальные операции, которые не вошли в 500 первых?
var detectedOperations = db.DetectedOperations
.Where(o => o.DateStart > dateStart)
.Where(o => o.DateStart > dateFrom)
.Where(o => o.OperationCategory.IdParent == MechanicalDrillingCategoryId)
.Take(500)
.ToArray();
@ -57,7 +57,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
.OrderBy(t => t.DateTime)
.ToArray();
var result = new List<CacheItem>();
var result = new List<ProcessMapDrillingCacheItem>();
foreach (var operation in detectedOperations)
{
var indexStart = 0;
@ -79,13 +79,13 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
}
}
return null;
return Task.CompletedTask;
}
private List<CacheItem> getRanges(Span<TelemetryDataSaub> span, DetectedOperation operation)
private List<ProcessMapDrillingCacheItem> getRanges(Span<TelemetryDataSaub> span, DetectedOperation operation)
{
var result = new List<CacheItem>();
var cacheItem = new CacheItem();
var result = new List<ProcessMapDrillingCacheItem>();
var cacheItem = new ProcessMapDrillingCacheItem();
cacheItem.Elems.Add(span[0]);
result.Add(cacheItem);
@ -106,7 +106,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
isNewCacheItem = isNewCacheItem || !(current.IdFeedRegulator == prev.IdFeedRegulator);
if (isNewCacheItem)
{
cacheItem = new CacheItem();
cacheItem = new ProcessMapDrillingCacheItem();
result.Add(cacheItem);
}
cacheItem.Elems.Add(current);
@ -115,7 +115,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
}
}
internal class CacheItem
internal class ProcessMapDrillingCacheItem
{
public List<TelemetryDataSaub> Elems = new List<TelemetryDataSaub>();
}

View File

@ -29,7 +29,7 @@ namespace AsbCloudInfrastructure
_ = provider.GetRequiredService<ITelemetryDataCache<TelemetryDataSpinDto>>();
var backgroundWorker = provider.GetRequiredService<PeriodicBackgroundWorker>();
backgroundWorker.Add<WorkProcessMapDrillingCashe>(TimeSpan.FromDays(1));
backgroundWorker.Add<WorkProcessMapDrillingCache>(TimeSpan.FromDays(1));
backgroundWorker.Add<WorkToDeleteOldReports>(TimeSpan.FromDays(1));
backgroundWorker.Add<WellInfoService.WorkWellInfoUpdate>(TimeSpan.FromMinutes(30));
backgroundWorker.Add<WorkOperationDetection>(TimeSpan.FromMinutes(15));