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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@neerinc/timeseries-importer

v1.0.1

Published

JavaScript library for easily importing timeseries data into NEER Grid™

Downloads

1

Readme

neer-timeseries-importer

JavaScript library for easily importing timeseries data into NEER Grid™

Getting Started

Install the package using NPM

npm install --save @neerinc/timeseries-importer
  1. Use the DataReader to parse the excel file

    Pass a generic type to the parse method to get a strongly typed result

  2. Map the parsed data into the required input to create new sites on the NEER Grid™

  3. Using the returned array of created sites (with their newly added ID's now), create a sensor for each one

import { DataReader } from '@neerinc/timeseries-importer';
import axios from 'axios';
import { readFileSync } from 'fs';
import { join } from 'path';

type SitesFileFormat = {
    ['Meter ID']: string;
    ['Serial Number']: string;
    ['Location']: string;
    ['Latitude']: number;
    ['Longitude']: number;
    ['Facility ID']: string;
};

const apiKey = process.env.NEER_API_KEY;

async function run() {
    // Step 1

    const sitesFilePath = join(__dirname, 'sites.xlsx');
    const sitesFileBuffer = readFileSync(sitesFilePath);
    const dataReader = new DataReader();
    const data = await dataReader.parse<SitesFileFormat>(buffer);

    // Step 2

    const createSitesInput = data.map(row => {
        return {
            client_id: 2, // the client you're to insert the sites for, see https://neer.stoplight.io/docs/neer-developers/b3A6MzUyNzU1MjM-get-clients
            facility_id: row['Facility ID'],
            name: row['Meter ID'],
            description: row['Location'],
            latitude: row['Latitude'],
            longitude: row['Longitude']
        }
    });

    const { status1, data: result1 } = await axios.post('https://api.neer.dev/sites', createSitesInput, {
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'X-API-KEY': apiKey
        }
    });
    if (status1 !== 200) { /* handle error */ }
    const createdSites = result1.data; // array of sites: https://neer.stoplight.io/docs/neer-developers/c2NoOjM1Mjg0MzE5-site

    // Step 3

    const createSensorsInput = createdSites.map(createdSite => {
        const matchingRowFromData = data.find(row => row['Meter ID'] === createdSite.name);
        const serialNumber = matchingRowFromData['Serial Number'];

        return {
            site_id: createdSite.id,
            name: `${createdSite.name}_flow_meter`, // optional
            type: 'flow',
            style: 'volumetric', // optional
            system: 'drinking water',
            label: 'Flow', // optional
            units: 'cfs',
            metadata: {
                serial_number: serialNumber
            },
            tags: ['AMI']
        }
    });

    const { status2, result2 } = await axios.post('https://api.neer.dev/sensors', createSensorsInput, {
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'X-API-KEY': apiKey
        }
    });
    if (status1 !== 200) { /* handle error */ }
    const createdSites = result1.data; // array of sensors: https://neer.stoplight.io/docs/neer-developers/c2NoOjM1Mjk5Njg1-sensor
}