2021-08-09 14:01:57 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
2021-07-21 15:29:19 +05:00
|
|
|
|
using System.Collections.Generic;
|
2021-06-25 15:10:05 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
|
|
|
|
public class SaubDataCache : ISaubDataCache
|
|
|
|
|
{
|
2021-08-09 14:01:57 +05:00
|
|
|
|
public TelemetryAnalysisDto CurrentAnalysis { get; set; }
|
2021-07-20 09:36:40 +05:00
|
|
|
|
|
2021-08-09 14:01:57 +05:00
|
|
|
|
private readonly Dictionary<int, List<DataSaubBaseDto>> saubData =
|
|
|
|
|
new Dictionary<int, List<DataSaubBaseDto>>();
|
2021-06-25 15:10:05 +05:00
|
|
|
|
|
2021-08-09 14:01:57 +05:00
|
|
|
|
public IEnumerable<DataSaubBaseDto> GetOrCreateCache(int telemetryId)
|
2021-06-25 15:10:05 +05:00
|
|
|
|
{
|
|
|
|
|
if (!saubData.ContainsKey(telemetryId))
|
2021-08-09 14:01:57 +05:00
|
|
|
|
saubData[telemetryId] = new List<DataSaubBaseDto>();
|
2021-06-25 15:10:05 +05:00
|
|
|
|
|
|
|
|
|
return saubData[telemetryId];
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 14:01:57 +05:00
|
|
|
|
public void AddData(DataSaubBaseDto data)
|
2021-06-25 15:10:05 +05:00
|
|
|
|
{
|
|
|
|
|
GetOrCreateCache(data.IdTelemetry);
|
|
|
|
|
|
|
|
|
|
saubData[data.IdTelemetry].Add(data);
|
|
|
|
|
|
|
|
|
|
if (saubData[data.IdTelemetry].Count > 10)
|
|
|
|
|
saubData[data.IdTelemetry].RemoveAt(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|