forked from ddrilling/AsbCloudServer
fix WorkDataSaubStat
This commit is contained in:
parent
ba56bfe274
commit
f043dbe4c9
@ -35,7 +35,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
||||
{
|
||||
GeDate = DateTime.UtcNow.AddDays(-Gap)
|
||||
};
|
||||
var idTelemetries = telemetryDataCache.GetIds(cacheRequest);
|
||||
var idTelemetries = telemetryDataCache.GetIds(cacheRequest).ToArray();
|
||||
|
||||
if (!idTelemetries.Any())
|
||||
return;
|
||||
@ -50,25 +50,27 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
||||
})
|
||||
.ToArrayAsync(token);
|
||||
|
||||
foreach ( var idTelemetry in idTelemetries)
|
||||
for( var i =0; i < idTelemetries.Length; i++)
|
||||
{
|
||||
var idTelemetry = idTelemetries[i];
|
||||
var lastDate = stats.FirstOrDefault(s => s.IdTelemetry == idTelemetry)?.DateEnd ?? DateTimeOffset.UnixEpoch;
|
||||
await CreateStatForTelemetryFromDate(db, idTelemetry, lastDate, token);
|
||||
var statsCount = await CreateStatForTelemetryFromDate(db, idTelemetry, lastDate, token);
|
||||
onProgressCallback($"Calculate stat for telemetry: {idTelemetry}; from {lastDate}; results count: {statsCount};", 100*i / idTelemetries.Length);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreateStatForTelemetryFromDate(IAsbCloudDbContext db, int idTelemetry, DateTimeOffset begin, CancellationToken token)
|
||||
private async Task<int> CreateStatForTelemetryFromDate(IAsbCloudDbContext db, int idTelemetry, DateTimeOffset begin, CancellationToken token)
|
||||
{
|
||||
var detectedOperations = await db.Set<DetectedOperation>()
|
||||
.Where(o => o.IdTelemetry == idTelemetry)
|
||||
.Where(o => o.DateStart > begin)
|
||||
.Where(o => o.OperationCategory.IdParent == MechanicalDrillingCategoryId)
|
||||
.OrderBy(o => o.DateStart)
|
||||
.Take(500)
|
||||
.Take(250)
|
||||
.ToArrayAsync(token);
|
||||
|
||||
if (!detectedOperations.Any())
|
||||
return;
|
||||
return 0;
|
||||
|
||||
var minDate = detectedOperations.First().DateStart;
|
||||
var maxDate = detectedOperations.OrderByDescending(d => d.DateEnd).First().DateEnd;
|
||||
@ -79,15 +81,16 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
||||
.Where(t => t.DateTime <= maxDate)
|
||||
.Where(t => Math.Abs(t.BitDepth - t.WellDepth) < 0.0001)
|
||||
.OrderBy(t => t.DateTime)
|
||||
.Take(100_000)
|
||||
.ToArrayAsync(token);
|
||||
|
||||
if (!telemetryDataSaub.Any())
|
||||
return;
|
||||
return 0;
|
||||
|
||||
var dataSaubStats = CreateDataSaubStat(detectedOperations, telemetryDataSaub);
|
||||
|
||||
db.Set<DataSaubStat>().AddRange(dataSaubStats);
|
||||
await db.SaveChangesAsync(token);
|
||||
return await db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
private static IEnumerable<DataSaubStat> CreateDataSaubStat(IEnumerable<DetectedOperation> detectedOperations, TelemetryDataSaub[] telemetryDataSaub)
|
||||
@ -137,6 +140,8 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
||||
var length = i - indexStart;
|
||||
var span = telemetryDataSaub.Slice(indexStart, length);
|
||||
indexStart = i;
|
||||
if (length <= 2 || (span[^1].WellDepth - span[0].WellDepth) < 0.001)
|
||||
continue; // мелкие выборки не учитываем.
|
||||
var stat = CalcStat(operation, span);
|
||||
result.Add(stat);
|
||||
}
|
||||
@ -214,6 +219,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
||||
private static bool IsNewCacheItem(TelemetryDataSaub previous, TelemetryDataSaub current)
|
||||
{
|
||||
return !(current.Mode == previous.Mode)
|
||||
|| !(current.WellDepth >= previous.WellDepth)
|
||||
|| !(current.BlockSpeedSp == previous.BlockSpeedSp)
|
||||
|| !(current.PressureIdle == previous.PressureIdle)
|
||||
|| !(current.PressureSp == previous.PressureSp)
|
||||
|
Loading…
Reference in New Issue
Block a user