0.2.6 • Published 6 years ago

enertalk-alwayson-calculator v0.2.6

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

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.

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago