forked from ddrilling/AsbCloudServer
CS2-88: Added refresh of Telemetry analyze start date (to prevent infinite loops)
This commit is contained in:
parent
c2c9bad200
commit
130feacdd5
@ -234,7 +234,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
public void SaveAnalytics()
|
||||
{
|
||||
var allTelemetryIds = (from telemetry in db.TelemetryDataSaub
|
||||
select telemetry.Id)
|
||||
select telemetry.IdTelemetry)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
@ -244,7 +244,9 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
while (GetDataSaubsToAnalyze(idTelemetry, analyzeStartDate).Any())
|
||||
{
|
||||
var dataSaubsToAnalyze = GetDataSaubsToAnalyze(idTelemetry, (long)analyzeStartDate);
|
||||
var dataSaubsToAnalyze = GetDataSaubsToAnalyze(idTelemetry, analyzeStartDate);
|
||||
|
||||
analyzeStartDate = dataSaubsToAnalyze.Last().Date;
|
||||
|
||||
foreach (var dataSaub in dataSaubsToAnalyze)
|
||||
{
|
||||
@ -312,39 +314,36 @@ namespace AsbCloudInfrastructure.Services
|
||||
};
|
||||
}
|
||||
|
||||
private long GetAnalyzeStartDate(int idTelemetry)
|
||||
private DateTime GetAnalyzeStartDate(int idTelemetry)
|
||||
{
|
||||
var lastAnalysisInDb = (from analysis in db.TelemetryAnalysis
|
||||
where analysis.Id == idTelemetry
|
||||
where analysis.IdTelemetry == idTelemetry
|
||||
orderby analysis.UnixDate
|
||||
select analysis)
|
||||
.DefaultIfEmpty()
|
||||
.Last();
|
||||
.DefaultIfEmpty()
|
||||
.Last();
|
||||
|
||||
var analyzeStartDate = lastAnalysisInDb?.UnixDate;
|
||||
var lastAnalysisUnixDate = lastAnalysisInDb?.UnixDate ?? 0;
|
||||
|
||||
if (analyzeStartDate is null)
|
||||
{
|
||||
var firstDataSaub = (from ds in db.TelemetryDataSaub
|
||||
where ds.IdTelemetry == idTelemetry
|
||||
select ds.Date).FirstOrDefault();
|
||||
var analyzeStartDate = DateTimeOffset.FromUnixTimeSeconds(lastAnalysisUnixDate);
|
||||
|
||||
analyzeStartDate = (long)(firstDataSaub - new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
}
|
||||
var firstDataSaub = (from ds in db.TelemetryDataSaub
|
||||
where ds.IdTelemetry == idTelemetry &&
|
||||
ds.Date > analyzeStartDate
|
||||
select ds).FirstOrDefault();
|
||||
|
||||
return (long)analyzeStartDate;
|
||||
var firstSaubUtcTime = firstDataSaub.Date.ToUniversalTime();
|
||||
|
||||
return firstSaubUtcTime;
|
||||
}
|
||||
|
||||
private IEnumerable<TelemetryDataSaub> GetDataSaubsToAnalyze(int idTelemetry, long analyzeStartDate)
|
||||
private IEnumerable<TelemetryDataSaub> GetDataSaubsToAnalyze(int idTelemetry,
|
||||
DateTime analyzeStartDate)
|
||||
{
|
||||
return (from ds in db.TelemetryDataSaub
|
||||
let lowerBorder = DateTimeOffset
|
||||
.FromUnixTimeSeconds(analyzeStartDate)
|
||||
let upperBorder = DateTimeOffset
|
||||
.FromUnixTimeSeconds(analyzeStartDate).AddHours(12)
|
||||
where ds.Id == idTelemetry
|
||||
&& ds.Date > lowerBorder
|
||||
&& ds.Date < upperBorder
|
||||
where ds.IdTelemetry == idTelemetry
|
||||
&& ds.Date > analyzeStartDate
|
||||
&& ds.Date < analyzeStartDate.AddHours(12)
|
||||
select ds).ToList();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user