public override List <VTTQ> ReadData(Timestamp startInclusive, Timestamp endInclusive, int maxValues, BoundingMethod bounding, QualityFilter filter) { long N = CountData(startInclusive, endInclusive, filter); PreparedStatement statement; switch (bounding) { case BoundingMethod.TakeFirstN: statement = stmtRawFirstN; break; case BoundingMethod.TakeLastN: statement = stmtRawLastN; break; case BoundingMethod.CompressToN: if (N <= maxValues) { return(ReadData(startInclusive, endInclusive, maxValues, BoundingMethod.TakeFirstN, filter)); } else { return(ReadDataCompressed(startInclusive, endInclusive, maxValues, N, filter)); } default: throw new Exception($"Unknown BoundingMethod: {bounding}"); } statement[0] = startInclusive.ToDateTime(); statement[1] = endInclusive.ToDateTime(); statement[2] = maxValues; var filterHelper = QualityFilterHelper.Make(filter); int initSize = N < maxValues ? (int)N : maxValues; var res = new List <VTTQ>(initSize); using (var reader = statement.ExecuteReader()) { while (reader.Read()) { VTTQ vttq = ReadVTTQ(reader); if (filterHelper.Include(vttq.Q)) { res.Add(vttq); } } } if (bounding == BoundingMethod.TakeLastN) { res.Reverse(); } return(res); }
private List <VTTQ> ReadDataCompressed(Timestamp startInclusive, Timestamp endInclusive, int maxValues, long count, QualityFilter filter) { PreparedStatement statement = stmtRawFirst; statement[0] = startInclusive.ToDateTime(); statement[1] = endInclusive.ToDateTime(); var result = new List <VTTQ>(maxValues); int maxIntervals = maxValues / 3; int itemsPerInterval = (maxValues < 6) ? (int)count : (int)Math.Ceiling(((double)count) / maxIntervals); var buffer = new List <VTTQ_D>(itemsPerInterval); var filterHelper = QualityFilterHelper.Make(filter); using (var reader = statement.ExecuteReader()) { while (reader.Read()) { VTTQ x = ReadVTTQ(reader); if (!x.V.IsEmpty) { double?value = x.V.AsDouble(); if (value.HasValue && filterHelper.Include(x.Q)) { buffer.Add(new VTTQ_D(x, value.Value)); } } if (buffer.Count >= itemsPerInterval) { FlushBuffer(result, buffer, maxValues); } } } if (buffer.Count > 0) { FlushBuffer(result, buffer, maxValues); } return(result); }
public override List <VTTQ> ReadData(Timestamp startInclusive, Timestamp endInclusive, int maxValues, BoundingMethod bounding, QualityFilter filter) { long N = CountData(startInclusive, endInclusive, filter); //double millis = (endInclusive - startInclusive).TotalMilliseconds + 1; //double avgInterval_MS = millis / N; //double requestInterval_MS = 60 * 1000; //double N_2 = N; //if (requestInterval_MS > avgInterval_MS) { // N_2 = N / (requestInterval_MS / avgInterval_MS); //} PreparedStatement statement; switch (bounding) { case BoundingMethod.TakeFirstN: statement = stmtRawFirstN; break; case BoundingMethod.TakeLastN: statement = stmtRawLastN; break; case BoundingMethod.CompressToN: if (N <= maxValues) { return(ReadData(startInclusive, endInclusive, maxValues, BoundingMethod.TakeFirstN, filter)); } else { return(ReadDataCompressed(startInclusive, endInclusive, maxValues, N, filter)); } default: throw new Exception($"Unknown BoundingMethod: {bounding}"); } statement[0] = startInclusive.JavaTicks; statement[1] = endInclusive.JavaTicks; statement[2] = maxValues; var filterHelper = QualityFilterHelper.Make(filter); int initSize = N < maxValues ? (int)N : maxValues; var res = new List <VTTQ>(initSize); using (var reader = statement.ExecuteReader()) { while (reader.Read()) { VTTQ vttq = ReadVTTQ(reader); if (filterHelper.Include(vttq.Q)) { res.Add(vttq); } } } if (bounding == BoundingMethod.TakeLastN) { res.Reverse(); } return(res); }