toMirSeries

Converts MeasurementSeries.Rows to Mir Series.

version(Have_mir_algorithm)
static if(__VERSION__ >= 2073)
Series!(T*, D*, 2)
toMirSeries
(
T = DateTime
D = double
)
(,
const(string)[] columns = null
)

Parameters

T

Time type. Default time type is DateTime. Supported types are SysTime, DateTime, and Date.

D

Data type. Default data type is double.

rows MeasurementSeries.Rows

MeasurementSeries rows

columns const(string)[]

List of columns (optional). The "time" colummn is ignored.

Return Value

Type: Series!(T*, D*, 2)

2D Mir Series.

Examples

import mir.series;
import std.datetime: DateTime;

auto influxSeries = MeasurementSeries("coolness",
    ["time", "foo", "bar"],
    [
        ["2015-06-11T20:46:02Z", "1.0", "2.0"],
        ["2013-02-09T12:34:56Z", "3.0", "4.0"],
    ]);

auto series = influxSeries.rows.toMirSeries;

// sort data if required
{
    import mir.algorithm.iteration: all;
    import mir.ndslice.allocation: uninitSlice;
    import mir.ndslice.topology: pairwise;

    if (!series.time.pairwise!"a <= b".all)
    {
        series.sort(
            uninitSlice!size_t(series.length), // index buffer
            uninitSlice!double(series.length)); // data buffer
    }
}

assert(series.time == [
    DateTime(2013,  2,  9, 12, 34, 56),
    DateTime(2015,  6, 11, 20, 46,  2)]);

assert(series.data == [
    [3.0, 4.0],
    [1.0, 2.0]]);

Meta