-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeter-util.js
39 lines (30 loc) · 1.09 KB
/
meter-util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*jslint node: true, nomen: true, es5: true*/
////////////////////////////////////////////////////
// Utility functions for working with meter readings
'use strict';
var MeterUtil = function () {
var self = this;
self.readingType = function (readingType) {
var values = readingType.ref.split('.'),
attributes = [
'TimeAttribute', 'DataQualifier', 'AccumlationBehaviour', 'FlowDirection',
'UomCategorySubclass', 'UomCategoryIndex', 'MeasurementCategory', 'Enumeration',
'Phase', 'metricMultiplier', 'UnitOfMeasure'
],
json = {},
i;
for (i = 0; i < attributes.length; i += 1) {
json[attributes[i]] = parseInt(values[i], 10);
}
return json;
};
self.wattHours = function (meterReading) {
var value = meterReading.value,
readingType = self.readingType(meterReading.readingType);
if (readingType.metricMultiplier === 3) {
return value * 1000;
}
return value;
};
};
exports.MeterUtil = MeterUtil;