Innovenergy_trunk/csharp/Lib/S3/Drivers/Internal/Reader.public.cs

37 lines
1.2 KiB
C#

using InnovEnergy.Lib.S3.Metadata;
using InnovEnergy.Lib.S3.Records.Specialized;
using InnovEnergy.Lib.Time.Unix;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Lib.S3.Drivers.Internal;
public partial class Reader
{
public Task<IReadOnlyList<TimeStampedRecord>> ReadRecords(UnixTime from, UnixTime to, Int32 minNumber)
{
var maxDt = (to - from) / minNumber;
return ReadRecords(from, to, maxDt);
}
public async Task<IReadOnlyList<TimeStampedRecord>> ReadRecords(UnixTime from, UnixTime to, UnixTimeSpan maxDt)
{
if (maxDt < SamplePeriod)
maxDt = SamplePeriod;
var level = AggregationLevels.LastOrDefault(l => l.SamplePeriod <= maxDt) ?? AggregationLevels[^1];
return await level
.RangeExclusive(from, to)
.Select(t => ReadRecord(level, t))
.WhenAll();
}
public async Task<TimeStampedRecord> ReadRecord(AggregationLevel level, UnixTime time)
{
var tsRecord = await ReadRecord(level, level.GetRetentionIndex(time));
return tsRecord.TimeStamp == time
? tsRecord
: TimeStampedRecord.Empty(time);
}
}