[Experimental] 'Always on' calculator based on 15 minute data
Install 'enertalk-alwayson-calculator' package via NPM or Yarn.
> npm install enertalk-alwayson-calculator
or
> yarn add enertalk-alwayson-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
-
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
It filters the items with daily lowest usage
It filters the items based on sleep time (22:00 ~ 06:00)
It filters cases where the amount of usage change is less than 1Wh for three or more consecutive times
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, ...)
To test this package, clone this repository on your local
> yarn test
yarn calculate
NOTE: To execute the integration test normally, you need to obtain
accessToken
andsiteHash
first.