Fixed Telemetry analysis start depending on analyze start date

This commit is contained in:
KharchenkoVV 2021-09-29 12:20:19 +05:00
parent c0918652a3
commit b60b84b45c
2 changed files with 32 additions and 29 deletions

View File

@ -35,7 +35,7 @@ namespace AsbCloudInfrastructure.Services
var timeToStartAnalysis = DateTime.Now;
while (false)//(!token.IsCancellationRequested)
while (!token.IsCancellationRequested)
{
if(DateTime.Now > timeToStartAnalysis)
{

View File

@ -242,44 +242,47 @@ namespace AsbCloudInfrastructure.Services
{
var analyzeStartDate = GetAnalyzeStartDate(idTelemetry);
while (GetDataSaubsToAnalyze(idTelemetry, analyzeStartDate).Any())
if(analyzeStartDate != default)
{
var dataSaubsToAnalyze = GetDataSaubsToAnalyze(idTelemetry, analyzeStartDate);
analyzeStartDate = dataSaubsToAnalyze.Last().Date;
foreach (var dataSaub in dataSaubsToAnalyze)
while (GetDataSaubsToAnalyze(idTelemetry, analyzeStartDate).Any())
{
var dataSaubDto = dataSaub.Adapt<TelemetryDataSaubDto>();
var dataSaubsToAnalyze = GetDataSaubsToAnalyze(idTelemetry, analyzeStartDate);
saubDataCache.AddData(dataSaubDto);
analyzeStartDate = dataSaubsToAnalyze.Last().Date;
if (saubDataCache.GetOrCreateCache(dataSaubDto.IdTelemetry).Count() > 1)
foreach (var dataSaub in dataSaubsToAnalyze)
{
var dataSaubs = saubDataCache.GetOrCreateCache(dataSaubDto.IdTelemetry)
.OrderBy(d => d.Date);
var dataSaubDto = dataSaub.Adapt<TelemetryDataSaubDto>();
var telemetryAnalysisDto = GetDrillingAnalysis(dataSaubs);
saubDataCache.AddData(dataSaubDto);
if (saubDataCache.CurrentAnalysis is null)
saubDataCache.CurrentAnalysis = telemetryAnalysisDto;
if (saubDataCache.CurrentAnalysis.IdOperation == telemetryAnalysisDto.IdOperation)
if (saubDataCache.GetOrCreateCache(dataSaubDto.IdTelemetry).Count() > 1)
{
saubDataCache.CurrentAnalysis.DurationSec +=
telemetryAnalysisDto.DurationSec;
saubDataCache.CurrentAnalysis.OperationEndDepth = dataSaubDto.WellDepth;
}
else
{
db.TelemetryAnalysis.Add(saubDataCache.CurrentAnalysis.Adapt<TelemetryAnalysis>());
saubDataCache.CurrentAnalysis = telemetryAnalysisDto;
saubDataCache.CurrentAnalysis.OperationStartDepth = dataSaubDto.WellDepth;
var dataSaubs = saubDataCache.GetOrCreateCache(dataSaubDto.IdTelemetry)
.OrderBy(d => d.Date);
var telemetryAnalysisDto = GetDrillingAnalysis(dataSaubs);
if (saubDataCache.CurrentAnalysis is null)
saubDataCache.CurrentAnalysis = telemetryAnalysisDto;
if (saubDataCache.CurrentAnalysis.IdOperation == telemetryAnalysisDto.IdOperation)
{
saubDataCache.CurrentAnalysis.DurationSec +=
telemetryAnalysisDto.DurationSec;
saubDataCache.CurrentAnalysis.OperationEndDepth = dataSaubDto.WellDepth;
}
else
{
db.TelemetryAnalysis.Add(saubDataCache.CurrentAnalysis.Adapt<TelemetryAnalysis>());
saubDataCache.CurrentAnalysis = telemetryAnalysisDto;
saubDataCache.CurrentAnalysis.OperationStartDepth = dataSaubDto.WellDepth;
}
}
}
}
db.SaveChanges();
db.SaveChanges();
}
}
}
}
@ -334,7 +337,7 @@ namespace AsbCloudInfrastructure.Services
ds.Date >= analyzeStartDate
select ds).FirstOrDefault();
var firstSaubUtcTime = firstDataSaub.Date.ToUniversalTime();
var firstSaubUtcTime = firstDataSaub?.Date.ToUniversalTime() ?? default;
return firstSaubUtcTime;
}