I have various time-series I’d like to correlate and present as either a csv-file or in-memory datatable (.NET). These time-series are arrays of time-value-pairs (actually these are objects containing more than just time and value). The time-series may span across different overlapping periods, and some might even have holes (missing values for given timestamps).
For those interested, I’m using the OPC HDA .NET library to extract historic time-series from an OPC HDA server.
The resulting datatable should have one column for each time-series all in chronological order based on a timestamp column. See example below:
|-------|-------|-------|-------|-------|
TIME TS1 TS2 TS3 TS4
|-------|-------|-------|-------|-------|
1 X X X
|-------|-------|-------|-------|-------|
2 X X X X
|-------|-------|-------|-------|-------|
3 X X X
|-------|-------|-------|-------|-------|
4 X X X
|-------|-------|-------|-------|-------|
5 X X X
|-------|-------|-------|-------|-------|
What would be the most effective way of achieving this? With “effective” I mean with the least amount of code. But considering that the timeseries could become quite large, memory usage might also be an issue.
You might go with a data structure like a nested dictionary and iterate over the contents:
Where your output code is writing out to something else, depending on your needs, and you replace the datatypes TimeSeries, Value, etc., with your actual data types.