Правки по результатам тестирования

This commit is contained in:
Olga Nemt 2024-02-02 11:15:03 +05:00
parent e39ac38129
commit cbec0b2cc5

View File

@ -40,13 +40,15 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
if (!idTelemetries.Any())
return;
var stats = await db.Set<DataSaubStat>()
var statsQuery = await db.Set<DataSaubStat>()
.Where(s => idTelemetries.Contains(s.IdTelemetry))
.ToArrayAsync(token);
var stats = statsQuery
.GroupBy(s => s.IdTelemetry)
.ToDictionaryAsync(
.ToDictionary(
g => g.Key,
g => g.OrderByDescending(s => s.DateEnd).First(),
token
g => g.OrderByDescending(s => s.DateEnd).First()
);
foreach ( var idTelemetry in idTelemetries)
@ -92,6 +94,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
{
var indexStart = 0;
var indexEnd = 0;
var result = new List<DataSaubStat>();
foreach (var operation in detectedOperations)
{
indexStart = Array.FindIndex(telemetryDataSaub, indexEnd, t => t.DateTime >= operation.DateStart);
@ -103,14 +106,21 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
var subset = telemetryDataSaub.AsSpan(indexStart, length + 1);
var stats = CalcStats(operation, subset);
foreach (var stat in stats)
yield return stat;
result.AddRange(stats);
}
else
{
indexStart = 0;
indexEnd = 0;
}
}
return result;
}
private static IEnumerable<DataSaubStat> CalcStats(DetectedOperation operation, Span<TelemetryDataSaub> telemetryDataSaub)
{
var result = new List<DataSaubStat>();
var indexStart = 0;
for (var i = 1; i < telemetryDataSaub.Length; i++)
{
@ -123,9 +133,11 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
var span = telemetryDataSaub.Slice(indexStart, length);
indexStart = i;
var stat = CalcStat(operation, span);
yield return stat;
result.Add(stat);
}
}
return result;
}
private static DataSaubStat CalcStat(DetectedOperation operation, Span<TelemetryDataSaub> span)