using InnovEnergy.S3.Drivers.Internal.Delegates; 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 IReadOnlyList AggregationLevels { get; } public UnixTimeSpan SamplePeriod => AggregationLevels[0].SamplePeriod; private readonly ReadRecord _ReadRecord; internal Reader(IReadOnlyList levels, ReadRecord readRecord) { _ReadRecord = readRecord; AggregationLevels = InitLevels(levels); } public Task ReadRecord(AggregationLevel level, UInt32 index) { return _ReadRecord(level, index); } private static IReadOnlyList InitLevels(IReadOnlyList levels) { if (!levels.Any()) throw new ArgumentOutOfRangeException(nameof(levels)); levels = levels .OrderBy(l => l.SamplePeriod.Ticks) .ToReadOnlyList(levels.Count); var pairwise = levels .Select(l => l.SamplePeriod) .Pairwise() .ToReadOnlyList(levels.Count - 1); var greater = pairwise.Any(ls => ls.right <= ls.left); var multiple = pairwise.Any(ls => ls.right % ls.left != 0 ); var retention = levels .Any(l => l.RetentionPeriod % l.SamplePeriod != 0); if (greater || multiple || retention) throw new ArgumentException(nameof(levels)); // TODO: error messages return levels; } }