37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using InnovEnergy.S3.Metadata;
|
|
using InnovEnergy.S3.Records.Specialized;
|
|
using InnovEnergy.Time.Unix;
|
|
using InnovEnergy.Lib.Utils;
|
|
|
|
namespace InnovEnergy.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);
|
|
}
|
|
} |