GithubHelp home page GithubHelp logo

solarnetwork / sn-datum-loader-js Goto Github PK

View Code? Open in Web Editor NEW
0.0 6.0 0.0 779 KB

Classes to load datum for time ranges.

License: Apache License 2.0

JavaScript 1.87% TypeScript 98.13%
solarnetwork typescript

sn-datum-loader-js's Introduction

SolarNetwork Datum Loader - JavaScript

This project contains classes to help with loading SolarNetwork datum over time ranges.

To include the library in your NPM-based project, run the following:

npm i solarnetwork-datum-loader

API docs

The latest API documentation is published here, or you can build the API documentation by running the apidoc script:

npm run apidoc

That will produce HTML documentation in docs/html.

DatumLoader

The DatumLoader class helps return data from the SolarQuery /datum/list endpoint. The class takes care of loading all results for a given search criteria, including making multiple API requests to download all result pages when more than one page of results are available.

Here's an example of loading a month's worth of data for SolarNode 123:

const filter = new DatumFilter();
filter.nodeId = 123;
filter.startDate = new Date("Sat, 1 Apr 2017 12:00:00 GMT");
filter.endDate = new Date("Mon, 1 May 2017 12:00:00 GMT");

const api = new SolarQueryApi();

new DatumLoader(api, filter).load((error, results) => {
	// results is an array of Datum objects
});

A Promise based API is available as well:

const result = await new DatumLoader(api, filter).fetch();

MultiLoader

The MultiLoader class helps load data from multiple Loader objects (the DatumLoader class conforms to that interface). This is useful for pulling down data from different search criterias all in one go. For example:

const filter1 = new DatumFilter();
filter1.nodeId = 123;
filter1.sourceId = "a";

const filter2 = new DatumFilter();
filter2.nodeId = 234;
filter2.sourceIds = ["b", "c"];

const api = new SolarQueryApi();

new MultiLoader([
	new DatumLoader(api, filter1),
	new DatumLoader(api, filter2),
]).load((error, results) => {
	// results is a 2-element array of Datum arrays
});

# or via promise...
const result = await new MultiLoader([
	new DatumLoader(api, filter1),
	new DatumLoader(api, filter2),
]).fetch();

DatumRangeFinder

The DatumRangeFinder class helps find the date range of available data for a set of SolarNodes. This is useful when generating reports or charts for a set of SolarNode datum streams, so the overall start/end dates can be determined before requesting the actual data. For example:

const api = new SolarQueryApi();

const filter = new DatumFilter();
filter.nodeId = 123;
filter.sourceIds = ["a", "b"];

const range = await new DatumRangeFinder(api, filter).fetch();

Ranges for more complex queries can be accomplished by passing in an array of filters, like this example, continuing from the last one:

const filter2 = new DatumFilter();
filter2.nodeId = 234;
filter2.sourceId = "c";

const range2 = await new DatumRangeFinder(api, [filter1, filter2]).fetch();

DatumSourceFinder

The DatumSourceFinder class helps find the available source IDs for a set of node IDs.

const api = new SolarQueryApi();

const filter = new DatumFilter();
filter.nodeId = 123;

const sources = await new DatumSourceFinder(api, filter).fetch();

Wildcard patterns can also be used to limit the search to a more specific set of source IDs, and start/end dates can also be used to narrow the search, for example:

const api = new SolarQueryApi();

const filter = new DatumFilter();
filter.startDate = new Date(Date.now() - 24 * 60 * 60 * 1000);
filter.sourceId = "/power/**";

const sources2 = await new DatumSourceFinder(api, filter).fetch();

Building

The build uses NPM and requires Node 18+. First, initialize the dependencies:

npm ci

Then you can run the build script:

npm run build:dist

That will produce ES2022 modules with an entry point in lib/index.js.

You can also produce an ES2022 bundle by running npm run build:bundle. That will produce a single bundled file at lib/solarnetwork-datum-loader.es.js.

Releases

Releases are done using the gitflow branching model. Gitflow must be installed on your host system. Then you can run

npm run release

to version, build, commit, and publish the release. See the generate-release site for more information.

Unit tests

The unit tests can be run by running the test script:

npm test

That will output the test results and produce a HTML code coverage report at coverage/index.html.

sn-datum-loader-js's People

Contributors

maxieduncan avatar msqr avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.