Created
October 9, 2019 10:44
-
-
Save jerryjj/3b93e6c2c4c8adb316e8b4711b062b0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A transforms incoming device signal event to BQ schema event | |
* @param {string} inJson | |
* @return {string} outJson | |
*/ | |
function transformDeviceSignalEvent(inJson) { | |
var original = JSON.parse(inJson) | |
var now = new Date() | |
var locationParts = original.l.split(',') | |
var transformed = { | |
timestamp: new Date(original.t * 1000), | |
processing_timestamp: now, | |
event_name: original.e, | |
device_id: original.d, | |
ride_id: original.i, | |
battery_percentage: original.b, | |
latitude: parseFloat(locationParts[0]) || 0.0, | |
longitude: parseFloat(locationParts[1]) || 0.0, | |
power_on_status: Boolean(original.p) | |
} | |
return JSON.stringify(transformed) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment