npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

timestream_processing

v2.0.7

Published

**timestream_processing**

Readme

timestream_processing

A package for parsing result of timestream query and also for generating energy report.

timestream_processing APIs

  1. generateEnergyReport(deviceIds, responseForPastData, main_response, deviceDictionary, groupBy)

    Computes energy consumed by each device per hour,day,month or year(based on the 'groupBy' parameter).

    Parameters

    • deviceIds: array of device ids.

    • responseForPastData: timestream data of device before start time as object with deviceIds as keys.

    • main_response: timestream data of device between start time and end time as array of objects.

    • deviceDictionary: an object with key as device id and values as device id and device name.

    • groupBy: the parameter which decides grouping of data for energy consumed calculation. Takes the following values:

      1. "Hr": hour-wise grouping.
      2. "Dy": day-wise grouping.
      3. "MM": month-wise grouping.
      4. "Yr": year-wise grouping.
  2. parseQueryResult(response)

    Converts a timestream query response object to key value pairs.

    Parameters

    • response: timestream query response(object).

    Example:

    const { parseQueryResult } = require("timestream_processing");
    
    let response =
    {
        QueryId: 'AEBQEAM2Q2GTYF2ZDVAGKALO7UXVDHQ4VU4XGGZ4233NITK7LWOXZ4GUBGRIVUK',
        Rows:[
         {Data:
         [
             { ScalarValue: '8910dh1937a73bf82' },
             { ScalarValue: 'Raj Malhotra' },
             { ScalarValue: '25' },
             { ScalarValue: 'M' },
             {ScalarValue: '2021-02-22 23:06:03.312000000'}
        ]}
        {Data:
        [
             { ScalarValue: '738hf3y837932h37r' },
             { ScalarValue: 'Mehul Bhanushali' },
             { ScalarValue: '28' },
             { ScalarValue: 'M' }
             {ScalarValue: '2021-02-22 23:07:03.312000000'}
        ]}
        ],
         ColumnInfo:
         [
             { Name: 'id', Type: { ScalarType: 'VARCHAR' } },
             { Name: 'name', Type: { ScalarType: 'VARCHAR' } },
             { Name: 'age', Type: { ScalarType: 'VARCHAR' } },
             { Name: 'Gender', Type: { ScalarType: 'VARCHAR' } },
             { Name: 'time', Type: { ScalarType: 'TIMESTAMP' } }
         ],
          QueryStatus:
          {
             ProgressPercentage: 100,
             CumulativeBytesScanned: 8464866,
             CumulativeBytesMetered: 10000000
         }
     };
    
     let result = parseQueryResult(response);
     console.log(result);

    Output:

    [{id:'8910dh1937a73bf82', name: 'Raj Malhotra', age: '25', Gender: 'M',time: 2021-02-22 23:06:03.312000000},{id: '738hf3y837932h37r', name: 'Mehul Bhanushali', age: '28', Gender: 'M', time: '2021-02-22 23:07:03.312000000'}]

  3. parseQueryResultWithProcessing(response)

    Converts a timestream query response object to an array of objects based on column type. Each object of the array represents a row of timestream table.It has keys as column names and values as their corresponding values.

    Parameters

    • response: timestream query response(object).

    Example:

    const { parseQueryResultWithProcessing } = require("timestream_processing");
    
    let response =
    {
       QueryId: 'AEBQEAM2Q2GTYF2ZDVAGKALO7UXVDHQ4VU4XGGZ4233NITK7LWOXZ4GUBGRIVUK',
       Rows:[
        {Data:
        [
            { ScalarValue: '8910dh1937a73bf82' },
            { ScalarValue: 'Raj Malhotra' },
            { ScalarValue: '25' },
            { ScalarValue: 'M' },
            {ScalarValue: '2021-02-22 23:06:03.312000000'}
       ]}
       {Data:
       [
            { ScalarValue: '738hf3y837932h37r' },
            { ScalarValue: 'Mehul Bhanushali' },
            { ScalarValue: '28' },
            { ScalarValue: 'M' }
            {ScalarValue: '2021-02-22 23:07:03.312000000'}
       ]}
       ],
        ColumnInfo:
        [
            { Name: 'id', Type: { ScalarType: 'VARCHAR' } },
            { Name: 'name', Type: { ScalarType: 'VARCHAR' } },
            { Name: 'age', Type: { ScalarType: 'VARCHAR' } },
            { Name: 'Gender', Type: { ScalarType: 'VARCHAR' } },
            { Name: 'time', Type: { ScalarType: 'TIMESTAMP' } }
        ],
         QueryStatus:
         {
            ProgressPercentage: 100,
            CumulativeBytesScanned: 8464866,
            CumulativeBytesMetered: 10000000
        }
    };
    
    let result = parseQueryResultWithProcessing(response);
    console.log(result);

    Output:

    [{id=8910dh1937a73bf82,name=Raj Malhotra,age=25,Gender=M,time=2021-02-22 23:06:03.312000000},{id=738hf3y837932h37r,name=Mehul Bhanushali,age=28,Gender=M,time=2021-02-22 23:07:03.312000000}]

  4. getParsedValue(value,dataType)

    Converts timestream query response object value(each object from array of objects output from parseQueryResult) to its corresponding data type based on the 'dataType' parameter of response.

    Parameters

    • value: value of parameter as string.
    • dataType: data type of parameter as string.

    Supported Type Conversions(from string)

    1. Boolean(dataType = "BOOL") : true or false
    2. Float(dataType = "FLOAT") : floating point number
    3. Date(dataType = "DATE"): date in the form YYYY-MM-DD (year-month-date).The supported range is from 1970-01-01 to 2262-04-11.
    4. TimeOfDay(dataType = "TOD") : unsigned integer number in milliseconds, with zero equal to midnight.
    5. Time(dataType = "TIME") : time of day in UTC.The time datatype is represented in the form HH:MM:SS(hours:minutes:seconds).
    6. Int(dataType = "INT"): 32-bit integer.
    7. Unsigned Int(dataType = "UINT") : 32-bit unsigned integer.
    8. Unsigned Short Int(dataType = "USINT") : 8-bit short(small) integer.
    9. Unsigned Large Integer(dataType = "UDINT_R") : 64-bit unsigned large integer.

    Example

    const { getParsedValue } = require("timestream_processing");
    let obj = {
        'measure_value::double': '249.45'
        dataType: 'FLOAT'
    };
    let result = getParsedValue(obj['measure_value::double'],obj.dataType);
    console.log("result = ",result);

    Output

    result = 249.45

  5. groupByKey(response, deviceDictionary, groupBy)

    Groups array of objects by a grouping parameter and converts key to the form "devicename-parametername".

    Parameters

    • response: timestream response as array of objects.
    • deviceDictionary: an object with key as device id and values as device id and device name.
    • groupBy: grouping parameter(any key from response).

    Example

    const { groupByKey } = require("timestream_processing");
    
    let deviceDictionary = {
    '921791a9r90q8e173': { _id: '921791a9r90q8e173', name: 'Device 1' },
    '1234d8793a837h217': { _id: '1234d8793a837h217', name: 'Device 2' }
    }
    
    let response = [{
        deviceId: '921791a9r90q8e173',
        time: '2021-02-24 16:31:29',
        dataType: 'FLOAT',
        measure_value::double: '251.14',
        measure_name: 'Voltage 1'
    },
    {
        deviceId: '1234d8793a837h217',
        time: '2021-02-24 16:31:29',
        dataType: 'FLOAT',
        measure_value::double: '219.14',
        measure_name: 'Voltage 2'
    },
    
    {
        deviceId: '1234d8793a837h217'
        time: '2021-02-24 16:31:39',
        dataType: 'FLOAT',
        measure_value::double: '239.14',
        measure_name: 'Voltage 2'
    }]
    
    let result = groupByKey(response,deviceDictionary,"time");
    console.log("result = ",result);

    Output

    result = [{ time: '2021-02-24 16:31:29', 'Device 1-Voltage 1': 251.14, 'Device 2-Voltage 2': 219.14 },{ time: '2021-02-24 16:31:39', 'Device 2-Voltage 2': 239.14 }]