@autofleet/node-common 1.2.1 → 1.2.3
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/package.json +1 -1
- package/router/index.js +1 -0
- package/settings/map.js +14 -0
- package/events/example.js +0 -20
- package/events/index.js +0 -78
package/package.json
CHANGED
package/router/index.js
CHANGED
package/settings/map.js
CHANGED
|
@@ -86,6 +86,13 @@ module.exports = {
|
|
|
86
86
|
defaultValue: 15000,
|
|
87
87
|
context: 'matching',
|
|
88
88
|
},
|
|
89
|
+
MATCHING_MINIMUM_PAID_RATIO: {
|
|
90
|
+
name: 'Matching min paid/unpaid air distance',
|
|
91
|
+
description: 'The ratio between paid to unpaid air distance - pre filter',
|
|
92
|
+
type: 'number',
|
|
93
|
+
defaultValue: 0.1,
|
|
94
|
+
context: 'matching',
|
|
95
|
+
},
|
|
89
96
|
ETA_MAX: {
|
|
90
97
|
name: 'Maximum time to pickup',
|
|
91
98
|
description: 'The maximum allowed time to pickup in matching',
|
|
@@ -360,4 +367,11 @@ module.exports = {
|
|
|
360
367
|
defaultValue: '["00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00"]',
|
|
361
368
|
context: 'demand prediction',
|
|
362
369
|
},
|
|
370
|
+
UPDATE_STOP_POINTS_DISTANCE_THRESHOLD: {
|
|
371
|
+
name: 'Maximum distance between original and updated stop points of a ride',
|
|
372
|
+
description: 'Threshold in kilimeters for limiting the distance between the original ride stop points and the updated ones',
|
|
373
|
+
type: 'number',
|
|
374
|
+
defaultValue: 500,
|
|
375
|
+
context: 'matching',
|
|
376
|
+
},
|
|
363
377
|
};
|
package/events/example.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const event = require('./index');
|
|
2
|
-
|
|
3
|
-
const vehicleEvent = {
|
|
4
|
-
event_timestamp: '2018-08-10 11:05:11',
|
|
5
|
-
vehicle_id: '1a',
|
|
6
|
-
fleet_id: '2b',
|
|
7
|
-
shift_id: '3c',
|
|
8
|
-
action: 'Changed State',
|
|
9
|
-
original_state: 'Activating',
|
|
10
|
-
new_state: 'Idle',
|
|
11
|
-
lat: 5.7,
|
|
12
|
-
lng: 8.9,
|
|
13
|
-
city_name: 'Tel Aviv',
|
|
14
|
-
region_name: 'Hamerkaz',
|
|
15
|
-
country_name: 'Israel',
|
|
16
|
-
duration: 1420,
|
|
17
|
-
additional_params: '{}',
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
event.publish('vehicle', vehicleEvent, true);
|
package/events/index.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
const PubSub = require('@google-cloud/pubsub');
|
|
2
|
-
const logger = require('../logger/index')();
|
|
3
|
-
|
|
4
|
-
let Client;
|
|
5
|
-
let Publisher;
|
|
6
|
-
|
|
7
|
-
const getPubsubPublisher = async () => {
|
|
8
|
-
if (Publisher) {
|
|
9
|
-
return Publisher;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const envv = process.env.NODE_ENV || 'development';
|
|
13
|
-
const projectId = process.env.PROJECT;
|
|
14
|
-
const topic = process.env.TOPIC;
|
|
15
|
-
|
|
16
|
-
if (!topic || !projectId) {
|
|
17
|
-
return {
|
|
18
|
-
debug: 'Missing project/topic',
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if ((envv === 'development' || envv === 'test')) {
|
|
23
|
-
return {
|
|
24
|
-
debug: 'Not publishing in dev/test',
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
Client = new PubSub({ projectId });
|
|
29
|
-
Publisher = Client.topic(topic).publisher();
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
client: Client,
|
|
33
|
-
publisher: Publisher,
|
|
34
|
-
topic,
|
|
35
|
-
envv,
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// EventType - 'vehicle'/'stop_point' etc.
|
|
40
|
-
const publish = (eventType, eventObj) => {
|
|
41
|
-
const {
|
|
42
|
-
debug,
|
|
43
|
-
publisher,
|
|
44
|
-
envv,
|
|
45
|
-
} = getPubsubPublisher();
|
|
46
|
-
|
|
47
|
-
if (debug) {
|
|
48
|
-
return debug;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const msg = {
|
|
52
|
-
type: eventType,
|
|
53
|
-
event: eventObj,
|
|
54
|
-
env: envv,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const data = JSON.stringify(msg);
|
|
58
|
-
const dataBuffer = Buffer.from(data);
|
|
59
|
-
|
|
60
|
-
return publisher
|
|
61
|
-
.publish(dataBuffer)
|
|
62
|
-
.then((messageId) => {
|
|
63
|
-
logger.info(`Message ${messageId} published to google pubsub`);
|
|
64
|
-
})
|
|
65
|
-
.catch((err) => {
|
|
66
|
-
logger.error('Error when try to publish to pubsub:', { error: err ? err.message : err });
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const publishRideAnalytics = (eventObject) => {
|
|
71
|
-
try {
|
|
72
|
-
publish('rideAnalytics', eventObject);
|
|
73
|
-
} catch (err) {
|
|
74
|
-
logger.error('Error when try to send ride analytics:', { error: err ? err.message : err });
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
module.exports = { publish, publishRideAnalytics };
|