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

enertalk-alwayson-calculator

v0.2.6

Published

[Experimental] 'Always on' calculator based on 15 minute data

Downloads

2

Readme

enertalk-alwayson-calculator

[Experimental] 'Always on' calculator based on 15 minute data

How to use

Installation

Install 'enertalk-alwayson-calculator' package via NPM or Yarn.

> npm install enertalk-alwayson-calculator
or
> yarn add enertalk-alwayson-calculator

Initialize the calculator

  • Import the package
const AlwaysOnCalculator = require('enertalk-alwayson-calculator');
  • Create a new instance with option
const instance = new AlwaysOnCalculator({
  accessToken: 'yourAccessToken'
});

// or inject existing API client instance
const myClient = new EnerTalkAPIClient({ ... });
const instance = new AlwaysOnCalculator({
  apiClient: myClient,
});

If you need more details about ENERTALK API client, see the document

Execute the 'calculate' method with setting

  • siteHash is required
  • The calculate method will return a promise
instance.calculate({
  siteHash: 'yourSiteHash',
  baseTime: Date.now(), // optional
  timezone: 'US/Pacific', // optional
}).then((result) => {
  const {
    start,  // start timestamp of usage items
    end, // end timestamp of usage items
    period, // '15min'
    usage,  // calculated 'always on' usage in milli watt
  } = result;
}).catch((error) => {
  // Handle errors
});

NOTE: The 'baseTime' is end of period for periodic usage API.
And start will be one month before the 'baseTime'.

  • If the baseTime is not given, it has the current time as the default.
  • If the timezone is not given, it will be retrieved by site hash you passed

Built-in filters

minimumDailyUsageFilter

It filters the items with daily lowest usage

sleepTimeFilter

It filters the items based on sleep time (22:00 ~ 06:00)

consistentItemsFilter

It filters cases where the amount of usage change is less than 1Wh for three or more consecutive times

[Advanced] Use your own filters

By default, the calculator uses a filter named 'minimumDailyUsageFilter'. The filter calculates an average of minimum usages of each day.

If you know more improved logic, you can replace the filter by using 'setFilters' method. The custom filter function should conform a following input/output signiture

([UsageItem], Setting) => [UsageItem]

input: array of UsageItem  
output: array of filtered UsageItem

And types are below,  

{Object} UageItem  
  - {Number} timestamp
  - {Number} usage

{Object} Setting  
  - {String} timezone

Set mutiple filters as follows,

const customFilter1 = (items, setting) => items.filter(...);
const customFilter2 = (items, setting) => items.filter(...);

instance.setFilters(customFilter1, customFilter2, ...)

How to test

To test this package, clone this repository on your local

Run unit tests

> yarn test

Run integration test

yarn calculate

NOTE: To execute the integration test normally, you need to obtain accessToken and siteHash first.