I have multiple identical length collections, one timestamp collection of type List<DateTime>
and several data collections of type List<double>
. The values at each index position in the List<double
correspond to the respective index position in List<DateTime>
.
I want to be able to compress the data in all data collections by a TimeSpan
that is applied to the List<DateTime>
and groups the timestamps into TimeSpan
bins and applies the same grouping to each data collection.
Here is how I currently "compress" a time series of time stamps:
var someTimeStamps = new List<DateTime>();
var compression = TimeSpan.FromHours(1).Ticks;
var compressedTimeStamps = from rawData in someTimeStamps
group rawData by rawData.Ticks / numberTicks
into tickData
select new DateTime(tickData.Key * compression);
How can I adjust the code in order to have the same groupings apply to the data collections List<double>
as well? I want to apply a grouping logic of averaging the values within each data group. I am aiming for computational efficiency, memory consumption is not an issue I look to optimize at this point.
For example:
List<DateTime>
items: (for simplicity purpose the order of the values below is (year, month, day, hour, minute, second):
(1) 2018, 8, 14, 08, 20, 05 (2) 2018, 8, 14, 08, 45, 25 (3) 2018, 8, 14, 09, 02, 53 (4) 2018, 8, 14, 09, 34, 12 (5) 2018, 8, 14, 09, 44, 12
List<value>
items:
(1) 12 (2) 15 (3) 27 (4) 03 (5) 12
Applying a compression of TimeSpan.FromHours(1)
the desired outcome for both collections is :
List<DateTime>
items:
(1) 2018, 8, 14, 08, 00, 00 (2) 2018, 8, 14, 09, 00, 00
List<double>
items (averaging is applied to the items in each group)
(1) 13.5 (avg of 12 and 15) (2) 14 (avg of 27, 3, and 12)