Created
October 13, 2011 11:49
-
-
Save mad/1284045 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
var fs = require('fs'); | |
var path = require('path'); | |
var cdr_files = process.argv[2]; | |
var bs_station_file = process.argv[3]; | |
if (cdr_files === undefined || bs_station_file === undefined) { | |
console.log("input file expected or bs station file expected"); | |
exit; | |
} | |
var cdr_json_file ="output.json"; | |
fs.open(cdr_json_file, "w+", function(err, fd) { | |
if(err) throw err; | |
var laccid = JSON.parse(fs.readFileSync(bs_station_file, 'ascii')); | |
var cdr_json = []; | |
cdr_files.split(' ').forEach( | |
function(cdr_file) { | |
var cdr = fs.readFileSync(cdr_file, 'ascii'); | |
cdr.split('\n').forEach( | |
function(line) { | |
var fileds = line.trim().split(/[ ]+/g); | |
// XXX: filter bad cdr (without number or imsi) | |
if (fileds.length != 8) | |
return; | |
var number = fileds[1]; | |
var datetime = new Date(fileds[2] + " " + fileds[3]).getTime(); | |
var duration = fileds[4]; | |
var imsi = fileds[5]; | |
var lac = fileds[6]; | |
var cid = fileds[7]; | |
var location = undefined; | |
if (laccid[lac] && laccid[lac][cid] !== undefined) | |
location = [ laccid[lac][cid][0].replace(',', '.'), | |
laccid[lac][cid][1].replace(',', '.') ]; | |
cdr_json.push([number, datetime, duration, imsi, lac, cid, location]); | |
}); | |
}); | |
fs.write(fd, JSON.stringify(cdr_json, null, '\t')); | |
fs.close(fd); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment