@etainabl/nodejs-sdk 1.1.22 → 1.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/consumption.d.ts +8 -17
- package/dist/consumption.js +18 -42
- package/dist/consumption.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
package/dist/consumption.d.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: number;
|
|
1
|
+
interface ConsumptionData {
|
|
2
|
+
date: Date;
|
|
3
|
+
consumption: number;
|
|
5
4
|
}
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
declare const _default: {
|
|
12
|
-
apportionedReadings: (readings: Reading[], granularity?: moment.unitOfTime.Diff, interpolationMethod?: string, startDate?: string | undefined, endDate?: string | undefined) => ApportionedReading[];
|
|
13
|
-
consumptionFromReadings: (readings: Reading[], startDate: string, endDate: string, granularity?: moment.unitOfTime.Diff, interpolationMethod?: string) => {
|
|
14
|
-
totalConsumption: any;
|
|
15
|
-
apportioned: ApportionedReading[];
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export default _default;
|
|
5
|
+
export declare const dayNightConsumption: (data: ConsumptionData[]) => any;
|
|
6
|
+
export declare const calcMaxConsumptionValue: (data: ConsumptionData[]) => number;
|
|
7
|
+
export declare const calcMaxDemand: (data: ConsumptionData[]) => number;
|
|
8
|
+
export declare const calcPeakLoad: (consumption: number, maxDemand: number, startDate: Date, endDate: Date) => number;
|
|
9
|
+
export {};
|
package/dist/consumption.js
CHANGED
|
@@ -1,47 +1,23 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// Array of every hour/day etc between the first and last reading
|
|
7
|
-
const intervals = moment(sortedReadings[sortedReadings.length - 1].submittedAt).diff(moment(sortedReadings[0].submittedAt), granularity);
|
|
8
|
-
const dates = [...Array(intervals).keys()]
|
|
9
|
-
.slice(1)
|
|
10
|
-
.map((interval) => moment(sortedReadings[0].submittedAt).startOf(granularity).add(interval, granularity));
|
|
11
|
-
let interpolatedReadings = dates.map((date) => {
|
|
12
|
-
const reading = interpolate(sortedReadings, date, interpolationMethod);
|
|
13
|
-
return {
|
|
14
|
-
date,
|
|
15
|
-
reading
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
interpolatedReadings = interpolatedReadings.map((reading, index) => {
|
|
19
|
-
const prevReading = interpolatedReadings[index - 1];
|
|
20
|
-
if (prevReading) {
|
|
21
|
-
return {
|
|
22
|
-
...reading,
|
|
23
|
-
consumption: reading.reading - prevReading.reading
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return reading;
|
|
27
|
-
});
|
|
28
|
-
if (startDate) {
|
|
29
|
-
interpolatedReadings = interpolatedReadings.filter((reading) => moment(reading.date).isSameOrAfter(startDate, granularity));
|
|
2
|
+
export const dayNightConsumption = (data) => data.reduce((acc, item) => {
|
|
3
|
+
const hour = moment(item.date).hour(); // End Time of HH consumption period
|
|
4
|
+
if (hour >= 0 && hour < 7) {
|
|
5
|
+
acc.nightConsumption += item.consumption;
|
|
30
6
|
}
|
|
31
|
-
|
|
32
|
-
|
|
7
|
+
else {
|
|
8
|
+
acc.dayConsumption += item.consumption;
|
|
33
9
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
10
|
+
acc.consumption += item.consumption;
|
|
11
|
+
return acc;
|
|
12
|
+
}, {
|
|
13
|
+
dayConsumption: 0,
|
|
14
|
+
nightConsumption: 0,
|
|
15
|
+
consumption: 0
|
|
16
|
+
});
|
|
17
|
+
export const calcMaxConsumptionValue = (data) => Math.max(...data.map((item) => item.consumption));
|
|
18
|
+
export const calcMaxDemand = (data) => calcMaxConsumptionValue(data) * 2;
|
|
19
|
+
export const calcPeakLoad = (consumption, maxDemand, startDate, endDate) => {
|
|
20
|
+
const days = Math.ceil(moment(endDate).diff(moment(startDate), 'days', true));
|
|
21
|
+
return maxDemand === 0 ? 0 : ((consumption / (maxDemand * 24 * days)) * 100);
|
|
46
22
|
};
|
|
47
23
|
//# sourceMappingURL=consumption.js.map
|
package/dist/consumption.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consumption.js","sourceRoot":"","sources":["../src/consumption.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"consumption.js","sourceRoot":"","sources":["../src/consumption.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAQ,EAAE,IAAqB,EAAE,EAAE;IAC9G,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,oCAAoC;IAE3E,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE;QACzB,GAAG,CAAC,gBAAgB,IAAI,IAAI,CAAC,WAAW,CAAC;KAC1C;SAAM;QACL,GAAG,CAAC,cAAc,IAAI,IAAI,CAAC,WAAW,CAAC;KACxC;IAED,GAAG,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC;IAEpC,OAAO,GAAG,CAAC;AACb,CAAC,EAAE;IACD,cAAc,EAAE,CAAC;IACjB,gBAAgB,EAAE,CAAC;IACnB,WAAW,EAAE,CAAC;CACf,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,IAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAqB,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;AAEvI,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAuB,EAAE,EAAE,CAAC,uBAAuB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE5F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAE,SAAiB,EAAE,SAAe,EAAE,OAAa,EAAE,EAAE;IACrG,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAE9E,OAAO,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;AAC/E,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import api from './api.js';
|
|
2
|
-
import consumption from './consumption.js';
|
|
3
2
|
import logger from './logger.js';
|
|
4
3
|
import db from './db.js';
|
|
5
4
|
import slack from './slack.js';
|
|
6
5
|
import * as units from './units.js';
|
|
6
|
+
import * as consumption from './consumption.js';
|
|
7
7
|
export { api, logger, consumption, db, slack, units };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import api from './api.js';
|
|
2
|
-
import consumption from './consumption.js';
|
|
3
2
|
import logger from './logger.js';
|
|
4
3
|
import db from './db.js';
|
|
5
4
|
import slack from './slack.js';
|
|
6
5
|
import * as units from './units.js';
|
|
6
|
+
import * as consumption from './consumption.js';
|
|
7
7
|
export { api, logger, consumption, db, slack, units };
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,EAAE,EACF,KAAK,EACL,KAAK,EACN,CAAA"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import api from './api.js';
|
|
2
|
-
import consumption from './consumption.js';
|
|
3
2
|
import logger from './logger.js';
|
|
4
3
|
import db from './db.js';
|
|
5
4
|
import slack from './slack.js';
|
|
6
5
|
import * as units from './units.js';
|
|
6
|
+
import * as consumption from './consumption.js';
|
|
7
7
|
|
|
8
8
|
export {
|
|
9
9
|
api,
|