Very simply I am storing a TimeSeries as a DateTime dictionary with a signature of IDictionary<Datetime, double?>
. This would contain a month of 10 min resolution data, so up to 4,464 entries.
In order to process sections of this time series we need to extract a section between a start
and an end
DateTime
.
A naïve way of doing this is to obtain a subset of the Dictionary keys for the range we're interested in:
var reducedKeys = timeSeries.Keys.Where(k => k >= start && k <= end).ToList();
Then extract the relevant section from the large timeSeries
var reducedTimeSeries = timeSeries.Where(kvp => reducedKeys .Contains(kvp.Key)).ToDictionary(w => w.Key, w => w.Value);
This doesn't feel like the most optimal solution; Any suggestions for a faster extraction strategy?
For clarity, the ordering of the time stamps is largely irrelevant at this stage as the higher level calculations are happening across multiple time series rather than within the same series. There is a flatline filter to run, after the extraction; but this is ok to run by iterating over a sorted copy of the keys from the time series extract as we would typically have a 12-24 sample series after extraction from the longer source series.