@statengine/siamese 0.0.18
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/.babelrc +5 -0
- package/.eslintrc +18 -0
- package/LICENSE +674 -0
- package/README.md +18 -0
- package/lib/helpers.js +70 -0
- package/lib/index.js +551 -0
- package/lib/priorityDispatchCodes.js +990 -0
- package/package.json +42 -0
- package/src/helpers.js +49 -0
- package/src/index.js +358 -0
- package/src/priorityDispatchCodes.js +985 -0
- package/test/test.helpers.js +487 -0
- package/test/test.js +114 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# siamese
|
|
2
|
+
|
|
3
|
+
Pluggable library to help transform public safety data into standardized schemas.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Using npm:
|
|
8
|
+
```
|
|
9
|
+
npm install @statengine/siamese
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Tests
|
|
13
|
+
To run the test suite, first install the dependencies, then run `npm test`:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install
|
|
17
|
+
npm test
|
|
18
|
+
```
|
package/lib/helpers.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
8
|
+
|
|
9
|
+
var _lodash = require('lodash');
|
|
10
|
+
|
|
11
|
+
var _lodash2 = _interopRequireDefault(_lodash);
|
|
12
|
+
|
|
13
|
+
var _priorityDispatchCodes = require('./priorityDispatchCodes');
|
|
14
|
+
|
|
15
|
+
var _priorityDispatchCodes2 = _interopRequireDefault(_priorityDispatchCodes);
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
var PRIORITY_DISPATCH_REGEX = /([0-9]+?)([ABCDEO])([0-9a-z]*)/;
|
|
20
|
+
var SUBDETERMINATE_REGEX = /([0-9]+)([a-z]*)/;
|
|
21
|
+
|
|
22
|
+
function split(code) {
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} code - Priority dispatch code (eg: 32B).
|
|
25
|
+
* https://wiki.radioreference.com/index.php/Priority_Dispatch_Codes
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
var check = code.match(PRIORITY_DISPATCH_REGEX);
|
|
29
|
+
|
|
30
|
+
if (!check) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var _check = _slicedToArray(check, 4),
|
|
35
|
+
protocol = _check[1],
|
|
36
|
+
determinate = _check[2],
|
|
37
|
+
subDeterminate = _check[3];
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
protocol: protocol,
|
|
41
|
+
determinate: determinate,
|
|
42
|
+
subDeterminate: subDeterminate
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getProtocolDescription(protocol) {
|
|
47
|
+
if (protocol) {
|
|
48
|
+
return _lodash2.default.get(_priorityDispatchCodes2.default, '[' + Number(protocol).toString() + ']description');
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getSubDeterminateDescription(protocol, determinate, subDeterminate) {
|
|
54
|
+
if (protocol && determinate && subDeterminate) {
|
|
55
|
+
var _subDeterminate$toStr = subDeterminate.toString().match(SUBDETERMINATE_REGEX),
|
|
56
|
+
_subDeterminate$toStr2 = _slicedToArray(_subDeterminate$toStr, 2),
|
|
57
|
+
noSuffix = _subDeterminate$toStr2[1];
|
|
58
|
+
|
|
59
|
+
return _lodash2.default.get(_priorityDispatchCodes2.default, '[' + Number(protocol).toString() + ']determinates[' + determinate + ']subdeterminants[' + Number(noSuffix).toString() + '.description]');
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.default = {
|
|
65
|
+
priorityDispatch: {
|
|
66
|
+
split: split,
|
|
67
|
+
getProtocolDescription: getProtocolDescription,
|
|
68
|
+
getSubDeterminateDescription: getSubDeterminateDescription
|
|
69
|
+
}
|
|
70
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.helpers = exports.VehicleTelemetryNormalizer = exports.BaseNormalizer = undefined;
|
|
7
|
+
|
|
8
|
+
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
9
|
+
|
|
10
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
11
|
+
|
|
12
|
+
exports.transformDate = transformDate;
|
|
13
|
+
|
|
14
|
+
var _ngeohash = require('ngeohash');
|
|
15
|
+
|
|
16
|
+
var _ngeohash2 = _interopRequireDefault(_ngeohash);
|
|
17
|
+
|
|
18
|
+
var _momentTimezone = require('moment-timezone');
|
|
19
|
+
|
|
20
|
+
var _momentTimezone2 = _interopRequireDefault(_momentTimezone);
|
|
21
|
+
|
|
22
|
+
var _proj = require('proj4');
|
|
23
|
+
|
|
24
|
+
var _proj2 = _interopRequireDefault(_proj);
|
|
25
|
+
|
|
26
|
+
var _lodash = require('lodash');
|
|
27
|
+
|
|
28
|
+
var _lodash2 = _interopRequireDefault(_lodash);
|
|
29
|
+
|
|
30
|
+
var _jsonschema = require('jsonschema');
|
|
31
|
+
|
|
32
|
+
var _shiftly = require('@statengine/shiftly');
|
|
33
|
+
|
|
34
|
+
var _schemas = require('@statengine/schemas');
|
|
35
|
+
|
|
36
|
+
var _fs = require('fs');
|
|
37
|
+
|
|
38
|
+
var _fs2 = _interopRequireDefault(_fs);
|
|
39
|
+
|
|
40
|
+
var _xml2js = require('xml2js');
|
|
41
|
+
|
|
42
|
+
var _xml2js2 = _interopRequireDefault(_xml2js);
|
|
43
|
+
|
|
44
|
+
var _bluebird = require('bluebird');
|
|
45
|
+
|
|
46
|
+
var _bluebird2 = _interopRequireDefault(_bluebird);
|
|
47
|
+
|
|
48
|
+
var _helpers = require('./helpers');
|
|
49
|
+
|
|
50
|
+
var _helpers2 = _interopRequireDefault(_helpers);
|
|
51
|
+
|
|
52
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
53
|
+
|
|
54
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
55
|
+
|
|
56
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
57
|
+
|
|
58
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
59
|
+
|
|
60
|
+
function transformDate(dateString, timeZone, format) {
|
|
61
|
+
return _momentTimezone2.default.tz(dateString, format, timeZone);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var BaseNormalizer = exports.BaseNormalizer = function () {
|
|
65
|
+
function BaseNormalizer() {
|
|
66
|
+
_classCallCheck(this, BaseNormalizer);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_createClass(BaseNormalizer, [{
|
|
70
|
+
key: 'transformCoordinates',
|
|
71
|
+
value: function transformCoordinates(x, y) {
|
|
72
|
+
var toProjection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'EPSG:4326';
|
|
73
|
+
|
|
74
|
+
return (0, _proj2.default)((0, _proj2.default)(this.projection), (0, _proj2.default)(toProjection), [x, y]);
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
key: 'parseDate',
|
|
78
|
+
value: function parseDate(incomingDate) {
|
|
79
|
+
// Assume dates are already in ISO-8601, just convert them into to the department's TZ.
|
|
80
|
+
return (0, _momentTimezone2.default)(incomingDate).tz(this.timeZone);
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: 'normalize',
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
// eslint-disable-next-line class-methods-use-this
|
|
87
|
+
value: function normalize() {
|
|
88
|
+
throw new Error('Not implemented.');
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: 'validate',
|
|
92
|
+
value: function validate() {
|
|
93
|
+
return (0, _jsonschema.validate)(this.normalize(), this.constructor.schema);
|
|
94
|
+
}
|
|
95
|
+
}], [{
|
|
96
|
+
key: 'latLongToGeohash',
|
|
97
|
+
value: function latLongToGeohash(x, y) {
|
|
98
|
+
var precision = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 12;
|
|
99
|
+
|
|
100
|
+
if (_lodash2.default.isNil(x) || _lodash2.default.isNil(y)) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return _ngeohash2.default.encode(y, x, precision);
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
key: 'schema',
|
|
107
|
+
|
|
108
|
+
// eslint-disable-next-line class-methods-use-this
|
|
109
|
+
get: function get() {
|
|
110
|
+
throw new Error('Not implemented.');
|
|
111
|
+
}
|
|
112
|
+
}]);
|
|
113
|
+
|
|
114
|
+
return BaseNormalizer;
|
|
115
|
+
}();
|
|
116
|
+
|
|
117
|
+
var IncidentNormalizer = function (_BaseNormalizer) {
|
|
118
|
+
_inherits(IncidentNormalizer, _BaseNormalizer);
|
|
119
|
+
|
|
120
|
+
function IncidentNormalizer(payload) {
|
|
121
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
122
|
+
_ref$timeZone = _ref.timeZone,
|
|
123
|
+
timeZone = _ref$timeZone === undefined ? 'US/Eastern' : _ref$timeZone,
|
|
124
|
+
_ref$projection = _ref.projection,
|
|
125
|
+
projection = _ref$projection === undefined ? 'EPSG:4326' : _ref$projection,
|
|
126
|
+
_ref$fdId = _ref.fdId,
|
|
127
|
+
fdId = _ref$fdId === undefined ? null : _ref$fdId,
|
|
128
|
+
_ref$firecaresId = _ref.firecaresId,
|
|
129
|
+
firecaresId = _ref$firecaresId === undefined ? null : _ref$firecaresId,
|
|
130
|
+
_ref$name = _ref.name,
|
|
131
|
+
name = _ref$name === undefined ? null : _ref$name,
|
|
132
|
+
_ref$state = _ref.state,
|
|
133
|
+
state = _ref$state === undefined ? null : _ref$state,
|
|
134
|
+
_ref$shiftConfig = _ref.shiftConfig,
|
|
135
|
+
shiftConfig = _ref$shiftConfig === undefined ? {} : _ref$shiftConfig;
|
|
136
|
+
|
|
137
|
+
_classCallCheck(this, IncidentNormalizer);
|
|
138
|
+
|
|
139
|
+
var _this = _possibleConstructorReturn(this, (IncidentNormalizer.__proto__ || Object.getPrototypeOf(IncidentNormalizer)).call(this));
|
|
140
|
+
|
|
141
|
+
_this.payload = payload;
|
|
142
|
+
_this.timeZone = timeZone;
|
|
143
|
+
_this.projection = projection;
|
|
144
|
+
_this.fdId = fdId;
|
|
145
|
+
_this.firecaresId = firecaresId;
|
|
146
|
+
_this.name = name;
|
|
147
|
+
_this.state = state;
|
|
148
|
+
// First use firecaresId to see if shift configuration exists in shiftly
|
|
149
|
+
var shiftlyConfig = IncidentNormalizer.lookupShiftlyConfig(_this.firecaresId);
|
|
150
|
+
if (shiftlyConfig != null) {
|
|
151
|
+
_this.shiftConfig = shiftlyConfig;
|
|
152
|
+
} else {
|
|
153
|
+
_this.shiftConfig = new _shiftly.ShiftConfiguration(shiftConfig);
|
|
154
|
+
}
|
|
155
|
+
return _this;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// eslint-disable-next-line class-methods-use-this
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
_createClass(IncidentNormalizer, [{
|
|
162
|
+
key: 'normalize',
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
// eslint-disable-next-line class-methods-use-this
|
|
166
|
+
value: function normalize() {
|
|
167
|
+
return _lodash2.default.omitBy({
|
|
168
|
+
address: this.normalizeAddress(),
|
|
169
|
+
description: this.normalizeDescription(),
|
|
170
|
+
apparatus: this.normalizeApparatus(),
|
|
171
|
+
fire_department: this.normalizeFireDepartment(),
|
|
172
|
+
version: this.constructor.schema.version
|
|
173
|
+
}, _lodash2.default.isNil);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// eslint-disable-next-line class-methods-use-this
|
|
177
|
+
|
|
178
|
+
}, {
|
|
179
|
+
key: 'normalizeAddress',
|
|
180
|
+
value: function normalizeAddress() {
|
|
181
|
+
throw new Error('Not implemented.');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// eslint-disable-next-line class-methods-use-this
|
|
185
|
+
|
|
186
|
+
}, {
|
|
187
|
+
key: 'normalizeDescription',
|
|
188
|
+
value: function normalizeDescription() {
|
|
189
|
+
throw new Error('Not implemented.');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// eslint-disable-next-line class-methods-use-this
|
|
193
|
+
|
|
194
|
+
}, {
|
|
195
|
+
key: 'normalizeApparatus',
|
|
196
|
+
value: function normalizeApparatus() {
|
|
197
|
+
throw new Error('Not implemented.');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// eslint-disable-next-line class-methods-use-this
|
|
201
|
+
|
|
202
|
+
}, {
|
|
203
|
+
key: 'combineEntries',
|
|
204
|
+
value: function combineEntries() {
|
|
205
|
+
throw new Error('Not implemented.');
|
|
206
|
+
}
|
|
207
|
+
}, {
|
|
208
|
+
key: 'calculateShift',
|
|
209
|
+
value: function calculateShift(date) {
|
|
210
|
+
return this.shiftConfig.calculateShift(date);
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
key: 'normalizeFireDepartment',
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
// eslint-disable-next-line class-methods-use-this
|
|
217
|
+
value: function normalizeFireDepartment() {
|
|
218
|
+
return {
|
|
219
|
+
fd_id: this.fdId,
|
|
220
|
+
firecares_id: this.firecaresId,
|
|
221
|
+
name: this.name,
|
|
222
|
+
state: this.state,
|
|
223
|
+
timezone: this.timeZone
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}], [{
|
|
227
|
+
key: 'calculateDuration',
|
|
228
|
+
value: function calculateDuration(startTime, endTime) {
|
|
229
|
+
return _momentTimezone2.default.duration(endTime.diff(startTime)).asSeconds();
|
|
230
|
+
}
|
|
231
|
+
}, {
|
|
232
|
+
key: 'calculateUnitStatusExtendedData',
|
|
233
|
+
value: function calculateUnitStatusExtendedData(unitStatus) {
|
|
234
|
+
var times = {};
|
|
235
|
+
|
|
236
|
+
var arr = _lodash2.default.values(unitStatus);
|
|
237
|
+
|
|
238
|
+
var clearedProperties = [];
|
|
239
|
+
|
|
240
|
+
_lodash2.default.map(['available', 'in_quarters', 'available_radio', 'available_mobile', 'cleared'], function (key) {
|
|
241
|
+
return clearedProperties.push(_lodash2.default.get(unitStatus, '' + key));
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
clearedProperties = _lodash2.default.filter(clearedProperties, function (prop) {
|
|
245
|
+
return !_lodash2.default.isNil(prop);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
var cleared = void 0;
|
|
249
|
+
if (clearedProperties.length > 0) {
|
|
250
|
+
cleared = _lodash2.default.minBy(clearedProperties, function (o) {
|
|
251
|
+
return (0, _momentTimezone2.default)(o.timestamp).valueOf();
|
|
252
|
+
});
|
|
253
|
+
} else {
|
|
254
|
+
cleared = _lodash2.default.maxBy(arr, function (o) {
|
|
255
|
+
return (0, _momentTimezone2.default)(o.timestamp).valueOf();
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
var scene_left = void 0;
|
|
260
|
+
if (unitStatus.transport_started) {
|
|
261
|
+
scene_left = unitStatus.transport_started;
|
|
262
|
+
} else {
|
|
263
|
+
scene_left = cleared;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
var scene_arrived = void 0;
|
|
267
|
+
if (unitStatus.staging) {
|
|
268
|
+
scene_arrived = unitStatus.staging;
|
|
269
|
+
} else {
|
|
270
|
+
scene_arrived = unitStatus.arrived;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
var requirements = {
|
|
274
|
+
turnout_duration: [unitStatus.enroute, unitStatus.dispatched],
|
|
275
|
+
travel_duration: [scene_arrived, unitStatus.enroute],
|
|
276
|
+
staging_duration: [unitStatus.arrived, unitStatus.staging],
|
|
277
|
+
response_duration: [scene_arrived, unitStatus.dispatched],
|
|
278
|
+
on_scene_duration: [scene_left, scene_arrived],
|
|
279
|
+
event_duration: [cleared, unitStatus.dispatched],
|
|
280
|
+
on_scene_to_patient_contact: [unitStatus.patient_contact, scene_arrived],
|
|
281
|
+
on_scene_to_transport_arrived_duration: [unitStatus.transport_arrived, scene_arrived],
|
|
282
|
+
patient_contact_to_transport_arrived_duration: [unitStatus.transport_arrived, unitStatus.patient_contact],
|
|
283
|
+
transport_duration: [unitStatus.transport_arrived, unitStatus.transport_started],
|
|
284
|
+
at_hospital_duration: [cleared, unitStatus.transport_arrived]
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
Object.entries(requirements).forEach(function (_ref2) {
|
|
288
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
289
|
+
key = _ref3[0],
|
|
290
|
+
value = _ref3[1];
|
|
291
|
+
|
|
292
|
+
if (!_lodash2.default.every(value)) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
times[key] = IncidentNormalizer.calculateDuration((0, _momentTimezone2.default)(value[1].timestamp), (0, _momentTimezone2.default)(value[0].timestamp));
|
|
296
|
+
});
|
|
297
|
+
return times;
|
|
298
|
+
}
|
|
299
|
+
}, {
|
|
300
|
+
key: 'calculateDescriptionExtendedData',
|
|
301
|
+
value: function calculateDescriptionExtendedData(description) {
|
|
302
|
+
var times = {};
|
|
303
|
+
var requirements = {
|
|
304
|
+
psap_answer_time_to_event_creation: [description.event_opened, description.psap_answer_time],
|
|
305
|
+
psap_answer_time_to_first_dispatch: [description.first_unit_dispatched, description.psap_answer_time],
|
|
306
|
+
psap_answer_time_to_first_arrival: [description.first_unit_arrived, description.psap_answer_time],
|
|
307
|
+
event_duration: [description.event_closed, description.event_opened],
|
|
308
|
+
response_duration: [description.first_unit_arrived, description.first_unit_dispatched]
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
Object.entries(requirements).forEach(function (_ref4) {
|
|
312
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
313
|
+
key = _ref5[0],
|
|
314
|
+
value = _ref5[1];
|
|
315
|
+
|
|
316
|
+
if (!_lodash2.default.every(value)) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
times[key] = IncidentNormalizer.calculateDuration((0, _momentTimezone2.default)(value[1]), (0, _momentTimezone2.default)(value[0]));
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
return times;
|
|
324
|
+
}
|
|
325
|
+
}, {
|
|
326
|
+
key: 'toJSON',
|
|
327
|
+
value: function toJSON(string) {
|
|
328
|
+
return new _bluebird2.default(function (resolve, reject) {
|
|
329
|
+
try {
|
|
330
|
+
var js = JSON.parse(string);
|
|
331
|
+
resolve(js || string);
|
|
332
|
+
} catch (e) {
|
|
333
|
+
try {
|
|
334
|
+
var parser = new _xml2js2.default.Parser({ explicitArray: false });
|
|
335
|
+
parser.parseString(string, function (err, result) {
|
|
336
|
+
return resolve(result || string);
|
|
337
|
+
});
|
|
338
|
+
} catch (err) {
|
|
339
|
+
reject(err);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}, {
|
|
345
|
+
key: 'fromBytes',
|
|
346
|
+
value: function fromBytes(buffer) {
|
|
347
|
+
var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8';
|
|
348
|
+
|
|
349
|
+
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
350
|
+
args[_key - 2] = arguments[_key];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return this.fromString.apply(this, [buffer.toString(encoding)].concat(args));
|
|
354
|
+
}
|
|
355
|
+
}, {
|
|
356
|
+
key: 'fromString',
|
|
357
|
+
value: function fromString(string) {
|
|
358
|
+
var _this2 = this;
|
|
359
|
+
|
|
360
|
+
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
361
|
+
args[_key2 - 1] = arguments[_key2];
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// eslint-disable-next-line consistent-return
|
|
365
|
+
return new _bluebird2.default(function (resolve, reject) {
|
|
366
|
+
try {
|
|
367
|
+
return _this2.toJSON(string).then(function (res) {
|
|
368
|
+
return resolve(new (Function.prototype.bind.apply(_this2, [null].concat([res], args)))());
|
|
369
|
+
});
|
|
370
|
+
} catch (e) {
|
|
371
|
+
reject(e);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}, {
|
|
376
|
+
key: 'fromStrings',
|
|
377
|
+
value: function fromStrings(strings) {
|
|
378
|
+
var _this3 = this;
|
|
379
|
+
|
|
380
|
+
for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
381
|
+
args[_key3 - 1] = arguments[_key3];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// eslint-disable-next-line consistent-return
|
|
385
|
+
return _bluebird2.default.map(strings, this.toJSON).then(function (jsons) {
|
|
386
|
+
return new (Function.prototype.bind.apply(_this3, [null].concat([_this3.combineEntries(jsons)], args)))();
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}, {
|
|
390
|
+
key: 'fromFile',
|
|
391
|
+
value: function fromFile(file) {
|
|
392
|
+
for (var _len4 = arguments.length, args = Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
|
|
393
|
+
args[_key4 - 2] = arguments[_key4];
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
var _this4 = this;
|
|
397
|
+
|
|
398
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { encoding: 'utf-8', flag: 'r' };
|
|
399
|
+
|
|
400
|
+
return new _bluebird2.default(function (resolve, reject) {
|
|
401
|
+
_fs2.default.readFile(file, options, function (err, data) {
|
|
402
|
+
if (err) {
|
|
403
|
+
reject(err);
|
|
404
|
+
}
|
|
405
|
+
return _this4.fromString.apply(_this4, [data].concat(args)).then(resolve);
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}, {
|
|
410
|
+
key: 'fromFiles',
|
|
411
|
+
value: function fromFiles(files) {
|
|
412
|
+
var _this5 = this;
|
|
413
|
+
|
|
414
|
+
for (var _len5 = arguments.length, args = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
|
|
415
|
+
args[_key5 - 1] = arguments[_key5];
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// eslint-disable-next-line
|
|
419
|
+
return _bluebird2.default.map(files, function (file) {
|
|
420
|
+
return new _bluebird2.default(function (resolve, reject) {
|
|
421
|
+
_fs2.default.readFile(file, 'utf-8', function (err, data) {
|
|
422
|
+
if (err) {
|
|
423
|
+
reject(err);
|
|
424
|
+
}
|
|
425
|
+
resolve(data);
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
}).then(function (jsons) {
|
|
429
|
+
return _this5.fromStrings.apply(_this5, [jsons].concat(args));
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}, {
|
|
433
|
+
key: 'lookupShiftlyConfig',
|
|
434
|
+
value: function lookupShiftlyConfig(firecaresId) {
|
|
435
|
+
var shiftlyFactoryMethod = _shiftly.FirecaresLookup[firecaresId];
|
|
436
|
+
var shiftlyConfig = null;
|
|
437
|
+
if (shiftlyFactoryMethod != null) {
|
|
438
|
+
shiftlyConfig = shiftlyFactoryMethod();
|
|
439
|
+
}
|
|
440
|
+
return shiftlyConfig;
|
|
441
|
+
}
|
|
442
|
+
}, {
|
|
443
|
+
key: 'schema',
|
|
444
|
+
get: function get() {
|
|
445
|
+
return _schemas.schemas.fire;
|
|
446
|
+
}
|
|
447
|
+
}]);
|
|
448
|
+
|
|
449
|
+
return IncidentNormalizer;
|
|
450
|
+
}(BaseNormalizer);
|
|
451
|
+
|
|
452
|
+
exports.default = IncidentNormalizer;
|
|
453
|
+
|
|
454
|
+
var VehicleTelemetryNormalizer = exports.VehicleTelemetryNormalizer = function (_BaseNormalizer2) {
|
|
455
|
+
_inherits(VehicleTelemetryNormalizer, _BaseNormalizer2);
|
|
456
|
+
|
|
457
|
+
function VehicleTelemetryNormalizer(payload) {
|
|
458
|
+
var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
459
|
+
_ref6$timeZone = _ref6.timeZone,
|
|
460
|
+
timeZone = _ref6$timeZone === undefined ? 'US/Eastern' : _ref6$timeZone,
|
|
461
|
+
_ref6$projection = _ref6.projection,
|
|
462
|
+
projection = _ref6$projection === undefined ? 'EPSG:4326' : _ref6$projection,
|
|
463
|
+
_ref6$fdId = _ref6.fdId,
|
|
464
|
+
fdId = _ref6$fdId === undefined ? null : _ref6$fdId,
|
|
465
|
+
_ref6$firecaresId = _ref6.firecaresId,
|
|
466
|
+
firecaresId = _ref6$firecaresId === undefined ? null : _ref6$firecaresId,
|
|
467
|
+
_ref6$name = _ref6.name,
|
|
468
|
+
name = _ref6$name === undefined ? null : _ref6$name,
|
|
469
|
+
_ref6$state = _ref6.state,
|
|
470
|
+
state = _ref6$state === undefined ? null : _ref6$state;
|
|
471
|
+
|
|
472
|
+
_classCallCheck(this, VehicleTelemetryNormalizer);
|
|
473
|
+
|
|
474
|
+
var _this6 = _possibleConstructorReturn(this, (VehicleTelemetryNormalizer.__proto__ || Object.getPrototypeOf(VehicleTelemetryNormalizer)).call(this));
|
|
475
|
+
|
|
476
|
+
_this6.payload = payload;
|
|
477
|
+
_this6.timeZone = timeZone;
|
|
478
|
+
_this6.projection = projection;
|
|
479
|
+
_this6.fdId = fdId;
|
|
480
|
+
_this6.firecaresId = firecaresId;
|
|
481
|
+
_this6.name = name;
|
|
482
|
+
_this6.state = state;
|
|
483
|
+
return _this6;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// eslint-disable-next-line class-methods-use-this
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
_createClass(VehicleTelemetryNormalizer, [{
|
|
490
|
+
key: 'normalize',
|
|
491
|
+
value: function normalize() {
|
|
492
|
+
var incident = this.normalizeIncident();
|
|
493
|
+
var response = {
|
|
494
|
+
version: this.constructor.schema.version,
|
|
495
|
+
fire_department: this.normalizeFireDepartment(),
|
|
496
|
+
apparatus: this.normalizeApparatus(),
|
|
497
|
+
telemetry: this.normalizeTelemetry()
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
if (!_lodash2.default.isEmpty(incident.incident_number)) {
|
|
501
|
+
response.incident = incident;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return response;
|
|
505
|
+
}
|
|
506
|
+
}, {
|
|
507
|
+
key: 'normalizeFireDepartment',
|
|
508
|
+
value: function normalizeFireDepartment() {
|
|
509
|
+
return {
|
|
510
|
+
fd_id: this.fdId,
|
|
511
|
+
firecares_id: this.firecaresId,
|
|
512
|
+
name: this.name,
|
|
513
|
+
state: this.state,
|
|
514
|
+
timezone: this.timeZone
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// eslint-disable-next-line class-methods-use-this
|
|
519
|
+
|
|
520
|
+
}, {
|
|
521
|
+
key: 'normalizeApparatus',
|
|
522
|
+
value: function normalizeApparatus() {
|
|
523
|
+
throw new Error('Not implemented.');
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// eslint-disable-next-line class-methods-use-this
|
|
527
|
+
|
|
528
|
+
}, {
|
|
529
|
+
key: 'normalizeIncident',
|
|
530
|
+
value: function normalizeIncident() {
|
|
531
|
+
throw new Error('Not implemented.');
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// eslint-disable-next-line class-methods-use-this
|
|
535
|
+
|
|
536
|
+
}, {
|
|
537
|
+
key: 'normalizeTelemetry',
|
|
538
|
+
value: function normalizeTelemetry() {
|
|
539
|
+
throw new Error('Not implemented.');
|
|
540
|
+
}
|
|
541
|
+
}], [{
|
|
542
|
+
key: 'schema',
|
|
543
|
+
get: function get() {
|
|
544
|
+
return _schemas.schemas.vehicleTelemetry;
|
|
545
|
+
}
|
|
546
|
+
}]);
|
|
547
|
+
|
|
548
|
+
return VehicleTelemetryNormalizer;
|
|
549
|
+
}(BaseNormalizer);
|
|
550
|
+
|
|
551
|
+
exports.helpers = _helpers2.default;
|