Function groupedBySourceMetricDataArray

  • Transform raw SolarNetwork timeseries data by combining datum from multiple sources into a single data per time key.

    This method produces a single array of objects with metric properties derived by grouping that property within a single time slot across one or more source IDs. Conceptually this is similar to Util.Datum.aggregateNestedDataLayers except groups of source IDs can be produced in the final result.

    The data will be passed through Util.Datum.normalizeNestedStackDataByDate so that every result object will contain every configured output group, but missing data will result in a null value.

    Here's an example where two sources A and B are combined into a single group Generation and a third source C is passed through as another group Consumption:

    const queryData = [
    {localDate: '2018-05-05', localTime: '11:00', sourceId: 'A', watts : 123},
    {localDate: '2018-05-05', localTime: '11:00', sourceId: 'B', watts : 234},
    {localDate: '2018-05-05', localTime: '11:00', sourceId: 'C', watts : 345},
    {localDate: '2018-05-05', localTime: '12:00', sourceId: 'A', watts : 456},
    {localDate: '2018-05-05', localTime: '12:00', sourceId: 'B', watts : 567},
    {localDate: '2018-05-05', localTime: '12:00', sourceId: 'C', watts : 678},
    ];
    const sourceMap = new Map([
    ['A', 'Generation'],
    ['B', 'Generation'],
    ['C', 'Consumption'],
    ]);

    const result = groupedBySourceMetricDataArray(queryData, 'watts', sourceMap);

    Then result would look like this:

    [
    {date : new Date('2018-05-05T11:00Z'), Generation : 357, Consumption: 345},
    {date : new Date('2018-05-05T12:00Z'), Generation : 1023, Consumption: 678}
    ]

    Parameters

    • data: Record<string, any>

      the raw data returned from SolarNetwork

    • metricName: string

      the datum property name to extract

    • Optional sourceIdMap: Map<string, string>

      an optional mapping of input source IDs to output source IDs; this can be used to control the grouping of data, by mapping multiple input source IDs to the same output source ID

    • Optional aggFn: ((iterable) => undefined | null | number)

      an optional aggregate function to apply to the metric values; defaults to d3.sum; note that the function will be passed an array of input data objects, not metric values

        • (iterable): undefined | null | number
        • Parameters

          • iterable: Iterable<undefined | null | number>

          Returns undefined | null | number

    Returns ({
        date: Date;
    } & Record<string, any>)[]

    array of datum objects, each with a date and one metric value per source ID

Generated using TypeDoc