forked from ddrilling/AsbCloudServer
Таблица БД ProcessMapDrillingCache + код формирования диапазонов в экшене задачи WorkProcessMapDrillingCache
This commit is contained in:
parent
49a5225ff4
commit
a0fc6af291
@ -90,6 +90,8 @@ namespace AsbCloudDb.Model
|
|||||||
public DbSet<Contact> Contacts => Set<Contact>();
|
public DbSet<Contact> Contacts => Set<Contact>();
|
||||||
|
|
||||||
public DbSet<DrillTest> DrillTests => Set<DrillTest>();
|
public DbSet<DrillTest> DrillTests => Set<DrillTest>();
|
||||||
|
|
||||||
|
public DbSet<ProcessMapDrillingCache> ProcessMapDrillingCache => Set<ProcessMapDrillingCache>();
|
||||||
public AsbCloudDbContext() : base()
|
public AsbCloudDbContext() : base()
|
||||||
{
|
{
|
||||||
Interlocked.Increment(ref referenceCount);
|
Interlocked.Increment(ref referenceCount);
|
||||||
|
@ -80,6 +80,7 @@ namespace AsbCloudDb.Model
|
|||||||
DbSet<DrillTest> DrillTests { get; }
|
DbSet<DrillTest> DrillTests { get; }
|
||||||
DbSet<TrajectoryFact> TrajectoriesFact { get; }
|
DbSet<TrajectoryFact> TrajectoriesFact { get; }
|
||||||
DbSet<WellSectionPlan> WellSectionsPlan { get; }
|
DbSet<WellSectionPlan> WellSectionsPlan { get; }
|
||||||
|
DbSet<ProcessMapDrillingCache> ProcessMapDrillingCache { get; }
|
||||||
DatabaseFacade Database { get; }
|
DatabaseFacade Database { get; }
|
||||||
|
|
||||||
Task<int> RefreshMaterializedViewAsync(string mwName, CancellationToken token);
|
Task<int> RefreshMaterializedViewAsync(string mwName, CancellationToken token);
|
||||||
|
21
AsbCloudDb/Model/ProcessMapDrillingCache.cs
Normal file
21
AsbCloudDb/Model/ProcessMapDrillingCache.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -11,12 +11,12 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
||||||
{
|
{
|
||||||
internal class WorkProcessMapDrillingCashe : Work
|
internal class WorkProcessMapDrillingCache : Work
|
||||||
{
|
{
|
||||||
private int MechanicalDrillingCategoryId = 4001;
|
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)
|
protected override Task Action(string id, IServiceProvider services, Action<string, double?> onProgressCallback, CancellationToken token)
|
||||||
@ -36,13 +36,13 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
|||||||
//7/ разбивка диапазонов:
|
//7/ разбивка диапазонов:
|
||||||
// параметры метода: массив из
|
// параметры метода: массив из
|
||||||
|
|
||||||
var dateStart = DateTimeOffset.UtcNow.AddDays(-3500);
|
|
||||||
|
|
||||||
using var db = services.GetRequiredService<IAsbCloudDbContext>();
|
using var db = services.GetRequiredService<IAsbCloudDbContext>();
|
||||||
|
var dateFrom = db.ProcessMapDrillingCache.OrderByDescending(c => c.DateTo).FirstOrDefault()?.DateTo ?? DateTimeOffset.MinValue;
|
||||||
|
|
||||||
|
|
||||||
//а остальные операции, которые не вошли в 500 первых?
|
//а остальные операции, которые не вошли в 500 первых?
|
||||||
var detectedOperations = db.DetectedOperations
|
var detectedOperations = db.DetectedOperations
|
||||||
.Where(o => o.DateStart > dateStart)
|
.Where(o => o.DateStart > dateFrom)
|
||||||
.Where(o => o.OperationCategory.IdParent == MechanicalDrillingCategoryId)
|
.Where(o => o.OperationCategory.IdParent == MechanicalDrillingCategoryId)
|
||||||
.Take(500)
|
.Take(500)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
@ -57,7 +57,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
|||||||
.OrderBy(t => t.DateTime)
|
.OrderBy(t => t.DateTime)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
var result = new List<CacheItem>();
|
var result = new List<ProcessMapDrillingCacheItem>();
|
||||||
foreach (var operation in detectedOperations)
|
foreach (var operation in detectedOperations)
|
||||||
{
|
{
|
||||||
var indexStart = 0;
|
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 result = new List<ProcessMapDrillingCacheItem>();
|
||||||
var cacheItem = new CacheItem();
|
var cacheItem = new ProcessMapDrillingCacheItem();
|
||||||
cacheItem.Elems.Add(span[0]);
|
cacheItem.Elems.Add(span[0]);
|
||||||
result.Add(cacheItem);
|
result.Add(cacheItem);
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
|||||||
isNewCacheItem = isNewCacheItem || !(current.IdFeedRegulator == prev.IdFeedRegulator);
|
isNewCacheItem = isNewCacheItem || !(current.IdFeedRegulator == prev.IdFeedRegulator);
|
||||||
if (isNewCacheItem)
|
if (isNewCacheItem)
|
||||||
{
|
{
|
||||||
cacheItem = new CacheItem();
|
cacheItem = new ProcessMapDrillingCacheItem();
|
||||||
result.Add(cacheItem);
|
result.Add(cacheItem);
|
||||||
}
|
}
|
||||||
cacheItem.Elems.Add(current);
|
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>();
|
public List<TelemetryDataSaub> Elems = new List<TelemetryDataSaub>();
|
||||||
}
|
}
|
@ -29,7 +29,7 @@ namespace AsbCloudInfrastructure
|
|||||||
_ = provider.GetRequiredService<ITelemetryDataCache<TelemetryDataSpinDto>>();
|
_ = provider.GetRequiredService<ITelemetryDataCache<TelemetryDataSpinDto>>();
|
||||||
|
|
||||||
var backgroundWorker = provider.GetRequiredService<PeriodicBackgroundWorker>();
|
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<WorkToDeleteOldReports>(TimeSpan.FromDays(1));
|
||||||
backgroundWorker.Add<WellInfoService.WorkWellInfoUpdate>(TimeSpan.FromMinutes(30));
|
backgroundWorker.Add<WellInfoService.WorkWellInfoUpdate>(TimeSpan.FromMinutes(30));
|
||||||
backgroundWorker.Add<WorkOperationDetection>(TimeSpan.FromMinutes(15));
|
backgroundWorker.Add<WorkOperationDetection>(TimeSpan.FromMinutes(15));
|
||||||
|
Loading…
Reference in New Issue
Block a user