Created
November 24, 2014 02:58
-
-
Save zekesonxx/efcf7d184bf8a9bef1b2 to your computer and use it in GitHub Desktop.
First attempt at using spider to create a tool to parse a log file I made whilst on vacation
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
/** | |
* Date|Long,lat|speed? | |
* Example lines (taken from the top of the actual file): | |
* 1407084781|42.94662477,-74.36839708|31.25 | |
* 1407084881|42.93916548,-74.40412034|32.25 | |
* 1407084927|42.9309027,-74.4175025|33.25 | |
* 1407085113|42.89578358,-74.47134403|31.0 | |
*/ | |
use :node, __dirname, Date, JSON, parseInt, parseFloat; | |
var fs = require('fs'); | |
var path = require('path'); | |
var moment = require('moment'); | |
var rawlog = fs.readFileSync(path.join(__dirname, 'loc.log'), 'utf8'); | |
var points = []; | |
rawlog.split('\n').forEach((line) -> { | |
var vars = line.split('|'); | |
if !vars[1]? { return; } | |
points.push({ | |
timestamp: parseInt(vars[0]), | |
lat: parseFloat(vars[1].split(',')[0]), | |
long: parseFloat(vars[1].split(',')[1]), | |
speed: parseFloat(vars[2]) | |
}); | |
}); | |
var i = 50; | |
var extrapoints = [], features = []; | |
points.map((point) -> { | |
i = i + 1; | |
extrapoints.push([point.long, point.lat]); | |
if (i < 15) { | |
return; | |
} else { | |
i = 0; | |
} | |
return { | |
"type": "Feature", | |
"geometry": { | |
"type": "Point", | |
"coordinates": [point.long, point.lat] | |
}, | |
"properties": { | |
"date": moment(point.timestamp*1000).format("dddd, MMMM Do YYYY, h:mm:ss a") | |
} | |
}; | |
}).concat([{ | |
"type": "Feature", | |
"properties": {}, | |
"geometry": { | |
"type": "LineString", | |
"coordinates": extrapoints | |
} | |
}]).forEach((k) -> { | |
if k? { | |
features.push(k); | |
} | |
}); | |
console.log(JSON.stringify({ | |
"type": "FeatureCollection", | |
"features": features, | |
}, null, ' ')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment